Skip to content

refactor(gateway): deslop gateway workers and turns - #164014

Merged
steipete merged 3 commits into
mainfrom
deslop/l333-simplify-gateway-workers-turns-20261002
Oct 3, 2026
Merged

steipete merged 3 commits into
mainfrom
deslop/l333-simplify-gateway-workers-turns-20261002

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Bind worker store kernels directly to the transaction already owned by the worker, removing one-implementation read/write callbacks and fake no-op authority checks. Host transaction and precommit admission remain authoritative.
  • Reuse the existing placement mutation settlement owner for workspace journal writes, and simplify joined placement filtering, attachment pruning, and retained-record projection.
  • Move single-caller provider identity and incompatible-lease handling into the existing teardown owner; return complete startup facts from environment lock callbacks.
  • Remove duplicate agent-turn result declarations and lifecycle/routing wrappers, and unify persistence rejection projection.
  • Consolidate terminal output batching into its sole controller, remove unused private options, and simplify sequential RFB reader and audio capture state.
  • Bind transfer capabilities through their existing exact context membership, share workspace ancestor traversal, flatten accepted-workspace publication, and remove duplicate identity-schema branches.
  • Share worker claim-admission recovery, canonical transcript digests, and bound ledger completion; inline single-use ledger inserts and derive media result types.
  • Remove redundant Talk room-access wrappers, relay issue forwarding, readiness handling, and ledger bookkeeping.

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.beginAgentSessionDrain and open, 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 commit 99e0e8ac8964ceae8dd49ea336b10362db121091, all changed file hashes, and all four deleted paths before running checks.

  • node scripts/run-vitest.mjs across 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.
  • The terminal regression fails against the original drain owner and passes with the fix on Linux. 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.
  • Both node --import ./scripts/tsx.mjs scripts/check-madge-import-cycles.ts and node --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-unused waitForFast test-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 on 00c7b0e936699d60ac1e444c43328ebb08d0fb76 (Blacksmith Testbox tbx_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.
  • Independent Codex autoreview: no actionable P0/P1 findings after fixing partial journal-publication staging rollback during conflict integration. The helper-only cleanup also passed its independent P0/P1 review.

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 on c00aff938113e04ef54b3df9850aa19b65c83aaf passed on Blacksmith Testbox tbx_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.ts passed 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 Testbox tbx_01m3zyxttmkpgjwj6756jgtejr remained queued for almost 14 minutes with no assigned run URL and was stopped without running the repair command. The authorized local fallback uses nice -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 completed store-worker.test.ts -t "serves committed inventory and performs guarded mutations without host SQLite" --maxWorkers=1 check 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 head 4db7dc7c5688fa421ad1d7d5f0c6eacad92087cb then 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:

PR job Failure Matching main job
checks-node-changed-compact-small-16-1 Two sessions.delete post-apply recovery cases return ok: true instead of ok: false. checks-node-compact-large-17
checks-node-changed-compact-large-19-1 Remote change after local acceptance resolves instead of rejecting. checks-node-compact-large-3
checks-node-changed-compact-large-17 Three reclaim cases: obsolete 14-event suffix, obsolete remote-fence call 2, and secondary dummy-workspace ENOENT. checks-node-compact-large-10

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 538f97bd8ba removed 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 in 4ec1118e7cc084651811ce52b5b4f2763df96e87, 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 main e159e3bcf61's single unconditional ancestor pass over all retained nodes, using the shared ancestor traversal. No authority fence or newer main behavior was removed.

  • Focused 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.
  • Both import-cycle commands: 0 cycles.
  • Core production types (node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo), conflict-file formatting and typed lint, and git diff --check: passed.
  • Fresh independent Codex autoreview of the full rebased candidate: scoped-clean through P1, no actionable findings. The ClawSweeper report's generic compatibility checkbox is not supported by a changed storage contract, consistent with its own technical assessment: SQL values, row contracts, schema installers, transaction ownership, and precommit admission remain unchanged.

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 on origin/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.

Lines Production file Result
993 src/gateway/talk/handlers/index.ts READ — Unchanged l314 overlap; catalog/config/speech policy and authorization remain necessary.
794 src/gateway/terminal/session-manager.ts READ — Spawn reservations, eviction, drain/reentrancy and detach ownership remain necessary.
758 src/gateway/agent-turn/agent-job.ts READ — Sticky terminal/source barriers and timer semantics remain necessary.
747 src/gateway/worker-environments/node-worker-tunnel.ts READ — Workspace settlement and exact epoch/claim fencing remain necessary.
739 src/gateway/worker-environments/provider-lifecycle.ts READ — Delegate incompatible lease cleanup directly to teardown owner.
738 src/gateway/worker-environments/bootstrap.ts READ — Archive integrity, host trust, locking and exact receipts remain necessary.
732 src/gateway/worker-environments/worker-turn-rpc.ts READ — Exact credential/claim binding, terminal ACK fences and post-await authority remain necessary.
729 src/gateway/desktop/managed-linux.ts READ — Native process/readiness/audio lifecycle remains necessary.
728 src/gateway/worker-environments/worker-turn-launcher.ts READ — Unify claim admission recovery for remote/local execution without changing fencing.
727 src/gateway/worker-environments/service.ts READ — Provider/environment queues, guarded reconciliation and shutdown settlement have distinct owners.
721 src/gateway/worker-environments/inference.ts READ — Durable settlement, unknown outcomes, replay and admission barriers remain necessary.
720 src/gateway/talk/relay/operations.ts READ — Cancellation epochs, final-result acceptance and exact ownership remain necessary.
716 src/gateway/agent-turn/agent-run-admission-phase.ts READ — Post-await authority and preaccept cleanup remain necessary.
715 src/gateway/agent-turn/agent-run-execution-phase.ts READ — Unchanged l314 overlap; postaccept execution/settlement and cleanup ownership remain necessary.
715 src/gateway/worker-environments/placement-dispatch-startup.ts READ — Remove injected test-only transition reporter.
714 src/gateway/worker-environments/placement-dispatch-pending-results.ts READ — Durable-result recovery and teardown retain distinct authority.
713 src/gateway/talk/relay/session-create.ts READ — Collapse issue construction/forwarding into its session owner.
705 src/gateway/worker-environments/local-workspace-projection.ts READ — Registry/session binding, cross-process lease, recovery and accepted-result custody remain necessary.
705 src/gateway/worker-environments/node-workspace-transfer-service.ts READ — Bind capabilities through exact context membership; retain live owner/TTL/signal authority.
693 src/gateway/worker-environments/node-launch-adapter.ts READ — Unchanged l314 overlap; supervisor receipts, bounded admission and confirmed cancellation remain necessary.
684 src/gateway/worker-environments/worker-turn-execution.ts READ — Prepared tool/turn authority, transfer custody and terminal receipt reconciliation remain necessary.
682 src/gateway/worker-environments/workspace-quiescence-scripts.ts READ — Process identity, renewal/recovery and platform branches enforce real leases.
680 src/gateway/talk/client-agent-consult.ts READ — Completion claims, runtime admission and confirmation lifetimes remain necessary.
680 src/gateway/worker-environments/computer-transport.ts READ — Placement, run, policy, execution and takeover authorities remain distinct.
668 src/gateway/worker-environments/placement-turn-authority.ts READ — Publication ordering and incarnation revocation remain necessary.
666 src/gateway/worker-environments/inference-runtime.ts READ — Unchanged l314 overlap; prepared runtime, route authentication and live turn authority remain necessary.
658 src/gateway/worker-environments/workspace-sync.ts READ — Use direct accepted publisher; preserve transport retries, quota and reconciliation.
654 src/gateway/agent-turn/agent-turn-service.ts READ — Partial-admission ownership and cleanup order remain necessary.
648 src/gateway/talk/handlers/session.ts READ — Remove one-use room checks and reuse the canonical administrator-scope helper.
646 src/gateway/talk/client-gateway-control.ts READ — FIFO admission, retained completion and provider shutdown boundaries remain necessary.
639 src/gateway/worker-environments/session-attachment-service.ts READ — Durable attachment close/provision and cleanup retry have distinct lifetimes.
632 src/gateway/worker-environments/placement-store.ts READ — Synchronous transitions, conflict publication and worker reads have distinct ownership.
631 src/gateway/worker-environments/environment-access.ts READ — Return startup and owner facts from lock callbacks instead of mutable out parameters.
630 src/gateway/worker-environments/node-worker-workspace-actions.ts READ — Repository checkpoint flow has no SSH duplicate; reconciliation already has one owner.
622 src/gateway/worker-environments/node-bootstrap-artifact-build.ts READ — Import closure, byte identity and prebuilt verification remain necessary.
615 src/gateway/worker-environments/placement-turn-claim-events.ts READ — Run/claim authority, ACK custody and cleanup observers remain necessary.
612 src/gateway/worker-environments/provider-intent.ts READ — Preparation, retention and replay have distinct authority/source contracts.
605 src/gateway/desktop/session-registry.ts READ — Observer reservations, epoch fencing and teardown retry remain necessary.
596 src/gateway/worker-environments/worker-session-tool-executor.ts READ — Durable tool replay, source/target incarnation and child-spawn settlement remain necessary.
596 src/gateway/worker-environments/workspace-result-finalize.ts READ — Run, result and transcript-publication authority deliberately differ.
594 src/gateway/worker-environments/placement-move-intent.ts READ — Unchanged l314 overlap; durable move ownership and atomic completion remain necessary.
590 src/gateway/worker-environments/prepared-pool.ts READ — Capacity, deferred observations and original expiry windows remain necessary.
585 src/gateway/worker-environments/live-events.ts READ — Ordered ACK windows, buffered terminal capacity and publication ownership remain necessary.
571 src/gateway/worker-environments/placement-dispatch-coordinator.ts READ — Queue loans, supersession and provider settlement preserve ordering.
563 src/gateway/agent-turn/agent-session-persist.ts READ — Unified rejection projection; lifecycle hooks now execute in their sole owner.
560 src/gateway/worker-environments/workspace-reconcile-recovery.ts READ — Reuse ancestor traversal; retain reversible patch and data-preservation conditions.
540 src/gateway/desktop/host-source.ts READ — Configuration generation and host authentication remain necessary.
530 src/gateway/worker-environments/store-projection.ts READ — Linearize attachment pruning and simplify recovery projection; retain authority overlays.
528 src/gateway/worker-environments/placement-turn-claims-store.ts READ — Uncertain writes need command-specific settlement.
525 src/gateway/worker-environments/bundle.ts READ — Unchanged l314 overlap; archive verification, atomic publication, prune ownership and npm integrity remain necessary.
525 src/gateway/worker-environments/placement-turn-claims.ts READ — Unchanged l314 overlap; exact claims, atomic settlement and revocation remain necessary.
519 src/gateway/talk/handlers/client-create.ts READ — Transport-specific startup/rollback and post-await fencing remain necessary.
519 src/gateway/worker-environments/placement-record.ts READ — Persisted validation and discriminated states encode real contracts.
516 src/gateway/worker-environments/store.ts READ — Host admission, native settlement reconciliation and serialized mutation APIs remain necessary.
516 src/gateway/worker-environments/workspace-sync-scripts.ts READ — Standalone worker cannot import host dependencies; Git/plain and platform modes remain necessary.
506 src/gateway/worker-environments/placement-dispatch.ts READ — Remove transition reporter forwarding.
502 src/gateway/worker-environments/workspace-accepted-remote-script.ts READ — Unchanged l314 overlap; transaction/rename settlement, rollback and permissions preserve crash recovery.
498 src/gateway/worker-environments/node-workspace-retain-coordinator.ts READ — Unchanged l314 overlap; live owner snapshots, result reachability and connection ACKs protect pruning.
498 src/gateway/worker-environments/workspace-result-staging.ts READ — Candidate/accepted/cleanup refs preserve crash windows.
478 src/gateway/agent-turn/agent-run-user-turn.ts READ — Unchanged l314 overlap; durable receipt and media custody remain necessary.
473 src/gateway/worker-environments/prepared-environment-store.ts READ — Use concrete admitted database; remove fake worker guard callbacks.
464 src/gateway/worker-environments/workspace-sync-helpers.ts READ — Transport parsing, quotas and abort identity remain necessary.
462 src/gateway/worker-environments/placement-dispatch-failure.ts READ — Unchanged l314 overlap; drain/reconcile ordering and teardown custody remain necessary.
458 src/gateway/worker-environments/session-repository-checkpoints.ts READ — Immutable ref admission and revision checks preserve recovery bytes.
458 src/gateway/worker-environments/workspace-actual-manifest.ts READ — Sparse/recursive inventory differ; descriptor budgets/hash identity and error ordering remain necessary.
450 src/gateway/worker-environments/provider-owner-lifecycle.ts READ — Absorb single-caller SSH identity and incompatible-lease factories.
443 src/gateway/talk/relay/state.ts READ — Response ownership and cancellation generation remain necessary.
439 src/gateway/worker-environments/node-enrollment.ts READ — Reserve-before-await, bearer ownership, grants and teardown remain necessary.
432 src/gateway/talk/transcription-relay.ts READ — Final transcript drainage differs from realtime relay shutdown.
430 src/gateway/agent-turn/agent-run-dispatch.ts READ — Unchanged l314 overlap; terminal/replay publication and followup settlement remain necessary.
429 src/gateway/agent-turn/internal-facade.ts READ — Separate acceptance/final deadlines and exact abort ownership remain necessary.
429 src/gateway/worker-environments/repository-project-admission.ts READ — REST/GraphQL auth capabilities and repository-instance fencing differ.
421 src/gateway/desktop/rfb-preauth.ts READ — Use one sequential handshake waiter.
420 src/gateway/worker-environments/credential-broker.ts READ — Persistence, rotation, delivery and live-turn checks protect distinct boundaries.
418 src/gateway/worker-environments/placement-dispatch-recovery.ts READ — Startup/runtime recovery have different authority and teardown rules.
416 src/gateway/talk/relay/forced-consults.ts READ — Native-call aliasing and async terminal acceptance remain necessary.
415 src/gateway/talk/session-config.ts READ — Retain protocol enum normalizers to avoid a concurrent baseline edit.
407 src/gateway/desktop/computer-service.ts READ — Generation, execution custody and idempotency remain necessary.
407 src/gateway/worker-environments/project-preparation.ts READ — Recipe authorization, transfer and capture are real lifecycle stages.
406 src/gateway/worker-environments/worker-turn-admission.ts READ — Initial setup, local claims and worker recovery waits have distinct ownership.
403 src/gateway/talk/voice-selection.ts READ — Replacement claims, readiness and original-target fencing remain necessary.
401 src/gateway/worker-environments/node-desktop-carrier.ts READ — Observer streams and app launches have distinct lifetimes.
399 src/gateway/worker-environments/placement-workspace-result.ts READ — Result fencing and acceptance transactions remain necessary.
398 src/gateway/worker-environments/placement-reclaim.ts READ — Final save, quiescence and cleanup retain distinct failure paths.
398 src/gateway/worker-environments/transcript-commit.runtime.ts READ — Use canonical digests and one bound ledger completion; retain precommit authority/settlement.
393 src/gateway/worker-environments/inference-control-internal.ts READ — Captured cancellation identity and drain custody protect pending writes.
392 src/gateway/worker-environments/placement-row-codec.ts READ — Filter joined environment directly instead of redundant profile subquery.
387 src/gateway/worker-environments/provider-node-provisioning.ts READ — Preparation, grants, enrollment and readiness cross distinct authority boundaries.
384 src/gateway/worker-environments/desktop-tunnel.ts READ — Epoch fencing, shutdown custody and single-attempt app launches remain necessary.
381 src/gateway/worker-environments/worker-turn-payload.ts READ — Replay fitting, identity minting and model-result projection protect wire/runtime contracts.
376 src/gateway/desktop/observe-bridge.ts READ — View-only enforcement, authentication and backpressure remain necessary.
375 src/gateway/worker-environments/node-worker-repository-preparation.ts READ — Seeded preparation, clone fallback, branch binding and publication remain necessary.
365 src/gateway/worker-environments/store-transitions.ts READ — Use concrete admitted database and remove worker no-op guard seam.
362 src/gateway/worker-environments/placement-turn-claims.worker.ts READ — Worker transaction and commit admission remain necessary.
361 src/gateway/worker-environments/placement-move-service.ts READ — Durable move intent owns source and destination recovery.
361 src/gateway/worker-environments/workspace-manifest.ts READ — Reuse canonical ancestor traversal; retain persisted manifest validation.
354 src/gateway/worker-environments/workspace-manifest-worker.ts READ — Worker offload and transfer budgets are real boundaries.
351 src/gateway/desktop/node-stream-broker.ts READ — Redeemed-ticket custody across awaited pairing authentication remains necessary.
351 src/gateway/worker-environments/inference-store.kernel.ts READ — Durable replay/conflict/cancellation and UTF-8 accounting remain necessary.
348 src/gateway/worker-environments/workspace-inventory-computation.runtime.ts READ — Reuse ancestor traversal; retain metadata/content budgets and eligibility.
338 src/gateway/worker-environments/session-placement-lifecycle.ts READ — Reset/archive/restore/stop have distinct allowed states and retirement duties.
336 src/gateway/worker-environments/ssh.ts READ — Host trust and advertised-port retry remain necessary; separate bootstrap pin is intentional.
331 src/gateway/worker-environments/transcript-commit-store.worker.ts READ — Inline single-caller inserts; retain admitted ledger transaction and request identity.
328 src/gateway/desktop/managed-linux-audio.ts READ — Private server/capture admission and cleanup remain necessary.
325 src/gateway/worker-environments/placement-workspace-journal.ts READ — Unchanged due to concurrent maintainer work; exact owner pruning remains required.
323 src/gateway/worker-environments/transcript-commit.kernel.ts READ — Prefix versus DAG replay protect distinct recovery cases; recheck snapshot inside transaction.
322 src/gateway/agent-turn/agent-dedupe-lifecycle.ts READ — Reservation and committed-reset ownership remain necessary.
320 src/gateway/talk/handlers/client.ts READ — Client compatibility, confirmation and relay ownership remain necessary.
319 src/gateway/worker-environments/store.kernel.ts READ — Remove single-implementation read/write dependency injection.
317 src/gateway/worker-environments/workspace-accepted-sync.ts READ — Remove factory-of-factory; retain rollback versus uncertain settlement distinction.
315 src/gateway/agent-turn/agent-request-preflight.ts READ — Derive result from its producer instead of duplicating its type.
315 src/gateway/worker-environments/node-worker-bundle-installer.ts READ — Unchanged l314 overlap; node authority, scoped grants and build receipts remain necessary.
315 src/gateway/worker-environments/node-workspace-upload-reader.ts READ — Stream framing, limits, current authority and staging cleanup remain necessary.
311 src/gateway/worker-environments/placement-projector.ts READ — State-specific wire projections preserve omitted/required fields.
305 src/gateway/worker-environments/worker-turn-media.ts READ — Infer producer result; preserve omission policy, model image gate and canonical paths.
305 src/gateway/worker-environments/workspace-mutation-lock-remote-script.ts READ — Exact lock identity, reclaim CAS, PID liveness and inode checks remain necessary.
303 src/gateway/worker-environments/workspace-reconcile-apply.ts READ — Compare prepared facts directly; preserve publication/rollback guards.
302 src/gateway/worker-environments/workspace-sync-inventory.ts READ — Bounded child I/O, shutdown and first-failure precedence remain necessary.
300 src/gateway/agent-turn/agent-request-routing.ts READ — Inline sole rebound helper and derive result type.
300 src/gateway/desktop/rfb-probe.ts READ — Use one sequential handshake waiter.
298 src/gateway/worker-environments/placement-session-tool-operations.kernel.ts READ — Replay identity, capacity and admission remain distinct contracts.
289 src/gateway/terminal/launch.ts READ — Remove unused private options and duplicate roster deduplication.
289 src/gateway/worker-environments/skill-resource-transfer.ts READ — Bounded chunk wire, directory identity and stale-resource cleanup remain necessary.
280 src/gateway/worker-environments/service-contract.ts READ — Leaf request-facing contracts preserve lazy runtime and prevent cycles.
278 src/gateway/worker-environments/placement-worker-gate.ts READ — Restart claims and runtime refresh require exact ownership.
278 src/gateway/worker-environments/workspace-result-inventory.runtime.ts READ — Retain September 2026 persisted v1/v2 compatibility and bounded singleton path.
275 src/gateway/agent-turn/agent-admission-controller.ts READ — Outcome precedence and currentness remain necessary.
274 src/gateway/agent-turn/agent-content-phase.ts READ — Attachment custody and routing boundaries remain necessary.
273 src/gateway/desktop/computer-process.ts READ — Helper launch/close custody and cancellation remain necessary.
270 src/gateway/worker-environments/tunnel-contract.ts READ — Workspace/launch ownership and reconciliation contracts remain necessary.
268 src/gateway/worker-environments/store-row-codec.ts READ — Persisted boundary validation and exact inventory facts remain necessary.
264 src/gateway/worker-environments/node-workspace-transfer-http.ts READ — Shared authority lifecycle has distinct streaming/manifest/upload protocols.
262 src/gateway/worker-environments/project-setup-script.ts READ — Recipe execution, retained workspaces and completion fences remain necessary.
261 src/gateway/desktop/audio-bridge.ts READ — Use capture AbortController instead of duplicate generation state.
257 src/gateway/agent-turn/agent-delivery-phase.ts READ — Derive result from its producer.
257 src/gateway/worker-environments/session-attachment-store.ts READ — Use concrete database; retain identity predicates and host admission.
252 src/gateway/worker-environments/artifact-transfer-http.ts READ — Streaming authority, ranges, limits and descriptor cleanup remain necessary.
252 src/gateway/worker-environments/worker-session-tool-source.ts READ — Source authority, policy hooks and gateway runtime identity remain necessary.
251 src/gateway/worker-environments/portal-node-carrier.ts READ — Portal/per-stream ownership and post-await checks remain necessary.
250 src/gateway/desktop/node-source.ts READ — Live node policy and stream ownership remain necessary.
246 src/gateway/worker-environments/worker-turn-run-owner.ts READ — Claim authority, cancellation and forced settlement share an exact live run owner.
244 src/gateway/worker-environments/placement-session-tool-operations.ts READ — Subscribe-before-check prevents teardown races.
243 src/gateway/worker-environments/worker-turn-attachments.ts READ — Managed originals, atomic writes, inode/hash/chunk validation and cleanup remain necessary.
243 src/gateway/worker-environments/workspace-hash-memo.ts READ — Placement-scoped bounded hashing memo is shared with the standalone program.
240 src/gateway/worker-environments/workspace-reconcile-preflight.ts READ — Merge repeated ancestor walk and share traversal.
239 src/gateway/worker-environments/repository-workspace-mutation.ts READ — Session, environment and result-custody checks protect different owners.
239 src/gateway/worker-environments/service-validation.ts READ — Provider results are untrusted runtime boundaries; validation remains necessary.
238 src/gateway/worker-environments/workspace-reconcile-fs.ts READ — Derived-only/journal traversal differ on empty directories and retained inputs.
235 src/gateway/worker-environments/artifact-transfer-service.ts READ — Capability and attempt lifetimes differ; revocation and descriptor checks remain necessary.
234 src/gateway/agent-turn/agent-handler-helpers.ts READ — Delete sole lifecycle wrapper and unused knobs.
233 src/gateway/worker-environments/admission.ts READ — Remove session/run pairing check already enforced by exact-claim admission branches.
233 src/gateway/worker-environments/computer-service.ts READ — Service wrapper owns connection lifetime and shutdown beyond transport.
232 src/gateway/agent-turn/agent-dedupe.ts READ — Replay key and source-publication contracts remain necessary.
224 src/gateway/agent-turn/agent-run-subagent.ts READ — Followup identity settlement guards remain necessary.
218 src/gateway/worker-environments/node-worker-workspace-fallback.ts READ — Credential-free source eligibility and canonical transfer fallback remain necessary.
216 src/gateway/talk/handlers/voice.ts READ — Managed/browser authorization differences require separate validation.
216 src/gateway/talk/session-registry.ts READ — Reentrant cleanup and failed-owner retention remain necessary.
216 src/gateway/worker-environments/placement-workspace-journal-store.ts READ — Reuse canonical mutation settlement and preserve partial-staging rollback.
216 src/gateway/worker-environments/store.worker.ts READ — Remove fake callbacks; preserve transaction and precommit admission.
215 src/gateway/worker-environments/placement-disk-space.ts READ — Exact-generation samples and stale-build suppression remain necessary.
212 src/gateway/worker-environments/local-workspace-archive.ts READ — Reuse ancestor traversal; retain archive delta and retention custody.
210 src/gateway/worker-environments/store-validation.ts READ — SSH/profile/credential boundary validation remains necessary.
205 src/gateway/worker-environments/workspace-reconcile-core.ts READ — Reuse ancestor traversal; retain stable snapshot and accepted-state validation.
203 src/gateway/worker-environments/workspace-git-base.ts READ — Thin/full pack routes reflect real inventory and performance contracts.
202 src/gateway/worker-environments/provider-machine-catalog.ts READ — Unchanged l314 overlap; provider-generation invalidation protects allocated-profile identity.
202 src/gateway/worker-environments/store-mutations.ts READ — Retain existing grouping; declaration target does not support Map.groupBy.

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 17ca947e1b5560b00a6ca84112422e847c781a9f
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/desktop/rfb-preauth.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@steipete
steipete enabled auto-merge (squash) October 3, 2026 03:56
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 3, 2026, 1:27 AM ET / 05:27 UTC (Revision 3).

ClawSweeper review

What this changes

This 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
Reviewed head: 17ca947e1b5560b00a6ca84112422e847c781a9f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A sound owner-consolidation patch with a meaningful lifecycle regression and scoped integration validation; no material remediation remains.
Proof confidence 🌊 off-meta tidepool Not applicable: The contributor-setup proof gate is exempt for this repository-admin PR. Reported terminal manager regression and affected worker integration checks provide supplemental validation; no material authority expansion or stored-data contract change creates an additional proof requirement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The contributor-setup proof gate is exempt for this repository-admin PR. Reported terminal manager regression and affected worker integration checks provide supplemental validation; no material authority expansion or stored-data contract change creates an additional proof requirement.
Evidence reviewed 9 items Pinned introduction and merge composition: Reviewed the introduced delta from 47a9dd7 to 17ca947. The test merge's raw parents are exactly the pinned base followed by the pinned PR head; its transcript and overlay delta preserves the newer base behavior.
Distinct fix still needed on main: Current main still uses a single active-key set: releasing one drain deletes the key despite another outstanding receipt. The proposed map retains admission until its final receipt releases, and the added manager-boundary regression checks partial release, duplicate release, and eventual successful admission.
Transaction authority retained: The kernel's sole production caller binds it to the existing synchronous worker transaction. Transaction admission and immediate precommit admission remain present; the removed worker callbacks were explicitly no-ops.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -542, Tests +38, Other +1. Total -503 across 63 files.

View PR surface stats
Area Files Added Removed Net
Source 57 1326 1868 -542
Tests 5 99 61 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 63 1426 1929 -503

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/agent-turn/agent-session-persist.ts, serialized state: src/gateway/worker-environments/provider-lifecycle.ts, unknown-data-model-change: src/gateway/agent-turn/agent-session-persist.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best 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.

Labels

Label changes:

  • add P2: The PR includes a bounded terminal lifecycle admission fix alongside internal cleanup, with no demonstrated urgent production outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The contributor-setup proof gate is exempt for this repository-admin PR. Reported terminal manager regression and affected worker integration checks provide supplemental validation; no material authority expansion or stored-data contract change creates an additional proof requirement.

Label justifications:

  • P2: The PR includes a bounded terminal lifecycle admission fix alongside internal cleanup, with no demonstrated urgent production outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The contributor-setup proof gate is exempt for this repository-admin PR. Reported terminal manager regression and affected worker integration checks provide supplemental validation; no material authority expansion or stored-data contract change creates an additional proof requirement.

Evidence

What I checked:

  • Pinned introduction and merge composition: Reviewed the introduced delta from 47a9dd7 to 17ca947. The test merge's raw parents are exactly the pinned base followed by the pinned PR head; its transcript and overlay delta preserves the newer base behavior. (2c2d77bd8f76)
  • Distinct fix still needed on main: Current main still uses a single active-key set: releasing one drain deletes the key despite another outstanding receipt. The proposed map retains admission until its final receipt releases, and the added manager-boundary regression checks partial release, duplicate release, and eventual successful admission. (src/gateway/terminal/agent-session-drain.ts:42, 17ca947e1b55)
  • Transaction authority retained: The kernel's sole production caller binds it to the existing synchronous worker transaction. Transaction admission and immediate precommit admission remain present; the removed worker callbacks were explicitly no-ops. (src/gateway/worker-environments/store.worker.ts:43, 17ca947e1b55)
  • Storage compatibility assessment: The introduced changes preserve SQL columns and values, attachment schema, ledger row identity, digest inputs and encodings, and manifest formats. Moving internal wrappers and transaction bindings does not introduce a stored-data contract change or require migration. (src/gateway/worker-environments/transcript-commit.runtime.ts:248, 17ca947e1b55)
  • Security-sensitive paths inspected: RFB reads remain sequential within each distinct handshake peer. Audio cancellation retains its per-capture abort controller and live requester checks; transfer capabilities retain exact context membership, live authorization, expiry, and cancellation checks. No permission expansion or supply-chain change was identified. (src/gateway/desktop/rfb-preauth.ts:76, 17ca947e1b55)
  • Captured body and re-review continuity: The retrieved full body matches captured SHA-256 2632313d75dd512a5f0a93e9ef2e78a441bbbb634b3ab5d038b8d010fcc8bd97. Its omitted tail contains the campaign coverage inventory. The integration section reports 213 passing tests across 12 affected files on the reviewed head, zero import cycles, and passing core types, lint, formatting, and diff checks. Earlier broader validation remains attributed to its original heads; these checks were not rerun by this reviewer. (17ca947e1b55)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-03T03:59:38.502Z sha c00aff9 :: blocked before merge. :: none
  • reviewed 2026-10-03T04:48:24.950Z sha 4db7dc7 :: blocked before merge. :: none

@steipete
steipete disabled auto-merge October 3, 2026 04:05
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 3, 2026
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.
@steipete
steipete force-pushed the deslop/l333-simplify-gateway-workers-turns-20261002 branch from 4db7dc7 to 17ca947 Compare October 3, 2026 05:22
@steipete
steipete enabled auto-merge (squash) October 3, 2026 05:23
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 3, 2026
@steipete
steipete merged commit 052efb3 into main Oct 3, 2026
146 checks passed
@steipete
steipete deleted the deslop/l333-simplify-gateway-workers-turns-20261002 branch October 3, 2026 05:37
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant