Skip to content

fix(daemon): keep schtasks SQLite lease-read retry deadline monotonic across clock jumps - #183002

Merged
steipete merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/schtasks-sqlite-lease-read-deadline-monotonic-182
Oct 26, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/schtasks-sqlite-lease-read-deadline-monotonic-182

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Windows Gateway stop and restart can abandon a recoverable SQLite lease read early, or keep retrying too long, when the system clock changes during transient database contention.

User Impact

The existing 15-second lease-read retry window now measures elapsed time across system-clock corrections. Successful reads still return immediately, and other errors retain their existing handling.

Why This Change Was Made

Use performance.now() consistently for the retry deadline and remaining wait. The stop test fixture now advances the same elapsed clock as its simulated sleeps. Two focused regressions replace the longer test scaffolding: recovery after a forward clock step and expiry after a backward step.

Thanks to @SunnyShu0925 for the original fix and Windows proof. The contributor's commits are preserved.

Evidence

  • Red → green: both clock-step cases fail with the old Date.now() implementation. 69 tests pass across the retry, Scheduled Task settlement, and stop suites on the fix.
  • Contributor-supplied Windows CLI and real SQLite contention comparison passed. With a +20-second clock step, the old CLI exited at about 15.46 seconds; the fix retained the approximately 24.30-second total command duration seen in the no-jump control. These totals include work outside the 15-second retry window.
  • Targeted oxlint and oxfmt pass. Production LOC delta: 0; tests: +54; documentation: +2. The new cases took 38 ms of test time; the cold three-file run took 217.73 seconds including compilation. Independent review reported no actionable findings at P2. Exact-head CI run 40245568761 passed, including openclaw/ci-gate. ClawSweeper reported zero findings on the final head.
  • Native Windows Scheduled Task/SQLite integration was not rerun on this Mac; local proof uses the production retry owner and existing lifecycle fixtures.

@clawsweeper

clawsweeper Bot commented Oct 24, 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 Oct 24, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/schtasks-sqlite-lease-read-deadline-monotonic-182 branch 2 times, most recently from d8a5585 to df94549 Compare October 24, 2026 23:16
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 24, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/schtasks-sqlite-lease-read-deadline-monotonic-182 branch from df94549 to ab3ec83 Compare October 24, 2026 23:28
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR measures Windows Scheduled Task SQLite lease-read retries with a monotonic clock.

Example: The wall clock advances 20 seconds during transient SQLite contention.

  • Before: The next failed lease read can exhaust the 15-second retry budget prematurely.
  • After: Retries retain their elapsed-time budget despite the clock correction.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused correction with shipped Windows CLI evidence, distinct clock-step regressions, and no actionable findings; exact-head CI is still running.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The contributor's Windows CLI comparison exercises the production SQLite retry path through daemon stop --force with real database contention and an injected forward wall-clock step; the recorded fixed duration matches the no-jump control. The production clock change is unchanged from the previously reviewed head. Workflow and probe source were inspected; downloading raw logs was blocked by this review environment, which does not invalidate the supplied evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Windows Gateway stop or restart can give up early or retry too long when the wall clock changes during SQLite contention.
Reason: The patch restores the existing elapsed-time budget without adding configuration, changing recovery policy, or introducing another owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a concrete retry-budget defect still present on current main, with no actionable patch findings.

Priority: P2
Reviewed head: c55c0e92d408f5ab837bfdae87912ca28e9b3eff

Before merge

None.

Findings

None.

Agent review details

How this fits together

Windows service control reads and revalidates Gateway ownership through the SQLite retry helper before proceeding with stop or restart.

flowchart TD
  A[Gateway stop or restart] --> B[Scheduled Task control]
  B --> C[Gateway ownership inspection]
  C --> D[SQLite lease retry]
  D --> E[Lease read succeeds]
  D --> F[Retry budget expires]
  E --> G[Continue lifecycle checks]
  F --> H[Existing error handling]
Loading

Technical review

Best possible solution:

Land the existing focused clock replacement once the required checks pass.

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

Current-main source directly exposes the clock-domain mismatch, supported by the contributor's Windows CLI comparison and reported red-to-green clock-step regressions.

Is this the best way to solve the issue?

Replacing the three clock reads in the existing retry owner is the smallest complete fix; the two regressions protect distinct premature-expiry and prolonged-retry failures.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 65f59b8b80bf.

Provenance checked

  • Scheduled Task SQLite sharing-error retries keeps the original intent (5232aba: Recover transient SQLite sharing errors during Windows Gateway lifecycle control while preserving replacement processes.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Focused introduced change: The introduced patch replaces all three retry-budget clock reads with performance.now(), adds forward-step recovery and backward-step expiry regressions, and aligns the existing simulated-sleep fixture. (src/daemon/schtasks-sqlite.ts:14, c55c0e92d408)
  • Current-main defect: Fetched main still seeds, checks, and subtracts the retry deadline using Date.now(), making the budget sensitive to wall-clock corrections. (src/daemon/schtasks-sqlite.ts:14, 65f59b8b80bf)
  • Original retry intent: The retry owner was introduced by merged fix(windows): recover Gateway restarts from SQLite sharing errors #159347 to recover transient Windows SQLite sharing errors; this patch preserves that recovery policy and its existing budget. (src/daemon/schtasks-sqlite.ts:13, 5232aba0030e)
  • Distinct related work: Open fix(daemon): keep scheduled-task fallback waits on the monotonic clock #182859 changes takeover-evidence and fallback-runtime waits in schtasks-runtime.ts; it does not repair the SQLite lease-read retry owner. (src/daemon/schtasks-runtime.ts, 16adf281f47f)
  • Windows shipped-command evidence: The linked completed Windows run exercises daemon stop --force against a real Scheduled Task and sibling SQLite exclusive lock, comparing unchanged and advanced wall clocks before and after reverting the retry clock. The PR records approximately 15.46 seconds before versus 24.30 seconds after, matching the no-jump control; these are whole-command durations. Probe source was inspected, but raw log download was blocked by the environment's host allowlist. (.github/workflows/shipped-contrast-183002.yml, fef330c50deb)
  • Review policy and inspection limits: Root and applicable docs AGENTS.md guidance were read and applied, including simplification and behavioral-test guidance; no maintainer-notes directory exists. Follow-history traversal encountered an unavailable historical object, while the retry introduction and current-main blame were independently verified. No target code or tests were executed, and the checkout remained clean. (AGENTS.md, c55c0e92d408)

Likely related people:

  • Peter Steinberger: Raw commit 5232aba adds src/daemon/schtasks-sqlite.ts:13 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5232aba0030e; files: src/daemon/schtasks-sqlite.ts)

PR surface

Source 0, Tests +54, Docs +2. Total +56 across 4 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 2 54 0 +54
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 59 3 +56

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Clock corrections during Windows SQLite contention can prematurely abandon recovery or prolong service-control retries.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-24T23:44:29.332Z sha ab3ec83209cf94416c2bd161d33910ddd70d743a :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-25T00:44:58.761Z sha c8d1234 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-25T05:28:29.254Z sha c8d1234 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-25T06:20:53.407Z sha c8d1234 :: needs maintainer review before merge. :: none

Reviewed October 25, 2026, 7:42 PM ET / 23:42 UTC (Revision 5).

@SunnyShu0925
SunnyShu0925 force-pushed the fix/schtasks-sqlite-lease-read-deadline-monotonic-182 branch from ab3ec83 to c8d1234 Compare October 25, 2026 00:25
@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 25, 2026
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 25, 2026
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 25, 2026
Measure the Scheduled Task SQLite retry budget with the monotonic clock.
Cover recovery and expiry across wall-clock steps, and keep the stop
fixtures' elapsed-time clock aligned with their simulated sleeps.

Co-authored-by: SunnyShu <0668000539@local>
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 25, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@steipete
steipete merged commit db6fc29 into openclaw:main Oct 26, 2026
130 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…nic clock (openclaw#183002)

Use the existing monotonic clock for the Windows ownership-lease read retry budget so system-clock corrections cannot prematurely abort recovery or extend the wait.

Preserve retry classification and service authority checks, align the stop fixture's elapsed clock, and cover forward and backward wall-clock corrections. The focused retry, settlement, and stop suites pass; exact-head CI passed.

Co-authored-by: SunnyShu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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