Repository navigation
Cron: bound cross-tick admission - #119195
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 6:23 AM ET / 10:23 UTC. ClawSweeper reviewWhat this changesThis PR admits later-due Cron jobs into immediately free shared slots across timer ticks, leaving saturated work unreserved until capacity returns. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep 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 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherCron 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
Before merge
Agent review detailsSecurityNone. PR surfaceSource +216, Tests +802. Total +1018 across 13 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (24 earlier review cycles; latest 8 shown)
|
a3a323f to
9be961d
Compare
|
Addressed the latest review at
Relevant regression suites: 80/80 passed; formatting and targeted lint passed. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Addressed the partial-admission finding at 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 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):
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Follow-up correction at 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. Formatting, targeted lint, @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Addressed the latest activation-gate finding at exact head 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: 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 @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
9a9dcf0 to
4810c2a
Compare
|
@- |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head independent read-only Codex review is now complete for @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Final immutable-head closeout pushed: The prior Fresh exact-head evidence:
Production remains +255/-46; tests/support are +905/-214. Original contributor commits and GitHub-recognized @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Accepted and fixed the independent verifier's open-tracker Gateway-root P1 at exact head 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 The owner-boundary repair captures the timer parent's 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 Exact-head evidence:
Full PR surface: production @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head runtime proof requested by the latest ClawSweeper review is now in the PR body for The disposable QA-Lab source-checkout lane used a real isolated Gateway with deterministic local Exact-head hosted CI is also fully settled: workflow @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* 修复 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]>
Summary
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
tryAcquireCronRunSlotsbeforepersistQueuedCronRunReservations. Only candidates with an acquired slot enter the existing durable owner. Every admitted candidate still:persistQueuedCronRunReservations;runReceipt;executeQueuedCronRun;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
CronServiceStateare 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
5b5027b6c9b762c822c1cbe4ada7b008d892f97bpreserves it.The subsequent P2 on the all-conflict partial-admission path was also correct. Head
dbb8c2a8dd8e5a96487e0ba7c6c9542b567643b9now 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:
Evidence
The new cross-tick regression first failed on unmodified current main:
After the receipt-safe rewrite, the 13-file verification suite passed on
5b5027b6c9b762c822c1cbe4ada7b008d892f97b: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
dbb8c2a8dd8e5a96487e0ba7c6c9542b567643b9passed the requested focused validation: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:changedalso 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 --checkpassed.Also passed on the exact head:
oxlintoxfmt --checkgit diff --checkThe implementation was tested on top of upstream
0c0153442615f46dc07cd1549561409ff671c53d. Main advanced once after the push to45cd2bae662b9bccef8a0f0daf264bf56e963416; that intervening CLI-only commit does not modifysrc/cronor Cron test helpers, so the branch was not rewritten again solely to chase the moving tip.Receipt-safe real Gateway proof
Commit
5b5027b6c9b762c822c1cbe4ada7b008d892f97bwas 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 at2026-08-17T03:25:50.679Zwhile A was still active.Observed behavior:
ok; delivery status wasnot-requestedfor every run.okwith a populated finish timestamp; active test receipts and global active receipts were both zero after completion.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:
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
state.runningbailout, and has the stronger invariant suite.if (state.running && state.activeTimerTicks === 0), and its copied implementation commits still resolve to no GitHub author despite the contributor attribution request.zhangchengimplementation commits remain intact. The maintainer integration commit also carries GitHub-recognizedCo-authored-by: mjzcng <[email protected]>credit.Exact integration
e7e1c53250083bac9b09f3b34a20c66ee491b631(origin/main, full fetched history at final cutoff)80a16dd163acf11da88078dbe0d44952dd08f0d967f5bf955b725037ceef63a1967f028e6b384e3e9feb1db00d6(scheduler-owned Gateway context); itsrun-admission.ts/state.tschanges merged cleanly and the Gateway owner suite passes.The selected invariants are:
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:Two independent-review follow-ups also fail against their pre-repair behavior:
Final validation:
Surface
+255/-46(net+209)+897/-213(net+684)+1152/-259across 12 filesIndependent 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
7fc82555d12896f0588f7b2ad6672d00b266983fdetaches 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→80a16dd163acf11da88078dbe0d44952dd08f0d9and 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
43f99b9ccde1c4318459d647f8a38d36cd5a8d61on integrated basee7e1c53250083bac9b09f3b34a20c66ee491b631. Production remains+255/-46; tests and test support are+905/-214; total diff is+1160/-260across 13 files. The original contributor head and all fivezhangchengimplementation commits remain ancestors, and the maintainer integration retains GitHub-recognizedmjzcngco-author credit.The previous exact-head workflow's sole failing shard,
checks-node-compact-large-7, was unrelated to Cron. Its shuffled worker order ransrc/mcp/codex-supervision-tools-serve.test.tsbeforesrc/entry.run-main.test.ts. The MCP test invokes the real server and left globalloggingState.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 inafterEach. 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:
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 finishedok, 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 correctwith 0.94 confidence.Current
origin/mainat the final integration check wasdfce5f695871aa2230037fdfb024f4c75fd180ef, 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
32461971548finished 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. Requiredopenclaw/ci-gatepassed, including the formerly failingchecks-node-compact-large-7shard. 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
05816ea3ae5a79353d3eeb6826671342545b9267on integrated basee7e1c53250083bac9b09f3b34a20c66ee491b631. 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 falseGatewayDrainingError.The repair captures the original timer
AsyncLocalStoragecontext 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 withGatewayDrainingErrorafter the direct root retires and passes on this head.Exact-head validation:
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 finishedokat1787307409747; the capacity-woken agent run finishedokat1787307409939, including its subordinate exec, with noGatewayDrainingError. All six fillers, both admitted siblings, the direct waiter, and the pending child finishedok; all ten temporary jobs were removed. QA evidence records exact source ref05816ea3ae5a79353d3eeb6826671342545b9267, Nodev24.19.0, Linux, real Gateway child, and one scenario passed with zero failures.Hosted exact-head CI is fully settled: workflow
32470221695completed 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/-46and tests/support+1018/-214across 13 files. All five originalzhangchengcommits through67f5bf955b725037ceef63a1967f028e6b384e3eremain ancestors. The PR remains intentionally unmerged for final independent re-verification.