Skip to content

fix(native-chat): stop multi-agent Codex chats from bloating the journal - #35226

Merged
AmethystLiang merged 1 commit into
mainfrom
AmethystLiang/bound-codex-running-command-output
Oct 28, 2026
Merged

AmethystLiang merged 1 commit into
mainfrom
AmethystLiang/bound-codex-running-command-output

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A Codex chat with sub-agents could save the same long command output to Orca's local history again and again. The history grew to gigabytes, and Orca froze on the next launch while it read all of it back. Now each output is saved far fewer times, and a command that is still running keeps only a short preview in that history.

What Changed

Two things compounded. Each one is fixed at its source:

  • Too many saves. Every event from any Codex thread forced a save of every other thread's in-progress output, skipping the normal save schedule. A forced save now covers only the event's own thread. Each stream's first save still happens before the event's row, so nothing is saved ahead of the text it follows.
  • Too big a save. Since fix(native-chat): save every chat reply and tool output whole; bound only the copy sent to clients #29982, a running Codex command saved its whole output on every update. The journal's contract, which ACP and Pi already follow, keeps a running tool call at a 16 KiB preview and saves it whole only when it finishes. The journal now applies that rule where item rows are built, so every provider gets it. Completed, failed and interrupted rows are saved whole, as before.

User-visible: while a Codex command is still running, its saved output is the 16 KiB preview. The full output is saved when the command finishes.

Not in this PR: journals that already grew from earlier versions are not cleaned up. A user with a large existing journal can still see a slow or frozen startup until a follow-up heals those rows.

Why

  • The running-preview rule is the journal's existing contract. Enforcing it in the two row builders covers every provider, and closing rows get whole output without any Codex-specific flags.
  • The forced save is narrowed, not removed. Removing it would let the event's own text be journaled ahead of its row, which breaks the "nothing journaled ahead of the text it follows" rule from fix(native-chat): reland large structured command results #17720.

Linked Issue

No issue. This regression came from #29982 (v1.4.234+).

Visual Proof

N/A — no visual change. The effect is on what the journal stores; the numbers are under Testing.

Testing

Replayed the incident's shape (an 8 MiB Codex command while another thread is active) through the real translator and row builder:

Version Command rows Written Translator time
main 354 1,370 MiB 1,043 ms
running-preview rule only 354 6.6 MiB 799 ms
thread-scoped flush only 51 77 MiB 76 ms
this PR 51 1.8 MiB 47 ms

Each half is needed: the preview rule shrinks each row, and the scoped flush cuts the number of rows. The 1 MiB of the 1.8 MiB is the completed row.

New automated tests (both fail on main):

  • journal-payload-bounds-retention.test.ts: running calls keep a 16 KiB preview on both row paths; completed and failed calls stay whole.
  • codex-structured-journal-translation.test.ts: another thread's streamed output keeps its own save cadence.

Gate: pnpm check:changed --maxWorkers=2: 19 of 20 checks pass. The unit-tests step ran 16,344 tests; 3 failed, all in src/main/runtime/tui-idle-name-only-real-pty.integration.test.ts. That file spawns real terminals through node-pty, and on this Mac posix_openpt fails (errno 6, Device not configured) because the pseudo-terminal pool is busy. The file does not touch journal or Codex translation code, but I have not run it on main to prove the failure is pre-existing.

The WSL test src/main/codex-cli/command-guest-path.test.ts passed in this run.

Not run manually in the app. Not run on Windows, Linux, or SSH.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered: no platform-specific code, but not tested on those platforms
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass: covered by check:changed above, see Gate

A long Codex command in a multi-agent chat could write gigabytes to the
agent-session journal and freeze Orca on the next launch while it replayed
them. One 16 MiB `rg` was saved 661 times in 163 s, 8.3 GB for one tool call.

Two things compounded:

- Every event from any Codex thread force-saved every other thread's
  in-flight stream, bypassing its x1.125 checkpoint cadence. The command's
  own thread wrote nothing else during that span; other sub-agents' events
  drove all 661 saves.
- Since #29982 a running Codex command saved its whole output on each
  revision, though the journal's contract (and ACP/Pi) keep a running call
  to a 16 KiB preview and save it whole only on the closing revision.

Forced flushes now re-save only the event's own thread. flushAll still
writes every other stream's first row first, so nothing is journaled ahead
of the text it follows. The journal enforces the running-preview contract
where item rows are built, so it holds for every provider; completed,
failed and interrupted rows stay whole.

Replaying the incident's shape (an 8 MiB command while another thread is
active) through the real translator and row builder: 354 command rows and
1,370 MiB before, 51 rows and 1.8 MiB after (1 MiB of it the completed
output), with translator time down from 1,043 ms to 47 ms.
@AmethystLiang

Copy link
Copy Markdown
Contributor Author

I'm trying to land it

@AmethystLiang
AmethystLiang marked this pull request as ready for review October 28, 2026 18:54
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3a84003d-dc36-478d-b45d-52e19f250d69
Commits

Reviewing files that changed from the base of the PR and between 117bbc4 and 917df03.

Files selected for processing: 8
  • src/main/codex/codex-structured-item-stream-contracts.ts
  • src/main/codex/codex-structured-item-streams.ts
  • src/main/codex/codex-structured-journal-translation.test.ts
  • src/main/codex/codex-structured-journal-translation.ts
  • src/main/native-chat/agent-session-journal/journal-lifecycle-mutation.ts
  • src/main/native-chat/agent-session-journal/journal-payload-bounds-retention.test.ts
  • src/main/native-chat/agent-session-journal/journal-payload-bounds.ts
  • src/main/native-chat/agent-session-journal/journal-row-builders.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

Stream flushes can now be scoped to a thread, while coalescer flushing remains global. Event handling passes the event’s thread ID when present. Journal item and lifecycle rows now bound output for running tool calls to a 16 KiB preview. Completed and failed calls retain full output.

Priority: Normal

Merge Risk: Minimal · up to 917df

No merge-blocking issue is established. Existing oversized journals are not cleaned up by this change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the affected area (native-chat) and the main problem (multi-agent Codex chats bloating the journal). It matches the changeset, which narrows forced journal saves to the event's own thr…
Description check Passed The description follows the template and fills every required section: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Ch…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the affected area (native-chat) and the main problem (multi-agent Codex chats bloating the journal). It matches the changeset, which narrows forced journal saves to the event's own thread and applies the 16 KiB running-tool-output preview when building item rows. The title is concise and specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description follows the template and fills every required section: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. It explains the mechanism of both fixes, the before/after effect, a measured replay table, and the new tests. Gaps remain. The Linked Issue section has no issue number, only a reference to PR #29982, and the template requires a linked issue (Fixes #) for outside contributors. The AI Disclosure section is empty. The lint, typecheck, test, and build checkbox is unchecked, and three integration tests failed locally without a main-branch comparison. The description is mostly complete, so the check passes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 8 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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

Comment @coderabbitai help to get the list of available commands.

@AmethystLiang
AmethystLiang merged commit 8eab52c into main Oct 28, 2026
73 of 74 checks passed
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