Repository navigation
fix(test): zalo lifecycle suites fail Windows teardown with EBUSY on agent state DB - #119809
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 6, 2026, 10:38 AM ET / 14:38 UTC. ClawSweeper reviewWhat this changesThis PR makes Zalo and Zalo-user lifecycle test fixtures close cached per-agent SQLite databases before deleting temporary state directories, and adds regressions for handle release and environment-restore ordering. Merge readinessKeep open: current main still has the faulty teardown order, while this PR applies the established lifecycle fix with exact-head native Windows proof and focused regressions. No actionable patch finding was found. Priority: P2 Review scores
Verification
How this fits togetherZalo and Zalo-user integration tests create temporary OpenClaw state while processing inbound channel events. Those events can open cached per-agent SQLite handles, which the fixture must close before removing the state directory on Windows. flowchart LR
Test[Channel lifecycle test] --> Fixture[Temporary state fixture]
Fixture --> AgentDb[Cached per-agent database]
Fixture --> SharedDb[Shared state database]
AgentDb --> Close[Close agent then shared handles]
SharedDb --> Close
Close --> Cleanup[Remove temporary state directory]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +16, Tests +61. Total +77 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Land this narrow fixture-owner repair, while keeping the remaining disjoint Zalo-user fixtures in #119964. Do we have a high-confidence way to reproduce the issue? Yes—current main retains the same close-shared-then-remove path, and the supplied native Windows before/after run plus the clear source path provide a high-confidence reproduction route. Is this the best way to solve the issue? Yes—the patch repairs the fixture lifecycle owner rather than relying on removal retries, follows the merged canonical ordering, and covers the Zalo-user environment-ordering sibling. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f5add8197fa9. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
I filed the Windows measurement behind #119796, so I ran this branch on the box that surfaces the defect. Windows 11, Node 24.15.0, source checkout, four arms, all run by me via 1. The fix does work on Windows
That covers the "Not verified: an actual Windows run (no Windows box here)" line in the body. 2. The agent-DB close carries the fix, not the retry budgetThe diff changes two things at once, and only one of them matters. At head I commented out just the two
Retry-only reproduces the exact stall I reported on the issue, so the retry half of the diff is hygiene, not the repair. Worth stating in the body, because it is the half that reads like the fix. 3. The sibling check does not hold — zalouser is affected, through the same handleThe body says zalouser "ingress tests only exercise the queue mechanics (
The base and head columns are identical, so this is inherited and not introduced here — same finding shape as my note on #110803. But it is the sibling half of the very defect this PR closes, and the error path names the per-agent DB under zalouser's own fixture directory: The claim is right for two of the three files: This is also the item ClawSweeper left open on the issue ("sibling Zalouser coverage needs resolution before this issue can be considered fixed"), so it is measured either way now. The analogous change is three lines, and it is exactly what produced the --- a/extensions/zalouser/src/ingress.test-support.ts
+++ b/extensions/zalouser/src/ingress.test-support.ts
@@ -5,6 +5,7 @@ import {
closeOpenClawStateDatabaseForTest,
createChannelIngressQueueForTests,
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
+import { closeOpenClawAgentDatabasesForTest } from "openclaw/plugin-sdk/sqlite-runtime-testing";
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
import { expect, vi } from "vitest";
import type { createZalouserIngressMonitor } from "./ingress.js";
@@ -80,8 +81,9 @@ export async function withZalouserIngressTestQueue<T>(
} else {
process.env.OPENCLAW_STATE_DIR = previousStateDir;
}
+ closeOpenClawAgentDatabasesForTest();
closeOpenClawStateDatabaseForTest();
- await fs.rm(stateDir, { recursive: true, force: true });
+ await fs.rm(stateDir, { recursive: true, force: true, maxRetries: 20, retryDelay: 25 });
}
}Whether that lands here or as a follow-up is your call — the scope argument for keeping this PR zalo-only is reasonable. The one thing to avoid is landing the zalo half while the body records the sibling as clean; if you keep it out of scope, narrowing that paragraph to " Scope of what I did not check: I only ran the zalo project config. I did not sweep the other channel fixtures for the same close-shared-then- Raw terminal output (native Windows 11, Node 24.15.0, exact head
|
|
@clawsweeper re-review Update on the two open items, head
The PR body is updated accordingly: the sibling paragraph now records the measured zalouser state, and it states explicitly that the |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…tate env (openclaw#119796) ClawSweeper re-review finding: the ingress fixture restored OPENCLAW_STATE_DIR before closing cached per-agent databases, so lease release could open a shared-state write against the parent fixture env. Move both closes ahead of the env restore (canonical fixture order) and add a nested-environment regression asserting the parent state dir stays untouched.
|
@clawsweeper re-review Addressed the P2 finding on the new head
Proof: new regression passes; full |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
My earlier proof was taken at head 1. The current head still holds
Per file:
Both files this revision adds pass natively: 2. The new ordering change is load-bearingI mutated only the teardown order in So the new test pins the close-before-restore order itself, not just the shape of the file. 3. What is still red on this head is not this PR'sThe 16 survivors sit in three files this PR does not touch, and they are the same EBUSY teardown class: That one is literally the handle this PR closes: the fixture calls
With those three, the whole shard goes green on Windows: 54 passed (54) files, 451 passed (451) tests. None of that is a blocker here — this PR fixes its own fixtures and regresses nothing. It just means #119796 is not fully closed by this PR alone; the three siblings above are a separate follow-up. |
|
Follow-up for the three sibling fixtures from my previous comment is open as #119964, so this PR does not need to grow. It touches only |
|
Merged via squash.
|
…agent state DB (openclaw#119809) * fix(test): close zalo agent state databases before lifecycle temp-dir removal (openclaw#119796) * fix(test): close zalouser agent state databases before ingress temp-dir removal (openclaw#119796) * fix(test): close zalouser fixture databases before restoring parent state env (openclaw#119796) ClawSweeper re-review finding: the ingress fixture restored OPENCLAW_STATE_DIR before closing cached per-agent databases, so lease release could open a shared-state write against the parent fixture env. Move both closes ahead of the env restore (canonical fixture order) and add a nested-environment regression asserting the parent state dir stays untouched.
Related: #119796
This PR covers the lifecycle fixtures. The remaining credential, quote-metadata, and doctor fixtures are handled by #119964, so #119796 stays open until both land.
What Problem This Solves
Fixes an issue where contributors running the Zalo extension test suites on a Windows checkout would see 9 of 26
monitor.polling-lifecycle.test.tscases fail in teardown withEBUSY: resource busy or locked, unlink '...\agents\main\agent\openclaw-agent.sqlite', cascading through every later hook in the file. Surfaced by @Yigtwxx while reviewing #110803 (measurement); Linux CI never sees it because unlinking an open file succeeds there.Why This Change Was Made
A fully processed inbound update opens the per-agent state database through the real session accessor inside the inbound envelope builder (
resolveChannelInboundRouteEnvelope→readSessionUpdatedAt→openOpenClawAgentDatabase), which caches the handle process-wide. The Zalo lifecycle teardown only closed the shared state database beforefs.rm, leaving the agent DB handle (and WAL sidecars) live — a live handle, not a slow release, sofs.rmretries alone cannot help.The fix mirrors the canonical fixture pattern from #113316 (
src/test-utils/openclaw-test-state.ts): close cached agent databases via the existingcloseOpenClawAgentDatabasesForTest()(already exported throughopenclaw/plugin-sdk/sqlite-runtime-testingand used by telegram/signal/whatsapp/matrix/slack tests) before closing shared state — agent close releases leases through shared state, so the reverse order can reopen it — and gives the temp-dir removal the same retry budget as the canonical fixture. Test-only change; no production code touched.User Impact
No end-user impact. Developers on Windows can now run the Zalo polling lifecycle/webhook suites to green locally; #110803's polling-ingress proof file (which amplifies the leak to 25/26 failures) becomes runnable on Windows once it lands on this base.
Evidence
Reproduced the leak cross-platform and verified the fix, on
6e4d387fed(currentmain), Node 24.18.0:monitor-mocks-test-support.test.tsopens the per-agent DB the same way the envelope builder does, then assertsresetLifecycleTestState()releases the handle. Without the fix it fails (handle.db.isOpenstilltrueafter teardown); with the fix it passes — the exact handle leak that Windows surfaces as EBUSY, observable on any OS.extensions/zalouseruses the same close-shared-then-rmpattern.ingress.test.tsandmonitor.account-scope.test.tsexercise queue mechanics only and are clean, butmonitor.group-gating.test.tsasserts on fully built dispatch context (ctx.WasMentioned,ctx.InboundHistory) — the envelope-builder path — and leaks the same handle: 18/26 cases failed with EBUSY on both6e4d387fedand the previous head. The same three-line teardown fix inextensions/zalouser/src/ingress.test-support.tsturns all three files green (42/42) on Windows, and is included in this PR.9 failed / 38 passed→ head48 passed (48). A mutation run commenting out only the twocloseOpenClawAgentDatabasesForTest()calls while keeping the retry budget reproduces the original stall, confirming the agent-DB close carries the fix and themaxRetries/retryDelaybump is hygiene matching the canonical fixture, not the repair.Punchcard-Session: calm-willow-river-a9