Repository navigation
refactor(gateway): deslop gateway workers and turns - #164014
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: blocked before merge. Reviewed October 3, 2026, 1:27 AM ET / 05:27 UTC (Revision 3). ClawSweeper reviewWhat this changesThis PR consolidates Gateway worker, turn, voice, desktop, and terminal bookkeeping and keeps terminal admission closed until all overlapping lifecycle drains release. Merge readiness⛔ Blocked before merge - 1 item remains Keep open: the terminal drain fix remains necessary on current main, and the prior conflict-integration blocker is resolved. No actionable introduced defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway coordinates agent requests, worker execution, persisted transcripts, and interactive terminal and voice connections. These lifecycle owners control when work starts, how results commit, and when connections release their resources. flowchart TD
A[Agent and client requests] --> B[Gateway lifecycle owners]
B --> C[Admission and ownership checks]
C --> D[Worker execution and storage]
C --> E[Terminal and voice connections]
D --> F[Committed results and transcripts]
E --> G[Client output and lifecycle release]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -542, Tests +38, Other +1. Total -503 across 63 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Use the existing lifecycle and transaction owners consistently, with terminal admission held by every outstanding drain receipt. Do we have a high-confidence way to reproduce the issue? Yes, from source: begin two drains for the same agent session, release the first, and attempt to open a terminal before releasing the second. Current main prematurely clears admission; the added regression exercises this manager boundary. Is this the best way to solve the issue? Yes: one receipt map removes competing drain bookkeeping, while the surrounding refactors reuse existing owners and retain their transaction, authorization, and settlement contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9c4a75fa73fa. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Consolidate worker transaction, journal settlement, workspace, terminal, and turn lifecycle code around their existing owners. Preserve protocol, storage, authority, and output contracts. Keep terminal admission fenced until all overlapping drain receipts release. Replace the receiver-reset test readiness poll with an exact dispatch gate while retaining its custody and cleanup assertions.
4db7dc7 to
17ca947
Compare
Consolidate Gateway worker, turn, Talk, and terminal lifecycle code around existing transaction and admission owners. Keep terminal admission fenced until all overlapping drain receipts release. Preserve current main transcript lifecycle capture, cold-restore and precommit authority checks, and workspace overlay semantics during conflict integration. Remove 542 net production lines without changing protocol, configuration, or persisted-data contracts.
What Problem This Solves
Gateway worker, turn, Talk, and terminal flows contain redundant forwarding layers, duplicate result declarations, and parallel bookkeeping around existing lifecycle owners.
User Impact
The cleanup preserves configuration, protocol and persisted-data shapes, tool descriptions, and visible output. It also fixes terminal admission reopening too early when two lifecycle drains overlap for the same agent session.
Why This Change Was Made
Fixes found along the way
Terminal drains used one active-key set alongside a map of waiter receipts. Releasing the first receipt deleted the active key even when another lifecycle operation still held a drain. One live-receipt map now owns both admission fencing and completion notification; only the last receipt releases admission. The regression exercises
TerminalSessionManager.beginAgentSessionDrainandopen, including duplicate release and successful admission after final release.The receiver-reset fixture also used a 10-second readiness poll covering real Git, rsync, and process startup. It now waits for the exact fallback-reset dispatch signal, retaining the test timeout and every existing fencing, content, and cleanup assertion.
Evidence
Linux proof used Blacksmith Testbox
tbx_01m3zrxgn7g0tekf13rpxnq7g7(lease workflow). The source capsule verified commit99e0e8ac8964ceae8dd49ea336b10362db121091, all changed file hashes, and all four deleted paths before running checks.node scripts/run-vitest.mjsacross the affected terminal, desktop, turn, Talk, and worker flows: 68 test files; 1,639 passed, 1 skipped; 342 s wall time.pnpm test src/gateway/worker-environments/workspace-sync-tunnel.test.ts --maxWorkers=1 --retry=0: 20 complete standalone Linux runs passed, 16–17 s each. The fixture uses the exact reset-dispatch signal; existing assertions, test timeout, and cleanup remain intact.pnpm test src/gateway/terminal/session-manager.agent-lifecycle.test.ts --maxWorkers=1: 2 tests passed; 3.09 s wall time; 53 ms for the new case. This is the added case's measured test cost, not a prediction of hosted job duration.node --import ./scripts/tsx.mjs scripts/check-madge-import-cycles.tsandnode --import ./scripts/tsx.mjs scripts/check-import-cycles.ts: 0 cycles.node scripts/check-changed.mjs: all guards, production typecheck, and all 27 test-type graphs passed; its final export scan identified the now-unusedwaitForFasttest-support export. The final cleanup inlines its one remaining internal call with identical Vitest options. The script, production, and full-tree export scans then all passed with zero entries on00c7b0e936699d60ac1e444c43328ebb08d0fb76(Blacksmith Testboxtbx_01m3zwr2fwfbcdqzm6mxdzgyyg).pnpm build: completed all phases in 7m42s. Its report-only Control UI budget output reported startup JS at 373,455 B against 373,454 B; no UI source or budget is changed here.The full-suite, stability, type, and build evidence above applies to the production candidate. Before the first push, subsequent changes were the test-support wrapper deletion and a clean rebase incorporating main’s existing quiescence-fixture repair (
f5683723b17f17fd31d286c2c57119a8f663a5a9). That repair resolved two stale renewal-script matchers exposed by the broader tunnel selection; it is not duplicated in this PR. The rebase retained the reviewed patch unchanged apart from preflight import context. Final post-rebase proof onc00aff938113e04ef54b3df9850aa19b65c83aafpassed on Blacksmith Testboxtbx_01m3zxn97062n7cz4fzr50x059(lease workflow):node scripts/run-vitest.mjs src/gateway/worker-environments/tunnel.test.ts src/gateway/worker-environments/workspace-sync-tunnel.test.ts src/gateway/agent-turn/agent-request-preflight.test.ts src/gateway/agent-turn/agent-request-preflight.source-lineage.test.tspassed 63 tests in four files across both shards in 42.33 s; both import-cycle commands again reported zero. Hosted CI validates the pushed head.Hosted CI follow-up
The first exact-head run (37094802807,
c00aff938113e04ef54b3df9850aa19b65c83aaf) found five lint diagnostics and the missing wrapper-inventory entry for the new ancestor helper. Those are corrected in the follow-up: equivalent array ordering and object copying, a non-shadowing parameter name, the default deferred type, and the required inventory entry. Independent review passed. Blacksmith Testboxtbx_01m3zyxttmkpgjwj6756jgtejrremained queued for almost 14 minutes with no assigned run URL and was stopped without running the repair command. The authorized local fallback usesnice -n 15, serial commands, and a single test worker: focused typed lint passed; all 17 wrapper/import-closure tests passed; workspace manifest/reset cases and three store intent cases passed in a broader repeat that was then stopped at the lane time box. The separately completedstore-worker.test.ts -t "serves committed inventory and performs guarded mutations without host SQLite" --maxWorkers=1check passed (143.84 s wall time, one selected case; other cases excluded by the explicit filter). This is targeted repair evidence, not a completed rerun of the full affected selection. Both cycle checks passed with zero cycles before the corrective push. The corrected head4db7dc7c5688fa421ad1d7d5f0c6eacad92087cbthen conflicted with newer main changes in transcript commit and workspace overlay ownership; the integration follow-up below supersedes that unfinished status.The other six failures from that historical run were also reproduced on scheduled main run 37094503398, head
5e6794cf5913e0c646b924753440cfaf2d80cf17:ok: trueinstead ofok: false.The finalizer, reclaim owner, mocked dispatch harness, and all three failing test files are byte-identical between this PR and that main run. Main commit
538f97bd8baremoved the pre-renewal verification pair; the fixtures still inject failures using the former call counts. The mocked reconciliation does not execute the ancestor/publisher refactors here. Production final fences remain present. Main subsequently repaired those fixtures in4ec1118e7cc084651811ce52b5b4f2763df96e87, using explicit before/after-apply failure phases and removing obsolete reclaim expectations. The rebased candidate includes that repair; no inherited-failure exception is claimed for those old failures. No assertions, retries, timeouts, or production fencing have been weakened in this PR.Completed conflict integration
Rebased onto
47a9dd748faa3ed7c47b4c96696f91c31f3a98b0; reviewed and tested candidate:17ca947e1b5560b00a6ca84112422e847c781a9f.The transcript conflict keeps main
d52d2b3de28's preparation-owned lifecycle revision, combined live-authority assertion, guarded cold restoration, worker precommit callback, and publication using the applied lifecycle revision. The PR retains canonical digest helpers and bound ledger completion. The overlay conflict keeps maine159e3bcf61's single unconditional ancestor pass over all retained nodes, using the shared ancestor traversal. No authority fence or newer main behavior was removed.node scripts/run-vitest.mjs ... --maxWorkers=1: 12 files, 213 tests passed; 1,914.97 s command wall time on the loaded local Mac. Selection: transcript commit, transcript lifecycle, transcript ledger store, workspace manifest worker, workspace sync manifest, accepted workspace sync, workspace finalization, workspace journal, node workspace transfer, placement dispatch, placement reclaim, and session worker-placement lifecycle. This includes all six historically failing cases with main's phase-based fixture repair.node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo), conflict-file formatting and typed lint, andgit diff --check: passed.Earlier full affected-suite, type, build, and test-stability evidence remains attributed to its original heads above. The current checks prove the overlapping integration. Exact-head CI run 37099604300 passed, and pinned native squash auto-merge landed
052efb366564f22b8f0f0e3fa1ea30f88ddc36cd. The merge is verified onorigin/main, and its tree equals the reviewed head merged into the actual main parent. No CI waiver or admin exception was used.Production delta after main absorbed overlapping reductions: 542 net lines removed (including the new 9-line shared ancestor helper), excluding tests/fixtures/docs/generated files. This is the campaign's final below-1,000 batch for this partition; the full coverage log follows. Recent fencing, replay, retention, and crash-recovery boundaries were retained where no sound simplification remained.
Complete production coverage (166 files over 200 lines)
Gateway worker/turn sweep coverage
Baseline: 4a0be71. All production files over 200 lines, sorted by baseline size. All were read; concurrent-owner paths were left unchanged. Main changes introduced during rebases were inspected. Test harnesses, fixtures and generated artifacts are excluded.