Skip to content

fix: deny retained stream output and raw email history - #1294

Merged
sidneyswift merged 3 commits into
mainfrom
codex/retained-stream-denial-2207
Nov 19, 2026
Merged

sidneyswift merged 3 commits into
mainfrom
codex/retained-stream-denial-2207

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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 #1294 (comment).

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.

@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api Ready Ready Preview Nov 19, 2026 7:23am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Pre-merge checks: Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Solid & Clean Code Warning The PR still contains the stream-guard code that the prior run flagged. Its cumulative diff against main (d267626 → 67092e7) adds 19 production lines to app/lib/workflows/runAgentStep.ts. The late… Before merge: - Extract the duplicated void Promise.resolve(result.finishReason).catch(() => {}); void Promise.resolve(result.response).catch(() => {}); pair into one named helper, for example silenceProviderPromises(result). Call it fr…
Full details: Solid & Clean Code

Explanation

The PR still contains the stream-guard code that the prior run flagged. Its cumulative diff against main (d267626 → 67092e7) adds 19 production lines to app/lib/workflows/runAgentStep.ts. The latest commit (67092e7) changes only the email adapter, its test, and the README, so the stream code is unchanged from the failing run. Verified findings: 1. DRY violation (introduced by this PR). The pair void Promise.resolve(result.finishReason).catch(() => {}); and void Promise.resolve(result.response).catch(() => {}); appears twice. The new refusal branch has it at lines 254–255. The existing user-stop branch has it at lines 272–273. The PR copies the block instead of extracting a helper. The custom check requires "Avoid copy-paste programming" and "Extract repeated patterns into abstractions." 2. SRP and function length (worsened). runAgentStep spans lines 114–293, about 180 lines. The PR adds a privacy-refusal capture (outputRefusal and the assertOutput closure) and a refusal-specific rethrow path inside it. The check says "Look for functions longer than 20 lines" and "Avoid … functions with multiple responsibilities." The PR adds responsibility to a function that already breaks that rule. 3. Implicit control flow. A mutable outer let outputRefusal is set inside a closure and read later in catch. The check favors "explicit over implicit behavior." The guard could be a named, separate function. The email change is clean. It adds three lines, reuses the existing assertNoRetainedFieldModelInput helper, and does not duplicate logic. It does not cause the failure. The prior run's required resolution was not applied. No helper was extracted for the duplicated Promise.resolve pair. The refusal guard was not moved to its own module. Because the prior failure is not addressed, this run cannot PASS. This verdict covers code-quality criteria only. It does not assess security behavior.

Resolution

Before merge: - Extract the duplicated void Promise.resolve(result.finishReason).catch(() => {}); void Promise.resolve(result.response).catch(() => {}); pair into one named helper, for example silenceProviderPromises(result). Call it from both the refusal branch and the user-stop branch. - Move the refusal guard (outputRefusal plus assertOutput) into a dedicated module with an explicit, named function. runAgentStep should only call that function. - Consider moving post-stream cleanup and error classification out of runAgentStep. This can be a follow-up if the security fix must land first. Record that follow-up explicitly.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T07:18:27.400538Z 37f7c6b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37f7c6b34b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@sidneyswift sidneyswift changed the title fix: deny retained structured output before client stream writes fix: deny retained stream output and raw email history Nov 19, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 3 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

View guided diff | Turn on auto-fix | Re-trigger cubic

@sidneyswift
sidneyswift merged commit 6db7e04 into main Nov 19, 2026
9 checks passed

This branch was successfully deployed

1 active deployment
Preview — 67092e7d Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant