Skip to content

test(memory-core): release cached databases before removing fixture state dirs - #128310

Merged
steipete merged 2 commits into
openclaw:mainfrom
Yigtwxx:fix/memory-core-windows-teardown-ebusy
Aug 23, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
Yigtwxx:fix/memory-core-windows-teardown-ebusy

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Related: #119796

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where contributors on Windows cannot get a green local run of extensions/memory-core:
eleven suites in the extension-memory shard fail in teardown with EBUSY: resource busy or locked,
never in an assertion. Each fixture removes its temporary state directory while a SQLite handle
opened underneath it is still cached, so the removal fails and the suite is reported as failed even
though every assertion in it passed. On Linux, unlinking an open file succeeds, so CI never sees it.

Error: EBUSY: resource busy or locked, unlink
  'C:\...\Temp\openclaw-session-startup-XXXXXX\state\openclaw.sqlite'
Error: EBUSY: resource busy or locked, unlink
  'C:\...\Temp\openclaw\memory-core-test-fixtures-XXXXXX\openclaw-dreaming-state-32\agents\main\agent\openclaw-agent.sqlite'

The file named varies between the shared state database, the per-agent database and their
-wal / -shm companions, because the removal walks the directory.

Why This Change Was Made

Each fixture now releases the databases it actually leaves open, immediately before the removal,
in the ordering merged for this class in #127201: close the cached per-agent databases first, then
the shared state store.

The order is load-bearing, not decoration. The agent close releases its leases through shared
state, which reopens it, so releasing shared state first only moves the lock from
openclaw-agent.sqlite to state\openclaw.sqlite-wal.

  • src/test-helpers.ts is the shared harness: its afterAll removed the fixture root without
    releasing anything, which is why four suites that never touch a state path of their own
    (dreaming-narrative, dreaming-phases, redaction-product-boundaries, session-backfill)
    failed at suite level. One teardown covers all four.
  • manager-sync-ops.startup-catchup.test.ts and dreaming-startup-cleanup.test.ts already closed
    the agent databases and never released the shared store, so only the store release was added.
  • manager.reindex-recovery.test.ts, manager.fts-only-reindex.test.ts,
    manager.self-heal-missing-identity.test.ts, manager.watcher-config.test.ts and cli.test.ts
    released neither at the removal point, so both calls were added in that order.

Tests only; no production file is touched.

User Impact

Contributors on Windows can run the extensions/memory-core suites to completion instead of reading
teardown failures that have nothing to do with the code under test. Behavior on Linux and macOS is
unchanged.

Evidence

Windows 11, Node 24.18.1. Base arm measured twice on main, at 8e04df0205c (this branch's base)
and again at bca206d794b, with identical results; the branch arm is that same tree with only these
eight files patched.

node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-memory.config.ts \
  --configLoader runner extensions/memory-core
whole extensions/memory-core main with this branch
test files 13 failed / 77 passed (90) 4 failed / 86 passed (90)
tests 47 failed / 1111 passed / 3 skipped 4 failed / 1154 passed / 3 skipped
EBUSY occurrences 50 0
duration 174s 178s

The four remaining failures are pre-existing on main and are not EBUSY: a stale-sqlite-lock
case in short-term-promotion, a watcher glob case in manager.watcher-config, a status-output case
in cli, and a timezone case in index. They are separate Windows defects and this branch does not
touch them.

Both calls are load-bearing. Measured on the five suites that go through the shared harness and the
CLI fixture, same command and same tree, only the teardown mutated:

arm result
main (bca206d794b) 5 files failed, 5 EBUSY
this branch 1 failed / 212 passed, 0 EBUSY (the one failure is the pre-existing cli case)
drop closeOpenClawAgentDatabasesForTest() 5 files failed, 5 EBUSY on openclaw-agent.sqlite
drop resetPluginStateStoreForTests() 4 files failed, 4 EBUSY on openclaw.sqlite

The same mutation pair on the four src/memory/ fixtures that received both calls: dropping the
agent close leaves 6 failed / 7 EBUSY on openclaw-agent.sqlite; dropping the store release leaves
9 failed / 10 EBUSY on openclaw.sqlite.

  • ./node_modules/.bin/tsgo -p test/tsconfig/tsconfig.extensions.test.json --noEmit -> byte-identical
    output to main (the same six pre-existing extensions/acpx errors, none in these files)
  • ./node_modules/.bin/oxlint <the eight files> -> exit 0
  • ./node_modules/.bin/oxfmt --check <the eight files> -> exit 0

One local note that is not a code issue: once the teardown failures stop, the shard goes quiet for
longer than scripts/run-vitest.mjs's 120s no-output watchdog allows, so the branch arm was run with
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=600000. The run itself finishes in the same wall-clock time as
the base arm.

Relationship to the other repairs in this class

Disjoint from every open or merged repair of the same Windows teardown class, so they can land in any
order:

#119809 (merged)  lifecycle fixtures
#126352 (merged)  eight extensions/ files, including extensions/memory-core/doctor-contract-api.test.ts
#127201 (merged)  src/gateway/github-publication.test-support.ts
#127236 (merged)  two extensions/nostr suites
#119964 (open)    three extensions/zalouser/ files
this PR           eight extensions/memory-core files

extensions/memory-core was swept after #127236 landed. doctor-contract-api.test.ts in the same
directory was repaired by #126352, is green on main, and is untouched here; the failures that
remained are the ones whose fixtures release nothing, or release only the agent databases, at the
point where they remove their directory.

…re dirs

Six memory-core fixtures remove their temporary state directory while the
per-agent or shared SQLite handles opened underneath it are still cached, so
Windows fails the removal with EBUSY while Linux unlinks the open files and
stays green.

Release both handles before each removal, in the ordering merged for this
class: the agent close releases its leases through shared state and reopens
it, so the shared store has to be released after it.
@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added the extensions: memory-core Extension: memory-core label Aug 23, 2026
@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 Aug 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 2:43 PM ET / 18:43 UTC.

ClawSweeper review

What this changes

The PR closes cached per-agent and shared SQLite test databases before Memory Core fixtures delete their temporary state directories, preventing Windows EBUSY teardown failures.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it is a focused, test-only repair for current-main fixture cleanup, and no patch defect was found. The ordered calls match the existing SQLite cache contracts and the merged gateway teardown precedent.

Priority: P2
Reviewed head: 7369497ca0c81ba8298a4cb3dbe800927e384d11

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused test-only patch with contract-backed ordering and concrete Windows before/after evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body supplies after-fix native Windows terminal results for the full affected shard plus mutation arms that isolate both cleanup calls; redact any local paths if reposting the evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies after-fix native Windows terminal results for the full affected shard plus mutation arms that isolate both cleanup calls; redact any local paths if reposting the evidence.
Evidence reviewed 6 items Current-main gap: Current main still removes the shared harness fixture directory without either cleanup call; the PR adds the calls immediately before removal, so the work is not already implemented.
Shared-state cleanup contract: The existing test helper closes the plugin-state database and the shared OpenClaw state database unless explicitly told not to.
Agent-cache cleanup contract: Closing cached agent databases closes SQLite/WAL handles, releases their leases through shared state, and clears test isolation state; this supports closing agent handles before the shared database.
Findings None None.
Security None None.

How this fits together

Memory Core tests create temporary OpenClaw state directories containing shared and per-agent SQLite databases. Teardown must release cached handles before removing the directory so Windows can unlink database and WAL files.

flowchart LR
  A[Memory Core test fixture] --> B[Temporary state directory]
  B --> C[Cached agent database]
  B --> D[Cached shared state database]
  C --> E[Ordered handle cleanup]
  D --> E
  E --> F[Remove fixture directory]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +36. Total +44 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 1 +8
Tests 7 36 0 +36
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 45 1 +44

Review metrics

Metric Value Why it matters
Production versus test LOC production 0; tests/test support +45/-1 All changes are in test fixtures and test support; no runtime or persisted-state behavior changes.

Technical review

Best possible solution:

Merge the existing test-only cleanup at the fixture owners, preserving the agent-handle then shared-state-handle order and its focused Windows proof.

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

Yes—source-reproducible: current main deletes fixture roots while the relevant agent and shared-state caches can remain open, and the PR supplies a concrete native-Windows before/after command and mutation evidence.

Is this the best way to solve the issue?

Yes: existing helpers already own agent-cache and shared-state cleanup, and calling them at each directory owner preserves production code while matching the merged ordering precedent.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded contributor test-reliability repair for Windows SQLite teardown failures.
  • 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 (live_output): The PR body supplies after-fix native Windows terminal results for the full affected shard plus mutation arms that isolate both cleanup calls; redact any local paths if reposting the evidence.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix native Windows terminal results for the full affected shard plus mutation arms that isolate both cleanup calls; redact any local paths if reposting the evidence.

Evidence

What I checked:

  • Current-main gap: Current main still removes the shared harness fixture directory without either cleanup call; the PR adds the calls immediately before removal, so the work is not already implemented. (extensions/memory-core/src/test-helpers.ts:213, d91627261791)
  • Shared-state cleanup contract: The existing test helper closes the plugin-state database and the shared OpenClaw state database unless explicitly told not to. (src/plugin-state/plugin-state-store.ts:521, d91627261791)
  • Agent-cache cleanup contract: Closing cached agent databases closes SQLite/WAL handles, releases their leases through shared state, and clears test isolation state; this supports closing agent handles before the shared database. (src/state/openclaw-agent-db.ts:488, d91627261791)
  • Merged ordering precedent: The current gateway publication fixture uses the same agent-close then shared-state-close ordering before recursive deletion, with the same lease-reopen rationale. (src/gateway/github-publication.test-support.ts:352, 60ae513bd9c6)
  • Real behavior proof: The PR body records native Windows before/after runs of the extension-memory shard and mutation arms showing that omitting either cleanup leaves EBUSY failures. (extensions/memory-core/src/test-helpers.ts:219, 7369497ca0c8)
  • Release provenance for precedent: The merged ordering precedent is on current main but is not contained in a local release tag, so it is main-only precedent rather than shipped-release behavior. (60ae513bd9c6)

Likely related people:

  • Yigtwxx: Authored the merged gateway fixture repair that established the same ordered cleanup invariant, in addition to this branch. (role: author of merged sibling teardown precedent; confidence: high; commits: 60ae513bd9c6; files: src/gateway/github-publication.test-support.ts)
  • Eden: Current-main blame attributes the exact Memory Core teardown lines to this recent change; this is routing evidence rather than fault attribution. (role: recent area contributor; confidence: medium; commits: 25f20cbc7fd9; files: extensions/memory-core/src/test-helpers.ts, extensions/memory-core/src/cli.test.ts)

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-08-23T18:00:23.715Z sha 7369497 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 3b1c8f2 into openclaw:main Aug 23, 2026
111 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@Yigtwxx
Yigtwxx deleted the fix/memory-core-windows-teardown-ebusy branch August 23, 2026 21:14
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 24, 2026
…tate dirs (openclaw#128310)

* test(memory-core): release cached state handles before removing fixture dirs

Six memory-core fixtures remove their temporary state directory while the
per-agent or shared SQLite handles opened underneath it are still cached, so
Windows fails the removal with EBUSY while Linux unlinks the open files and
stays green.

Release both handles before each removal, in the ordering merged for this
class: the agent close releases its leases through shared state and reopens
it, so the shared store has to be released after it.

* test(memory-core): release cached handles in the shared fixture harness and cli teardown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core 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.

2 participants