Repository navigation
fix(worker): keep background servers alive after replies - #130733
Conversation
Retain the supervised worker environment while background execs are live, while recreating turn admission, tools, connections, and authorization for each turn. Keep physical worker ownership separate from bounded turn receipts so cancellation, restart recovery, and environment retirement cannot discard a still-running worker. Preserve process polling across turns, release turn callbacks, join exec finalization before environment cleanup, and require exact worker stop confirmation unless a dedicated provider proves the machine is gone. Fixes #130450.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 3:20 AM ET / 07:20 UTC. ClawSweeper reviewWhat this changesThis PR keeps node-worker background servers alive after a reply by moving their lifetime from an individual turn to the active environment. Warning SQLite table change This PR modifies persisted SQLite tables in Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessThe PR remains necessary: current main still cancels the worker process scope when a turn ends, breaking the documented background-preview flow. The proposed environment-owned lifecycle is substantively tested, but exact-head CI and the PR's cited Codex runtime boundary require direct maintainer verification before merge. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway dispatches session turns to enrolled node workers, which start processes and expose previews through portals. The change separates turn completion from environment retirement so a server can remain reachable after the agent replies. flowchart LR
A[Gateway session turn] --> B[Node worker admission]
B --> C[Worker process scope]
C --> D[Background development server]
D --> E[Environment portal]
B --> F[Turn receipt]
F --> G[Turn finalization]
G --> H[Environment retirement]
H --> C
Decision needed
Why: The candidate repair is source-supported, but the required sibling Codex checkout is unavailable locally and CI could not be refreshed. Before merge
Agent review detailsSecurityNone. Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Merge only after exact-head CI and direct Codex-boundary verification show that stale, revoked, or replaced placements cannot retain or stop a successor worker and the old-node upgrade path is clear. Do we have a high-confidence way to reproduce the issue? Yes for source reproduction: current main unconditionally cancels the turn process scope, and focused lifecycle tests exercise the retained-worker invariant; this review did not execute a live worker environment. Is this the best way to solve the issue? Yes, conditionally: environment-owned process lifetime repairs the producer-side cancellation without deleting cleanup, provided exact-head authority and compatibility checks succeed. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2fd16c2855b8. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Record provider-loss teardown intent before remote stop, prevent pending cleanup from being recovered as an active placement, and preserve exact physical ownership until stop is confirmed. Keep draining state when the provider becomes unavailable. Remove the ownership/lifecycle import cycle and align workspace-retention proof with physical teardown. Exercise missing-capability rejection and reconnect on real Gateway/node wire, preserving scenario and cleanup failures in the harness.
|
Final behavior proof passed on 903568b. An isolated real CLI Gateway and paired node used Redacted live observations{
"commit": "903568b42aad7278dc36546eadf7694b57461be6",
"model": "openai/gpt-5.6-luna",
"runtime": "v26.7.0",
"platform": "darwin",
"phases": [
{
"phase": "start",
"status": "ok"
},
{
"phase": "poll",
"status": "ok"
},
{
"phase": "replace",
"status": "ok"
}
],
"afterFirstTurn": {
"httpStatus": 200,
"serverPid": 11947,
"workerPid": 11183,
"retainedPhysicalWorkers": 1
},
"retainedCapacity": {
"total": 32,
"available": 31
},
"afterSecondTurn": {
"httpStatus": 200,
"sameServerPid": true,
"sameWorkerPid": true
},
"afterThirdTurn": {
"httpStatus": 200,
"replacedServerPid": 59997,
"sameWorkerPid": true
},
"foreignOwnerStop": {
"rejected": true,
"serverReachable": true,
"sameWorkerPid": true
},
"retirement": {
"placement": "local",
"retainedPhysicalWorkers": 0,
"serverReachable": false,
"portalClosed": true
},
"releasedCapacity": {
"total": 32,
"available": 32
}
}All three built-runtime wire scenarios passed: 3/3 tests, 391.22 seconds. They cover real Docker execution/mounts/cleanup without approvals; bundle loss, disconnect, capacity, and node-role revocation; workspace transfer, transcript recovery, and capability negotiation. The missing-capability scenario visibly rejects the turn with update/reconnect guidance before any worker launch, then succeeds after the same node identity reconnects with support. This uses a current supervisor advertising the older capability shape; it is not an older-binary installer/upgrade test. OPENCLAW_DOCKER_NODE_WORKER_E2E=1 OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_WORKERS=1 \
node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts \
test/e2e/qa-lab/runtime/paired-node-worker-lifecycle-wire.e2e.test.ts \
test/e2e/qa-lab/runtime/node-worker-launch-wire.e2e.test.ts \
test/e2e/qa-lab/runtime/node-worker-container-wire.e2e.test.tsThe ClawSweeper rank-up requests for retained reachability, later-turn control, stale-owner denial, exact-owner stop, slot release, and missing-capability reconnect are covered above. The unchanged older-binary installer itself was not exercised. Media below are inspected screenshots from the live run; the connected Chrome tool did not provide continuous video recording. DOM-snapshot inspection timed out, but direct screenshots showed the Control UI updating across all three replies and the portal responding to reloads, then refusing connections after retirement. CI for this exact head is still running. The earlier CI failures were an import cycle, drain-state ordering, and an obsolete turn-completion/physical-exit assumption in a retention test; these were repaired and the focused rerun passed 266 tests. An optional duplicate local run of the broad CI shard was cancelled for runtime after 585.77 seconds, not counted as a pass; the final CI gate remains required. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…0733) * fix(worker): keep background servers alive between turns Retain the supervised worker environment while background execs are live, while recreating turn admission, tools, connections, and authorization for each turn. Keep physical worker ownership separate from bounded turn receipts so cancellation, restart recovery, and environment retirement cannot discard a still-running worker. Preserve process polling across turns, release turn callbacks, join exec finalization before environment cleanup, and require exact worker stop confirmation unless a dedicated provider proves the machine is gone. Fixes openclaw#130450. * fix(worker): fence revoked placements and verify retained lifetimes Record provider-loss teardown intent before remote stop, prevent pending cleanup from being recovered as an active placement, and preserve exact physical ownership until stop is confirmed. Keep draining state when the provider becomes unavailable. Remove the ownership/lifecycle import cycle and align workspace-retention proof with physical teardown. Exercise missing-capability rejection and reconnect on real Gateway/node wire, preserving scenario and cleanup failures in the harness. * test(worker): verify durable startup revocation cleanup




Closes #130450. Follow-up to #130434 and the original portal work in #130105.
What Problem This Solves
Fixes an issue where users opening a development-server portal on a paired-node or node-backed cloud worker would lose the server as soon as the agent finished its reply. The portal survived, but its process did not; a later turn also lost the process handle needed to inspect or stop it.
Why This Change Was Made
Background processes now belong to the worker environment. The supervisor retains the physical worker while background execs remain, but every turn receives fresh admission, tools, credentials, and Gateway connections. Turn cancellation stops foreground work; environment retirement, replacement, node shutdown, and unrecoverable worker failure stop the physical worker and its descendants.
Physical ownership stays in
node_worker_launchesuntil extinction is confirmed. A separate, lazy, boundednode_worker_turnstable records per-turn results without releasing live capacity or losing container recovery ownership. This additive SQLite design was explicitly approved before implementation; there is no schema-version bump, global protocol-version bump, or new operator configuration.Provider loss and node revocation record teardown intent before any fallible remote stop. Recovery cannot adopt that invalid placement, while an unconfirmed physical stop keeps its exact ownership record for cleanup. The same repair removes turn-bound exec callbacks after yield, joins process finalizers before deleting environment state, bounds cancellation even under stdin backpressure, and requires exact worker-stop confirmation on shared hosts. Dedicated provider destruction can prove extinction only for the exact dedicated owner. Codex remote-exec remains a separate execution path and does not acquire the embedded-worker lifetime requirement.
User Impact
A server can keep serving its portal after the reply finishes. Later turns in the same environment can list, poll, send input to, kill, or restart the process. A retained worker occupies one capacity slot and can accept its next turn even when no additional slots are available.
Process handles remain in memory and do not survive worker/node restart. Worker background completion does not yet wake the Gateway session automatically; the documented path is
process poll. Closing a portal closes the proxy, not the server. Matching worker/Gateway build and capability checks remain enforced.Evidence
903568b42aad7278dc36546eadf7694b57461be6: real CLI Gateway/node withopenai/gpt-5.6-luna, three completed turns, retained/restarted server visible in Chrome, non-current owner rejection without stopping the server, exact-owner teardown, and capacity restored from 31/32 to 32/32. Redacted observations and inspected screenshots. The successor32ce1863c3dc37cca22106a5c7bae37c4cf83703changes only one startup test expectation; all production code, docs, protocol, and build inputs are identical to this live-tested head.orphanedafter an unattached provider lease is authoritatively absent; the final test-only correction checks the canonical failed state and durable teardown intent. Final exact-head CI passed on32ce1863c3dc37cca22106a5c7bae37c4cf83703: 129 jobs succeeded, 19 were skipped, and the required gate is green.Production LOC: +2,753/-1,076 (net +1,677); tests/support: +3,519/-788 (net +2,731, including test moves); generated declarations: +14; docs: +34; policy baseline: -3. Pure ownership-helper moves add no capability or net production lines. The production growth adds the previously missing environment lifetime, bounded managed-turn protocol, and separate durable turn/physical-owner contracts. A portal-only guard or a detached shell process would leave process control, capacity, recovery, and authority ownership broken. Existing single-turn standalone CLI behavior is preserved as its public contract; the managed supervisor has one canonical turn flow.
Landed through the native maintainer workflow as e4d602c6f374. Maintainer-tooling follow-up: concurrent fetches in a shared repository twice raced while updating
origin/main, aborting merge verification before the merge. Existing exact-owner lock recovery and a native retry succeeded; no code, CI gate, or review requirement was bypassed. The fetch path should tolerate an already-completed concurrent update.