Skip to content

Cron: bound cross-tick admission - #119195

Merged
steipete merged 19 commits into
openclaw:mainfrom
mjzcng:agent/cron-cross-tick-bounded-dispatcher
Aug 21, 2026
Merged

steipete merged 19 commits into
openclaw:mainfrom
mjzcng:agent/cron-cross-tick-bounded-dispatcher

Conversation

@mjzcng

@mjzcng mjzcng commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • admit newly due scheduled Cron jobs across timer ticks while earlier jobs are still running
  • acquire only immediately free shared-admission slots before creating durable run reservations
  • preserve current main's receipt-backed reservation, activation, fencing, recovery, and finalization owners
  • leave saturated jobs unreserved and receipt-free in durable storage, then wake them immediately when capacity is released
  • keep manual, startup, and on-exit admission behavior unchanged

Fixes #119083.

What Problem This Solves

Current main serializes scheduled timer batches behind state.running, so a newly due job can wait for a long earlier batch even when the shared Cron admission pool still has free capacity. Persisting all due jobs before shared admission is also unsafe: saturated ticks can accumulate durable queued receipts and in-memory waiters that do not own an execution slot.

This change gives scheduled work non-waiting, globally bounded admission while preserving durable receipt ownership.

Current-main integration

This is a receipt-safe rewrite on current main, not a mechanical rebase of the old marker-only implementation.

The scheduled dispatcher now calls tryAcquireCronRunSlots before persistQueuedCronRunReservations. Only candidates with an acquired slot enter the existing durable owner. Every admitted candidate still:

  1. claims a durable receipt through persistQueuedCronRunReservations;
  2. registers the local reservation with that exact runReceipt;
  3. activates and executes through executeQueuedCronRun;
  4. uses the existing foreign-owner fencing, activation rollback, terminal receipt settlement, and cleanup paths.

If capacity is full, no queuedAtMs, runningAtMs, local reservation, receipt, Gateway waiter, or retained timer batch is created for the blocked scheduled job. One first-owner capacity listener requests an immediate scheduler recheck when a slot becomes available. A partial batch gates that recheck until its initial receipt activations settle, so an activation failure cannot admit additional work.

No public config, API, or storage-schema changes are introduced. The additions to CronServiceState are process-local scheduler bookkeeping only.

Review finding addressed

The previous ClawSweeper P1 was correct: the old branch bypassed current main's receipt-backed owner. Commit 5b5027b6c9b762c822c1cbe4ada7b008d892f97b preserves it.

The subsequent P2 on the all-conflict partial-admission path was also correct. Head dbb8c2a8dd8e5a96487e0ba7c6c9542b567643b9 now lets the activation gate recheck when a partially admitted batch produces zero activations because its only receipt reservation was fenced. Genuine activation failures still resolve the gate false.

Coverage specifically proves:

  • a later-due job starts while an earlier receipt-backed run remains active;
  • full saturation creates no receipt or queued/running marker for blocked work;
  • partial admission starts the remaining receipt-free job on the first released slot;
  • future scheduled wakes remain armed while an earlier batch runs;
  • receipt conflicts, activation failures, one-shot ownership, setup-timeout recovery, session reaping, and reservation cleanup retain their current-main behavior.

Evidence

The new cross-tick regression first failed on unmodified current main:

expected runIsolatedAgentJob to be called 2 times, but got 1

After the receipt-safe rewrite, the 13-file verification suite passed on 5b5027b6c9b762c822c1cbe4ada7b008d892f97b:

Test Files  13 passed (13)
Tests       226 passed (226)

The 13-file suite includes cross-tick admission, shared admission, durable cleanup, timer rearm, receipt conflicts, batch finalization, timer regressions, one-shot ownership, owner hardening, overdue scheduling, and session reaping.

After the all-conflict wake follow-up, current head dbb8c2a8dd8e5a96487e0ba7c6c9542b567643b9 passed the requested focused validation:

Test Files  3 passed (3)
Tests       47 passed (47)

The added regression creates a durable sibling receipt and running marker between due-job collection and reservation, with only one shared slot free. It proves that the conflicted first candidate is fenced while the second due candidate executes through the released slot without advancing the two-second refire timer. The shared active count, capacity listener, timer-tick count, terminal status, and receipt owner cleanup are all asserted.

check:changed also passed for the four affected Cron paths on the PR base, including production and core-test type checks, targeted type-aware lint, formatting, conflict-marker and max-lines policies, boundary checks, dead-export checks, import-cycle checks, and the database-first/runtime-sidecar guards. git diff --check passed.

Also passed on the exact head:

  • production TypeScript check
  • root test TypeScript check
  • targeted oxlint
  • oxfmt --check
  • conflict-marker and max-lines policy checks
  • git diff --check

The implementation was tested on top of upstream 0c0153442615f46dc07cd1549561409ff671c53d. Main advanced once after the push to 45cd2bae662b9bccef8a0f0daf264bf56e963416; that intervening CLI-only commit does not modify src/cron or Cron test helpers, so the branch was not rewritten again solely to chase the moving tip.

Receipt-safe real Gateway proof

Commit 5b5027b6c9b762c822c1cbe4ada7b008d892f97b was exercised through a real isolated Gateway using command Cron jobs. The Gateway had its own temporary state directory and loopback port, channels were disabled, and every job used no delivery. No finance production container, business Cron definition, external API, or chat channel was touched.

The scheduler used its default shared cap of eight. One 7-second job A was due at 2026-08-17T03:25:48.679Z; eight 2.5-second jobs B1-B8 became due on a later timer tick at 2026-08-17T03:25:50.679Z while A was still active.

Observed behavior:

  • A started 37 ms after its due time.
  • B1-B7 started 55-120 ms after their later due time, within a 65 ms window, and overlapped A.
  • Peak concurrency was exactly eight: A plus B1-B7.
  • B8 did not exceed the cap. It started 56 ms after B1 released the first slot, while A was still running, and overlapped A for 2.43 seconds.
  • all nine runs finished ok; delivery status was not-requested for every run.
  • every durable receipt reached terminal ok with a populated finish timestamp; active test receipts and global active receipts were both zero after completion.
  • every job had null queued/running markers after completion.
  • all nine temporary jobs were removed by exact UUID; the active Gateway list contained none of them.
  • the isolated Gateway then completed a clean SIGINT shutdown in 16 ms.

This directly demonstrates on the exact PR head that a later timer tick is admitted while an earlier tick is still running, the shared limit is never exceeded, the first released slot immediately refills receipt-free blocked work, and durable receipt/marker cleanup completes.

Historical runtime proof

The earlier bounded-admission implementation was exercised in an isolated no-delivery Gateway with nine same-millisecond command jobs under a cap of eight. The first eight started within 77 ms; the ninth stayed outside the first wave and started 51 ms after the first slot was released. Peak concurrency remained eight, all jobs completed successfully, and all temporary jobs were removed by exact ID. The current rewrite changes ownership integration, not the capacity policy demonstrated by that trace.

No finance production container or business Cron definition was modified during this review follow-up.

Provenance

#119139 opened first with an independent concurrent-tick implementation. This PR introduced the bounded non-waiting admission, capacity-release listener, and activation-gated recheck design. #119139 was later closed by its author as superseded by this PR while asking that its distinct earliest-due/no-op-tick ideas remain available for maintainers to incorporate. The detailed public chronology remains in the existing provenance comment on this PR.

2026-08-18 current-main refresh

The branch was semantically rebased onto upstream main 9564b9f after the prior implementation conflicted with the removal of restartRecoveryPending and the current receipt-backed scheduler lifecycle. The refreshed head is 67f5bf9.

The integration preserves current main behavior while retaining bounded cross-tick admission: later due work consumes free shared slots immediately, saturated work remains unreserved, capacity release wakes durable overdue work, and stop/receipt-conflict paths release capacity exactly once. Two tests that asserted the superseded state.running early-return implementation were removed; the real watchdog, future-wake, receipt, saturation, and cross-tick behavior tests remain. Capacity-edge tests were split into a dedicated file to satisfy the repository line-count gate.

Validation on the refreshed head:

  • focused Cron regression set: 10 files, 152 tests passed; subsequent affected set: 6 files, 116 tests passed
  • repository check-changed lane: all format, policy, dead-export, production/test typecheck, type-aware lint, database-first, sidecar, and import-cycle checks passed
  • full pnpm build passed
  • complete branch autoreview and secret scan passed with no accepted/actionable finding
  • the broader changed-test sweep passed all selected suites until the unrelated Gateway workspace-transfer matrix encountered this host Git 2.34 inability to parse the current-main git worktree list --porcelain -z invocation; the isolated transfer test itself passed, and this PR does not touch that surface

During final verification upstream main advanced from 9564b9f to afa3e18 through 17 non-Cron commits. None touches src/cron or Cron test helpers, GitHub reports the refreshed PR mergeable, and the branch was intentionally not rebased again only to chase unrelated tip movement. The accepted isolated-Gateway proof remains in this description; this refresh changed integration with current-main scheduler state, not the bounded admission policy. No finance production container, business Cron, channel, or external delivery was touched.

2026-08-21 maintainer refresh and canonical selection

Maintainer review selected this contributor-owned PR as the canonical existing-work repair for #119083. No third fix PR was created.

Selection and attribution

  • Chosen: Cron: bound cross-tick admission #119195. It is owned by the original contributor, remains maintainer-editable, contains the latest receipt/conflict fixes, removes the obsolete batch-wide state.running bailout, and has the stronger invariant suite.
  • Not selected: fix: prevent long automations from delaying scheduled runs #125422. That bot-owned replacement is not maintainer-editable, retains if (state.running && state.activeTimerTicks === 0), and its copied implementation commits still resolve to no GitHub author despite the contributor attribution request.
  • All five original zhangcheng implementation commits remain intact. The maintainer integration commit also carries GitHub-recognized Co-authored-by: mjzcng <[email protected]> credit.

Exact integration

  • Integrated base: e7e1c53250083bac9b09f3b34a20c66ee491b631 (origin/main, full fetched history at final cutoff)
  • Head: 80a16dd163acf11da88078dbe0d44952dd08f0d9
  • Original contributor head preserved as ancestor: 67f5bf955b725037ceef63a1967f028e6b384e3e
  • The branch also integrates main commit 9feb1db00d6 (scheduler-owned Gateway context); its run-admission.ts/state.ts changes merged cleanly and the Gateway owner suite passes.

The selected invariants are:

  1. scheduled work takes only immediately free shared slots before creating a durable receipt/reservation;
  2. existing manual/direct waiters retain FIFO priority, and scheduled work never joins that waiter queue;
  3. runnable state and receipt ownership are revalidated under the lock before activation;
  4. reservation conflicts, clean skips, activation failures, stop, and completion release pre-acquired slots exactly once;
  5. one first-owner capacity listener triggers an immediate activation-gated child tick;
  6. listener delivery before tracker close remains nested and parent-drained; delivery after close transfers to an independent Gateway root;
  7. clean post-reservation skips permit immediate refill, while stop and reachable fatal activation paths veto it;
  8. activeTimerTicks, batch child draining, durable receipt fencing, and the fixed shared cap prevent overlapping state corruption, duplicate claims, and over-admission.

Before/after proof

The focused reproduction failed on unmodified then-current main ee337708de67fedc2645d3ac48970d84877bf8ac:

expected "vi.fn()" to be called 2 times, but got 1 times

Two independent-review follow-ups also fail against their pre-repair behavior:

waiter-delayed listener: expected pending start count 1, received 0
clean post-reservation skip: expected runner once, received 0 calls

Final validation:

cross-tick/root-ownership stress: 20/20 independent rounds passed
scheduler/admission/finalization suite: 13 files, 212 tests passed
Gateway admission owner suite: 1 file, 20 tests passed
Gateway cron owner suite: 1 file, 76 tests passed
final focused exact-head suite after the last main merge: 2 files / 7 tests plus 20 Gateway admission tests passed
check:changed: passed all selected policy, format, typecheck, type-aware lint, database-first, sidecar, and import-cycle gates
git diff --check: passed

Surface

  • Runtime production: +255/-46 (net +209)
  • Tests and test support: +897/-213 (net +684)
  • Total: +1152/-259 across 12 files

Independent review follow-ups

The first independent review found that ordinary timer callbacks and fully saturated wakes inherited an earlier tick’s Gateway root without being parent-drained. Commit 7fc82555d12896f0588f7b2ad6672d00b266983f detaches those untracked wake paths; real-timer ordering regressions release the earlier tick first and prove the later tick retains active-root ownership.

The second independent review found two more valid lifecycle holes. A partial-batch listener delayed behind direct waiters could fire after its parent tracker/root closed, and one benign post-reservation skip could suppress the only immediate refill. The final tracker now atomically closes nested ownership and transfers a later allowed wake to an independent root; clean skips settle the activation gate true only when neither stop nor fatal state is active. Both focused regressions fail before and pass after.

Final independent read-only Codex autoreview verified exact base/head e7e1c53250083bac9b09f3b34a20c66ee491b631 → 80a16dd163acf11da88078dbe0d44952dd08f0d9 and returned no P0-P2 findings (patch is correct, confidence 0.87). It independently rejected the post-activation-throw hypothesis after tracing the same contained production boundaries. Hosted CI is still running; the latest readback had one unresolved Node shard failure whose logs were not yet available.

The PR is pushed and prepared for review. It has not been merged.

2026-08-21 exact-head closeout

The immutable review head is 43f99b9ccde1c4318459d647f8a38d36cd5a8d61 on integrated base e7e1c53250083bac9b09f3b34a20c66ee491b631. Production remains +255/-46; tests and test support are +905/-214; total diff is +1160/-260 across 13 files. The original contributor head and all five zhangcheng implementation commits remain ancestors, and the maintainer integration retains GitHub-recognized mjzcng co-author credit.

The previous exact-head workflow's sole failing shard, checks-node-compact-large-7, was unrelated to Cron. Its shuffled worker order ran src/mcp/codex-supervision-tools-serve.test.ts before src/entry.run-main.test.ts. The MCP test invokes the real server and left global loggingState.forceConsoleToStderr = true; the later entry test visibly wrote the expected message directly to stderr, bypassing its console-error spy. The branch now restores that global in afterEach. The deterministic two-file shuffled reproducer failed before and passed after; the exact prior 146-file CI shard then passed all 1,811 tests.

Exact-head local proof:

deterministic MCP/entry reproducer: 2 files, 6 tests passed
exact prior CI shard: 146 files, 1,811 tests passed
focused Cron/admission suite: 7 files, 118 tests passed
Gateway admission owner suite: 20 tests passed
Gateway Cron owner suite: 76 tests passed
check:changed: all selected policy, format, production/test typecheck, type-aware lint, database-first, sidecar, and import-cycle gates passed
git diff --check: passed

A fresh real-Gateway trace on this exact head used isolated state, command jobs, no channels, no delivery, and the fixed shared cap of eight. A long-running scheduled A overlapped seven later scheduled B jobs; seven direct FIFO waiters consumed the initial B releases; the delayed eighth B transferred to an independent Gateway root after its parent tracker closed. Observed peak command concurrency was exactly eight, root counts were [2] during the ordinary cross-tick overlap and [1] after A/direct waiters ended while delayed B remained, then zero after completion. All 16 histories and durable receipts finished ok, no active receipt or queued/running marker remained, all temporary jobs were removed, and Gateway shutdown completed cleanly in 264 ms.

The final structured Codex autoreview ran over the exact 70,509-byte branch bundle with max priority P2 and TruffleHog clean. A first pass resurfaced the previously adjudicated post-activation-throw hypothesis. Direct source tracing rejected it because normal execution/Gateway errors are normalized into outcomes, task-ledger and event-subscriber errors are contained, completion settles before slot release, and notification errors cannot escape. A focused exact-head follow-up independently rejected the hypothesis and returned no findings: patch is correct with 0.94 confidence.

Current origin/main at the final integration check was dfce5f695871aa2230037fdfb024f4c75fd180ef, ten commits beyond the integrated base. It has no path overlap with this 13-file diff, and a synthetic merge completed without conflicts, so the branch was not rewritten merely to chase unrelated tip movement.

Exact-head CI completed green: workflow 32461971548 finished with 182 successful and 16 skipped jobs; the full PR rollup has 209 successful, 53 skipped, and one neutral check, with no failures or pending checks. Required openclaw/ci-gate passed, including the formerly failing checks-node-compact-large-7 shard. ClawSweeper then reviewed this exact head, accepted the isolated-Gateway proof as terminal, and reported no P0-P2 code or security findings. This PR remains intentionally unmerged and is ready for the requested separate final verifier.

2026-08-21 open-tracker root repair and final proof

The final immutable head is 05816ea3ae5a79353d3eeb6826671342545b9267 on integrated base e7e1c53250083bac9b09f3b34a20c66ee491b631. A separate verifier correctly found that an open partial-batch capacity listener delivered by a direct FIFO run inherited that unrelated run's Gateway ALS root. The direct root could retire before the capacity-woken cron child attempted subordinate work, causing a false GatewayDrainingError.

The repair captures the original timer AsyncLocalStorage context when the capacity tracker is created. Open-tracker requests restore that context before starting their nested, parent-drained child tick. Requests received after close retain the existing transfer to a fresh independent Gateway root. The new behavioral regression fails on the prior implementation with GatewayDrainingError after the direct root retires and passes on this head.

Exact-head validation:

focused Cron scheduler/admission/finalization: 7 files / 119 tests passed
Gateway admission + command queue: 2 files / 55 tests passed
Gateway Cron owner suite: 76/76 passed
focused open-tracker stress: 10/10 sequential runs passed
check:changed and git diff --check: passed
local and branch-wide max-P2 Codex autoreviews: no findings; patch is correct (0.91 each)
independent exact-head read-only review: no P0-P2 findings

ClawSweeper requested exact-head runtime evidence for the final lifecycle change, so this commit was also exercised through a disposable QA-Lab source-checkout scenario with a real isolated Gateway, local deterministic mock-openai, qa-channel, and no external provider or delivery. Six long-running direct command jobs plus two scheduled siblings filled the fixed cap of eight. A seventh direct run waited FIFO, consumed scheduled A's first release, and then released the slot that woke the unreserved scheduled agent turn while scheduled B kept the parent tracker open. The direct run finished ok at 1787307409747; the capacity-woken agent run finished ok at 1787307409939, including its subordinate exec, with no GatewayDrainingError. All six fillers, both admitted siblings, the direct waiter, and the pending child finished ok; all ten temporary jobs were removed. QA evidence records exact source ref 05816ea3ae5a79353d3eeb6826671342545b9267, Node v24.19.0, Linux, real Gateway child, and one scenario passed with zero failures.

Hosted exact-head CI is fully settled: workflow 32470221695 completed with 182 successful and 16 skipped jobs. The complete PR rollup is 208 successful, 40 skipped, and one neutral check, with no failures or pending checks. Full current surface is production +260/-46 and tests/support +1018/-214 across 13 files. All five original zhangcheng commits through 67f5bf955b725037ceef63a1967f028e6b384e3e remain ancestors. The PR remains intentionally unmerged for final independent re-verification.

@openclaw-barnacle openclaw-barnacle Bot added size: L triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 4, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 6:23 AM ET / 10:23 UTC.

ClawSweeper review

What this changes

This PR admits later-due Cron jobs into immediately free shared slots across timer ticks, leaving saturated work unreserved until capacity returns.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. Current main still returns from a later Cron tick while an earlier batch is running; this PR replaces that gate with receipt-safe bounded admission. No blocking patch defect was found, and the exact-head isolated-Gateway evidence is sufficient.

Priority: P1
Reviewed head: 05816ea3ae5a79353d3eeb6826671342545b9267

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused owner-boundary design, regression coverage, settled exact-head CI, and directly relevant isolated-Gateway proof.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body and latest maintainer comment provide an exact-head isolated-Gateway trace covering capacity wake, restored Gateway-root behavior, terminal receipts, and cleanup.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body and latest maintainer comment provide an exact-head isolated-Gateway trace covering capacity wake, restored Gateway-root behavior, terminal receipts, and cleanup.
Evidence reviewed 6 items Current-main behavior: A timer tick seeing an active batch re-arms and returns before collecting later due jobs, leaving free Cron capacity unused.
Admission owner boundary: The PR acquires only available slots before persisting reservations and installs one bounded capacity wake for unreserved work.
FIFO and bounded wake: Scheduled work yields to existing direct-run waiters; the first capacity listener is consumed only after waiters are drained.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/cron/service.cross-tick-admission.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs src/cron/service.cross-tick-admission.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-119195-mK1gZ1/target$ node scripts/run-vitest.mjs src/cron/service.cross-tick-admission.test.ts
node scripts/run-vitest.mjs src/cron/service.cross-tick-admission.test.ts
[test] starting test/vitest/vitest.cron.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-119195-mK1gZ1/target

 ✓  cron  src/cron/service.cross-tick-admission.test.ts (5 tests) 2595ms
     ✓ starts a later-due job while an earlier receipt-backed run is still active  341ms
     ✓ runs the next future wake under its own Gateway root while an earlier batch runs  2074ms

 Test Files  1 passed (1)
      Tests  5 passed (5)
   Start at  10:24:15
   Duration  11.23s (transform 6.79s, setup 944ms, import 7.34s, tests 2.59s, environment 0ms)

[test] passed 1 Vitest shard in 17.20s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-119195-mK1gZ1/target$ node scripts/run-vitest.mjs src/cron/service.cross-tick-admission.test.ts

































Assertions:

  • PASS expect_output: starts a later-due job while an earlier receipt-backed run is still active

How this fits together

Cron timer ticks collect due jobs, reserve durable run receipts, and execute isolated jobs under one shared concurrency cap. The change modifies the admission step while retaining the existing receipt, activation, and finalization lifecycle.

