Skip to content

fix(daemon): retry a transient SQLITE_IOERR owner-lease read after schtasks /End - #159297

Closed
chelsealong wants to merge 7 commits into
openclaw:mainfrom
chelsealong:fix-windows-schtasks-owner-lease-ioerr-retry-159222
Closed

chelsealong wants to merge 7 commits into
openclaw:mainfrom
chelsealong:fix-windows-schtasks-owner-lease-ioerr-retry-159222

Conversation

@chelsealong

@chelsealong chelsealong commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #159222

What Problem This Solves

On Windows, openclaw gateway restart/stop fail with Error: 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 after schtasks /End, leaving the gateway stopped.

User Impact

User impact: openclaw gateway restart/stop on 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 manual schtasks /Run.

Why This Change Was Made

stopScheduledTask/restartRegisteredScheduledTask run schtasks /End (a hard kill, no graceful shutdown) and then immediately call terminateScheduledTaskGatewayListeners → 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 unmapping openclaw.sqlite-shm when that read lands, so Windows' win32 VFS occasionally returns SQLITE_IOERR_TRUNCATE (errcode 1546) 80–700 ms later — exactly the timing and stack trace reported in the issue.

This adds isSqliteIoError next to the existing isSqliteLockError/isSqliteCorruptionError classifiers in src/infra/sqlite-error-diagnostics.ts (same primary-result-code pattern already used for SQLITE_BUSY/SQLITE_LOCKED retries elsewhere in the codebase), and wraps just this one lease read in a small bounded retry (readGatewayOwnerLeaseWithTransientRetry, 4 retries at 150 ms) in src/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 snapshot restore() path (line 124) runs /Change /DISABLE, /End, then, if the just-activated replacement task was still running, calls terminateScheduledTaskGatewayListeners(env) before restoring the prior task registration. That is the same post-/End lease read, on the same timing window, so the same transient SQLITE_IOERR_TRUNCATE could 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 run schtasks.exe directly.

Evidence

Added a regression test that reproduces the exact failure from the issue: readGatewayOwnerLease throws { code: "ERR_SQLITE_ERROR", errcode: 1546 } (SQLITE_IOERR_TRUNCATE) once, then succeeds, while terminateScheduledTaskGatewayListeners runs 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):

FAIL src/daemon/schtasks-owner-publication.test.ts > retries the owner-lease read after a transient SQLITE_IOERR from schtasks /End teardown (#159222)
AssertionError: promise rejected "Error: disk I/O error { …(2) }" instead of resolving
Caused by: Error: disk I/O error
Serialized Error: { code: 'ERR_SQLITE_ERROR', errcode: 1546 }

With the fix, the full acceptance-criteria suite passes:

$ pnpm test src/daemon/schtasks-owner-publication.test.ts src/daemon/schtasks.stop.test.ts src/daemon/schtasks.startup-fallback.test.ts --maxWorkers=1
...
 ✓ |daemon| src/daemon/schtasks-owner-publication.test.ts > retries the owner-lease read after a transient SQLITE_IOERR from schtasks /End teardown (#159222) 10ms
...
 Test Files  3 passed (3)
      Tests  131 passed (131)

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 --check on the same three files (all correctly formatted)

Gap: I could not get the full pnpm tsgo:test:src project-wide test typecheck to finish inside this sandbox's time budget (cold tsgo project 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//Run trace: this sandbox is Linux-only with no Windows host, so schtasks.exe and 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:

$ pnpm test src/daemon/schtasks-owner-publication.test.ts src/daemon/schtasks.stop.test.ts src/daemon/schtasks.startup-fallback.test.ts --maxWorkers=1
...
 Test Files  3 passed (3)
      Tests  132 passed (132)
   Start at  06:23:20
   Duration  45.55s (transform 87%, tests 6%, import 4%, worker 3%, setup 1%)
[test] passed 1 Vitest shard in 49.23s

real  0m49.822s

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)):

  • Head: 4880c84c8d03caf123eb194cbb757b13895c5544
  • 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 — real Scheduled Task install, schtasks /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_TRUNCATE firing, and it does not cover the schtasks-install-files.ts restore() 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):

 Test Files  1 passed (1)
      Tests  6 passed (6)
   Start at  05:28:40
   Duration  37.23s (transform 95%, worker 3%, import 2%, tests 1%)
[test] passed 1 Vitest shard in 40.98s

real  0m41.555s

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 the agentic-command-support Vitest shard of job checks-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) reports Duration 32.91s. The job's total wall time, including checkout and dependency restore shared by every shard in it, is 5m1s per GitHub Actions.

