Repository navigation
fix(daemon): retry a transient SQLITE_IOERR owner-lease read after schtasks /End - #159297
chelsealong wants to merge 7 commits into
Conversation
…htasks /End On Windows, schtasks /End kills the Scheduled Task gateway before terminateScheduledTaskGatewayListeners reads its owner lease from the state DB. The dying process can still be unmapping its WAL/SHM files when that read happens, so SQLite's win32 VFS occasionally raises SQLITE_IOERR_TRUNCATE 80-700ms later, which fails the whole gateway restart/stop instead of just needing a short retry. Fixes openclaw#159222
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. Reviewed September 28, 2026, 8:58 PM ET / September 29, 2026, 00:58 UTC (Revision 10). ClawSweeper reviewWhat this changesThis branch retries a transient SQLite owner-lease error during Windows Scheduled Task installer rollback and rechecks caller and update authority before terminating a Gateway process. Regression provenancePossible regression — probable (failure trace; reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 5 items remain The merged Windows lifecycle repair covers the reported stop/restart failure, but this PR retains a distinct installer-rollback fix that current main lacks. The latest head addresses the prior authority finding; proof of recovery after the injected fault and refusal before the native termination effect remains outstanding. Priority: P0 Review scores
Verification
How this fits togetherOpenClaw manages a Windows Gateway through Task Scheduler. During an update rollback, the installer inspects the Gateway's SQLite owner lease before stopping a captured process and restoring the previous task. flowchart LR
A[Update rollback] --> B[Scheduled Task cleanup]
B --> C[Read Gateway owner lease]
C --> D[Retry sharing error]
D --> E[Check current authority]
E --> F[Terminate captured process]
F --> G[Restore previous task]
Before merge
Findings
Agent review detailsSecurityNeeds attention: Source places authority checks before native termination, but the changed awaited path lacks final-effect revocation proof. PR surfaceSource +13, Tests +146. Total +159 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Make installer rollback restore the previous Scheduled Task after a transient lease-read error while ensuring revoked authority prevents either native process termination effect. Do we have a high-confidence way to reproduce the issue? No real current-main Windows rollback reproduction was supplied. Source shows the unretied pre-signal read, and the branch's injected-error regression targets that path. Is this the best way to solve the issue? Yes, reusing the existing bounded Windows lease retry is a narrow repair. The latest synchronous authority checks address the prior finding in source, pending final-effect proof. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against caf777893868. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
…ient SQLITE_IOERR assertOwnerCurrent read the owner lease again right before signaling the Scheduled Task gateway process, without the transient-SQLITE_IOERR retry already added for the initial ownership read, so the same post-/End disk I/O blip (openclaw#159222) could still abort termination at that point.
|
Addressed the P1 merge-risk finding: `assertOwnerCurrent`'s owner-lease read immediately before process termination ( I still can't produce the real Windows Scheduled Task stop/restart trace requested for the "needs proof" item — this sandbox has no Windows host or live Gateway to capture that from. |
|
Added an Update Behavior section to the PR body addressing the "stated update behavior" half of the P1 finding: I still cannot produce the two execution-based asks in this sandbox: it's Linux-only (no |
|
Investigated the CI failure (the trigger for this run): only one job actually failed — The other ~50 checklist entries marked "fail" are cascade cancellations from that single shard, not independent failures: e.g. job 108558355464 ( No code change made — the failure isn't caused by or related to this PR's diff. |
ericcaiwx-star
left a comment
There was a problem hiding this comment.
Reproduced on Windows 11 at head 4880c84c8d03caf123eb194cbb757b13895c5544.
Lane: Windows 11
Command: node --import ./scripts/tsx.mjs scripts/run-with-env.mts CI_WINDOWS_SCHTASKS_INTEGRATION=1 OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_VERBOSE=1 OPENCLAW_VITEST_MAX_WORKERS=1 CI_WINDOWS_SCHTASKS_PROOF_PATH=schtasks-proof-159297.json CI_WINDOWS_SCHTASKS_HEAD=4880c84c8d03caf123eb194cbb757b13895c5544 -- node scripts/run-vitest.mjs src/daemon/schtasks.integration.e2e.test.ts
Result: exit 0, passed 1 Vitest shard in 247.88s
Isolated Scheduled Task on this head: install, schtasks /End, start, then restart. The restart assertions require outcome completed and mutations schtasks-end then schtasks-restart, which is the registered-task path that reads the owner lease after /End. The proof record result is pass. That record does not contain SQLITE_IOERR.
Additional evidence: The author has no Windows host. This is a real Scheduled Task install, schtasks /End, and restart on Windows 11, not the injected-error unit test. It does not cover updater rollback, and this run did not observe the transient I/O error itself.
Sibling surface checked: src/daemon/schtasks-install-files.ts:124.
Not covered: updater restore() in schtasks-install-files.ts, and any run in which SQLITE_IOERR_TRUNCATE actually fired.
|
Added a section to the PR body citing @ericcaiwx-star's real Windows 11 run (exit 0, stop/restart completed via the owner-lease-after- |
|
Added the outstanding P1 item: the changed test file's individual wall time and CI seconds (separate from the combined 3-file suite already reported). Isolated run of The other two P1 items (observed SQLITE_IOERR_TRUNCATE on Windows, and updater-rollback coverage) are unchanged: this sandbox still has no Windows host, and @ericcaiwx-star's real-hardware run already confirmed neither is covered by their pass. No code changed in this update. |
terminateScheduledTaskGatewayListeners's per-pid loop rereads the owner lease immediately before signaling the process, inside terminateGatewayProcessTree's assertCurrent callback. That recheck was not wrapped in the retryScheduledTaskLeaseRead retry that openclaw#159347 added elsewhere, so a transient post-/End SQLITE_IOERR there still aborted callers with no stop context to fall back on -- notably schtasks-install-files.ts's installer rollback restore(), which calls terminateScheduledTaskGatewayListeners(env) directly. Widen terminateGatewayProcessTree's assertCurrent callback to accept an async function and await it, then route this one recheck through the existing retryScheduledTaskLeaseRead helper instead of adding a separate retry policy.
|
Addressed the P2 next step: merged main (bringing in the merged #159347 Windows lifecycle repair) and removed this branch's now-superseded retry code ( That merge closes the initial-lease-read and most pre-termination recheck gaps this PR originally targeted — main already retries those. The one gap it doesn't cover is the pre-signal recheck inside Net diff against main is now +48/-6 across Still can't produce a real Windows after-fault trace for this specific path (no Windows host in this sandbox) — that gap is unchanged from before. |
The pre-signal lease recheck inside terminateGatewayProcessTree's callback can await retryScheduledTaskLeaseRead for up to 15s. Both assertGatewayServiceUpdateCurrent() and the caller's assertCurrent had only run before that wait started, so a revocation during the wait still let taskkill fire on the captured PID. Recheck both immediately after the retry, before the native termination effect.
|
Addressed the P1: revalidate authority after the lease retry before taskkill. Added a regression test ( The two remaining "needs proof" items (a real Windows after-fault SQLITE_IOERR trace, and installer-rollback coverage) are unchanged from before — this sandbox still has no Windows host. |
terminateGatewayProcessTree checked assertGatewayServiceUpdateCurrent() before awaiting the pre-signal callback, then trusted the callback's own internal recheck to be the final gate. The await's resumption is a separate microtask hop after that internal recheck, so a revocation microtask queued during the callback's own settlement could still land before the following synchronous taskkill/killProcessTree call. Move the assertGatewayServiceUpdateCurrent() recheck to run synchronously right after the awaited callback resolves, immediately before each native termination effect, at both the graceful and forced taskkill checkpoints.
|
Addressed the P1: the previous fix rechecked authority at the end of the awaited pre-signal callback, but the callback's Added a regression test ( The two remaining "needs proof" items (a real Windows after-fault SQLITE_IOERR trace, and installer-rollback coverage) are unchanged — this sandbox still has no Windows host. |
|
Pushed a fix for the P1: |
|
This pull request has been automatically marked as stale due to inactivity. |
Closes #159222
What Problem This Solves
On Windows,
openclaw gateway restart/stopfail withError: disk I/O error(SQLITE_IOERR_TRUNCATE) when the Scheduled Task gateway is still unmapping its WAL/SHM files at the moment the CLI reads the owner lease right afterschtasks /End, leaving the gateway stopped.User Impact
User impact:
openclaw gateway restart/stopon a Windows Scheduled Task install now survive a brief post-kill SQLite I/O blip instead of aborting and leaving the gateway offline until a manualschtasks /Run.Why This Change Was Made
stopScheduledTask/restartRegisteredScheduledTaskrunschtasks /End(a hard kill, no graceful shutdown) and then immediately callterminateScheduledTaskGatewayListeners→resolveScheduledTaskGatewayOwnership→readGatewayOwnerLease, which opens a fresh read-only connection to the WAL-mode state DB (src/daemon/schtasks-process.ts). The dying process can still be releasing its SQLite locks and unmappingopenclaw.sqlite-shmwhen that read lands, so Windows' win32 VFS occasionally returnsSQLITE_IOERR_TRUNCATE(errcode 1546) 80–700 ms later — exactly the timing and stack trace reported in the issue.This adds
isSqliteIoErrornext to the existingisSqliteLockError/isSqliteCorruptionErrorclassifiers insrc/infra/sqlite-error-diagnostics.ts(same primary-result-code pattern already used forSQLITE_BUSY/SQLITE_LOCKEDretries elsewhere in the codebase), and wraps just this one lease read in a small bounded retry (readGatewayOwnerLeaseWithTransientRetry, 4 retries at 150 ms) insrc/daemon/schtasks-process.ts. All existing ownership/authority checks (task-supervisor identity, live-process verification, unattributed-owner refusal) are unchanged — only the transient I/O error on this one read is retried; a persistent I/O error still surfaces after the retry budget.Update Behavior
terminateScheduledTaskGatewayListeners(the function whose lease read this PR retries) is not only reached from the CLI stop/restart path above —openclaw update's own Scheduled Task installer calls it too.src/daemon/schtasks-install-files.ts's snapshotrestore()path (line 124) runs/Change /DISABLE,/End, then, if the just-activated replacement task was stillrunning, callsterminateScheduledTaskGatewayListeners(env)before restoring the prior task registration. That is the same post-/Endlease read, on the same timing window, so the same transientSQLITE_IOERR_TRUNCATEcould previously abort an in-progress update rollback with the task left disabled and the old registration unrestored.This is a same-version, in-process reliability fix, not a schema/config migration: it touches no persisted state, needs no version-gated activation marker, and there is no "old parent updater vs. new candidate" split to reason about — the installer's rollback and the CLI's stop/restart both run whichever version's code is currently executing, so the retry applies uniformly the moment this fix ships. A persistent (non-transient) I/O error still surfaces exactly as before, so no failure mode is being newly swallowed.
I could not produce a published-driver × candidate cell for this. The Docker update-survivor lanes in
docs/help/testing-updates-plugins.md(projects-doctor,taskflow-restoration,channel-owner-policy,legacy-operator-state) pin a Linux[email protected]baseline and exercise config/schema/plugin state; none of them installs or replaces a Windows Scheduled Task, so that matrix has no cell that covers this code path, and this sandbox has no Windows host to runschtasks.exedirectly.Evidence
Added a regression test that reproduces the exact failure from the issue:
readGatewayOwnerLeasethrows{ code: "ERR_SQLITE_ERROR", errcode: 1546 }(SQLITE_IOERR_TRUNCATE) once, then succeeds, whileterminateScheduledTaskGatewayListenersruns on a mocked Windows Scheduled Task gateway.Confirmed the test fails without the fix (
git checkout HEAD~1 -- src/daemon/schtasks-process.ts src/infra/sqlite-error-diagnostics.ts, rerun,git checkout HEAD -- ...to restore):With the fix, the full acceptance-criteria suite passes:
Also ran, both clean on the touched files:
pnpm tsgo:core(production typecheck, no errors)npx oxlint src/daemon/schtasks-process.ts src/infra/sqlite-error-diagnostics.ts src/daemon/schtasks-owner-publication.test.ts(no findings)npx oxfmt --checkon the same three files (all correctly formatted)Gap: I could not get the full
pnpm tsgo:test:srcproject-wide test typecheck to finish inside this sandbox's time budget (coldtsgoproject graph build repeatedly ran past 10 minutes); the narrower, targeted checks above cover the actual diff.I also still cannot produce a real Windows Scheduled Task
/End//Runtrace: this sandbox is Linux-only with no Windows host, soschtasks.exeand the real Task Scheduler timing this bug depends on aren't available here. The regression test above reproduces the exact reported error and stack shape by injecting it at the real call site instead.Focused test wall time
Re-ran the full focused acceptance suite on current HEAD (
4880c84c8d0), with wall-clock timing, per repository test-cost policy:Independent Windows verification (reviewer-provided)
@ericcaiwx-star ran this PR's stop/restart path on real Windows 11 hardware and posted the result as a PR review (#159297 (review)):
4880c84c8d03caf123eb194cbb757b13895c5544node --import ./scripts/tsx.mjs scripts/run-with-env.mts CI_WINDOWS_SCHTASKS_INTEGRATION=1 OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_VERBOSE=1 OPENCLAW_VITEST_MAX_WORKERS=1 CI_WINDOWS_SCHTASKS_PROOF_PATH=schtasks-proof-159297.json CI_WINDOWS_SCHTASKS_HEAD=4880c84c8d03caf123eb194cbb757b13895c5544 -- node scripts/run-vitest.mjs src/daemon/schtasks.integration.e2e.test.tsschtasks /End, then restart completed with the registered-task path that reads the owner lease after/End.Per that review, this run did not itself observe
SQLITE_IOERR_TRUNCATEfiring, and it does not cover theschtasks-install-files.tsrestore()updater-rollback path. This sandbox still has no Windows host, so it cannot supply either of those two remaining cells; they're unchanged open gaps from the "Evidence" section above, now independently confirmed rather than assumed.Changed test file — individual wall time and CI seconds
The "Focused test wall time" section above measured the combined 3-file acceptance suite. Per the outstanding ask, here is the changed test file alone.
Local, isolated single-file run (
pnpm test src/daemon/schtasks-owner-publication.test.ts --maxWorkers=1, Node 24.16.0):The six added/changed cases themselves run in 12ms + 6ms + 36ms + 28ms + 7ms + 7ms = 96ms; the remaining ~37s is Vitest/tsgo transform and worker startup shared by any single-file invocation, not test-owned cost — well under the 5s-per-file budget.
CI seconds, from the actual run at this head (
4880c84c8d0, run 36296893094): the file runs inside theagentic-command-supportVitest shard of jobchecks-node-changed-config-compact-large-19. Per that job's log, the six tests pass in 12ms/6ms/36ms/28ms/7ms/7ms, and the shard itself (87 files: 84 passed, 3 skipped) reportsDuration 32.91s. The job's total wall time, including checkout and dependency restore shared by every shard in it, is 5m1s per GitHub Actions.