Skip to content

test(sessions): close SQLite fixtures before cleanup - #113074

Merged
steipete merged 1 commit into
mainfrom
steipete/test-session-db-cleanup
Aug 9, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/test-session-db-cleanup

Conversation

@steipete

@steipete steipete commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session tests removed fixture roots while process-cached agent and shared-state SQLite handles could still own files below those roots. The leaked owners contaminate later tests and can make Windows directory removal fail with EBUSY.

The three surviving original suites remain repaired. The stale fourth original target was deleted from main and stays omitted. A current-main sibling in the entry-freshness suite is repaired under the same invariant.

Why This Change Was Made

Every affected teardown now closes cached agent databases first, closes the shared-state database second, and only then removes tracked fixture roots. The order is required because closing an agent database releases its durable lease through a shared-state write transaction; closing shared state first would let the agent close reopen it.

Temporary roots are registered by their producers and removed through the canonical cleanupTempDirs helper, matching #113342. createFixtureSuite now owns that policy for all of its consumers instead of maintaining a second removal implementation.

The sequential regression opens the real agent and shared-state cache owners, then proves the next test observes both owners closed and the prior root removed.

User Impact

Developers and CI workers get deterministic SQLite fixture teardown without stale cached handles. Production behavior and persisted schemas are unchanged.

The PR is currently blocked from landing because current main fails the core-test typecheck in an unrelated file: src/sessions/user-turn-transcript.test.ts:548 references an undefined createTempDir. This PR does not touch that file, and no gate is bypassed.

Evidence

  • Regression before the ordered close (node scripts/run-vitest.mjs src/config/sessions/session-accessor.test.ts -- -t 'session database teardown boundary'):
    • Test Files 1 failed
    • Tests 1 failed | 1 passed | 105 skipped
    • the next test observed the prior agent cache handle still open
    • [vitest] FAILED (exit 1)
  • Regression after the repair (same command):
    • Test Files 1 passed
    • Tests 2 passed | 105 skipped
    • [test] passed 1 Vitest shard in 4.23s
  • Affected and producer-sibling suites:
    • node scripts/run-vitest.mjs src/config/sessions/ambient-transcript-watermark.test.ts src/config/sessions/entry-freshness.test.ts src/config/sessions/session-accessor.test.ts src/config/sessions/session-registry-maintenance.test.ts src/config/sessions/store.pruning.test.ts
    • Test Files 5 passed
    • Tests 176 passed
    • [test] passed 1 Vitest shard in 32.20s
  • Changed-file gate (node scripts/check-changed.mjs):
  • git diff --check: passed.
  • Codex autoreview on head 1bd736ac6065: clean after one round; no accepted/actionable findings, confidence 0.99.
  • ClawSweeper rank-up moves applied: current-main reconstruction contains only the surviving original targets, the deleted target remains omitted, and focused before/after proof is recorded above.

AI-assisted: yes.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Jul 23, 2026
@steipete
steipete marked this pull request as ready for review July 23, 2026 15:58
@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 1:06 AM ET / 05:06 UTC.

ClawSweeper review

What this changes

The PR closes cached agent and shared SQLite test databases before four session-test fixtures delete their temporary roots.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep open for maintainer handling: the test-cleanup need remains on current main, but the branch is dirty because one target test was removed and the other three were substantially rewritten.

Priority: P3
Reviewed head: 395137ecb81984e37b6bfc7ff77aea73955cb174
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The cleanup is source-supported and focused, but the stale conflict requires current-main reconstruction and fresh validation before it is merge-ready.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied PR evidence records a focused Blacksmith run of 92 tests, and the current item carries the proof-sufficient label.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied PR evidence records a focused Blacksmith run of 92 tests, and the current item carries the proof-sufficient label.
Evidence reviewed 5 items Current teardown gap: Current main still removes the session-accessor fixture root directly after tests; the same pattern remains in the ambient-watermark and registry-maintenance suites.
Lifecycle owner: The agent test helper closes cached handles and clears test latches, while the shared-state helper closes cached shared database handles and its latch.
Existing sibling pattern: Current session lifecycle and conformance tests already close both database caches immediately before removing their temporary roots.
Findings None None.
Security None None.

How this fits together

Session tests create temporary state directories that session accessors back with cached agent and shared SQLite handles. Teardown must release those handles before removing the fixture root so later tests and Windows cleanup remain isolated.

flowchart LR
  A[Session test] --> B[Temporary fixture root]
  B --> C[Cached agent database]
  B --> D[Shared state database]
  C --> E[Teardown closes handles]
  D --> E
  E --> F[Fixture root removal]
Loading

Decision needed

Question Recommendation
Should this protected PR be rebased or replaced with the three surviving teardown changes and fresh focused proof? Adopt the three surviving teardowns: Rebase or replace the branch with only the current ambient, accessor, and registry cleanup calls, then run focused tests.

Why: The maintainer label prevents automated cleanup, and preserving the useful cleanup requires deciding how to adopt it across current-main test rewrites.

Before merge

  • Resolve merge risk (P1) - The current branch is merge-conflicted: it retains a change to a deleted test and predates substantial rewrites of the three surviving test files, so its prior 92-test proof does not cover the required current-main patch.
  • Complete next step (P2) - The protected, dirty branch needs a maintainer-approved current-main rebase or narrow replacement; it is not safe to close or auto-dispatch unchanged.
Agent review details

Security

None.

PR surface

Tests +18. Total +18 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 4 19 1 +18
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 19 1 +18

Review metrics

Metric Value Why it matters
Production versus test LOC production +0/-0; tests +19/-1 The original branch is test-only, so the remaining merge concern is current-main applicability rather than production behavior growth.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/ambient-transcript-watermark.test.ts, serialized state: src/config/sessions/session-accessor.test.ts, serialized state: src/config/sessions/session-registry-maintenance.test.ts, serialized state: src/config/sessions/store.session-key-normalization.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Recreate the two close calls in the three surviving current-main teardowns, omit the deleted normalization test, and rerun the focused suites on the rebased code.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Recreate the two close calls in the three surviving current-main teardowns, omit the deleted normalization test, and rerun the focused suites on the rebased code.

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

Yes, at source level: the three current suites remove fixture roots while cached database close helpers are absent; a focused run after rebasing can exercise the teardown order.

Is this the best way to solve the issue?

No: the four-file stale branch is not the best landing shape because one target was deleted; a three-file current-main patch is the narrowest maintainable repair.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5a1daf81a554.

Labels

Label justifications:

  • P3: This is low-risk test-fixture cleanup with no production behavior change.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied PR evidence records a focused Blacksmith run of 92 tests, and the current item carries the proof-sufficient label.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied PR evidence records a focused Blacksmith run of 92 tests, and the current item carries the proof-sufficient label.

Evidence

What I checked:

Likely related people:

  • steipete: Recent history contains the canonical session-lifecycle and SQLite refactors underlying these tests, and this PR is aligned with that ownership area. (role: recent session and SQLite refactor contributor; confidence: high; commits: ec06118f8331, d894a235e88d, e7950d968b87; files: src/config/sessions/session-accessor.test.ts, src/state/openclaw-agent-db.ts, src/state/openclaw-state-db.ts)
  • vincentkoc: Recent history includes Windows SQLite fixture-release work adjacent to the handle-cleanup invariant. (role: adjacent SQLite test-cleanup contributor; confidence: medium; commits: 48d65f94a13c; files: src/state/openclaw-agent-db.ts)

Rank-up moves

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

  • Rebase or replace the branch with the three surviving teardown changes.
  • Run the focused current-main session suites and post redacted terminal output.

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-07-30T16:24:12.450Z sha 395137e :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T02:42:29.433Z sha 395137e :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 3, 2026
@steipete steipete self-assigned this Aug 9, 2026
@steipete
steipete force-pushed the steipete/test-session-db-cleanup branch from 395137e to 4b27783 Compare August 9, 2026 13:04
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete force-pushed the steipete/test-session-db-cleanup branch from 4b27783 to 1bd736a Compare August 9, 2026 13:25
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 9, 2026
@steipete
steipete force-pushed the steipete/test-session-db-cleanup branch from 1bd736a to ae08601 Compare August 9, 2026 14:12
@steipete
steipete merged commit e9250be into main Aug 9, 2026
117 checks passed
@steipete
steipete deleted the steipete/test-session-db-cleanup branch August 9, 2026 14:29
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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