Skip to content

fix(state): retire fixture reader validation before removal - #188767

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-session-reader-owner-race-20261030
Oct 30, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-session-reader-owner-race-20261030

Conversation

@steipete

@steipete steipete commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes fixture teardown that can cause intermittent Session reader validation does not match its current physical owner failures in later session-sharing tests. Related: #184243. This is a maintainer-requested investigation and fixture lifecycle repair.

User Impact

No production behavior changes. Tests retire the previous fixture's validation authority before removing its files. Actual owner replacement and revoked-authority checks still fail closed.

Why This Change Was Made

Normal database close intentionally preserves physical validation and its directory observation. The test-state cleanup helper drained native/worker handles but removed the directory without retiring that retained validation. A queued observation of the removed pathname could invalidate a later fixture's receipt when Linux reused the inode. The reader then correctly refused the revoked receipt.

Use the existing root-scoped fixture-retirement owner after the async drain in both fixture cleanup paths. The existing deterministic queued-observation regression now invokes the actual cleanup helper instead of the lower-level retirement API. Runtime disposal and agent removal already revoke validation explicitly; no retry or weaker reader guard is introduced.

Evidence

PR head: eaa44e17fc8d3b2f964834193ec97346ce23b156.

  • The changed regression fails on unchanged main 4d2a9f8bb4c47da0daae7fd820cab33fa450ef7b: the actual cleanup helper leaves the observer active. It passes with the repair, including delivery of the retired observer's queued callback and preservation of the successor receipt.
  • Validation-cache, read-only-scope, and test-state consumer tests: 94 passed. Vitest wall time 115.44 seconds, including transforms; the changed regression's candidate fixture-retirement case took 420 ms.
  • Session-share integration: all 10 cases passed 20 executions each, using --maxWorkers=1 --repeats=19, alongside a bounded CPU/I/O worker (SHA-256 work and repeated 64 KiB synthetic-file overwrites). Host one-minute load 65.9–91.0. Command wall time 454.37 seconds including cold worker preparation. The original paged-title case and both replaced-source refusal cases passed all repetitions.
  • The second cleanup path's session-store-runtime.stats.test.ts consumer passed on the rebased PR head (1 test; 42.15-second Vitest wall including transforms). The final zero-growth regression rerun also passed (2 selected cases).
  • Targeted state test typecheck and pnpm tsgo:test:root: passed. Changed-file oxlint, oxfmt, and diff whitespace checks passed. Test-line ratchet passed with net delta 0 (the inherited tree is 1,042 lines above its ceiling; this patch adds none).
  • Independent subagent review (autoreview route unavailable): fresh-context review of the complete two-file diff and lifecycle/validation/fixture owners found no actionable P0/P1/P2 findings. Autoreview preflight refused the requested provider because it did not match the operator configuration; configuration was not changed. The subsequent test-only import alias is mechanical.
Deterministic lifecycle observation Main Candidate
Removed fixture's watcher after cleanup Still active Retired
Successor receipt after queued old-path callback Revoked in the ordinary-close control Remains live after fixture cleanup
Test-line delta — 0

The original native Bun/Linux timing failure did not recur naturally in the initial baseline run. The regression deterministically proves the fixture-lifecycle defect and its revocation mechanism; it does not claim to exclude every unrelated ownership race.

Runtime production LOC delta: 0. Test cleanup helper: +6 net lines; regression: 0 net lines. CPU/allocation microbenchmarks and whole-Gateway load measurements are not applicable to this harness-only repair. No live server was accessed. No schema, stored format, runtime authorization, or configuration changes.

Retire root-scoped agent validation after draining fixture handles so queued observations of deleted paths cannot revoke a successor fixture after inode reuse. Keep production close and reader authority checks unchanged; exercise the actual cleanup helper in the queued-observation regression.
@clawsweeper

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T22:19:23.501617Z eaa44e1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Retire fixture-owned database validation after draining handles and before removing temporary files.

Example: A removed fixture's queued filesystem observation arrives after a successor fixture reuses its physical database identity.

  • Before: The retained observation can revoke the successor's validation receipt.
  • After: Fixture cleanup retires the old observation, preserving the successor's receipt.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused and source-supported, with useful reported harness coverage; native inode-reuse timing is modeled rather than naturally reproduced.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored fixture repair is outside the ordinary shipped-behavior proof gate; supplied evidence exercises the actual cleanup helper and affected test consumers, with filesystem notification timing injected deterministically.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes · Fix scope: Complete
User problem: Session-sharing tests can fail intermittently when removed fixtures retain physical validation observations.
Reason: The maintainer-directed repair fixes fixture ownership at its existing cleanup boundary and preserves runtime validation behavior.

Merge readiness

✅ Ready for maintainer review

This PR repairs a concrete fixture lifecycle defect using the existing retirement owner; no actionable code or security findings remain, and exact-head CI is still pending.

Priority: P2
Reviewed head: eaa44e17fc8d3b2f964834193ec97346ce23b156

Before merge

None.

Findings

None.

Agent review details

How this fits together

Test-state cleanup drains session work and database handles before deleting fixture directories; validation retirement removes the retained pathname observations that ordinary runtime close deliberately preserves.

flowchart TD
A[Test fixture cleanup] --> B[Drain session work]
B --> C[Close database handles]
C --> D[Retire root validation]
D --> E[Close shared state]
E --> F[Remove fixture files]
Loading

Technical review

Best possible solution:

Use the existing root-scoped retirement operation after asynchronous drainage in both fixture cleanup paths.

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

Source inspection establishes that current-main cleanup drains handles but retains pathname validation; the PR reports deterministic red/green coverage, although the original native timing failure did not recur naturally and no tests were run during this review.

Is this the best way to solve the issue?

This is the smallest complete repair: reuse the existing retirement owner at both removal boundaries and strengthen the existing regression without adding state, retries, or weaker reader checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Root-scoped fixture cleanup keeps the original intent (6788532: Configured session stores must close across the allocated fixture root while unrelated fixtures remain live and shared-state close remains last.)
  • Ordinary close versus fixture retirement regression keeps the original intent (62cb03a: Prove that ordinary close retains physical validation while fixture retirement prevents queued old-path observations from revoking successor proof.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduction and current-main comparison: The introduced patch changes only fixture cleanup and its existing regression; fetched main still lacks both retirement calls. (src/test-utils/session-state-cleanup.ts:57, eaa44e17fc8d)
  • Existing lifecycle owner: The existing test retirement operation closes selected handles, clears root-scoped validation observations, and clears terminal failures; asynchronous ordinary close intentionally does not clear that validation. (src/state/openclaw-agent-db-lifecycle.ts:462, eaa44e17fc8d)
  • Regression reaches the affected cleanup boundary: The existing ordinary-close versus fixture-retirement regression now invokes cleanupSessionStateForTest and delivers the old queued callback after publishing an independent successor receipt. (src/state/openclaw-agent-db-validation-cache.test.ts:141, eaa44e17fc8d)
  • Original lifecycle regression: Commit 62cb03a introduced the queued-observation regression and its distinction between ordinary close and fixture retirement; this PR preserves that contract while moving coverage to the actual cleanup caller. (src/state/openclaw-agent-db-validation-cache.test.ts:127, 62cb03ac7a95)
  • Related observed failure: The merge discussion at fix(plugins): keep admitted turns running during opted-in reloads #184243 (comment) records the intermittent session-share physical-owner validation failure and distinguishes it from plugin reload behavior.
  • Supplied validation and current checks: The full PR body reports a failing-base/passing-fix regression, affected consumer runs, and repeated session-share integration coverage, while explicitly limiting its native-race claim; live checks show three PostgreSQL conformance jobs running and the CI gate pending, with no failed check observed. (eaa44e17fc8d)

PR surface

Tests +6. Total +6 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 10 4 +6
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 10 4 +6

Labels

Label changes:

  • add P2: The repair addresses intermittent test failures from leaked fixture validation without changing production behavior.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The repair addresses intermittent test failures from leaked fixture validation without changing production behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 execution lanes are retired.

Reviewed October 30, 2026, 6:35 PM ET / 22:35 UTC.

@steipete
steipete merged commit 6487823 into main Oct 30, 2026
156 checks passed
@steipete
steipete deleted the steipete/fix-session-reader-owner-race-20261030 branch October 30, 2026 22:43
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…w#188767)

Retire root-scoped agent validation after draining fixture handles so queued observations of deleted paths cannot revoke a successor fixture after inode reuse. Keep production close and reader authority checks unchanged; exercise the actual cleanup helper in the queued-observation regression.
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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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