fix: deny retained stream output and raw email history

Merged
SI
3d ago
+245-6

Structured retained output had two disclosure paths: runAgentStep wrote marked tool-output parts before the workflow's returned-message check, and email history adaptation removed markers while preserving sibling private text before agent.generate.

The step now checks each UI stream part before acquiring its writer and checks accumulated onFinish output before capture. A refusal remains fatal across cancellation races, so withheld output cannot return as an ordinary aborted result for persistence. Existing poller/provider abort cleanup and workflow ownership of stream closure remain intact.

Email's getEmailRoomMessages now checks raw stored content before text-only adaptation. It denies the whole generation before agent.generate, preserving room query ordering and authenticated account/organization context. The existing inbound handler's generic error response is unchanged. Addresses https://github.com/recoupable/api/pull/1294#discussion_r4625513513.

Base main d26762603d2881875766e078f37561ff18424f9f includes merged #1293. Current head 67092e7da7e84da540cb814d9db9b11b357d5628, tree ddde012fac2bdc82424228c18e71f88f040a180b. Full delta against main: five files, 22 added production lines (19 stream guard +3 email adapter), tests and README. Ordinary composition merge4719d97c preserved reviewed37f7c6b3 tree; this successor adds only email adapter/test/README changes. Stream production and tests remain byte-identical to OAuth455-reviewed37f7c6b3; that evidence remains attributed to its original head.

Validation: email failing-first 2 failures/2 passes, then4 actual generateEmailResponse caller tests pass with real adapter and synthetic DB/agent seams. Cases cover part/metadata marker plus sibling text, whole-call static FatalError, zero agent.generate/footer room lookup, unchanged source data and room/account context, and ordinary text/HTML history behavior. Full lint and diff checks pass. No broad or stream-suite rerun. Prior stream qualification at37f7 remains 31 focused tests plus final8 stream tests and independent synthetic SDK/cancellation review. Whole-repository tsc previously failed on unrelated tests/dependencies, no changed-file diagnostics; not claimed green. Exact-head CI/independent email closure pending.

No real email sending, tool/provider/account/history reads, network, SQL, browser, spending or activation. Tests use synthetic seams only. No positive authority, inference from serialized/unmarked data, or retraction of independently emitted prose. Stream guard cannot prevent an operation that already produced its output. Both paths reuse the existing reserved-family recognizer and redacted nonretrying FatalError. Root owns final review, merge and release.