Repository navigation
fix(sessions): keep Gateway responsive with long transcripts - #138094
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 8:48 AM ET / 12:48 UTC. ClawSweeper reviewWhat this changesThis PR moves long session-history and model-context reads onto worker-backed paths, with supporting validation and packaging changes to keep Gateway work responsive. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 7 items remain Keep open: two worker-backed read paths can continue with hooks or autonomous review work after their owning projection or Gateway admission has closed. Priority: P1 Review scores
Verification
How this fits togetherSession transcripts feed both the Codex app-server event projector and background Skill Workshop reviews. Worker reads produce detached history that those consumers use for compaction hooks, review execution, and proposal actions. flowchart LR
A[Session transcript] --> B[Worker history reader]
B --> C[Codex event projector]
B --> D[Skill Workshop review]
C --> E[Compaction hooks]
D --> F[Proposal actions]
G[Projection close or Gateway reset] --> C
G --> D
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +430, Tests +409, Docs +2, Other +3. Total +844 across 29 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Carry the original closure or restart signal through each read-to-side-effect chain, recheck it after the read, add both delayed-read race regressions, and absorb any avoidable production growth. Do we have a high-confidence way to reproduce the issue? No live reproduction was run in this read-only review, but the delayed-read interleavings are directly reproducible from the source paths and existing test seams. Is this the best way to solve the issue? No: worker offloading is appropriate, but the current implementation fails to preserve lifecycle authority across the new awaits. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d0f061242bbd. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
Keep the required context worker in both release-check packaging fixtures.
Use the in-memory SessionManager and normal structured-error projection in the attempt denial fixture. Assert the policy refusal or unavailable guest global, recorded nested denial, and zero source preparation or execution. This fixes the integration failure exposed when main removed the redundant Code Mode outcome hook, while preventing missing fixture methods from passing as permission denials. The exact CI merge reproduced three failing cases before the correction; ordered owner and continuation siblings pass.
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Acceptance-time fencing is the key property here. Moving durable scans to workers is safe only if stale snapshots cannot be published; admission revalidation plus rewrite/sequence checks provides that while admitted later appends remain valid.
Merge current main and preserve the fixture cleanup from #138238. Retain real in-memory session management, structured denial classification, and recorded nested denial assertions while removing the redundant observation array. The CPU context-reader implementation remains unchanged. The combined candidate preserves main's batching and normal Code Mode continuation.
Retain the original Workshop restart signal and fence closed compaction and preview continuations. Transfer MCP cleanup and abort-listener ownership at acquisition, preserving original failures and immediate cancellation during connection preparation.
|
@clawsweeper re-review Head 99c2875 repairs both delayed-read P1s with the original restart/run signals and owner checks. It also fixes reproduced MCP cleanup and connection-listener leaks, and prevents preview recording after projection closure. The PR body documents regression failures, positive controls, cleanup ownership, production growth, and the Workshop apply-transaction follow-up. Independent P2 review is clean in both packs. The final 256 affected tests pass; the preceding 326-case run and requester-MCP fork/restart proof cover unchanged sibling paths. The fresh runtime build passed. Full local checks, final packaged probes, and exact-head CI are still being completed before landing. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…9-prep * commit '407a8f453c0f0306af1ddc0aafa8697c1d49a9e7': (312 commits) perf(ui): coalesce automation event refreshes (#138065) fix: reject incomplete Skill Workshop directory reads (#138082) test(ui): decouple rendering checks from generated wording (#138283) perf: avoid temporary entries in bounded JSON traversal (#138017) fix(irc): render complete messages before splitting (#138328) perf: prepare worker trajectory payloads only for recorded events (#138086) fix(mcp): paginated listings no longer time out after a forward clock step (#137206) fix(codex): page native transcripts and bound UI previews (#136282) feat(gateway): apply more settings without restarting (#138112) fix(docs): preserve mirrored ClawHub maturity links (#138241) fix(test): own UI animation and legacy database setup (#138296) fix(tts): preserve literal directives in Markdown code (#138319) fix: load chat widgets behind authenticated gateways (#138074) chore(ui): cover native approval finalization (#137259) fix(cron): cancel conditions before main-session handoff (#138313) fix(backup): preserve text after embedded NUL characters (#138327) fix(android): align composer control sheets (#137442) fix(ci): wait for replacement PR runs instead of stale failures (#138307) fix(sessions): keep Gateway responsive with long transcripts (#138094) fix(computer): map window inputs to delivered image coordinates (#138271) ... # Conflicts: # scripts/release-check.ts # test/release-check.test.ts
…w#138094) * fix(sessions): keep Gateway responsive with long transcripts * fix(codex): remove history reader type cycle Keep the required context worker in both release-check packaging fixtures. * fix(sessions): reject stale unadmitted context snapshots * test(agents): verify catalog denials through real sessions Use the in-memory SessionManager and normal structured-error projection in the attempt denial fixture. Assert the policy refusal or unavailable guest global, recorded nested denial, and zero source preparation or execution. This fixes the integration failure exposed when main removed the redundant Code Mode outcome hook, while preventing missing fixture methods from passing as permission denials. The exact CI merge reproduced three failing cases before the correction; ordered owner and continuation siblings pass. * fix(sessions): preserve cancellation across history preparation Retain the original Workshop restart signal and fence closed compaction and preview continuations. Transfer MCP cleanup and abort-listener ownership at acquisition, preserving original failures and immediate cancellation during connection preparation. * test(workshop): keep context acquisition spies bound
What Problem This Solves
Long Codex transcripts could pause the Gateway for seconds even when compaction left only a few visible messages. The synchronous SQLite scan blocked timers, channel work, Workshop review, and settled-turn verification. Moving that scan to workers also exposed callers that could resume canceled work or leak resources while waiting for history.
Why This Change Was Made
Core model-context reads and Codex native-history verification now use bounded, reusable workers. The existing readonly snapshot and selection remain authoritative; the native reader stays lazy, so a rejected projection never decodes later payloads. The accepting facade validates the original turn admission or the same snapshot's existing rewrite generation and event sequence. Admitted later appends and unrelated-session appends remain accepted.
Cancellation belongs to the operation that acquired the work. Workshop carries its original Gateway restart signal through context acquisition and checks it before starting a review or entering another proposal. The Codex compaction projector checks its closure/abort state before and after awaited history and hooks. Asynchronous MCP preview preparation now finishes before the existing closure check and synchronous recording, preventing late progress or transcript writes.
The attempt owner disposes configured and requester MCP handles on every exit after acquisition; each disposer runs independently, preserving the original setup error. The connection factory releases its upstream abort listener if preparation fails before ownership transfers. Cancellation remains observable during pending rotation. Duplicate cleanup paths and the asynchronous record-before-check helper are removed.
The shipped synchronous APIs remain available; incognito reads remain in the process that owns their in-memory database. This changes no configuration, environment surface, SQLite schema, stored representation, retention, or native protocol. Native realtime voice remains enabled; its separate interruption/reply repair landed in #138072.
User Impact
The Gateway can service timers and other requests while durable context is built. Canceled compaction and Workshop work cannot start later hooks or reviews. Closed projections cannot record late MCP previews; ordinary native results can still settle after abort while the projection remains open. Failed history preparation releases startup resources. This moves scan work off the event loop; it does not make SQL scanning constant-time or remove worker startup and memory costs.
Evidence
The candidate preserves main's eager payload batching from #138168 and fixture cleanup from #138238. Final head
90193d75bd3b5dd8005c3fc095fbf928c87aee9cdiffers from99c2875only by a Workshop test spy correction. Independent P2 review is clean for the complete 44-path implementation in two packs and for that final test-only delta. The complete canonical changed-check run passed on this head, including full type checking, all three dead-code scans, full lint, runtime import cycles and structural/config/SDK/store guards. All 44 committed files and 8,323 runtime artifacts were independently rehashed afterward and remained unchanged. Exact-head CI passed: 112 jobs succeeded and 15 were skipped, with no failures.Validation passed 326 owner/sibling cases, the canonical requester-MCP fork/restart integration with a real loopback HTTP server, 256 final affected cases across eight projector families and startup/MCP ownership, and 21 Workshop cases after the spy correction. These runs overlap and are not summed as unique tests. Full lint caught two unbound-method references in the new Workshop regression; the corrected test passes targeted type-aware lint and retains every behavioral assertion.
The runtime build at
99c2875passed all five supported phases, 90 plugin runtimes, and native loading of 53 control-plane modules. Eight fresh packaged probes passed on Node 26.8.1 and checksum-verified official Node 22.22.3, bound to source digest94ed931eand the same 8,323 JavaScript artifacts (04ae46d4). The subsequent test-only correction leaves production source unchanged; it is not described as a new runtime build.A synthetic SQLite history contains 1,600 large messages (421,412,864 bytes), a compaction boundary, and 13 visible context messages. Output hashes and the complete raw transcript fingerprint remained identical. Warm model/native worker timer lateness was 2.8–6.9 ms, compared with 574–580 ms for the batched synchronous read. The full mutation/projection suite's highest sample was 22.5 ms. Cold worker reads took 1.01–1.21 seconds, and warm process RSS was 409–638 MiB. Whole-process peaks of 686–801 MiB include artifact hashing and the separate observer. These are observed fixture results, not latency or memory guarantees; they demonstrate responsiveness, not faster scans or an authenticated provider turn.
Packaged proof covers cancellation/reuse, admission rewrite rejection, admitted later-append acceptance, unrelated-session acceptance, unadmitted durable/incognito append and rewrite rejection, complete settled projection, and lazy budget rejection with zero later payload decodes. All processes exit naturally with idle workers. Earlier stock Codex 0.153.0 proof passed four finalizer scenarios against a synthetic loopback provider, including host-capability closure; it was not authenticated provider testing.
New regressions failed before repair: five Workshop restart boundaries; six late compaction-hook calls and four late compaction-event continuations, with two additional signal-forwarding cases; two late MCP preview results; MCP handle/listener leaks before startup; setup cleanup skipping the second disposer and replacing the original error; and connection-factory failure retaining a listener and invoking a stale abort callback. Controls preserve positive compaction, aborted-but-open native result settlement, immediate cancellation during rotation, and normal resource disposal. An initial Workshop test fixture error was corrected and its five cases rerun to valid red before accepting green.
The lead personally compared OSS Codex at
1b53f6a44eff890b5169bde8d3bd5b12b8766946:codex-rs/core/src/tasks/mod.rs:301–405owns the task and child cancellation token;:909–945cancels and joins/aborts it;tasks/compact.rsandtasks/review.rs:54–91retain work inside that lifecycle. OpenClaw's JavaScript continuations need explicit checks at their own ownership boundaries; this PR does not change Codex protocol behavior.Review and CI
Final CI tested merge
a17dd17b60c35f9509a276e4c10d48d3bb473be2, whose parents are main068ef71bd20e0b22f92c26364b758551aa13363band PR head90193d75bd3b5dd8005c3fc095fbf928c87aee9c. The production dependency audit executed and found no matching high-or-higher advisories from npm bulk. It explicitly excludes upstream repository advisories and is not comprehensive vulnerability clearance.The ClawSweeper review identified the two late-continuation P1s on
0901bf7: compaction hooks after projection closure and Workshop acquiring a fresh restart signal after reset. Both are repaired at their lifecycle owners, with failing/passing regressions. Its Rank-up moves require those repairs, green exact-head CI, and a production-growth explanation; packaged proof, all local checks and exact-head CI are complete. The durable review was rechecked before landing; no additional finding had been published, and the requested re-review remains a publisher refresh. The earlier unadmitted snapshot P1 is also repaired at the accepting facade, with durable/incognito regressions and admitted-append controls.Historical CI 33873290186 passed all 111 executed jobs, with 15 skipped, on
0901bf7; its actual tested merge was740d537abc78de06645edbc6ea122f675b7d0a6c. The production dependency audit executed successfully and reported no high-or-critical registry matches; its output explicitly excludes upstream repository advisories. That run predates the lifecycle repairs and does not clear their final head.Earlier CI exposed a type-import cycle and missing-worker packaging fixture, both repaired. Run 33867413182 exposed three Code Mode denial fixture failures after main removed an outcome hook. The fixture now uses the real in-memory session manager and structured-result classifier, retaining specific denial, guest/bridge phase, nested-denial, and zero-action assertions. Main's concurrent cleanup is preserved. No production fallback, timeout increase, retry, or weakened assertion was added.
The broader recovery run 33860752777 was canceled after classifying advisory-service timeout, PowerShell pre-READY failure, registry teardown race, and an old rollback fixture timeout. It is not passing evidence. Normal CI passed those cases; the registry's six ordered local cases also passed without context workers, and main already carries the rollback fixture repair.
Scope and Follow-ups
Production: +1,041/-531 (net +510). Tests and test support: +1,024/-71 (net +953). Docs: net +2; build entries: net +2. Raw counts include method moves and try-scope indentation, which do not represent new behavior. Growth provides the two worker boundaries, the additive API needed to preserve shipped synchronous callers, snapshot acceptance checks, and cleanup/cancellation ownership around newly asynchronous work. Existing verification is moved rather than duplicated; the obsolete generic history wrapper and duplicate resource cleanup are removed. No new database design or operator action is required.
Already-entered Workshop apply transitions retain their existing commit/rollback behavior. This patch fences entry and subsequent proposals; a named follow-up is to audit cancellation and lease enforcement inside that existing transaction. Other bounded follow-ups from the CI investigation are PowerShell startup timing, registry fixture writer/cleanup lifetime, and cold session-deletion profiling if it recurs on the current fixture.