Repository navigation
perf(worker): deliver replies before workspace reconciliation - #169484
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: needs real behavior proof before merge. What this changesThis PR delivers durable worker replies before workspace reconciliation while retaining settlement custody and delaying follow-up execution. Example: A worker returns "Worker reply" while accepted.txt still contains "before reconciliation".
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 7 items remain Keep this PR open: the approved latency improvement remains absent from main, but both earlier correctness findings remain unresolved. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherThe Gateway worker launcher receives terminal worker receipts, validates committed transcripts, produces reply payloads, and retains placement ownership until workspace settlement finishes. flowchart TD
A[Worker terminal receipt] --> B[Validate durable transcript]
B --> C[Deliver reply]
B --> D[Retained result owner]
D --> E[Reconcile workspace]
E --> F[Publish acceptance and notices]
F --> G[Release claim and admit follow-up]
Technical reviewBest possible solution: Keep early replies while preserving acceptance-before-maintenance ordering, originating-channel warnings, and live result authority. Do we have a high-confidence way to reproduce the issue? Main source establishes the reply barrier, and the changed owner plus its callers establish the remaining defects; no target code or tests were executed during this read-only review. Is this the best way to solve the issue? Separating reply completion from the existing settlement owner is a reasonable approved approach, provided downstream maintenance and warning delivery retain their contracts. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f466872e035b. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: The retained result owner needs final-effect rejection evidence after foreground writer authority closes. EvidenceSecurity concerns:
What I checked:
PR surfaceSource +59, Tests +242, Docs +2. Total +303 across 21 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed October 12, 2026, 2:08 AM ET / 06:08 UTC (Revision 5). |
Keep live-turn collision semantics while waiting for the prior delivered reply to finish workspace settlement. Update recovery fixtures to distinguish reply completion from claim release.
## What Problem This Solves After #169484 delivered worker final replies before workspace reconciliation, session subscribers could observe reconciliation in progress without receiving its later completion. The claim owner installed internal row-change facts on completion, but that notification does not reach the existing WebSocket lifecycle bridge. ## Change Publish the existing placement lifecycle event after an owned closure commits with both the turn claim and pending workspace result cleared. Subscribers receive the settled placement after its facts are installed. Retained recovery fences stay pending; ordinary local-turn receipts are excluded. Production LOC: +9, a bounded correctness fix. Three files change; the archive assertion now includes its response for diagnostics without changing the expected result. The existing owner boundary test proves acceptance stays silent and completion publishes already-cleared claim and result authority. No new RPC, lifecycle state, timer, or polling. ## Evidence Changed-file formatting, type-aware lint, and independent review passed with no actionable P0/P1 findings. `pnpm test src/gateway/worker-environments/placement-store.turn-claim-closure.test.ts --maxWorkers=1` was not run locally under the CI-only host constraint; local test wall time is unavailable. The integrated [CI run 38340516247](https://github.com/openclaw/openclaw/actions/runs/38340516247) at 7be861c selected and passed all four affected E2Es with both production fixes: native-slot 36.141 test seconds, upgrade-wire 158.587, same-session 82.785, and skill-library 41.308. Native A/B claims clear, and all four same-session pairs publish the settled placement. This PR runs the focused owner regression and required static gates independently. The four E2E contract updates are tracked separately in #170537. Release-note context: session subscriptions publish worker workspace settlement after an early final reply. Focused CI run 38341715059 passed all 42 tests in the owner group (21.40 seconds), including the new completion-publication assertion (665 ms), abort and lifecycle closure cases. All selected static gates passed. The prior head had a separate orphaned-provisioning archive failure. Current main passed all 10 archive tests in [probe CI](https://github.com/openclaw/openclaw/actions/runs/38343515030/job/115119831896), so no inherited-failure exception is claimed. This branch is refreshed against that main baseline, and the archive assertion now reports the response if it fails again. Final head 38916dd: [CI 38344022221](https://github.com/openclaw/openclaw/actions/runs/38344022221) passes the archive cases (successful orphan cleanup 2.261s, failing cleanup 2.280s) and all 42 owner-group tests (24.55s, new publication assertion 650ms). The earlier archive failure did not recur after main integration; it is not claimed as inherited proof. The sole remaining static failure is inherited from main #170530: `src/commands/config-preflight-snapshot.test.ts:41` imports `readConfigPreflightSnapshot`, which that main commit made private. The CI checkout is merge 137ab4a7c73d03c5d5cb1f2713e68b966cb3614c (main 33a438a plus this head); neither config file is changed here. Both files are identical to current main: implementation blob afc97b5, test blob b85a1d9. [Exact TS2724 job](https://github.com/openclaw/openclaw/actions/runs/38344022221/job/115121788481). This is recorded for the config owner; landing uses the authorized inherited-static-failure exception. No behavioral failure is waived.
## What Problem This Solves Three selectively run node-worker E2Es assert ordering that #169484 intentionally retired by delivering the durable reply before workspace reconciliation. The skill-library E2E also exposed a retained-transcript regression during its sequential worker flow; its original assertions did not explicitly equate a final reply with settlement. ## User Impact The final diff is test-only. It verifies early replies while preserving claim release, workspace settlement, upgrade recovery, retained-session continuation, and skill-library behavior. ## Change - Native-slot waits on the existing session-change signal, then asserts that the claim and pending result are gone before proving physical-slot reuse. - Upgrade-wire checks its attempted upload after the existing durable recovery observation. - Required-native receives A's final while quiescence is held, preserves the queued-follow-up proof, and waits for B's settled placement. - Skill-library joins workspace settlement before sequential turns; its wire fixture exposes existing events. The updated waits uncovered two production defects: #169622 tied retained transcript facts to a writer that early final releases, and successful claim closure did not reach the existing lifecycle/WebSocket bridge. Those fixes landed separately in #170556 and #170575. Main is now integrated at 38033f1, and the final diff contains only the five test/fixture files. Production LOC: 0. No timers, polling, retries, budgets, or assertion weakening were added. ## Evidence [Integrated CI 38340516247](https://github.com/openclaw/openclaw/actions/runs/38340516247) at 7be861c passed all four E2Es and the required CI gate: | File | Test seconds | Runner seconds | | --- | ---: | ---: | | native-worker-slot | 36.141 | 45.72 | | paired-node-worker-upgrade-wire | 158.587 | 168.53 | | required-native-same-session | 82.785 | 94.17 | | skill-library-worker-wire | 41.308 | 67.21 | [Native/upgrade/same-session log](https://github.com/openclaw/openclaw/actions/runs/38340516247/job/115110480812) shows A and B claims clearing and all four same-session pairs settling on their retained environments. [Skill log](https://github.com/openclaw/openclaw/actions/runs/38340516247/job/115110480823) shows eight remote placements move from reconciling to clear; the complete authoring, continuation, cancellation, and reclaim flow passes. The [unchanged-main probe](https://github.com/openclaw/openclaw/actions/runs/38331787910/job/115083216251) reproduced the original four failures. [Control CI 38339534658](https://github.com/openclaw/openclaw/actions/runs/38339534658/job/115107577910), with only the test alignment and the extra active-run condition removed, still reached a reconciling placement twice and received no further event before the 300-second watchdog. No E2E artifacts were uploaded; the retained Vitest resource was watchdog cleanup evidence, not proof of a product child leak. Changed-file formatting, type-aware lint, and independent review pass with no actionable P0/P1 findings. Local diagnostic command `pnpm test:e2e:gateway test/e2e/qa-lab/runtime/native-worker-slot.e2e.test.ts --maxWorkers=1` took 179.68 seconds before test execution and refused to proceed because artifact separation could not be verified. The guard was preserved; subsequent proof used GitHub CI only, with no leases. The earlier skill local-first rejection with an unsettled database writer remains recorded for the session-actor campaign; this change does not alter that guard. Related credential-diagnostics PR: #170257. Final-head CI 38344788931 has the same inherited main-only TS2724 error as #170575: config-preflight-snapshot.test.ts:41 imports the function made private by main #170530. CI checkout 1e93e8ab merges this head into main 88e5ae8; this test-only PR does not change either config file. [Exact static failure](https://github.com/openclaw/openclaw/actions/runs/38344788931/job/115124083706). The config owner follow-up is recorded; no worker behavior failure is waived. Final test-only head 38033f1 passes all four selected E2Es in CI 38344788931: native-slot 45.28s Vitest / 46.69s runner; upgrade-wire 166.37s / 167.94s; required same-session 100.49s / 102.91s; skill-library 64.35s / 66.24s. Final diff is exactly five test/fixture files and zero production LOC. The only remaining failure is the documented inherited main TS2724 check; landing uses that scoped static-failure exception.
…aw#169484) ## What Problem This Solves Node worker replies waited for workspace synchronization after the final assistant message was already durable, adding hundreds of milliseconds to the visible reply tail. ## User Impact Worker-turn replies now finish before workspace reconciliation. A quick follow-up is accepted into durable custody and starts against the reconciled workspace. Conflicts and reconciliation failures appear as separate transcript notices and through existing placement/recovery state; they do not replace a delivered reply. No new RPC or stored state is added. ## Why This Change Was Made Decision: **Peter, 2026-10-11** — deliver the reply when the worker is terminal and its transcript is durable; reconcile the workspace in the background. The existing turn owner retains execution, the result claim, transcript scope, and recovery handling while delivering the reply separately. Context candidates are recorded before returning; workspace-dependent maintenance still follows acceptance. The old conflict suffix and assistant delta are removed. A completed prior reply joins its existing settlement promise before a follow-up prepares placement state. This prevents a real placement-read invalidation during claim release while preserving live-turn collision and duplicate-run behavior. Production LOC: **+59**, within the approved +80 contract-change allowance. ## Evidence Same-box Hetzner ccx33, OpenAI `gpt-4.1-mini`, two warmups and five measured turns per route and revision. Values are milliseconds: | Path | Request → provider, before → after | TTFT, before → after | Provider terminal → chat final, before → after | |---|---:|---:|---:| | Local | 438 → 381 | 1720 → 1783 | 120 → 118 | | Loopback node | 492 → 1045 | 1741 → 2321 | **412 → 236** | The node reply tail improved **176 ms (42.7%)**, with a flat local control. Requests are sent immediately after the preceding final: the longer next-request admission deliberately includes the remaining prior reconciliation wait. TTFT includes that wait and provider variance; this is a reply-tail improvement, not a throughput or TTFT claim. All final replies and post-final `agent.wait` observations succeeded. - Instrumented census confirms reconciliation finishes after chat final. Remaining node overhead is primarily terminal receipt/journal/transport handoff. Shorter reply-window counts do not imply that all background reconciliation work was deleted. - Boundary proof covers durable early reply, retained result claim, immediate follow-up reading reconciled files, separate conflict notice, failure notice/recovery custody, and Stop/Move behavior. The accepted case fails on original production while reconciliation is held. - New regression command: `pnpm test src/gateway/worker-environments/worker-turn-early-final.test.ts --maxWorkers=1`, 3/3 passed, **55.19 s** local wall time including setup; approximately **8.8 CI seconds** for the three cases in the initial hosted run. Remote runs also passed 111 sibling tests in 589.48 s and the final remaining 60 cases in 391.18 s; overlapping proof is not counted twice. - Final-head [CI run](https://github.com/openclaw/openclaw/actions/runs/38206809322) is green, including required CI, source contracts, core lint, production types, all test type stripes, and runtime tests. Earlier CI caught obsolete settlement assertions, the quick-follow-up read race, and a detached callback receiver-type contract; all are fixed. - Codex autoreview: no actionable P0/P1 findings. Formatting and `git diff --check` pass. No limits, timeouts, or baselines were raised. - dbasync overlap checked: no shared production changes; the shared build-recovery test file has a separate fixture-initialization hunk in openclaw#169432. The optional two-machine measurement could not complete worker installation through the relay, so no remote-node performance claim is made. Release-note context: worker-turn final replies no longer wait for workspace synchronization; queued follow-ups still use the reconciled workspace, and workspace problems remain visible separately.
…170575) ## What Problem This Solves After openclaw#169484 delivered worker final replies before workspace reconciliation, session subscribers could observe reconciliation in progress without receiving its later completion. The claim owner installed internal row-change facts on completion, but that notification does not reach the existing WebSocket lifecycle bridge. ## Change Publish the existing placement lifecycle event after an owned closure commits with both the turn claim and pending workspace result cleared. Subscribers receive the settled placement after its facts are installed. Retained recovery fences stay pending; ordinary local-turn receipts are excluded. Production LOC: +9, a bounded correctness fix. Three files change; the archive assertion now includes its response for diagnostics without changing the expected result. The existing owner boundary test proves acceptance stays silent and completion publishes already-cleared claim and result authority. No new RPC, lifecycle state, timer, or polling. ## Evidence Changed-file formatting, type-aware lint, and independent review passed with no actionable P0/P1 findings. `pnpm test src/gateway/worker-environments/placement-store.turn-claim-closure.test.ts --maxWorkers=1` was not run locally under the CI-only host constraint; local test wall time is unavailable. The integrated [CI run 38340516247](https://github.com/openclaw/openclaw/actions/runs/38340516247) at 7be861c selected and passed all four affected E2Es with both production fixes: native-slot 36.141 test seconds, upgrade-wire 158.587, same-session 82.785, and skill-library 41.308. Native A/B claims clear, and all four same-session pairs publish the settled placement. This PR runs the focused owner regression and required static gates independently. The four E2E contract updates are tracked separately in openclaw#170537. Release-note context: session subscriptions publish worker workspace settlement after an early final reply. Focused CI run 38341715059 passed all 42 tests in the owner group (21.40 seconds), including the new completion-publication assertion (665 ms), abort and lifecycle closure cases. All selected static gates passed. The prior head had a separate orphaned-provisioning archive failure. Current main passed all 10 archive tests in [probe CI](https://github.com/openclaw/openclaw/actions/runs/38343515030/job/115119831896), so no inherited-failure exception is claimed. This branch is refreshed against that main baseline, and the archive assertion now reports the response if it fails again. Final head 38916dd: [CI 38344022221](https://github.com/openclaw/openclaw/actions/runs/38344022221) passes the archive cases (successful orphan cleanup 2.261s, failing cleanup 2.280s) and all 42 owner-group tests (24.55s, new publication assertion 650ms). The earlier archive failure did not recur after main integration; it is not claimed as inherited proof. The sole remaining static failure is inherited from main openclaw#170530: `src/commands/config-preflight-snapshot.test.ts:41` imports `readConfigPreflightSnapshot`, which that main commit made private. The CI checkout is merge 137ab4a7c73d03c5d5cb1f2713e68b966cb3614c (main 33cbbd1 plus this head); neither config file is changed here. Both files are identical to current main: implementation blob afc97b5, test blob b85a1d9. [Exact TS2724 job](https://github.com/openclaw/openclaw/actions/runs/38344022221/job/115121788481). This is recorded for the config owner; landing uses the authorized inherited-static-failure exception. No behavioral failure is waived.
## What Problem This Solves Three selectively run node-worker E2Es assert ordering that openclaw#169484 intentionally retired by delivering the durable reply before workspace reconciliation. The skill-library E2E also exposed a retained-transcript regression during its sequential worker flow; its original assertions did not explicitly equate a final reply with settlement. ## User Impact The final diff is test-only. It verifies early replies while preserving claim release, workspace settlement, upgrade recovery, retained-session continuation, and skill-library behavior. ## Change - Native-slot waits on the existing session-change signal, then asserts that the claim and pending result are gone before proving physical-slot reuse. - Upgrade-wire checks its attempted upload after the existing durable recovery observation. - Required-native receives A's final while quiescence is held, preserves the queued-follow-up proof, and waits for B's settled placement. - Skill-library joins workspace settlement before sequential turns; its wire fixture exposes existing events. The updated waits uncovered two production defects: openclaw#169622 tied retained transcript facts to a writer that early final releases, and successful claim closure did not reach the existing lifecycle/WebSocket bridge. Those fixes landed separately in openclaw#170556 and openclaw#170575. Main is now integrated at 38033f1, and the final diff contains only the five test/fixture files. Production LOC: 0. No timers, polling, retries, budgets, or assertion weakening were added. ## Evidence [Integrated CI 38340516247](https://github.com/openclaw/openclaw/actions/runs/38340516247) at 7be861c passed all four E2Es and the required CI gate: | File | Test seconds | Runner seconds | | --- | ---: | ---: | | native-worker-slot | 36.141 | 45.72 | | paired-node-worker-upgrade-wire | 158.587 | 168.53 | | required-native-same-session | 82.785 | 94.17 | | skill-library-worker-wire | 41.308 | 67.21 | [Native/upgrade/same-session log](https://github.com/openclaw/openclaw/actions/runs/38340516247/job/115110480812) shows A and B claims clearing and all four same-session pairs settling on their retained environments. [Skill log](https://github.com/openclaw/openclaw/actions/runs/38340516247/job/115110480823) shows eight remote placements move from reconciling to clear; the complete authoring, continuation, cancellation, and reclaim flow passes. The [unchanged-main probe](https://github.com/openclaw/openclaw/actions/runs/38331787910/job/115083216251) reproduced the original four failures. [Control CI 38339534658](https://github.com/openclaw/openclaw/actions/runs/38339534658/job/115107577910), with only the test alignment and the extra active-run condition removed, still reached a reconciling placement twice and received no further event before the 300-second watchdog. No E2E artifacts were uploaded; the retained Vitest resource was watchdog cleanup evidence, not proof of a product child leak. Changed-file formatting, type-aware lint, and independent review pass with no actionable P0/P1 findings. Local diagnostic command `pnpm test:e2e:gateway test/e2e/qa-lab/runtime/native-worker-slot.e2e.test.ts --maxWorkers=1` took 179.68 seconds before test execution and refused to proceed because artifact separation could not be verified. The guard was preserved; subsequent proof used GitHub CI only, with no leases. The earlier skill local-first rejection with an unsettled database writer remains recorded for the session-actor campaign; this change does not alter that guard. Related credential-diagnostics PR: openclaw#170257. Final-head CI 38344788931 has the same inherited main-only TS2724 error as openclaw#170575: config-preflight-snapshot.test.ts:41 imports the function made private by main openclaw#170530. CI checkout 1e93e8ab merges this head into main 8526c5b; this test-only PR does not change either config file. [Exact static failure](https://github.com/openclaw/openclaw/actions/runs/38344788931/job/115124083706). The config owner follow-up is recorded; no worker behavior failure is waived. Final test-only head 38033f1 passes all four selected E2Es in CI 38344788931: native-slot 45.28s Vitest / 46.69s runner; upgrade-wire 166.37s / 167.94s; required same-session 100.49s / 102.91s; skill-library 64.35s / 66.24s. Final diff is exactly five test/fixture files and zero production LOC. The only remaining failure is the documented inherited main TS2724 check; landing uses that scoped static-failure exception.
Node-worker owner changes now select 13 keyless process E2Es through an explicit path-to-test mapping. Hourly main retains the complete group in one serial row with a shared build, inside the existing matrix cap. No production code changes. Validation: aggressive planner selects all 13 files for node-launch-adapter changes and none for docs-only changes; hourly plans fit 77/77 hybrid and 76/77 hosted rows. Independent review is clean after enforcing serial execution in the manifest. CI: https://github.com/openclaw/openclaw/actions/runs/38510459970 Related: #169484
Node-worker owner changes now select 13 keyless process E2Es through an explicit path-to-test mapping. Hourly main retains the complete group in one serial row with a shared build, inside the existing matrix cap. No production code changes. Validation: aggressive planner selects all 13 files for node-launch-adapter changes and none for docs-only changes; hourly plans fit 77/77 hybrid and 76/77 hosted rows. Independent review is clean after enforcing serial execution in the manifest. CI: https://github.com/openclaw/openclaw/actions/runs/38510459970 Related: openclaw#169484
What Problem This Solves
Node worker replies waited for workspace synchronization after the final assistant message was already durable, adding hundreds of milliseconds to the visible reply tail.
User Impact
Worker-turn replies now finish before workspace reconciliation. A quick follow-up is accepted into durable custody and starts against the reconciled workspace. Conflicts and reconciliation failures appear as separate transcript notices and through existing placement/recovery state; they do not replace a delivered reply. No new RPC or stored state is added.
Why This Change Was Made
Decision: Peter, 2026-10-11 — deliver the reply when the worker is terminal and its transcript is durable; reconcile the workspace in the background.
The existing turn owner retains execution, the result claim, transcript scope, and recovery handling while delivering the reply separately. Context candidates are recorded before returning; workspace-dependent maintenance still follows acceptance. The old conflict suffix and assistant delta are removed.
A completed prior reply joins its existing settlement promise before a follow-up prepares placement state. This prevents a real placement-read invalidation during claim release while preserving live-turn collision and duplicate-run behavior. Production LOC: +59, within the approved +80 contract-change allowance.
Evidence
Same-box Hetzner ccx33, OpenAI
gpt-4.1-mini, two warmups and five measured turns per route and revision. Values are milliseconds:The node reply tail improved 176 ms (42.7%), with a flat local control. Requests are sent immediately after the preceding final: the longer next-request admission deliberately includes the remaining prior reconciliation wait. TTFT includes that wait and provider variance; this is a reply-tail improvement, not a throughput or TTFT claim. All final replies and post-final
agent.waitobservations succeeded.pnpm test src/gateway/worker-environments/worker-turn-early-final.test.ts --maxWorkers=1, 3/3 passed, 55.19 s local wall time including setup; approximately 8.8 CI seconds for the three cases in the initial hosted run. Remote runs also passed 111 sibling tests in 589.48 s and the final remaining 60 cases in 391.18 s; overlapping proof is not counted twice.git diff --checkpass. No limits, timeouts, or baselines were raised.The optional two-machine measurement could not complete worker installation through the relay, so no remote-node performance claim is made.
Release-note context: worker-turn final replies no longer wait for workspace synchronization; queued follow-ups still use the reconciled workspace, and workspace problems remain visible separately.