Skip to content

test(workers): reuse service readers and stabilize transcript fencing - #168806

Merged
steipete merged 2 commits into
mainfrom
test/node-worker-service-reader-reuse
Oct 11, 2026
Merged

steipete merged 2 commits into
mainfrom
test/node-worker-service-reader-reuse

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Worker environment service tests repeatedly tear down and reload shared SQLite reader threads. The transcript-fence regression also waited for ledger reservation rather than the queued writer, making its result timing-dependent.

User Impact

No user-visible behavior changes. The same service, storage, recovery, and authority tests run with less fixture overhead and deterministic queued-write coverage.

Why This Change Was Made

Use the existing path-scoped database close after each test, then close the reader pool after the suite. Each case still drains its accepted work, invalidates admission, closes native handles, and removes its own state directory. Only reader thread code survives between cases. Explicit full-close/reopen tests remain intact.

Remove the fixture switch and its redundant opt-ins. All 59 consumers were checked for additional database roots, module resets, and process-lifecycle expectations.

The transcript test now observes the real transcript worker store’s queued run() call before replacing its claim, and joins the pending commit during cleanup. Every existing assertion and the held writer remain intact.

Production LOC: +0 / −0. Seven test/support files, +53 / −32. No timeout, assertion, retry, or production seam changes.

Evidence

On one Linux AWS Crabbox lease (cbx_8d4dd0798673, Node 24), after warming compiled declarations, the same command ran the same 102 assertions before and after:

pnpm test src/gateway/worker-environments/provider-provisioning.test.ts src/gateway/worker-environments/provider-reconciliation.test.ts src/gateway/worker-environments/service-lifetime.test.ts --maxWorkers=1 --reporter=json
Metric Before After Change
Command wall time 210.729 s 142.960 s −67.769 s (−32.16%)
Sum of file test time 178.970 s 110.805 s −38.09%
Tests 102 passed 102 passed unchanged

Remote comparison. All 59 consumer files / 710 tests pass. The transcript file passes before and after the ordering fix (44.620 s → 45.647 s; no speed claim for that fix); all 20 standalone runs and all three original four-file shard runs pass without retries. Standalone total: 916.598 s (45.558–46.220 s each); shard walls: 45.146 / 45.502 / 45.190 s.

Formatting, typechecks, lint and all changed guards pass except the dead-export scan. Running that exact scan on the original base independently reproduces the identical 29 findings (28 UI exports and GatewayApprovalEventPublisherV2). No baseline or guard was weakened. Original-base qualification.

The first PR CI run exposed the transcript fixture’s earlier gate; the repair above addresses that ordering. Both independent Codex P0/P1 reviews are scoped-clean. The repair CI run passes, including openclaw/ci-gate: 440 s elapsed CI wall time, with 1,270 summed job-seconds across seven Node test jobs. These CI figures cover the selected PR jobs; they are not the three-file benchmark above.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Oct 11, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR reuses SQLite reader threads across worker-service tests and synchronizes transcript-fencing coverage with the queued writer.

Example: The transcript test replaces a worker claim while sequence 1 waits behind a held writer.

  • Before: It waits for ledger reservation, which does not establish that the transcript writer is queued.
  • After: It observes the real transcript worker's run call before replacing the claim.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Harness evidence supports the optimization, but the retained teardown defect blocks merge.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-directed test-only change requires no shipped-entry-point media; reported benchmarks and repeated harness runs support the optimization, while exact-head CI is independently verified.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Contributors wait for worker-service tests that repeatedly reload SQLite readers, and transcript-fencing coverage depends on timing.
Reason: The maintainer-directed change extends an established fixture optimization and preserves meaningful storage and publication assertions.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: the fixture optimization is useful, but the previously reported session-worker cleanup defect remains unfixed.

Priority: P3
Reviewed head: f921b95623e42e1b1e5cf79e9c53c307a929394b

Before merge

  • Drain case-owned session workers before deleting their directory (P2) - The earlier cleanup finding remains unfixed. The first live ACK describe block calls recoveredTurn(), which writes a session beneath testState.root without the fixture environment. Its executor captures the default shared-state identity, so its asynchronous cleanup callback skips the different identity passed here. Completed writes can retain a native executor generation, and closeOpenClawStateDatabaseForTest() does not await its retirement. Consequently, afterEach removes the case directory while its session executor remains alive, leaving handles and worker state across cases. Await cleanupSessionStateForTest({ stateDir: testState.root }) before fs.rm, retaining exact-path cleanup for explicit reopening.

Findings

  • [P2] Drain case-owned session workers before deleting their directory — src/gateway/worker-environments/service.test-support.ts:195-196
Agent review details

How this fits together

The shared test fixture creates temporary worker-service databases, exercises service and transcript operations, and closes case resources before deleting their directories.

flowchart TD
A[Test case] --> B[Service fixture]
B --> C[Worker service]
C --> D[Shared state database]
C --> E[Session database executor]
B --> F[Case cleanup]
F --> G[Directory removal]
B --> H[Suite reader shutdown]
Loading

Technical review

Best possible solution:

Drain root-scoped session resources before removing each case directory while preserving exact-path reopening and suite-level reader shutdown.

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

Source inspection establishes the teardown defect through the live ACK session write, executor identity selection, and retained native lifetime; no target code was run during this read-only review.

Is this the best way to solve the issue?

Shared-fixture reader reuse and observing the actual queued writer are appropriate, provided teardown closes every session resource beneath the case root.

Full review comments:

  • [P2] Drain case-owned session workers before deleting their directory — src/gateway/worker-environments/service.test-support.ts:195-196
    The earlier cleanup finding remains unfixed. The first live ACK describe block calls recoveredTurn(), which writes a session beneath testState.root without the fixture environment. Its executor captures the default shared-state identity, so its asynchronous cleanup callback skips the different identity passed here. Completed writes can retain a native executor generation, and closeOpenClawStateDatabaseForTest() does not await its retirement. Consequently, afterEach removes the case directory while its session executor remains alive, leaving handles and worker state across cases. Await cleanupSessionStateForTest({ stateDir: testState.root }) before fs.rm, retaining exact-path cleanup for explicit reopening.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4a7d53616a5d.

Provenance checked

  • Worker-service reader reuse keeps the original intent (24150a2: Retain prepared readers while preserving fresh case databases and complete resource cleanup.)
  • Transcript-fencing synchronization keeps the original intent (85c64c2: Prove queued transcript writes cannot persist or publish after live turn ownership changes; later worker offloading changed the asynchronous boundary.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/worker-environments/worker-turn-rpc.live-ack.test.ts src/test-utils/session-state-cleanup.test.ts --maxWorkers=1
  • pnpm test src/gateway/worker-environments/worker-turn-rpc.transcript.test.ts --maxWorkers=1
  • pnpm test src/gateway/worker-environments/provider-provisioning.test.ts src/gateway/worker-environments/provider-reconciliation.test.ts src/gateway/worker-environments/service-lifetime.test.ts --maxWorkers=1
  • git diff --check

What I checked:

PR surface

Tests +21. Total +21 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 7 53 32 +21
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 53 32 +21

Review metrics

Metric Value Why it matters
Production versus test changes Production +0/-0; tests and support +53/-32 The synchronization observes a real worker operation without adding production seams or removing behavioral assertions.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is an internal test-cost and determinism improvement without shipped behavior changes.
  • merge-risk: 🚨 automation: The changed teardown can delete case directories while session executors remain alive, weakening CI isolation despite passing assertions.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-11T01:49:47.689Z sha 511ecb6 :: needs changes before merge. :: [P2] Drain case-owned session workers before deleting their directory
  • reviewed 2026-10-11T01:57:01.387Z sha 511ecb6 :: needs changes before merge. :: [P2] Drain case-owned session workers before deleting their directory
  • reviewed 2026-10-11T03:31:12.260Z sha f921b95 :: needs changes before merge. :: [P2] Drain case-owned session workers before deleting their directory

Reviewed October 10, 2026, 11:51 PM ET / October 11, 2026, 03:51 UTC (Revision 4).

@steipete
steipete marked this pull request as ready for review October 11, 2026 01:52
@steipete steipete changed the title test(workers): reuse reader threads across service cases test(workers): reuse service readers and stabilize transcript fencing Oct 11, 2026
@steipete
steipete merged commit b6f0b64 into main Oct 11, 2026
131 checks passed
@steipete
steipete deleted the test/node-worker-service-reader-reuse branch October 11, 2026 04:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor Author

Follow-up: verify root-scoped session-worker retirement before the service fixture removes its directory. The reader-reuse cleanup drains the shared-state database path; the review identifies a live-ACK fixture that can retain a session executor bound to a different shared-state identity. The 59-consumer pass does not prove handle retirement. Track the proposed root-scoped session cleanup with the existing work in #158658, or a focused follow-up; no production behavior changed here.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…openclaw#168806)

* test(workers): reuse reader threads across service cases

* test(workers): wait for queued transcript writes before fencing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant