Skip to content

fix(tests): join terminal persistence fixtures after cancellation - #156197

Merged
vincentkoc merged 4 commits into
mainfrom
fix/session-test-poll-timing
Sep 23, 2026
Merged

vincentkoc merged 4 commits into
mainfrom
fix/session-test-poll-timing

Conversation

@obviyus

@obviyus obviyus commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: cancelled Gateway persistence tests can leave their run claim and subscriptions alive after the test wrapper finishes, contaminating the next case.

User Impact

No runtime behavior change. The terminal-persistence table now finishes its owned cleanup before shared teardown and before the next case reuses the same run ID.

Why This Change Was Made

The original timing repair by @obviyus is now covered by main's direct claim-settlement notification in 897b8e9. This update preserves that notification and its exact-claim, status, warning, and held-writer assertions.

Vitest cancellation aborts the test wrapper without joining a suspended body. The remaining wait now observes the actual test-context signal; the existing fixture lifetime retains the body, and a file hook joins its normal cleanup before shared teardown. Scenario order, assertions, and timeouts are unchanged. Production LOC: 0; tests: +127/-116, including reindent (net +11).

Evidence

Fresh proof for signed candidate eda2268d3b64d6c7be5d7da35d152efc90c2278c, tree e01fa9b173fab0291cf2eca2db59c98bd77b9016, in the focused Linux campaign:

  • Full persistence file: 9 passed; persistence-owner siblings: 13 passed.
  • Same-candidate timing: 47.390 s single-worker wrapper wall time (--maxWorkers=1, nine passes; Vitest file 6.489 s). End/cancellation/settled-failure rows took 608/104/613 ms; the AWS execution recorded 790/100/786 ms. Its test command passed, but the publisher later failed; these timings do not claim gate success.
  • Original CI cohort, preserving all 22 selectors and their order: 22 files / 264 passed with three workers and plan concurrency one. These total 286 normal passing executions.
  • The private control withholds the matching claim notification and uses controlled signal cancellation. Main's baseline exposes exactly the missing body join, rescues cleanup, then passes the untouched same-ID successor. The correction passes both selected cases and proves the file hook waits for the real cleanup tail. The other seven cases are intentionally excluded from each control.
  • Node 24.21.0, pnpm 12.4.0, Vitest 5.0.0, and fs-safe 0.18.2; frozen install, targeted formatting, diff check, independent source review, and fresh autoreview passed.
  • Private control edits were restored; all owned test process groups finished and the one-shot proof box stopped.

This observes controlled cancellation, not a real outer Vitest timeout or a production failure. Required publication gates and exact-head CI remain separate.

Cancellation-control observations
Baseline: expected TERMINAL_PRIVATE_BODY_JOIN_REQUIRED failure, then healthy successor
CLAIM_NOTIFICATION_WITHHELD claimMatches=true owner=clear-requested
WRAPPER_RETURN bodySettled=false notificationCount=1
JOIN_OBSERVED bodySettled=false cleanupEntered=false unsubSettled=false
RETIRED bodySettled=true ownerAbsent=true unsubSettled=true cleanupFinished=true
SUCCESSOR_ENTERED

Correction: both selected cases pass
CLAIM_NOTIFICATION_WITHHELD claimMatches=true owner=clear-requested
WRAPPER_RETURN bodySettled=false notificationCount=1
AFTER_EACH_WAIT bodySettled=false cleanupEntered=true unsubSettled=false
JOIN_OBSERVED bodySettled=true cleanupEntered=true unsubSettled=true
RETIRED bodySettled=true ownerAbsent=true unsubSettled=true cleanupFinished=true
SUCCESSOR_ENTERED

@clawsweeper

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

@obviyus
obviyus marked this pull request as ready for review September 23, 2026 05:04
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed September 23, 2026, 5:37 AM ET / 09:37 UTC (Revision 3).

ClawSweeper review

What this changes

The Gateway persistence tests now observe test cancellation and wait for fixture cleanup before another case reuses the same run ID.

Merge readiness

⛔ Needs changes before merge - 1 item remains

The cancellation cleanup remains useful on current main. The integrated patch addresses the previous review request, preserves the settlement assertions, and has no identified correctness defect.

Priority: P2
Reviewed head: eda2268d3b64d6c7be5d7da35d152efc90c2278c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct fixture repair with discriminating cancellation proof; the remaining follow-up is test-cost reporting.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The exact-head Linux control exercises the changed fixture around real Gateway persistence and claim cleanup: cancellation leaves the baseline body unjoined, while the correction waits for cleanup before the same-ID successor. The embedded trace is sufficient for this test-lifetime change; ordinary passing tests are supplemental. It does not establish an actual outer timeout, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The exact-head Linux control exercises the changed fixture around real Gateway persistence and claim cleanup: cancellation leaves the baseline body unjoined, while the correction waits for cleanup before the same-ID successor. The embedded trace is sufficient for this test-lifetime change; ordinary passing tests are supplemental. It does not establish an actual outer timeout, and no stored-data contract changes.
Evidence reviewed 7 items Introduced change preserves existing assertions: The pinned introduction diff adds the existing fixture-lifetime helper, a file cleanup hook, test-context signal access, and an abort-aware settlement wait. Ignoring indentation confirms that scenario order, exact-claim notification, terminal status, warnings, held-writer assertions, and finally cleanup order remain intact.
Current main still needs cancellation joining: The affected file has the identical blob ea3ae890f3b9a86e9c47208a54b5d353abf69822 at the pinned base and fetched main. Main still awaits clearRequested.promise without the signal race or retained fixture-body join, so its earlier timing repair does not supersede this contribution.
Existing lifetime owner: The fully inspected fixture helper retains body promises, observes late rejection, and joins their settlement during cleanup. The abort helper rejects on cancellation and removes its listener. The retained finally block awaits subscription shutdown before releasing the run claim and deleting temporary state.
Findings None None.
Security None None.

How this fits together

Gateway lifecycle persistence records terminal run outcomes and releases run ownership afterward. These tests hold a database writer to verify that ordering, then retire subscriptions and claims before shared teardown.

flowchart TD
  A[Terminal test scenario] --> B[Held database writer]
  B --> C[Exact claim settlement]
  D[Test cancellation] --> E[Cancellation-aware wait]
  C --> E
  E --> F[Fixture cleanup]
  F --> G[Shared teardown and next case]
Loading

Before merge

  • Complete next step (P2) - Add the already-measured single-worker wall time and available CI case time for the changed persistence file to the PR body.
Agent review details

Security

None.

PR surface

Tests +11. Total +11 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 127 116 +11
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 127 116 +11

Review metrics

None.

Technical review

Best possible solution:

Retain main's exact settlement notification and use the existing fixture lifetime to finish cancellation cleanup before shared teardown.

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

Yes: current main contains the uninterruptible notification wait, and the supplied controlled-cancellation comparison exposes the missing body join and verifies successor isolation. No tests were executed during this read-only review.

Is this the best way to solve the issue?

Yes: the patch reuses the existing cancellation and fixture-lifetime owners without weakening assertions, changing timeouts, or modifying production behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded fixture-lifetime repair that prevents cancelled persistence tests from contaminating subsequent cases.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 exact-head Linux control exercises the changed fixture around real Gateway persistence and claim cleanup: cancellation leaves the baseline body unjoined, while the correction waits for cleanup before the same-ID successor. The embedded trace is sufficient for this test-lifetime change; ordinary passing tests are supplemental. It does not establish an actual outer timeout, and no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The exact-head Linux control exercises the changed fixture around real Gateway persistence and claim cleanup: cancellation leaves the baseline body unjoined, while the correction waits for cleanup before the same-ID successor. The embedded trace is sufficient for this test-lifetime change; ordinary passing tests are supplemental. It does not establish an actual outer timeout, and no stored-data contract changes.

Evidence

What I checked:

  • Introduced change preserves existing assertions: The pinned introduction diff adds the existing fixture-lifetime helper, a file cleanup hook, test-context signal access, and an abort-aware settlement wait. Ignoring indentation confirms that scenario order, exact-claim notification, terminal status, warnings, held-writer assertions, and finally cleanup order remain intact. (src/gateway/session-lifecycle-state.persistence.test.ts:503, eda2268d3b64)
  • Current main still needs cancellation joining: The affected file has the identical blob ea3ae890f3b9a86e9c47208a54b5d353abf69822 at the pinned base and fetched main. Main still awaits clearRequested.promise without the signal race or retained fixture-body join, so its earlier timing repair does not supersede this contribution. (src/gateway/session-lifecycle-state.persistence.test.ts:613, b51ea77c1ece)
  • Existing lifetime owner: The fully inspected fixture helper retains body promises, observes late rejection, and joins their settlement during cleanup. The abort helper rejects on cancellation and removes its listener. The retained finally block awaits subscription shutdown before releasing the run claim and deleting temporary state. (test/helpers/fixture-lifetime.ts:25, eda2268d3b64)
  • Integrated cancellation proof: The captured PR body and maintainer re-review request identify exact head eda2268. Embedded Linux cancellation-control output shows the baseline wrapper returning with an unsettled body, while the correction's file hook joins completed cleanup before the unchanged same-ID successor enters. It also reports 9 focused, 13 sibling, and 264 ordered-cohort passes. This directly exercises the changed fixture lifetime; it does not claim a real outer timeout. The linked campaign log redirected to a host blocked by the review environment, so its full log was not independently inspected. (eda2268d3b64)
  • Earlier review request addressed: The previous review required integrating main's settlement callback and verifying cancellation followed by the original successor. Current source retains onClearRequested and the captured current-head control supplies those observations. Live GitHub metadata confirms the same head remains open and cleanly mergeable; the stale test-merge ref was not used as introduction or removal evidence. (src/gateway/session-lifecycle-state.persistence.test.ts:568, eda2268d3b64)
  • Feature-history routing: Current-main history identifies Peter Steinberger's direct settlement repair and repeated fixture-lifetime maintenance. GitHub commit metadata verifies steipete and the callback patch. Vincent Koc is independently relevant through the explicit maintainer review and assignment. Some deeper local history comparisons failed on unavailable historical blobs; no introduction or regression attribution relies on those failures. (src/gateway/session-lifecycle-state.persistence.test.ts:568, 897b8e9016d6)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Restore the already-measured single-worker wall time and available CI case time for the persistence file to the PR body.

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 (2 earlier review cycles)
  • reviewed 2026-09-23T05:15:30.486Z sha 6d656bd :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-23T07:26:31.420Z sha f0ef7b6 :: blocked before merge. :: none

@vincentkoc

Copy link
Copy Markdown
Member

Reviewed 6d656bddd5cc32b01855c4ed7808b024f8ea66f0: the terminal publication is the correct synchronization boundary, and the original durability assertions should stay.

One cleanup regression needs fixing before landing: the new uncancelled terminalChanged.promise wait can outlive Vitest's timeout wrapper. If publication is missing, the test body remains suspended before its finally, retaining the exclusive worker-terminal-run claim and subscriptions. Shared afterEach does not release those owners, so the next same-ID table case cannot acquire its claim.

The bounded correction is to race this wait with the real test-context signal and retain/join the body through the existing createFixtureLifetime/file afterEach pattern. Keep normal finally cleanup, original case order and all assertions. This is a test-lifetime finding, not a production failure claim. I'll make that maintainer correction here and validate cancellation followed by the original next case, preserving @obviyus's repair.

@obviyus

obviyus commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

The PR body now embeds the inspectable original poll failure followed by the same execution’s terminal publication and verified persisted/owner states, the passing contention output, 20 clean standalone runs with one-worker cost, three clean original local reproduction-group runs, and 58 passing owner-sibling cases. Hosted CI is green at the unchanged exact head. Broader hosted-shard repetitions were outside the explicitly focused validation scope; the original failure reproduced standalone as well as in the local group.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

Retain the terminal owner-claim table body and join its cleanup after cancellation. Race the publication wait against the test signal so a missing event cannot leave the claim owned by an abandoned body.

Preserves the terminal persistence synchronization and contributor history from #156197.
@areslp

areslp commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Extra data point from #148397, whose CI hit exactly this case: checks-node-compact-large-10 failed with expected 'active' to be 'clear-requested' on the settled-failure case (263/264 passed in that shard).

Locally (Apple M1 Pro, no CPU contention) I timed the gap between the persisted status matching and the owner reaching clear-requested:

Case Gap
end → done ~26 ms
cancellation → killed ~26 ms
settled failure → failed 692–751 ms over 6 measurements; ~1.1 s when run alone with -t

Only the failed path is slow. For failed and timeout, persistGatewaySessionLifecycleEvent awaits recordGatewaySessionRunFailure after the status patch commits, and finalizeLifecycleEvent chains the owner clear on that same persistence promise. A probe around that call measured 745 ms and 695 ms, with clear-requested following within 6 ms. End and cancellation write no failure record, so they clear right after the commit.

So contention isn't required: running only the settled-failure case with no load failed 2/2 against the original 1 s vi.waitFor default. Contention just eats the ~300 ms margin a full-file run leaves.

This supports waiting on the terminal publication instead of a deadline. The terminal sessions.changed and the owner clear are both reactions to that persistence promise, and the clear is queued ahead of the test's continuation, so asserting synchronously after await terminalChanged.promise is safe.

The awaited failure record dates from #139439. #156095 moving transcript writes to a worker could plausibly lengthen that step, which fits your hypothesis, but I didn't bisect it. I also haven't timed recordGatewaySessionRunFailure in a running gateway; each case uses a fresh temp store, so part of the cost is likely store initialization.

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Please review current head f0ef7b64539018cbc28f6ccebeb2a26080b75171. The author’s terminal-publication repair is preserved; the maintainer correction abort-races that wait with the real test-context signal and joins the retained fixture body before shared teardown.

The updated PR body separates the author’s 6d656 evidence from the corrected tree’s 985 passing ordinary test executions and the baseline/fixed cancellation controls, including inspectable output and measured standalone/cohort costs. The cancellation control simulates wrapper cancellation; it does not claim an observed outer timeout. Production delta remains zero. Protected AWS build/check publication and required CI are still pending.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 23, 2026
@vincentkoc vincentkoc changed the title fix(tests): await terminal persistence before checking owner release fix(tests): join terminal persistence fixtures after cancellation Sep 23, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Please review exact head eda2268. The main overlap is resolved by retaining its direct exact-claim onClearRequested callback, terminal-status and warning assertions, and original cleanup order. This PR now adds only cancellation-aware waiting and joined fixture-body cleanup.

The rewritten PR body records fresh proof for this integrated tree: 9 focused tests, 13 owner siblings, the original ordered 22-file/264-case cohort, and discriminating baseline/fixed cancellation controls with the unchanged next same-ID case. The control uses a simulated wrapper cancellation signal; it does not claim an observed outer timeout. Source restoration, process cleanup, and native Testbox closure were verified. The earlier review's integration and cancellation-proof requests are addressed; required publication gates and CI remain separate.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper status

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper status:

  • Current PR: 156197
  • Branch: fix/session-test-poll-timing
  • ClawSweeper PR: no
  • Automerge: not-enabled
  • Automerge job: jobs/openclaw/inbox/automerge-openclaw-openclaw-156197.md
  • Merge state: UNKNOWN
  • Checks: SUCCESS:54 SKIPPED:46 NEUTRAL:1

@vincentkoc
vincentkoc merged commit 5b108eb into main Sep 23, 2026
106 of 108 checks passed
@vincentkoc
vincentkoc deleted the fix/session-test-poll-timing branch September 23, 2026 09:39
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
…enclaw#156197)

* fix(tests): await terminal persistence before checking owner release

* style: format terminal event condition

* fix(tests): join terminal persistence fixture cancellation

Retain the terminal owner-claim table body and join its cleanup after cancellation. Race the publication wait against the test signal so a missing event cannot leave the claim owned by an abandoned body.

Preserves the terminal persistence synchronization and contributor history from openclaw#156197.

* fix(tests): join terminal claim fixture cancellation

Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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: M 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.

3 participants