Skip to content

fix(cron): pause the setup watchdog during session persistence - #184460

Closed
HeMiaolin wants to merge 3 commits into
openclaw:mainfrom
HeMiaolin:fix/cron-setup-watchdog-storage-184429
Closed

HeMiaolin wants to merge 3 commits into
openclaw:mainfrom
HeMiaolin:fix/cron-setup-watchdog-storage-184429

Conversation

@HeMiaolin

@HeMiaolin HeMiaolin commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

An isolated cron run can be recorded as failed even though only the session-row write was slow. Setup waits for persistSessionEntry(), but the 60 s setup watchdog keeps counting that storage time and aborts before the runner starts; the write then completes and setup finishes after the deadline, leaving a failed occurrence for work that never ran.

This change reports the pre-run write as a new session-persistence wait. The setup watchdog pauses while that write is in flight and restarts with a fresh setup budget when it completes. The pause is bounded by the existing CRON_AGENT_SETUP_WATCHDOG_MS; a write that stalls for the whole budget still times out, so a hung cron slot cannot stay paused indefinitely.

Controller-admission waits are deliberately untouched. The existing session-preparation signal keeps its original behavior (pause the setup watchdog for the session turn, with lane-wait attribution), and a separate stage now distinguishes actual persistence from admission.

Why This Change Was Made

withCronSessionPreparation already emits stage: "session-preparation" while waiting for the session turn, and that contract must keep pausing setup indefinitely while the session is busy. Reusing that stage for storage would cap admission waits at 60 s, so this revision adds a distinct session-persistence stage:

  • The isolated runner wraps persistSessionEntry() with waiting: true/false and stage: "session-persistence".
  • The shared-session replay path wraps prepareSessionEventTargetForHost() the same way.
  • applyCronWatchdogWaitSignal() routes session-persistence to notePersistenceWait() / notePersistenceResumed() and leaves every other signal on the existing lane-admission path.
  • The persistence timer uses the same 60 s budget. Resuming clears it and starts a fresh setup budget; firing marks the existing setup timeout.

Cancellation is unchanged: the abort signal still governs the run, and the fix never revives a run after a timeout.

Scope note: this addresses the reported storage-accounting path. It does not add a configurable timeout or a general post-deadline revival path; a write that exceeds the bounded budget still fails with the existing setup-timeout message.

User Impact

Scheduled automation no longer reports a false setup failure when a slow volume makes the session-row write outlast the deadline but preparation completes normally. Operators keep a bounded failure mode for genuinely hung storage. Controller admission, lane waits, cancellation, and command jobs keep their existing behavior.

Evidence

Running Gateway proof from this PR head: a dev Gateway with a real isolated agentTurn cron job, real session/agent SQLite, and a local OpenAI-compatible endpoint returning PROOF_OK. Storage latency was injected at pwrite64 with a local LD_PRELOAD shim (5 s on the state DB, then the agent-DB session write) to emulate the reported slow volume.

Scenario Observed
Total setup 61.7 s, session-entry.patch 57.3 s status: ok, summary: PROOF_OK
Total setup 60.2 s, session-entry.patch 65.3 s failed: cron: isolated agent setup timed out before runner start; no execution

Why this is the reported case: with a 5 s pre-write stall, the 57.3 s session write is still in flight when the former 60 s setup deadline expires. The fix pauses the setup timer for that write and restarts it, so the occurrence executes; a write that exceeds the bounded allowance still fails.

Raw observed lines:

success: status=ok completionStatus=succeeded durationMs=61716 summary=PROOF_OK
success: session-entry.patch elapsedMs=57303 queueWaitMs=0 writerExecutionMs=57302
bounded: status=error completionStatus=failed durationMs=60240
bounded: error="cron: isolated agent setup timed out before runner start"
bounded: session-entry.patch elapsedMs=65305 queueWaitMs=0 writerExecutionMs=65305

Watchdog/router real-timer matrix (60 s budget): admission wait 65 s -> fired: 0; persistence write 37 s -> fired: 0; persistence write 65 s -> fired: 1.

