Skip to content

fix(cron): stop deferred jobs retrying every two seconds - #193063

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-cron-deferred-admission-busy-loop-20260919
Nov 5, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-cron-deferred-admission-busy-loop-20260919

Conversation

@steipete

@steipete steipete commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Timed automations whose admission is deferred retry about every two seconds, churning skipped receipts while the job still looks healthy.

User Impact

Deferred jobs now show Waiting: since , with a warning after five attempts. They retry after 30 seconds, doubling to a five-minute cap, and run the pending occurrence once admission clears. Their last completed run remains unchanged. This can delay recovery by up to five minutes; no configuration or migration is required.

Why This Change Was Made

The cron worker retains the original occurrence and owns a separate retry deadline. Startup preserves that episode. Retries atomically replace the prior unstarted receipt while retaining a fresh execution fence. Completion, cancellation, or a scheduling change clears waiting. Existing runtime events and full/compact/tool projections publish the reason to clients. Stream retry ownership is unchanged.

Receipt retention already capped stored rows at 64 per job; the defect was continuous write/prune churn and missing visibility, not unbounded retained rows. No SQLite schema, cache, or host-admission handshake was added. Production grows 125 lines to implement the retry lifecycle and its read-only public/UI projections; benchmark tooling is separate.

Evidence

  • Regression is red before the fix: nine service cases lack waiting state, and the pinned baseline performs 300 admission attempts over ten modeled minutes. Afterward, 160 focused service, worker, receipt, scheduler, and protocol tests pass (52.68 seconds including compilation). Tests cover bounded backoff, coalescing, restart, cancellation, no replay after effects, and execution when the blocker clears.
  • UI: 22 browser/render/inventory tests pass (2.96 seconds); two UI E2E tests pass (13.31 seconds), including visible waiting → recovery. The before-state E2E fails at the missing waiting reason. The test-line allocation is limited to these regression and projection contracts.
  • Isolated Codex autoreview against 12218cbc4e40caddbb11f4a57b273fe0bf35f75a: scoped clean through P2, no actionable findings.
  • Full pnpm check:changed passed the runtime/UI type graphs, database ratchets, formatting, dead-code and import-cycle gates. It identified a benchmark worker-context type error and an array-search lint error in the new assertion; both were corrected and their targeted type/lint commands pass. The focused pnpm check:changed -- scripts/perf/cron-deferred-admission-measure.ts replay and test-line ratchet also pass.

Synthetic owner benchmark, 1,000 jobs, ten modeled minutes, five serial alternating pairs:

Metric Before After
Admission attempts 300 5
Retained episode receipts 64 1
SQLite row changes 1,436 24
Owner wall median / p95, ms 2,446.53 / 2,497.40 52.38 / 55.30
Owner thread CPU median, ms 2,444.73 52.34
V8 JavaScript allocation median, bytes 2,898,720,552 73,791,392

Five A/A pairs: wall differences −8.19% to +3.33%; allocation −0.042% to +0.164%. CPU profiles show repeated cron-row decoding/SQLite reads disappearing with the eliminated attempts. The acceptance rule is fewer attempts/writes, one retained deferred receipt, lower CPU/allocation, and preservation of the original occurrence.

Reproduce each side with node --expose-gc --import ./scripts/tsx.mjs scripts/perf/cron-deferred-admission-measure.ts --output <output.json>, adding --revision 12218cbc4e40caddbb11f4a57b273fe0bf35f75a for the baseline and --profile for CPU profiles. Imports and fixture setup are outside measurement; each sample starts a fresh deferral episode. This measures the actual shared-cron owner on macOS/APFS, not whole-Gateway/model latency or large agent-database/btrfs performance. Agent transcripts and workspace files are outside this owner's read set; no production data was copied or live deployment touched.

Before: overdue job appears healthy

After: explicit waiting reason and warning

Hosted CI: inherited main regressions

Run 41936481448 tested merge 33512ad2ed0430bc79db8ed46d5ec28c59d62fce of this head into main 943904e8c4cae76b64bf83b1b53a8c230122fb9b. The two failed shards reproduce with the same assertions on that exact main parent; their failed tests and copy producers are unchanged by this PR:

These are main test regressions requiring separate repair, including the newly added table-copy failure; they are not ignored noise. The cron boundary proof and affected UI tests pass. No CI rerun was requested. Landing uses the explicitly authorized, pinned-head inherited-failure route, retaining the failed CI evidence rather than claiming a green run.

PR-specific media verification waiver

The task lead explicitly waived rendered PR-image verification for this PR only on 2026-11-04. Both synthetic screenshots were inspected, uploaded, embedded, and verified byte-identical after download. Browser automation failed and Peekaboo confirmed that the Mac GUI session is locked, so rendering verification is limited by the environment. The Mac will remain locked. This waiver does not waive CI, inherited-failure attribution, final-head Codex autoreview, or native landing checks.

