fix(server): coalesce Codex child progress before ingestion - #6004
fix(server): coalesce Codex child progress before ingestion#6004cheruvian wants to merge 4 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
One convention finding: the new coalescer's public interface is re-declared locally in CodexAdapter.ts instead of being imported from its owning module. Everything else in the changed scope (namespace subpath imports, scoped make construction, callback-based emit rather than service injection, test-only service instance passing) follows the conventions.
Posted via Macroscope — Effect Service Conventions
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — The PR adds an always-on 250 ms coalescing and lifecycle mechanism to the production Codex event pipeline, changing progress timing, snapshot retention, ordering, and shutdown behavior before durable ingestion. It also introduces a line-level static-analysis suppression, so the combined runtime and review-policy impact warrants human review. You can add or adjust custom eligibility rules. Learn more. |
Coalesce Codex child item and token-usage notifications independently per session and child before provider runtime ingestion. Flush pending progress before terminal lifecycle events and cancel pending work when the runtime closes. Add focused adapter and ingestion coverage for bounded durable event volume, latest-value preservation, terminal ordering, isolation, and shutdown.
a0e69c6 to
8d27611
Compare
Semantically ports pingdotgg#6004 onto current main and flushes buffered progress before identity refinements as well as terminal lifecycle events.
Human hold
Prepared for human review, not automatic merging. This preserves Ryan Idrogo's original proposal and commit history. The 250 ms delay, discarded intermediate snapshots, and discard-on-explicit-stop behavior need a maintainer decision.
Related #5681. This is a bounded Codex write-amplification repair, not a claim that the reported 17–37-minute stalls are reproduced or fully fixed.
Problem and change
Each Codex child item and cumulative usage notification currently becomes a durable progress event. Stable projected activity IDs do not bound those writes or the serial ingestion work.
Keep the newest item and usage snapshot independently for each session/child in fixed 250 ms windows. Flush a child's pending values before its mapped non-progress updates, including waiting and metadata changes. Flush every child before root completion, abort, runtime error, or session exit; close the coalescer after exit. Mixed mapped batches pass through intact. Explicit session stop still cancels and discards pending progress, as proposed originally.
The current-main adaptation also fixes a verified ordering regression in the original proposal: delayed progress could follow completion/error boundaries or overwrite a child's newer waiting state/name. No queue-fairness, other-provider, schema, or client changes are included.
Losses requiring approval
lastbreakdown. The intermediate sample disappears. Native protocol breakdown fields are required; arbitrary partial or non-monotonic synthetic inputs are not claimed to preserve every historical field/maximum.Verification
Latest tested base: eced382b, September 5, 2026. Tests use an owned inert JSON-RPC peer, the actual Codex runtime/adapter, ingestion receipts and worker drains, and disposable SQLite—not a provider account.
Both preserve the final query, every mapped cumulative usage field, and progress-before-completion ordering. The latest-main baseline fails the reduction assertions; the candidate passes. The ingestion tests wait for completion enqueue receipts and worker drains, with no sleep/polling.
All 129 tests in these three files pass:
Coverage includes fixed windows, independent lanes/keys, two-child flush order, root and child boundaries, same-thread session restart, unexpected exit, and tick/flush/close races. Targeted lint/format and server typecheck pass; typecheck has existing nonblocking suggestions elsewhere.
Additional local checks passed actual mapped events through the server activity mapper and client fold: the repaired order retains the new name and waiting state; the original reordered payloads produce the old name/running state. Actual committed SQLite rows fold to idle with
latest-query-31and total/input/cached/output/reasoning counts 10031/9031/8031/1000/31. These are logic/runtime receipts, not native UI evidence.No real-provider, Windows/macOS, or multi-client stall verification was performed. Claude reports, other high-volume event kinds, and global ingestion fairness remain outside this PR. Current-head CI and configured reviews are tracked separately; human hold applies regardless of green checks.
Adapted and verified by GPT 6 Astra via Codex in T3 Code.
Note
Coalesce Codex child progress before ingestion in
CodexAdapterCodexProgressCoalescer(CodexProgressCoalescer.ts), which buffers item and token-usage progress per child thread in a 250 ms window, keeping only the newest value per lane and emitting item before usage.CodexAdaptersession lifecycle: child progress is offered to the coalescer instead of queued immediately, and all pending progress is flushed before child or root terminal events (turn completion, idle, closure, error, exit, interruption).stopSessionInternaland session exit close the coalescer before tearing down the runtime and event fiber, discarding any pending values.CodexAdapter.streamEventswill see fewer progress events (at most two per lane per window per child) and different ordering — the latest buffered values now precede lifecycle events. Any consumer relying on per-notification delivery or specific progress counts will need adjustment.Macroscope summarized a2c1f9b.