…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
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Sep 27, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

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 review

What this changes

This 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 provenance

Possible 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
Reviewed head: e69db156d1196037ee997ae9da86c5f00b31c4ad

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The repair is focused and the prior code finding is addressed, but the decisive rollback and authority behavior lacks real final-effect proof.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: Authority-chain proof required: An earlier-head Windows 11 run exercised normal Scheduled Task stop/restart, but did not observe SQLITE_IOERR or enter installer restore. Current-head tests inject the error and revocation with mocked lease and native calls; they do not show after-fault rollback recovery or revoked-authority refusal at the production final effect. No stored-data contract changes. A redacted Windows trace or production-path harness can fill this gap; redact private addresses, keys, phone numbers, and endpoints. Updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: An earlier-head Windows 11 run exercised normal Scheduled Task stop/restart, but did not observe SQLITE_IOERR or enter installer restore. Current-head tests inject the error and revocation with mocked lease and native calls; they do not show after-fault rollback recovery or revoked-authority refusal at the production final effect. No stored-data contract changes. A redacted Windows trace or production-path harness can fill this gap; redact private addresses, keys, phone numbers, and endpoints. Updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 8 items Introduced repair: The pinned PR delta adds a retry to the pre-termination lease check and passes a separate caller-authority check to the process termination owner.
Rollback entry point: Installer restore can call listener termination without a stop context after ending the Scheduled Task; an error there precedes restoration of the old registration.
Final authority checks: The latest head checks caller and update authority synchronously after each awaited callback and before both graceful and forced taskkill calls, addressing the previous P1 finding in source.
Findings None None.
Security Needs attention Prove revoked authority prevents native termination: The lease retry can await before taskkill. Current tests mock the native call; a production-path fault harness should show caller or update authority revoked during that wait is rejected before termination.

How this fits together

OpenClaw 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]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: An earlier-head Windows 11 run exercised normal Scheduled Task stop/restart, but did not observe SQLITE_IOERR or enter installer restore. Current-head tests inject the error and revocation with mocked lease and native calls; they do not show after-fault rollback recovery or revoked-authority refusal at the production final effect. No stored-data contract changes. A redacted Windows trace or production-path harness can fill this gap; redact private addresses, keys, phone numbers, and endpoints. Updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security concern: Prove revoked authority prevents native termination - The lease retry can await before taskkill. Current tests mock the native call; a production-path fault harness should show caller or update authority revoked during that wait is rejected before termination.
  • Resolve merge risk (P1) - The current head has no real Windows or production-path fault trace showing installer rollback complete after a transient SQLITE_IOERR at the pre-signal lease read; failure can leave the previous task unrestored.
  • Resolve merge risk (P1) - The new awaited check controls native process termination, but available revocation tests mock native calls; final-effect proof for a revoked caller and update grant on the changed path is still missing.
  • Complete next step (P2) - Provide redacted after-fault installer-rollback and revoked-authority final-effect evidence through a real Windows run or authorized production-path harness before merge.

Findings

  • [medium] Prove revoked authority prevents native termination — src/daemon/schtasks-process.ts:694
Agent review details

Security

Needs attention: Source places authority checks before native termination, but the changed awaited path lacks final-effect revocation proof.

PR surface

Source +13, Tests +146. Total +159 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 20 7 +13
Tests 2 147 1 +146
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 167 8 +159

Review metrics

Metric Value Why it matters
Production versus test growth production +13 net lines; tests +146 net lines The production growth is focused on reusing the existing retry owner and placing authority checks at native effects.

Merge-risk options

Maintainer options:

  1. Prove rollback and final authority (recommended)
    Use a redacted Windows trace or authorized production-path harness to inject the sharing error through installer restore, observe restoration, and show revoked caller and update grants prevent native termination.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P0: A failed Windows update rollback can leave a non-technical user's Gateway offline with Task Scheduler intervention needed to recover.
  • merge-risk: 🚨 availability: The changed rollback path can affect whether the prior Scheduled Task registration and Gateway service return after update failure.
  • merge-risk: 🚨 security-boundary: The new awaited lease retry sits before process termination, so final-effect behavior under revoked authority needs direct proof.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: An earlier-head Windows 11 run exercised normal Scheduled Task stop/restart, but did not observe SQLITE_IOERR or enter installer restore. Current-head tests inject the error and revocation with mocked lease and native calls; they do not show after-fault rollback recovery or revoked-authority refusal at the production final effect. No stored-data contract changes. A redacted Windows trace or production-path harness can fill this gap; redact private addresses, keys, phone numbers, and endpoints. Updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [medium] Prove revoked authority prevents native termination — src/daemon/schtasks-process.ts:694
    The lease retry can await before taskkill. Current tests mock the native call; a production-path fault harness should show caller or update authority revoked during that wait is rejected before termination.
    Confidence: 0.78

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • ericcaiwx-star: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Dallin Romney: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Capture installer-rollback recovery after an injected SQLITE_IOERR through the production Scheduled Task boundary.
  • Show that revoking the caller and update grants during the retry prevents native termination on that same boundary.

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 (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-27T05:27:03.678Z sha 4880c84 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-27T05:50:36.333Z sha 4880c84 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-27T06:30:30.217Z sha 4880c84 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-28T00:47:30.658Z sha 4880c84 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-28T05:40:07.483Z sha 4880c84 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-28T06:29:14.615Z sha 5910d58 :: needs real behavior proof before merge. :: [P1] Revalidate authority after the lease retry before taskkill
  • reviewed 2026-09-28T07:03:44.208Z sha 33f0773 :: needs real behavior proof before merge. :: [P1] Recheck authority after awaiting the callback
  • reviewed 2026-09-28T10:39:46.031Z sha f88f718 :: needs real behavior proof before merge. :: [P1] Recheck caller authority after the callback await

…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.
@chelsealong

Copy link
Copy Markdown
Contributor Author

Addressed the P1 merge-risk finding: `assertOwnerCurrent`'s owner-lease read immediately before process termination (src/daemon/schtasks-process.ts, previously line 283) called readGatewayOwnerLease directly, without the transient-SQLITE_IOERR retry added for the initial ownership read. A transient error there could still abort stop/restart right after /End. It's now routed through the same classify-and-retry logic (factored into src/daemon/schtasks-owner-lease-retry.ts, with a sync variant since this call site runs from a sync assertCurrent callback that can't await). Added a regression test (schtasks-owner-publication.test.ts) that injects the transient error at this exact call site; confirmed it fails without the fix and passes with it. pnpm tsgo:core, oxlint, and oxfmt --check are clean on the touched files, and the full acceptance suite (132 tests) passes.

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.

@chelsealong

Copy link
Copy Markdown
Contributor Author

Added an Update Behavior section to the PR body addressing the "stated update behavior" half of the P1 finding: terminateScheduledTaskGatewayListeners (whose lease read this PR retries) is also called from schtasks-install-files.ts's installer restore() path (line 124) during openclaw update's Scheduled Task rollback — same post-/End lease read, same transient-I/O-error window. It's a same-version in-process fix with no persisted-state or migration impact, so no version-gated activation is needed.

I still cannot produce the two execution-based asks in this sandbox: it's Linux-only (no schtasks.exe/Windows host) for the real /End//Run trace, and separately, the repo's Docker "published-driver × candidate" update-survivor lanes (docs/help/testing-updates-plugins.md) pin a Linux config/schema/plugin baseline and don't install or replace a Windows Scheduled Task at all — there's no cell in that matrix that covers this code path. Said so explicitly in the PR body rather than fabricating either.

@chelsealong

Copy link
Copy Markdown
Contributor Author

Investigated the CI failure (the trigger for this run): only one job actually failed — checks-node-core-test-nondist-shard (shard agentic-control-plane-auth-node, job 108558354184) — on src/gateway/server.auth.hello-order.test.ts > Gateway hello publication > does not publish connect presence after hello write-error and retains disconnect cleanup. That file is untouched by this PR (diff is limited to src/daemon/schtasks-*, src/infra/sqlite-error-diagnostics.ts, src/utils.ts, src/utils/sleep.ts). Re-running it in isolation passed 3/3 (node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server.auth.hello-order.test.ts), consistent with a real-timer WebSocket-ordering race under full-matrix load rather than a regression from this diff.

The other ~50 checklist entries marked "fail" are cascade cancellations from that single shard, not independent failures: e.g. job 108558355464 (checks-node-changed-config-compact-large-37) has GitHub conclusion cancelled, not failure. The ci-gate summary confirms only checks-node-core-test-nondist-shard=failure; every other required job is success or skipped.

No code change made — the failure isn't caused by or related to this PR's diff.

@ericcaiwx-star ericcaiwx-star left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chelsealong

Copy link
Copy Markdown
Contributor Author

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-/End path). That leaves two gaps their review itself flags as uncovered: the schtasks-install-files.ts restore() updater-rollback path, and an actual observed SQLITE_IOERR_TRUNCATE. This sandbox is still Linux-only with no Windows host, so I can't produce either from here.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 28, 2026
@chelsealong

Copy link
Copy Markdown
Contributor Author

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 schtasks-owner-publication.test.ts alone: 6 tests pass in 96ms total, vitest-reported Duration 37.23s (95% transform/startup), real 41.555s. From the actual CI run at this head (run 36296893094), the file executes inside the agentic-command-support shard of job checks-node-changed-config-compact-large-19 (https://github.com/openclaw/openclaw/actions/runs/36296893094/job/108558353986): same 6 tests at 12/6/36/28/7/7ms, shard Duration 32.91s across 87 files, job wall time 5m1s. Added as a new "Changed test file — individual wall time and CI seconds" section in the PR body.

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.
@chelsealong

Copy link
Copy Markdown
Contributor Author

Addressed the P2 next step: merged main (bringing in the merged #159347 Windows lifecycle repair) and removed this branch's now-superseded retry code (schtasks-owner-lease-retry.ts, isSqliteIoError, sleepSync) in favor of main's own retryScheduledTaskLeaseRead/isScheduledTaskSqliteSharingError.

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 terminateGatewayProcessTree's assertCurrent callback when there's no stop context, which is exactly how schtasks-install-files.ts's installer restore() calls terminateScheduledTaskGatewayListeners(env) (line 124) — a transient SQLITE_IOERR_TRUNCATE there still aborted the rollback. Fixed by widening terminateGatewayProcessTree's callback to accept async and routing that one recheck through the existing retryScheduledTaskLeaseRead, instead of a competing retry policy.

Net diff against main is now +48/-6 across schtasks-process.ts and its test. Added a regression test reproducing the exact gap (transient IOERR on the pre-signal recheck with no stop context); confirmed it fails against pre-fix schtasks-process.ts and passes with the fix. Full acceptance suite (schtasks-owner-publication, schtasks.stop, schtasks.startup-fallback, schtasks.shutdown) passes at 145/145, pnpm tsgo:core clean, oxlint/oxfmt --check clean on touched files.

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.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 28, 2026
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.
@chelsealong

Copy link
Copy Markdown
Contributor Author

Addressed the P1: revalidate authority after the lease retry before taskkill. terminateGatewayProcessTree's pre-signal callback (schtasks-process.ts:585-593) checked assertGatewayServiceUpdateCurrent() and the caller's assertCurrent only before retryScheduledTaskLeaseRead, which can wait up to 15s — a revocation during that wait still let taskkill fire. Both are now rechecked immediately after the retry, right before the native termination effect.

Added a regression test (schtasks-owner-publication.test.ts, "refuses taskkill when authority is revoked while the pre-signal lease retry is waiting (#159297)") that revokes authority mid-retry and asserts taskkill is never invoked; confirmed it fails without the fix and passes with it. Full acceptance suite (124 tests across the 3 touched files) passes, pnpm tsgo:core, oxlint, and oxfmt --check are clean on the touched files.

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.
@chelsealong

Copy link
Copy Markdown
Contributor Author

Addressed the P1: the previous fix rechecked authority at the end of the awaited pre-signal callback, but the callback's await resumption in terminateGatewayProcessTree is itself a separate microtask hop, so a revocation microtask queued during the callback's settlement could still land before the following synchronous taskkill. Moved assertGatewayServiceUpdateCurrent() to run synchronously right after await assertCurrent?.() resolves, immediately before each native termination effect (both the graceful and forced taskkill checkpoints in terminateGatewayProcessTree, src/daemon/schtasks-process.ts).

Added a regression test (service-stop-fence.test.ts, "refuses graceful taskkill when update authority is revoked between the awaited callback and the effect (#159297)") that queues a revocation via queueMicrotask from inside the awaited callback, simulating a revocation landing in exactly that gap; confirmed it fails without this fix (taskkill fires) and passes with it. Full acceptance suite (133 tests across the 4 touched files) passes, pnpm tsgo:core, oxlint, and oxfmt --check are clean on the touched files.

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.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 28, 2026
@chelsealong

Copy link
Copy Markdown
Contributor Author

Pushed a fix for the P1: terminateGatewayProcessTree now takes a synchronous caller-authority check and runs it, together with the update-authority check, right after the callback await and before both taskkill effects (src/daemon/schtasks-process.ts). service-stop-fence.test.ts gets a case where the caller grant is revoked in the gap after the callback settles, and taskkill is not spawned. The fence, owner-publication and stop suites pass locally (63 tests). I still have no Windows host, so there is no new Windows trace of the after-fault rollback; that part of the proof request is unchanged.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Sep 29, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

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

Labels

gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

2 participants