Preserve unstarted timed occurrences with bounded retry deadlines, coalesce their receipts, and publish waiting reasons without overwriting the prior run outcome. Warn after five deferred attempts and preserve pending admission across restart.
@clawsweeper

clawsweeper Bot commented Nov 4, 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 docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L labels Nov 4, 2026
@steipete
steipete marked this pull request as ready for review November 4, 2026 23:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T23:50:33.366569Z ec43d02 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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 Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR adds bounded backoff, receipt coalescing, and visible waiting reasons for timed automations deferred before execution.

Example: A one-minute automation is due at 12:00 while its agent is busy.

  • Before: Admission retries about every two seconds while the automation appears healthy.
  • After: The automation shows its waiting reason and retries after 30, 60, 120, 240, then 300 seconds while retaining the original occurrence.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused implementation with no definite introduced defect; available behavior evidence is primarily harness-based and persisted-state compatibility remains unproven.
Proof confidence 🦐 gold shrimp (3/6) Ordinary contributor proof gating is exempt for this maintainer-authored PR; inspected screenshots prove waiting presentation, while the benchmark and tests exercise worker behavior with synthetic deferrals. The new persisted waiting state and deferred-receipt replacement lack a latest-stable upgrade run demonstrating preserved jobs, history, and pending occurrences; the PR owner must supply that compatibility evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Deferred timed automations repeatedly attempt admission while appearing healthy and hiding why execution is delayed.
Reason: The change removes repeated work and exposes an intentional waiting state; the maintainer-authored direction explicitly accepts the bounded recovery delay.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this PR addresses a current cron retry loop through the existing worker owner, and inspection found no discrete introduced correctness defect.

Priority: P2
Reviewed head: ec43d029b0c5b5d94565aaffb2827bb75265f00d

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide a latest-stable upgrade scenario preserving existing jobs and history, followed by deferred admission, restart, and recovery through the shipped Gateway.
Agent review details

How this fits together

The cron worker turns stored job schedules into fenced execution requests, persists outcomes in SQLite, and publishes runtime state through Gateway projections to Automations clients.

flowchart LR
  A[Stored cron jobs] --> B[Cron scheduler worker]
  B --> C[Receipt queue]
  C --> D[Execution admission]
  D --> E[Outcome finalizer]
  E --> A
  E --> F[Gateway projections]
  F --> G[Automations UI]
Loading

Technical review

Best possible solution:

Keep retry deadlines and receipt replacement in the existing cron worker, with clients consuming its recorded waiting state.

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

Current-main source preserves the overdue occurrence after unstarted deferral and rearms it without a separate retry deadline; the submitted benchmark reports the resulting repeated attempts, but no target code was executed during this review.

Is this the best way to solve the issue?

The smallest complete repair is to retain one pending occurrence with worker-owned backoff and fresh receipt fencing, then expose that state through existing projections; the patch follows that design without a parallel scheduler or configuration knob.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Unstarted admission and retained occurrences keeps the original intent (ec5d369: Preserve one-shot jobs outside active hours and retain unstarted admission without falsely recording completion.)
  • Worker scheduling and catch-up keeps the original intent (b943945: Give the worker authoritative ownership of timers, scheduling, catch-up, and durable queue decisions.)
  • Receipt claim and execution fencing keeps the original intent (1a16286: Use database uniqueness to arbitrate claims while retaining durable duplicate exclusion and fresh execution identity.)
  • Automation next-run presentation keeps the original intent (0b1cd5f: Present effective runtime state separately from the authored schedule while keeping running and paused states truthful.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +125, Tests +170, Docs +1, Other +254. Total +550 across 31 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 21 129 4 +125
Tests 7 188 18 +170
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 2 254 0 +254
Total 31 572 22 +550

Review metrics

Metric Value Why it matters
Production versus regression growth Production +129/-4; tests/support +188/-18; separate benchmark +252 Growth implements the worker retry lifecycle, client projections, and distinct persistence, cancellation, restart, and presentation contracts.

Labels

Label changes:

  • add P2: Repeated admission attempts create avoidable database churn and obscure delayed automations, with limited scope and no demonstrated outage or data loss.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: Repeated admission attempts create avoidable database churn and obscure delayed automations, with limited scope and no demonstrated outage or data loss.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rank-up moves

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

  • Add latest-stable upgrade evidence covering preserved jobs and history plus deferred-occurrence recovery.

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.

Reviewed November 4, 2026, 7:22 PM ET / November 5, 2026, 00:22 UTC.

@steipete
steipete merged commit c3cdd6b into main Nov 5, 2026
244 of 252 checks passed
@steipete
steipete deleted the steipete/perf-micro-cron-deferred-admission-busy-loop-20260919 branch November 5, 2026 00:27
@steipete

steipete commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 5, 2026
Preserve unstarted timed occurrences with bounded retry deadlines, coalesce their receipts, and publish waiting reasons without overwriting the prior run outcome. Warn after five deferred attempts and preserve pending admission across restart.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant