Repository navigation
fix(native-chat): stop multi-agent Codex chats from bloating the journal - #35226
Conversation
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.
|
I'm trying to land it |
|
No actionable comments were generated in the recent review.
|
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:
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
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:
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 insrc/main/runtime/tui-idle-name-only-real-pty.integration.test.ts. That file spawns real terminals through node-pty, and on this Macposix_openptfails (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.tspassed in this run.Not run manually in the app. Not run on Windows, Linux, or SSH.
Agent skill upstream boundary
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass: covered bycheck:changedabove, see Gate