Repository navigation
fix(windows): recover Gateway restarts from SQLite sharing errors - #159347
Conversation
|
🦞👀 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 27, 2026, 9:12 PM ET / September 28, 2026, 01:12 UTC (Revision 15). ClawSweeper reviewWhat this changesThe branch changes Windows Scheduled Task Gateway stop and restart to request graceful shutdown, retry transient SQLite lease reads, inspect task settlement, and report recovery, with a new Gateway RPC, Android protocol entry, documentation, and tests. Regression provenancePossible regression — suspected (failure trace). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 13 items remain Keep open. Current main still has the reported Windows restart failure, and the smaller open retry PR has not superseded this work. Three process-authority and result-reporting defects remain on this head, and the installed restart boundary lacks proof. Priority: P0 Review scores
Verification
How this fits togetherThe Windows service driver receives Gateway stop and restart requests from the CLI and service lifecycle. It combines the SQLite owner lease with Windows process and task observations before stopping processes, launching a task, and reporting the outcome. flowchart TD
A[CLI service request] --> B[Windows service driver]
B --> C[SQLite owner lease]
B --> D[Process and task observations]
C --> E[Ownership decision]
D --> E
E --> F[Graceful stop or process termination]
F --> G[Task settlement]
G --> H[Task launch and result]
Decision needed
Why: That choice trades recovery against the risk of activating a changed or already-running task; the PR body's acceptance claim does not independently establish a decision covering this final-effect boundary, and the separate follow-up reserves the broader handoff design for sign-off. Before merge
Findings
Agent review detailsSecurityNeeds attention: The new process-capture path can carry termination authority to an unrelated matching-command process; no dependency or supply-chain change was found. PR surfaceSource +213, Tests +1121, Docs +11, Config 0, Other +1. Total +1346 across 22 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. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: The Windows lifecycle owner should recover a ready Gateway from transient SQLite sharing failures while binding cleanup and activation to the captured task, reporting refusals accurately, and offering an in-product Fix action when recovery cannot complete. Do we have a high-confidence way to reproduce the issue? Yes. The reporter supplied Windows Scheduled Task CLI steps and a captured SQLITE_IOERR_TRUNCATE stack on v2026.9.6; current main has the matching stop-then-lease-read path. This review did not execute the intermittent Windows race. Is this the best way to solve the issue? No. The existing Windows service driver is the right repair owner, but this branch must bind captured children and final task activation to current authority and report a preserved replacement as a refusal. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5cda19987e98. LabelsLabel changes: No label changes. Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (14 earlier review cycles; latest 8 shown)
|
1ca8adb to
071038d
Compare
|
Ask the verified Gateway owner to drain before Task Scheduler termination, wait for task completion, and retry transient Windows lease reads. Preserve restart activation with a warning when post-stop inspection remains unavailable and the port is free. Thanks @eddiekk for the failure traces.
Route Scheduled Task probes independently of CIM observation, retain listeners until their owned process is terminated, and revoke continuation authority at the intended post-End phase. Preserve owner termination and foreign-process protection assertions.
Keep cleanup bound to captured process identities, preserve later replacements, and wait for the Scheduled Task to settle before activation. Record recovery when transient SQLite owner inspection remains locked after confirmed exit.
f80ccea to
8708d59
Compare
…enclaw#159347) * fix(windows): recover Gateway restarts from SQLite sharing errors Ask the verified Gateway owner to drain before Task Scheduler termination, wait for task completion, and retry transient Windows lease reads. Preserve restart activation with a warning when post-stop inspection remains unavailable and the port is free. Thanks @eddiekk for the failure traces. * test(windows): tie stop fixtures to process termination Route Scheduled Task probes independently of CIM observation, retain listeners until their owned process is terminated, and revoke continuation authority at the intended post-End phase. Preserve owner termination and foreign-process protection assertions. * fix(windows): bind restart cleanup and wait for task settlement Keep cleanup bound to captured process identities, preserve later replacements, and wait for the Scheduled Task to settle before activation. Record recovery when transient SQLite owner inspection remains locked after confirmed exit. * fix(windows): preserve captured children and report refused stops * fix(windows): recover restart after unavailable task inspection * fix(android): regenerate gateway stop protocol method
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.
Closes #159222
Reported by @eddiekk. Auto-merge remains enabled.
What Problem This Solves
Fixes Windows Scheduled Task Gateway stop/restart failing with
SQLITE_IOERR_TRUNCATEafter task termination, and failed task inspection leaving restart offline while reporting completion.User Impact
Stop requests graceful shutdown first. Restart retries transient SQLite sharing errors, preserves replacement processes, and waits for task settlement. If settlement inspection stays unavailable after confirmed Gateway exit, it still attempts
/Runand reports restart as unverified. It never reports a completed restart for an owner-change path that skipped activation.Why This Change Was Made
The Windows driver ended the task before reading its SQLite owner lease. The dying process could still hold WAL/SHM handles, and the first I/O error prevented
/Run. The existing lifecycle owner now captures process/start identities before shutdown, retries recognized sharing errors, and records recovery after confirmed exit. Pre-existing matching children are captured together; cleanup never adopts a later replacement.Task settlement returns a closed
settled/replaced/unavailableunion. An observed replacement is preserved and reported as a refusal. Unavailable inspection retries within the existing stop budget, then permits the requested recovery attempt after confirmed exit, with an explicit unverified error. Continued positive Running observations still require settlement or the/Endfallback. Native/Runerrors retain the settlement fact; accepting/Rundoes not claim successor health.The broader activation-authority and successor-preflight redesign remains in follow-up #159729, requiring Peter's design sign-off. Its patch remains in
.local/l1307-fence.patch. Service-specific graceful-RPC credential projection remains a named follow-up.Evidence
users.mergemethod position and appendedgateway.stop.request, updated the existing ordering assertions, and regenerated Kotlin. The full protocol chain passed again. All 14 touched suites / 320 tests passed three times locally, command wall 217.616 s / 77.471 s / 49.323 s. The cold Gateway shard took 165.55 s, with only 1% test time (transform 74%, worker preparation 19%); longest individual case across all runs was 5.587 s. Lifecycle patches are unchanged by the rebase. Fresh direct-route Codex P1 review after the rebase was scoped-clean.gateway.stop.requestis an additive core method in train 2026.9; no protocol version bump is needed. The full local chain passed:pnpm protocol-registry:check && pnpm protocol:gen && pnpm protocol:check:swift && pnpm protocol:gen:kotlin && node --import ./scripts/tsx.mjs scripts/check-protocol-since.mts. The since guard passed (one new core method, zero restored compatibility methods). Generation added the missing Kotlin enum entry; Swift was current and the schema build artifact was regenerated. A fresh direct-route Codex P1 review of the generated-only delta was scoped-clean./Run, and owner changes reported completion without activation. Coverage includes transient retry, persistent unavailability, denied/Run, denied/Endfollowed by unavailable inspection, observed replacement, standalone stop, and no captured owner. Settlement cases are split into their own file by concern.tbx_01m3ja71x3qbkecmzrr33zgk7t: 320 passed three times, wrapper 43.41 s / 30.51 s / 28.90 s. All 128 importer selectors ran: 3,039 passed / 13 skipped, plus E2E preparation 4 passed / 1 Windows-only skip, exit 0. Full remote command 1,291.183 s. Ordinary importers and E2E preparation use separate build preparation.update-command-original-service.test.tsfixture; 126.867 s across 67 cases, unchanged in this PR.node scripts/check-changed.mjs --base origin/main, Testboxtbx_01m3jcw2zfd0q4fcqdg3zts4nd: passed, exit 0, remote command 1,811.469 s after the no-shadow fix. All types, lint, unused-export, line-cap, and runtime guards passed.812235f313934560aba7d28cb9c44f02e33336f6(before the generated-only Kotlin correction), run 36354719773, job108720043497: passed, 321/321 tests, three projects in the declared order; wrapper 123.70 s. The native Windows state probe is included. Longest individual test: 12.597 s.1ea24b2dc36f809ff2113965ef4ca6ba6c1387f9; upstreame9af8ebcde6b25813d2fdb45662fe40dd4452089fixed the unrelated task-registry type error. This PR leaves that test untouched.8708d59347fd035c4cb7a67986ef33e910357c6d.openclaw gateway restartcell. Existing install/update/readiness/stop coverage and a source restart probe do not prove installed CLI preflight. This gap remains explicit in the follow-up.Per-file test time (seconds, summed Vitest cases)
src/gateway/server-methods-list.test.tssrc/gateway/server-methods/restart.test.tssrc/gateway/server-methods/stop.test.tssrc/daemon/schtasks.startup-fallback.test.tssrc/daemon/schtasks.stop.test.tssrc/daemon/schtasks.install.test.tssrc/daemon/schtasks.shutdown.test.tssrc/daemon/schtasks-install-rollback.test.tssrc/daemon/schtasks.settlement.test.tssrc/daemon/schtasks.startup-launch.test.tssrc/daemon/schtasks-owner-publication.test.tssrc/daemon/schtasks.update-autostart.test.tssrc/daemon/schtasks-state-probe.test.tssrc/daemon/schtasks.redirect-stop.test.tsWhole-command wall times are reported above. The Windows stop suite spends 33.0 seconds across 48 cases, primarily serializing production COM queries while virtual time walks the stop budget; these owner-boundary cases cover localized native failures, settlement, and refusal. Tests add no real sleeps, retries, weaker assertions, or skipped regressions.