Skip to content

test(worker): chat.abort queued-preview cases fail after the first case on main - #166529

Merged
jalehman merged 2 commits into
mainfrom
fix/worker-chat-abort-warm-executors
Oct 7, 2026
Merged

jalehman merged 2 commits into
mainfrom
fix/worker-chat-abort-warm-executors

Conversation

@jalehman

@jalehman jalehman commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: src/worker/worker.chat-abort.test.ts fails 7 of 8 cases on main (every queued-preview case times out at "worker did not reach the cancellation boundary"), which turns any PR whose changed-scope shard includes it red.

User Impact

User impact: no user-visible change. Unblocks CI for PRs that touch session or memory code.

Why This Change Was Made

Each case captured the runtime config snapshot only after ComposedGatewayHarness.create had already run Gateway session storage work, which pins the ambient test-home config. The case then "restored" that pinned config, so every later case started with it. Since #165993, agent database executors watch the runtime config's store locator: from case 2 on, publishing harness.cfg retired the Gateway's warm executor, the in-process simulated worker reopened the database under its own shared-state directory, and Gateway transcript commits were refused for the rest of the case. The fix captures the snapshot per test before harness creation and restores it in a finally after harness.close(), so a rejected cleanup cannot leak the case's config either. Production code and test expectations are unchanged. A direct push to main under the red-main policy was refused by the repository ruleset ("Changes must be made through a pull request"), so this lands as a PR.

