Repository navigation
refactor(gateway): run placement transitions and drain settlement in workers - #164252
Conversation
Run transitions, drain/reconcile and terminal failure settlement through placementTurns and the existing shared-state writer. Preserve exact claims, physical store identity, live grants, publication order and unknown-outcome custody. Keep the current terminal-failure policy unchanged. Validation: changed-file gate, 297 focused tests, database-worker ratchet, zero import cycles and independent Codex review through P2.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: blocked before merge. Reviewed October 3, 2026, 7:43 AM ET / 11:43 UTC (Revision 5). ClawSweeper reviewWhat this changesMoves cloud-worker placement transitions, draining, reconciliation, and terminal-failure persistence into database workers, with callers awaiting settlement. Merge readiness⛔ Blocked before merge - 2 items remain This PR remains useful: current main still performs the targeted placement writes synchronously. No remaining actionable code or security finding was identified, and the previous generic configuration and data-model blockers are unsupported by the complete introduced diff. Priority: P2 Review scores
Verification
How this fits togetherGateway placement controls where an agent session executes and how its worker is reclaimed or recovered. Lifecycle requests enter this subsystem; committed placement facts then control execution authority, cleanup, and session notifications. flowchart TD
A[Session lifecycle requests] --> B[Gateway placement owner]
B --> C[Live authority admission]
C --> D[Database worker]
D --> E[Exact placement transaction]
E --> F[Committed receipt]
F --> G[Authority and environment publication]
G --> H[Execution and cleanup observers]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep placement persistence under the existing worker writer, with exact transaction predicates and acknowledged facts published before dependent lifecycle work. Do we have a high-confidence way to reproduce the issue? Not applicable as a user-facing bug reproduction: this is an internal execution refactor. Current-main source directly establishes the synchronous placement writes being moved. Is this the best way to solve the issue? Yes. Extending the existing worker dispatcher and receipt-publication owners avoids a competing persistence implementation while preserving current lifecycle semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c81d86e82f60. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
Await remaining fixture transitions, settle duplicate recovery before asserting, and keep the standalone wrapper free of the application command worker. Finish admitted failed-worker teardown after caller revocation while preserving authorization for new Gateway materialization.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…workers (openclaw#164252) * refactor(gateway): move placement transition writes into workers Run transitions, drain/reconcile and terminal failure settlement through placementTurns and the existing shared-state writer. Preserve exact claims, physical store identity, live grants, publication order and unknown-outcome custody. Keep the current terminal-failure policy unchanged. Validation: changed-file gate, 297 focused tests, database-worker ratchet, zero import cycles and independent Codex review through P2. * fix(gateway): preserve placement settlement through async cutover Await remaining fixture transitions, settle duplicate recovery before asserting, and keep the standalone wrapper free of the application command worker. Finish admitted failed-worker teardown after caller revocation while preserving authorization for new Gateway materialization.
What Problem This Solves
Placement transitions, drain/reconcile, and terminal-failure writes still ran SQLite on the Gateway main thread during dispatch, reclaim, and recovery.
Why This Change Was Made
Extend the existing
placementTurnscommands and shared-state broker from #163594 and #163819. The worker rereads the exact state, generation, environment, epoch, pending result, and claim inside the synchronous transaction. Host authority is checked at transaction and commit admission. Acknowledged placement, closed-claim, and activation-demand facts publish through the existing owners before observers.All affected runtime callers await settlement, including activation/reclaim lifecycle barriers and diagnostic terminal recovery. Idle drain compares the captured activity timestamp in the worker and rechecks current host policy without placement reads in the grant. Unknown outcomes retain recovery custody; they never authorize replay, generic failure compensation, or inverse filesystem effects.
User Impact
Internal execution change only. Main's current terminal-failure semantics remain intact. No schema, stored format, retention, durability, permission, configuration, or update behavior changes; zero new
OPENCLAW_*names. No operator action is required.Released SDK check against
v2026.9.8: the five store mutations and terminal-recovery callbacks are internal. Gateway readers, retirement, and asynchronous dispatch contracts remain compatible. The callable reclaim source check retains its signature, with an optional host-only eligibility assertion; the SDK type regression accepts the original plain callback. Existing compatibility adapters are unchanged.Overlap: #164014/#164022 cleanup is already in the baseline; #160108 remains adjacent. #121063 will need to rebase on this cutover. Its proposed capability-fenced-worker drain/fail behavior is deliberately untouched.
Evidence
node scripts/check-changed.mjs --base efcd9ff82b8488abfc6f9dbd6443ba0afb2fdcd8passed in 1,125.38 s, including all 27 core test typecheck groups, formatting, lint, SDK/export checks, and storage guards.pnpm test <file> --maxWorkers=1; detailed timings are below.efcd9ff82b8488abfc6f9dbd6443ba0afb2fdcd8. No accepted/actionable findings remain.tbx_01m40gb7mt52wyd0mmgy36ajra, run 37112041188. The receiver verified source treec2f63d4c2f4e95a001766c90fb880d9352303c0band every changed file. The staged commit tree matches exactly.Earlier validation found the startup line cap and async test-fixture signatures. The provisioning-retention helper was moved into its existing sibling owner, and the fixtures were corrected. No assertion, timeout, skip, or baseline exception was weakened.
The first Testbox lease reached its approximately 60-minute workflow lifetime after the gate and 17 suites passed; its Actions job is cancelled, not a green overall run. The completed command prefix remains valid proof. A replacement lease remained queued and was stopped before execution. The two unfinished suites passed locally on the same source. Both leases are verified completed. The first Testbox check job consumed 3,900 CI wall seconds including setup, earlier fixture corrections, and shutdown; the table records focused command seconds separately. Exact-head PR CI will run after publication and is not included in this prepublication proof.
Authority-read follow-up debt
The existing short indexed reads remain live in grants: session revision/transcript-owner checks at
src/gateway/server-worker-placement-session-target.ts:129, canonical session binding atsrc/gateway/server-worker-placement-session-target.ts:275, and the worktree lookup atsrc/agents/worktrees/registry.ts:258. They use other owners' admitted native handles or prepared facts, not maintenance-scoped shared-state snapshots. Boundary tests assert zero caller-thread SQL for the moved placement operations, not for these unrelated authority owners. Prepared-environment binding, placement moves, retirement, and general placement reads remain separate migration work.Focused test timings
Longer suites exercise real SQLite workers, lost-reply settlement, claim-close observers, and session lifecycle barriers. A mock of those owners would not establish the thread or custody contract. Existing fixtures gained awaits; no additional per-test Gateway boots were added.
src/gateway/worker-environments/placement-turn-claims.worker.test.tssrc/gateway/worker-environments/placement-store-terminal.test.tssrc/gateway/worker-environments/placement-store.turn-claim-closure.test.tssrc/gateway/worker-environments/placement-store.reconcile.test.tssrc/gateway/worker-environments/placement-worker-gate.test.tssrc/gateway/worker-environments/worker-turn-launcher-failure-recovery.test.tssrc/gateway/worker-environments/worker-turn-launcher-initial-setup.test.tssrc/gateway/worker-environments/worker-turn-launcher-terminal-results.test.tssrc/gateway/server-worker-placement-reclaim.preparation.test.tssrc/gateway/worker-environments/placement-force-abandon.test.tssrc/gateway/worker-environments/placement-idle-sweep.test.tssrc/gateway/worker-environments/provider-provisioning.shutdown-replay.test.tssrc/plugin-sdk/gateway-placement-compat.test.tstest/scripts/pr-wrapper-source-closure.test.tssrc/gateway/server.sessions.recover.test.tssrc/gateway/server.sessions.worker-original-order.test.tssrc/gateway/server-worker-placement-cancel.test.tssrc/gateway/server-worker-placement-provision-cancellation.test.tssrc/gateway/worker-environments/placement-dispatch-reclaim.test.tsLanding review and CI repairs
The released SDK check was repeated against
v2026.9.8: no removed public export or changed released sync/async signature. The optional reclaim source assertion preserves plain callback compatibility. ClawSweeper completed onf69fe0f6f4007775409bcc1ba421dd8840ac47f8with no code findings; its config/data-model flags came from a truncated file list. The complete diff changes no schema, stored format, configuration default, retention, permission, or update contract.Initial CI run 37117055531 exposed missed awaits in the canonical-descendant and cloud-worker disappearance fixtures, an obsolete exact spy-call expectation, a duplicate-recovery fixture that asserted before the first recovery progressed, an unnecessary placement command root in the standalone PR wrapper inventory, and a caller-authority check incorrectly applied to final bookkeeping after admitted teardown. These are attributed to this cutover and repaired in
6e5de1de3fd427f26fc2f75c0705d9f740bfc891; the failed run is not passing evidence. Authorization still gates new teardown and Gateway workspace materialization. The existing exact generation predicate and held lifecycle fence protect final settlement.The required shared-registry checks passed:
runtime-process-build-graph, shared-state worker imports, get-reply imports, and worker-turn-launcher imports (16 tests, 100.66 s total local wall time). The wrapper command runtime remains outside the standalone lease wrapper; the extracted transition module is part of the compiled application worker graph, whose dependency inventory is generated from imports.ClawSweeper revision 2 on the original head independently identified the same five wrapper, fixture, and post-destroy completion defects. The repair removes the unnecessary wrapper root instead of expanding a standalone lease wrapper to include application commands; both wrapper inventory/export tests and real extracted-wrapper lease execution pass. The duplicate-recovery fixture now starts both calls before awaiting their settlement and asserts the duplicate result, without a dangling wait or timer.
Repair validation: 191 tests passed across six files in 515.70 s local wrapper wall time:
eager-import-closure(17),placement-dispatch-authorityandplacement-move-abandon(38),canonical-descendantand diagnostic recovery (125), and followup recovery (11). Every invocation used--maxWorkers=1. Both affected root test typechecks, scoped formatting/lint, the pinned database-worker ratchet, and fresh P2 Codex autoreview passed. Initial failing CI is retained above; exact-head CI run 37118573977 passed at6e5de1de3fd427f26fc2f75c0705d9f740bfc891(452 s elapsed; 4,088 aggregate Node test job seconds).ClawSweeper revision 3 completed on the repaired head and confirms all five findings are resolved with no remaining actionable code or security defect. The two generic config/data compatibility checklist items are covered by the complete-diff and released-SDK checks above.
Independent attribution is complete: five singly executed invocations per revision for diagnostic recovery, dispatch authority, move abandonment, canonical descendant, and the two selected wrapper closure cases. All 25 original-head invocations reproduced the expected failures; all 25 merge-base invocations passed. Each used
node scripts/run-vitest.mjs <file> --maxWorkers=1(wrapper selection:-t 'PR wrapper inventory|wrapper package exports'). Total serial command wall time was 2,681.04 s for the original head and 2,655.52 s for the merge base, run concurrently in isolated worktrees; no CI was rerun for attribution. Main run 37113342869 had the separate import-graph and attempt-stream fixture failures noted in the handoff. No inherited-failure admin exception is needed or claimed.