flowchart LR
  A[Timer wakeup] --> B[Collect due Cron jobs]
  B --> C[Acquire free shared slots]
  C --> D[Create durable run receipts]
  D --> E[Execute isolated jobs]
  E --> F[Release capacity]
  F --> G[Immediate scheduler recheck]
  G --> B
Loading

Before merge

  • Resolve merge risk (P1) - This availability-sensitive repair adds net production lifecycle code; retain focused Cron admission and Gateway-root checks on the final merge result.
  • Complete next step (P2) - This selected canonical implementation already owns the repair; no separate ClawSweeper fix PR is useful.
Agent review details

Security

None.

PR surface

Source +216, Tests +802. Total +1018 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 5 263 47 +216
Tests 8 1015 213 +802
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 1278 260 +1018

Review metrics

Metric Value Why it matters
Production versus test delta production +260/-46; tests/support +1018/-214 The positive production growth implements bounded admission and Gateway lifecycle ownership, so focused final-head proof matters.

Stored data model

Persistent data-model change detected: serialized state: src/cron/service/ops.run-admission-cleanup.test.ts, serialized state: src/cron/service/state.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #119083
Summary: This is the selected canonical candidate repair for the cross-tick Cron admission defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Refresh merge-result scheduler proof (recommended)
    Before merging, validate the final merge result with the focused Cron admission and Gateway-root regressions because this changes scheduling availability.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Validate the final merge result with focused Cron admission and Gateway-root regression suites.

Technical review

Best possible solution:

Land the receipt-safe pre-reservation admission path after the final merge result preserves its focused Cron and Gateway lifecycle proof.

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

Yes — source reproducibly shows current main returning before a later tick collects due work, and the PR supplies a focused failing-to-passing regression path.

Is this the best way to solve the issue?