Evidence

  • Bisect with the full file as predicate: first bad commit 1240759624a (perf(state): switching between agents reopens agent database executors on every request #165993); passes 8/8 at dd619529b24.
  • main (a282f8002a3): 7 failed, 1 passed. Running a single later case alone passes, confirming cross-case leakage.
  • With this change on fa420c6eb27: 20/20 consecutive standalone runs of src/worker/worker.chat-abort.test.ts at 8/8; --maxWorkers=1 27.9 s wall (22.1 s Vitest).
  • Original failing shard (checks-node-changed-8 of fix(memory): Knowledge calls fail mid-turn after unrelated session activity #166419: tools.onboarding, tools.optional, openclaw-agent-execution-incognito.sessions, agent-consult-runtime.lineage, worker.chat-abort): 3/3 clean runs, all files passing.
  • Related suites pass: openclaw-agent-execution.idle 15/15, openclaw-agent-db.worker-admission 22/22, worker.fault-injection and worker-fault-injection.cleanup/live-chat 17/17 each, native-worker integration 9 passed / 1 skipped.
  • node scripts/check-changed.mjs --base origin/main: pass.

Follow-ups noted, not in scope: the Gateway trajectory recorder in this harness still resolves storage from the shared process.env the in-process worker overwrites (pre-existing; refused writes are logged and swallowed), and a warm idle executor bound to one shared-state database refuses callers from another until its idle timeout.

🤖 Generated with Claude Code

Each chat.abort case captured the runtime config snapshot only after
ComposedGatewayHarness.create had run Gateway session storage work, which
pins the ambient test-home config through getRuntimeConfig. The case then
"restored" that pinned config, so every later case started with it.

Since #165993, agent database executors watch the runtime config's store
locator. In case 2+, the Gateway executor for the harness agent database
captured the inherited test-home locator, and the case's
setRuntimeConfigSnapshot(harness.cfg) retired it. The in-process simulated
worker had already replaced process.env.OPENCLAW_STATE_DIR, so the Gateway
live-event trajectory recorder reopened that database under the worker's
shared-state database and the executor stayed warm. Gateway transcript
commits were then refused ("belongs to another shared-state database"),
the worker reconnected and retried about a thousand times, and never
reached the provider before the cancellation-boundary timeout.

Capture the snapshot before the harness exists and restore it after
harness.close(), so each case starts from the same state as the first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 7, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 5:08 AM ET / 09:08 UTC (Revision 2).

ClawSweeper review

What this changes

The PR captures runtime configuration before each worker cancellation fixture starts and restores it after cleanup, including when cleanup fails.

Merge readiness

✅ Ready for maintainer review

The prior cleanup finding is resolved, and the required standalone and original-shard validation is recorded. Current main still needs this focused test-isolation repair; no remaining actionable patch defect was found.

Priority: P2
Reviewed head: 7a51c0585bf615053d14fa5768cb03526e069401

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused fixture repair with the prior defect resolved and the repository's repeated-run validation recorded.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed behavior is test-fixture isolation itself: recorded full-file and original-shard runs exercise the actual composed Gateway, local WebSocket client, and session storage across successive cases, with all eight cases passing after the repair. Production cancellation behavior and stored-data contracts are unchanged; tests were not rerun by this reviewer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed behavior is test-fixture isolation itself: recorded full-file and original-shard runs exercise the actual composed Gateway, local WebSocket client, and session storage across successive cases, with all eight cases passing after the repair. Production cancellation behavior and stored-data contracts are unchanged; tests were not rerun by this reviewer.
Evidence reviewed 8 items Introduced change: The pinned merge-base-to-head diff changes only snapshot capture and restoration in the existing cancellation suite; its eight scenarios and assertions remain intact.
Previous finding fixed: The follow-up commit wraps harness.close() in try/finally, ensuring snapshot restoration executes after rejected cleanup. This directly addresses the previous review's concrete finding.
Fixture lifecycle: Harness creation performs session storage work before returning. Cleanup drains connection work, stops services, joins database resources, and removes the fixture. Its sibling cleanup suite explicitly covers resource-retirement rejection.
Findings None None.
Security None None.

How this fits together

Worker cancellation tests connect an in-process worker to a composed Gateway over a real local WebSocket transport. Their runtime configuration determines which session databases the Gateway uses while processing cancellation and settlement.

flowchart TD
 A[Test case begins] --> B[Capture ambient configuration]
 B --> C[Create Gateway fixture]
 C --> D[Exercise worker cancellation]
 D --> E[Close fixture]
 E --> F[Restore configuration on success or failure]
 F --> G[Next independent test case]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +8. Total +8 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 16 8 +8
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 16 8 +8

Review metrics

None.

Technical review

Best possible solution:

Keep each cancellation case isolated through the existing configuration owner while preserving the cancellation and settlement assertions.

Do we have a high-confidence way to reproduce the issue?

Yes: running the complete cancellation file in its existing case order exercises the source-backed leak; the body records seven failures on main and passing standalone later cases. This review inspected the mechanism without executing tests.

Is this the best way to solve the issue?

Yes: moving capture before fixture creation and restoring after cleanup addresses the test-owned leak without changing production behavior or weakening expectations.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5dcf668765de.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed behavior is test-fixture isolation itself: recorded full-file and original-shard runs exercise the actual composed Gateway, local WebSocket client, and session storage across successive cases, with all eight cases passing after the repair. Production cancellation behavior and stored-data contracts are unchanged; tests were not rerun by this reviewer.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed behavior is test-fixture isolation itself: recorded full-file and original-shard runs exercise the actual composed Gateway, local WebSocket client, and session storage across successive cases, with all eight cases passing after the repair. Production cancellation behavior and stored-data contracts are unchanged; tests were not rerun by this reviewer.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs a bounded test-fixture leak affecting changed-scope CI, with no user-visible runtime change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed behavior is test-fixture isolation itself: recorded full-file and original-shard runs exercise the actual composed Gateway, local WebSocket client, and session storage across successive cases, with all eight cases passing after the repair. Production cancellation behavior and stored-data contracts are unchanged; tests were not rerun by this reviewer.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed behavior is test-fixture isolation itself: recorded full-file and original-shard runs exercise the actual composed Gateway, local WebSocket client, and session storage across successive cases, with all eight cases passing after the repair. Production cancellation behavior and stored-data contracts are unchanged; tests were not rerun by this reviewer.

Evidence

What I checked:

  • Introduced change: The pinned merge-base-to-head diff changes only snapshot capture and restoration in the existing cancellation suite; its eight scenarios and assertions remain intact. (src/worker/worker.chat-abort.test.ts:54, 7a51c0585bf6)
  • Previous finding fixed: The follow-up commit wraps harness.close() in try/finally, ensuring snapshot restoration executes after rejected cleanup. This directly addresses the previous review's concrete finding. (src/worker/worker.chat-abort.test.ts:64, 7a51c0585bf6)
  • Fixture lifecycle: Harness creation performs session storage work before returning. Cleanup drains connection work, stops services, joins database resources, and removes the fixture. Its sibling cleanup suite explicitly covers resource-retirement rejection. (src/worker/worker-fault-injection.test-support.ts:209, 7a51c0585bf6)
  • Configuration retirement mechanism: The executor configuration watcher captures the current agent directory and session store locator, then retires the executor when a configuration publication changes either locator. This supports the reported cross-case leakage mechanism without requiring a production change. (src/state/openclaw-agent-execution-config.ts:13, 7a51c0585bf6)
  • Still necessary on main: GitHub contents at the fetched main revision retain capture inside the test body and restoration before harness cleanup. Local Git object retrieval encountered HTTP 403; the read-only GitHub contents endpoint supplied the pinned source instead. (src/worker/worker.chat-abort.test.ts:49, 5dcf668765de)
  • Latest release comparison: The latest supplied release also retains the old harness setup and cleanup ordering; this repair is not already available there. (src/worker/worker.chat-abort.test.ts:48, fc23bc864e45)

Likely related people:

  • Patrick-Erichsen: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jacobtomlinson: 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 (1 earlier review cycle)
  • reviewed 2026-10-07T08:45:53.439Z sha 0f56c82 :: needs changes before merge. :: [P2] Restore runtime config even when harness cleanup rejects

@jalehman

jalehman commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Addressed: the runtime config is now restored in a finally around harness.close(). Evidence in the body: 20/20 standalone runs and 3/3 runs of the original failing shard. @clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 7, 2026
@jalehman
jalehman merged commit 5077ad4 into main Oct 7, 2026
110 of 113 checks passed
@jalehman
jalehman deleted the fix/worker-chat-abort-warm-executors branch October 7, 2026 09:18
@jalehman

jalehman commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…se on main (openclaw#166529)

* test(worker): stop chat.abort cases inheriting a pinned runtime config

Each chat.abort case captured the runtime config snapshot only after
ComposedGatewayHarness.create had run Gateway session storage work, which
pins the ambient test-home config through getRuntimeConfig. The case then
"restored" that pinned config, so every later case started with it.

Since openclaw#165993, agent database executors watch the runtime config's store
locator. In case 2+, the Gateway executor for the harness agent database
captured the inherited test-home locator, and the case's
setRuntimeConfigSnapshot(harness.cfg) retired it. The in-process simulated
worker had already replaced process.env.OPENCLAW_STATE_DIR, so the Gateway
live-event trajectory recorder reopened that database under the worker's
shared-state database and the executor stayed warm. Gateway transcript
commits were then refused ("belongs to another shared-state database"),
the worker reconnected and retried about a thousand times, and never
reached the provider before the cancellation-boundary timeout.

Capture the snapshot before the harness exists and restore it after
harness.close(), so each case starts from the same state as the first.

* test(worker): restore the runtime config even when harness cleanup fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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