fix(server): coalesce Codex child progress before ingestion #6004
main fromrefs/pull/6004/head·opened View on GitHubHuman 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#
- Item summaries A then B inside a window retain B only. A's transient history and timestamp disappear; the latest summary and separately mapped completion/result events remain.
- Cumulative usage 100 then 200 retains 200 and all currently mapped breakdown fields, not an additive delta or the smaller
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. - Explicit stop before a tick discards pending item/usage. Persisted progress and usage may remain stale, even though the session lifecycle is unchanged and old pending work cannot leak into a restarted session. Final usage preservation on explicit stop is not claimed.
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.
| Actual 32-item + 32-usage wire burst | Current main | Candidate |
|---|---|---|
| No intervening lifecycle update | 64 durable progress events | 2 |
| Waiting/running boundary halfway through | 64 | 4 |
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:
# From apps/server
vp test run src/provider/Layers/CodexProgressCoalescer.test.ts \
src/provider/Layers/CodexAdapter.test.ts \
src/orchestration/Layers/ProviderRuntimeIngestion.test.ts --maxWorkers=2
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-31 and 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 CodexAdapter#
- Adds
CodexProgressCoalescer(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. - Integrates the coalescer into
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.- Risk: downstream consumers of
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.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
One convention finding: the new coalescer's public interface is re-declared locally in
Posted via Macroscope — Effect Service ConventionsCodexAdapter.tsinstead of being imported from its owning module. Everything else in the changed scope (namespace subpath imports, scopedmakeconstruction, callback-basedemitrather than service injection, test-only service instance passing) follows the conventions.apps/server/src/provider/Layers/CodexAdapter.ts lines 100 to 105OutdatedResolvedby cheruvian(GitHub profile, opens in a new tab)@@ -91,7 +92,14 @@9192 readonly threadId: ThreadId;9293 readonly scope: Scope.Closeable;9394 readonly runtime: CodexSessionRuntimeShape;95+ readonly progress: CodexSessionProgressCoalescer;9496 readonly eventFiber: Fiber.Fiber<void, never>;9597 stopped: boolean;9698 }9799100+interface CodexSessionProgressCoalescer {101+ readonly offerItem: (key: string, value: ProviderRuntimeEvent) => Effect.Effect<void>;102+ readonly offerTokenUsage: (key: string, value: ProviderRuntimeEvent) => Effect.Effect<void>;103+ readonly flush: (key: string) => Effect.Effect<void>;104+ readonly close: Effect.Effect<void>;105+}CodexSessionProgressCoalescerduplicates the public interface already exported byCodexProgressCoalescer.ts, so the two shapes can drift. Consider dropping the local copy and referring to the owning module's shape instead.
Posted via Macroscope — Effect Service Conventions-import { makeCodexProgressCoalescer } from "./CodexProgressCoalescer.ts"; +import { + type CodexProgressCoalescer, + makeCodexProgressCoalescer, +} from "./CodexProgressCoalescer.ts"; - readonly progress: CodexSessionProgressCoalescer; + readonly progress: CodexProgressCoalescer<string, ProviderRuntimeEvent>; -interface CodexSessionProgressCoalescer { - readonly offerItem: (key: string, value: ProviderRuntimeEvent) => Effect.Effect<void>; - readonly offerTokenUsage: (key: string, value: ProviderRuntimeEvent) => Effect.Effect<void>; - readonly flush: (key: string) => Effect.Effect<void>; - readonly close: Effect.Effect<void>; -}Fixed in a0e69c692. CodexAdapter now imports the exported CodexProgressCoalescer type from its owning module and removes the duplicate local interface. Re-ran the focused suite (83/83), server typecheck, targeted lint, formatting, and diff checks; all pass.
Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Approvability#
Verdict: 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](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thanks for the PR. We're not taking changes to the orchestration and provider layers right now: that part of the server is being rewritten for V2, and merging into the current code would either conflict with or be thrown away by that work.
Closing for now. If this is still an issue once V2 lands, please reopen (or open a fresh PR against the new code) and we'll take a proper look.
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
d1d811d6-4797-4b4d-ac70-ac90e796e62fYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.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.
❤️ Share