Yes — acquiring slots before durable reservation fixes the owner boundary without retaining saturated receipts or bypassing direct-run FIFO waiters.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9b37e538a8f9.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: Current main can leave later-due Cron work overdue despite unused configured execution capacity.
  • merge-risk: 🚨 availability: The patch changes Cron timer scheduling, shared admission, and execution-root lifecycle behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body and latest maintainer comment provide an exact-head isolated-Gateway trace covering capacity wake, restored Gateway-root behavior, terminal receipts, and cleanup.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and latest maintainer comment provide an exact-head isolated-Gateway trace covering capacity wake, restored Gateway-root behavior, terminal receipts, and cleanup.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame attributes the active batch-wide scheduler gate to this recent lifecycle work. (role: recent Cron and Gateway lifecycle owner; confidence: high; commits: 2ecd342fbbf8; files: src/cron/service/timer-scheduler.ts, src/process/gateway-work-admission.ts)
  • mjzcng: The PR history preserves the contributor's Cron admission implementation commits. (role: original cross-tick admission contributor; confidence: high; commits: afb91da4c4f3, 67f5bf955b72; files: src/cron/service/timer-scheduler.ts, src/cron/service/run-admission.ts)
  • Amp: Authored the exact-head Gateway-context restoration and associated lifecycle regression. (role: recent integration contributor; confidence: medium; commits: 05816ea3ae5a; files: src/cron/service/timer-capacity-recheck.ts, src/cron/service.cross-tick-admission-lifecycle.test.ts)

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 (24 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-18T08:42:52.770Z sha 67f5bf9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-21T03:59:35.585Z sha d713fa8 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-21T04:56:26.907Z sha 5163058 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-21T07:18:50.989Z sha 80a16dd :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-21T07:33:56.054Z sha 80a16dd :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-21T08:17:05.915Z sha 43f99b9 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-21T08:34:14.453Z sha 43f99b9 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-21T10:02:02.126Z sha 05816ea :: needs real behavior proof before merge. :: none

@mjzcng

mjzcng commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the latest review at 9be961dea1c:

Relevant regression suites: 80/80 passed; formatting and targeted lint passed.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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 Aug 6, 2026
@mjzcng

mjzcng commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the partial-admission finding at bfa981862c1.

The review was correct: with one free slot and two due jobs, the second row had no capacity listener. The new regression failed on the reviewed head with expected null to be type of function.

The fix now registers one replaceable listener whenever due work remains unreserved. Scheduled admission releases carry a batch-owner token: another run releasing capacity triggers the immediate recheck, while the current batch's own releases preserve its existing bounded recursive drain and finalization semantics.

Inline proof (also copied into the PR body):

Test Files 7 passed (7)
Tests 81 passed (81)
Duration 13.69s
[test] passed 1 Vitest shard in 17.17s

oxfmt, targeted oxlint, and git diff --check pass; the available full typecheck is dependency-incomplete but reports no errors in the four touched files. No production deployment was modified.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@mjzcng

mjzcng commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up correction at baa5748c963: the previous bfa981862c1 version handled a slot released by unrelated work, but the latest review correctly requires the same guarantee when one job from the partially admitted batch finishes first.

The final regression now uses two available slots and three due jobs. It keeps one admitted sibling blocked, completes the other admitted job, and proves the third unreserved job starts through the capacity listener without advancing the fake clock through the 2-second refire floor.

Capacity-triggered child ticks now wait for the parent batch's initial activation attempts to settle, so an activation failure cannot admit more work. The parent tracks and drains child ticks so its completion and durable-finalization contract remains intact.

Test Files 7 passed (7)
Tests 81 passed (81)
Duration 13.95s
[test] passed 1 Vitest shard in 16.88s

Formatting, targeted lint, git diff --check, and touched-file type diagnostics pass. No production deployment was modified.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Aug 6, 2026
@mjzcng

mjzcng commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the latest activation-gate finding at exact head 9a9dcf077a9.

The review was correct: a later zero-slot tick could replace a partial batch’s activation-gated listener with an unconditional recheck. Capacity-listener installation is now first-owner-wins until release consumes it, and the recursive same-batch drain no longer clears a listener it may not own.

Two regressions reproduce the reviewed interleaving: the later saturated tick is queued ahead of the admitted mappers, a sibling activation persist is blocked and then fails, and the unreserved job is never admitted. Both tests fail on the prior behavior and pass after the fix.

Exact-head validation:

Test Files 7 passed (7)
Tests 81 passed (81)
Duration 14.23s
[test] passed 1 Vitest shard in 17.65s

Real isolated Gateway proof is now inline in the PR body. Nine no-delivery command Cron jobs were scheduled for one millisecond under the real default cap of 8: the first wave started within 84ms, peak concurrency stayed at 8, and job 9 started 52ms after the first slot was released. All nine completed ok; all nine definitions were removed by exact ID and the isolated Gateway stopped cleanly. No production deployment was touched.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 6, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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 Aug 6, 2026
@mjzcng
mjzcng force-pushed the agent/cron-cross-tick-bounded-dispatcher branch from 9a9dcf0 to 4810c2a Compare August 10, 2026 06:54
@mjzcng

mjzcng commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@-

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

steipete commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Exact-head independent read-only Codex review is now complete for e7e1c53250083bac9b09f3b34a20c66ee491b631 → 80a16dd163acf11da88078dbe0d44952dd08f0d9: no P0-P2 findings, patch is correct (0.87). It independently rejected the speculative post-activation-throw path after tracing the contained production boundaries. Hosted CI remains in progress with one Node shard failure whose logs are not yet available. The PR is still unmerged.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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 Aug 21, 2026

Copy link
Copy Markdown
Contributor

Final immutable-head closeout pushed: 43f99b9ccde1c4318459d647f8a38d36cd5a8d61 (base e7e1c53250083bac9b09f3b34a20c66ee491b631).

The prior checks-node-compact-large-7 failure was a deterministic cross-test leak on current main, not a Cron failure: the real MCP supervision server test left loggingState.forceConsoleToStderr enabled, so a later shuffled entry test bypassed its console spy. The new test-only afterEach restoration makes the two-file shuffle pass; the exact prior CI shard now passes 146 files / 1,811 tests.

Fresh exact-head evidence:

  • focused Cron/admission: 7 files / 118 tests; Gateway admission: 20/20; Gateway Cron: 76/76
  • check:changed and git diff --check: passed
  • real isolated Gateway: 16/16 histories and receipts terminal ok; peak execution concurrency 8; ordinary cross-tick roots [2]; delayed post-parent child retained root [1]; final roots 0; no active receipt/marker/temp-job residue; clean 264 ms shutdown
  • max-P2 structured Codex follow-up: TruffleHog clean, one 70,509-byte pass, no findings, patch is correct (0.94)
  • latest origin/main dfce5f695871aa2230037fdfb024f4c75fd180ef: no changed-path overlap and synthetic merge clean; no tip-chasing rewrite

Production remains +255/-46; tests/support are +905/-214. Original contributor commits and GitHub-recognized mjzcng credit remain intact. Please review this exact head; the PR remains intentionally unmerged for a separate verifier.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 21, 2026

steipete commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Accepted and fixed the independent verifier's open-tracker Gateway-root P1 at exact head 05816ea3ae5a79353d3eeb6826671342545b9267 (integrated base e7e1c53250083bac9b09f3b34a20c66ee491b631).

The finding was correct: a direct FIFO waiter could release the slot that delivered an open partial-batch capacity listener. The listener and activation continuation then inherited the direct request's Gateway ALS root, so the direct root could retire before the cron child's subordinate enqueue and produce a false GatewayDrainingError.

The owner-boundary repair captures the timer parent's AsyncLocalStorage.snapshot() when its capacity tracker is created. Requests accepted while that tracker is open restore the captured timer context before the nested/drained recheck starts. Requests delivered after close retain the existing transfer to an independent Gateway root.

The new behavioral regression keeps a scheduled sibling blocked so the parent tracker remains open, lets a direct waiter complete and deliver the listener, retires the direct root, then performs a subordinate command enqueue from the admitted cron child. Before the production repair it failed exactly because the result was GatewayDrainingError; after the repair the enqueue is accepted and the timer root remains active.

Exact-head evidence:

  • focused Cron scheduler/admission/finalization: 7 files / 119 tests passed;
  • Gateway admission + command queue: 2 files / 55 tests passed;
  • canonical Gateway Cron owner: 76/76 passed;
  • focused regression stress: 10/10 sequential runs passed;
  • full check:changed, formatting, typecheck, lint, import-cycle, database/runtime guards, and git diff --check: passed;
  • local and full-branch max-P2 Codex autoreviews: no findings, patch is correct (0.91 each), with TruffleHog clean;
  • latest fetched origin/main 81628db1d7f45b60266128a8bc87580ace04a1da: no changed-path overlap and synthetic merge clean, so no tip-chasing rebase.

Full PR surface: production +260/-46; tests/support +1018/-214. The original five zhangcheng commits through 67f5bf955b725037ceef63a1967f028e6b384e3e remain ancestors. This PR remains intentionally unmerged for exact-head independent re-verification.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

Copy link
Copy Markdown
Contributor

Exact-head runtime proof requested by the latest ClawSweeper review is now in the PR body for 05816ea3ae5a79353d3eeb6826671342545b9267.

The disposable QA-Lab source-checkout lane used a real isolated Gateway with deterministic local mock-openai and no external delivery. Six direct command runs plus two scheduled siblings filled the cap; a queued direct FIFO run consumed the first scheduled release, then its release woke the pending scheduled agent turn while the parent timer tracker remained open. The direct run and capacity-woken child both finished ok; the child completed its subordinate exec without GatewayDrainingError; all ten runs completed successfully and all ten temporary jobs were removed. QA evidence records exact ref 05816ea..., Node 24.19.0, Linux, real Gateway child, and 1/1 scenario passed.

Exact-head hosted CI is also fully settled: workflow 32470221695 completed with 182 successful / 16 skipped jobs; the full rollup has no failures or pending checks. The PR remains unmerged.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 21, 2026
@steipete
steipete merged commit 8f8895c into openclaw:main Aug 21, 2026
260 checks passed

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 22, 2026
* 修复 Cron 跨批次有界准入

* 修复 Cron 收据冲突后的容量唤醒

* 适配最新主线的 Cron 运行态测试

* 拆分 Cron 容量边界测试

* 满足 Cron 即时重检返回类型约束

* fix(cron): track independent timer tick roots

Amp-Thread-ID: https://ampcode.com/threads/T-01a0223e-d6cf-70c1-b0f8-5ea0193d09c0

* fix(cron): retain delayed capacity wake ownership

Amp-Thread-ID: https://ampcode.com/threads/T-01a0223e-d6cf-70c1-b0f8-5ea0193d09c0

* test(cron): await deferred cleanup runs

Amp-Thread-ID: https://ampcode.com/threads/T-01a0223e-d6cf-70c1-b0f8-5ea0193d09c0

* fix(cron): keep admission helper within lint budget

Amp-Thread-ID: https://ampcode.com/threads/T-01a0223e-d6cf-70c1-b0f8-5ea0193d09c0

* test(mcp): restore stderr routing after supervision tests

Amp-Thread-ID: https://ampcode.com/threads/T-01a0223e-d6cf-70c1-b0f8-5ea0193d09c0

* fix(cron): restore partial wake admission context

Amp-Thread-ID: https://ampcode.com/threads/T-01a0223e-d6cf-70c1-b0f8-5ea0193d09c0

---------

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

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

[Feature]: Continuously admit newly due cron jobs while earlier timer-batch jobs are still running

3 participants