Regression tests (pre-fix failure confirmed by reverting production files, then re-applied): 21 passed across src/cron/service/command-timeout.test.ts and src/cron/isolated-agent/run.session-lane.test.ts, including the busy-admission and bounded-persistence routing cases. timer-job-runner.interruption.test.ts (6) and agent-runner-execution-session-events.test.ts (17) also pass; tsc, oxlint, and oxfmt are clean for the changed files.

What was not tested: operator cancellation during persistence through a Gateway cancel RPC (none is exposed). That path is unchanged and covered by timer-job-runner.interruption.test.ts; the model endpoint was a local mock, while persistence, the watchdog, cron admission, and settlement were real.

AI Assistance

This PR is AI-assisted. Used git diff, rg, and node --import tsx to analyze issue #184429, locate the setup watchdog accounting in src/cron/service/agent-watchdog.ts, and implement the bounded persistence pause. The implementer understands the code: admission waits and persistence waits are separate stages, persistence is bounded by the existing setup budget, and cancellation is unchanged. All evidence above is from real local runtime execution.

Isolated cron setup counts the session-row write against the 60 s setup
watchdog, so a slow storage commit can fail a run whose setup finishes
moments later. Report the pre-run write as a session-preparation pause so
the watchdog gives storage its own bounded budget.

The pause is capped by the existing setup budget, and lane-wait
attribution stays untouched, so a hung write still times out and
cancellation remains authoritative.

Related to openclaw#184429
@clawsweeper

clawsweeper Bot commented Oct 26, 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.

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR gives pre-run session persistence a bounded 60-second allowance and restarts the setup watchdog afterward.

Example: An isolated automation takes 61.7 seconds overall, including a 57.3-second session write.

  • Before: The 60-second setup watchdog aborts before agent execution.
  • After: The supplied Gateway logs show successful execution and settlement with summary PROOF_OK.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Production-path storage proof resolves the earlier proof gap; the patch appears correct, with one low-value test and an outstanding timeout-policy decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied head-specific Gateway logs exercise real cron admission, SQLite persistence, agent dispatch, and recorded settlement under injected storage latency, showing successful completion beyond the former setup deadline and bounded failure for an overlong write; the model endpoint was local and mocked.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: Scheduled agent work can be marked failed before execution when session persistence consumes the setup deadline.
Reason: The storage-accounting repair has demonstrated value, but extending the existing setup timing contract requires owner direction.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it addresses a current storage-accounting failure without an identified correctness defect, but the new timeout policy needs an owner decision.

Priority: P2
Reviewed head: 22680e14171b2079563ff632bb6eff286d838448
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should pre-run session storage receive a separate 60-second allowance followed by a fresh 60-second setup budget?
  • Recommendation: Approve the bounded storage allowance: Accept this focused accounting change while retaining finite storage failure and irreversible cancellation.
  • Why: This changes the setup timing contract built by the area owner, and neither this PR nor its linked issue contains human maintainer approval of that policy.

Before merge

  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Tests

  • Low-value test src/cron/isolated-agent/run.session-lane.test.ts: Remove or replace the added signal-shape test: it asserts callback pairs without delaying persistence or observing watchdog behavior, so it can pass while the original timeout remains broken.
Agent review details

How this fits together

The cron service supervises scheduled agent preparation, receives admission and persistence signals, and records execution or timeout outcomes.

flowchart TD
A[Scheduled automation] --> B[Cron service runner]
B --> C[Session admission]
C --> D[Session persistence]
D --> E[Agent execution]
C --> F[Setup watchdog]
D --> F
E --> G[Recorded outcome]
F --> G
Loading

Technical review

Best possible solution:

Adopt an owner-approved bounded storage allowance in the existing watchdog, preserving admission exemptions and authoritative cancellation.

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

Current-main source establishes the accounting mechanism, and the linked release report supplies concrete storage timings; this read-only review ran no target code.

Is this the best way to solve the issue?

The focused repair uses the existing watchdog and wait callbacks, retains the earlier admission fix, and avoids post-abort revival; its separate storage budget is an owner policy choice.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Admission-wait exemption keeps the original intent (457a83a: Exclude queue contention from setup timing and restart a complete setup budget after admission.)
  • Preparation versus execution admission keeps the original intent (4af30f6: Prevent session-preparation signals from accepting HTTP hooks before execution-lane admission.)
  • Pre-run session persistence keeps the original intent (c42bd6e: Serialize preparation with session ownership and prior settlement to protect compaction and persisted state.)
  • Setup timeout accounting changes intended behavior with a stated reason (457a83a: Retain a finite setup deadline after admission; this PR explains why slow persistence should receive its own bounded allowance.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Andy Tien: Raw commit c42bd6e adds src/cron/isolated-agent/run-prepare.ts:545 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c42bd6eae5e8; files: src/cron/isolated-agent/run-prepare.ts)

PR surface

Source +81, Tests +76. Total +157 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 92 11 +81
Tests 2 78 2 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 170 13 +157

Review metrics

Metric Value Why it matters
Setup timing policy 60-second persistence allowance; fresh 60-second setup budget afterward Changes how long admitted preparation may remain active without introducing a configuration option.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Slow storage can fail scheduled work before execution, with limited demonstrated blast radius and a reported operational mitigation.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • 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 (2 earlier review cycles)
  • reviewed 2026-10-26T10:02:31.185Z sha 8a66cef :: needs real behavior proof before merge. :: [P1] Preserve the exemption for session-controller admission waits
  • reviewed 2026-10-27T01:27:44.744Z sha 22680e1 :: needs real behavior proof before merge. :: none

Reviewed October 27, 2026, 12:01 AM ET / 04:01 UTC (Revision 3).

Keep the existing session-preparation admission exemption unbounded, and
report the pre-run session write as its own session-persistence stage so
only storage gets the bounded allowance.

Add routing regressions for a busy admission beyond 60 s and for the
bounded persistence path.

Related to openclaw#184429
@HeMiaolin

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the P1 admission-wait regression: storage now uses a distinct session-persistence stage, so session-preparation keeps its original unbounded admission exemption. Added a routing regression for a busy session held beyond 60 s plus the bounded persistence path.

Real-timer proof against the production watchdog/router:
[{"scenario":"admission_wait_65s","fired":0},{"scenario":"persistence_write_37s","fired":0},{"scenario":"persistence_write_65s","fired":1}]

21 relevant tests pass; the PR body was updated with the matrix and the remaining gap (no running-Gateway slow-disk reproduction).

@clawsweeper

clawsweeper Bot commented Oct 27, 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. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 27, 2026
@HeMiaolin

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added the running-Gateway behavior proof requested in the last review. Dev Gateway from this head, real isolated agentTurn cron job, real session/agent SQLite; storage latency was injected at pwrite64 (5 s state DB, then the agent session write) to emulate the slow volume, and a local OpenAI-compatible endpoint returned PROOF_OK.

Observed:

  • Total setup 61.7 s, session-entry.patch 57.3 s -> status: ok, summary: PROOF_OK
  • Total setup 60.2 s, session-entry.patch 65.3 s -> failed with cron: isolated agent setup timed out before runner start, no execution

The 57.3 s write is still in flight when the former 60 s setup deadline expires, so this is the reported case. The PR body was updated with the raw lines. The bounded-allowance maintainer decision is unchanged. Cancellation through a Gateway cancel RPC is not exposed; that path is unchanged and covered by timer-job-runner.interruption.test.ts.

@clawsweeper

clawsweeper Bot commented Oct 27, 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-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Oct 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@HeMiaolin

Copy link
Copy Markdown
Contributor Author

Closing as stale: this branch is 4160 commits behind main and now conflicts in session-event-handoff.ts and run-prepare.ts, while the watchdog and cron setup paths it edits have been restructured since. Re-doing the fix against current main would be a different change, so this branch is not worth reviving as-is.

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

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant