Repository navigation
fix(cron): native completion waits on its own session cleanup - #180877
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR defers isolated cron continuation deletion until session admission unwinds and retains the selected runtime until deletion finishes. Example: An isolated Agents API cron job completes with summary CRON_NATIVE_COMPLETED.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a concrete cleanup self-dependency still present on current main, and no introduced correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe isolated cron runner receives a scheduled job, prepares and admits its agent turn, executes and finalizes it, then releases session resources before returning the outcome for durable run history. flowchart TD
A[Scheduled cron job] --> B[Prepare runtime and session]
B --> C[Admit and execute turn]
C --> D[Finalize outcome and release admission]
D --> E[Delete idle continuation]
E --> F[Dispose retained runtime]
F --> G[Publish durable run history]
Technical reviewBest possible solution: Use the existing disposal stack to delete idle continuations after controller settlement while retaining the selected runtime through cleanup. Do we have a high-confidence way to reproduce the issue? Source establishes the cleanup-to-owner settlement cycle, and obviyus supplies repeated built-Gateway base/candidate captures; this read-only review ran no target code. Is this the best way to solve the issue? The patch fixes lifecycle ordering at the cron orchestration owner without weakening native drain budgets or duplicating deletion policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5f1d487758a8. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +4, Tests +34. Total +38 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 26, 2026, 11:32 AM ET / 15:32 UTC (Revision 3). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
Built Gateway native cron captureActual shipped commands: All six: Main baseline: Not fixed here: persistent missing-history or every cron stall reported in #180758. This proves the completed-turn cleanup self-drain and its resource-ordering repair; main eventually published its history. |
|
🦞👀 Re-review progress:
|
|
Landed in 1206d80. Thanks @yinx65588-boop. Native cron turns now report completion without waiting on their own cleanup. |
…aw#180877) fix(cron): report a native cron turn complete without waiting on its own continuation session A completed native cron turn waited for its own continuation session to be deleted before it reported completion, which held it for about the full deletion timeout and left a warning. It now reports completion right away and cleans up the continuation separately. Evidence: built Gateway with a native cron turn. On main completion took 97.8s and 97.3s, with one continuation row left and a warning; with this change it took 3.3s and 2.8s, with no continuation row and no warning, one native session and no cancel. Embedded-runtime cron runs behave the same on both refs. Details are in the PR body; the broader items under "Not fixed here" are not addressed here. Thanks @yinx65588-boop. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #205435, #195478 ## What Problem This Solves A plugin reload after an update could make the whole Gateway fail `/readyz` for its 60-second drain, even though the previous plugin generation was still serving. A cancelled cron run could also abandon its selected plugin-generation lease before execution started, leaving future reloads waiting on work that had ended. ## User Impact Ordinary plugin reload drains no longer make the Gateway not-ready. Failed activation or recovery still fails readiness. Cancelling a prepared cron run releases its selected generation. No settings, stored formats, drain budgets, retries, or active-turn pinning rules change. ## Why This Change Was Made The readiness owner treated every reload status as a core outage. It now distinguishes an ordinary reload from failed or recovering activation. Cron preparation acquired its selected execution lease before two awaits, but execution only registered disposal inside the later callback. The preparation owner now owns the lease across resource cleanup, session admission, and execution; the later duplicate ownership is removed. Its existing cleanup stack releases the session preparation hold, joins the session owner's settlement receipt, deletes the continuation after admission unwinds, then releases the lease. This preserves #180877 without a timer or retry. This fixes a concrete leak on the cron preparation path used by the fleet run. The decision-only path reported in #205435 is **not yet proven** to have this cause, so that issue remains open. This does not solve #195478: active turns still retain their admitted plugins; only abandoned cron holds are removed. ## Evidence - Base `caf2a4d4f7dc`: the new cron owner regression fails because one real retained plugin work reference remains after cancelled session admission; execution never starts (45 ms test time). - Readiness owner regression fails on the base with `plugin-reload` and passes on the candidate. Recovery/failed-health cases remain covered. - Real isolated source Gateway, with `plugins.reload` unresolved behind an admitted held request: base HTTP **200 → 503 → 200**; candidate HTTP **200 → 200 → 200**. Base run 23.11 s, candidate run 50.34 s. Both Gateways and state were cleaned. - Gateway consumer batch: 8 files / 179 tests passed, including real HTTP readiness during a held drain and after its forced drain failure. - Production delta measured with `tokei`: **+8 code lines** (971 → 979 across the three changed production modules). - Initial focused batch: **15 files / 271 tests passed** in 376.50 s wall time. After the cleanup-order repair, the final three cron owner files passed **21/21 tests**, including #180877's external ordering assertion and the cancelled-continuation regression (12 ms; 45 ms on the failing base). - `check:changed` passed core production/test typechecks, formatting, and guards. Its dead-export scan reported three untouched exports (`readUpdateDatabaseEngineConfig`, `DoctorContributionPending`, `formatUpdateSnapshotCapacity`); no suppression or unrelated code repair is included. - Final scoped checks passed: formatting, oxlint (zero warnings/errors), core production types, and the services-cron test type graph. Final checks plus the three-file test run took 69.40 s; Vitest itself took 43.60 s. - Local ClawSweeper reviewed `caf2a4d4f7dc` → `25e3fdb6b90c` at default service tier: complete, **patch is correct**, zero findings, security cleared. The offline review did not receive execution receipts; the observed runs are summarized above. ### Readiness decision Serving-health readiness is the requested contract for this repair: an ordinary reload does not report the whole serving Gateway as unavailable. New agent runs still wait on the existing replacement gate, visible in status. Recovery and failed activation remain unhealthy. This resolves the local review's advisory product-direction question without changing admission policy. Co-authored-by: Ayaan Zaidi <[email protected]>
…06299) Related: openclaw#205435, openclaw#195478 ## What Problem This Solves A plugin reload after an update could make the whole Gateway fail `/readyz` for its 60-second drain, even though the previous plugin generation was still serving. A cancelled cron run could also abandon its selected plugin-generation lease before execution started, leaving future reloads waiting on work that had ended. ## User Impact Ordinary plugin reload drains no longer make the Gateway not-ready. Failed activation or recovery still fails readiness. Cancelling a prepared cron run releases its selected generation. No settings, stored formats, drain budgets, retries, or active-turn pinning rules change. ## Why This Change Was Made The readiness owner treated every reload status as a core outage. It now distinguishes an ordinary reload from failed or recovering activation. Cron preparation acquired its selected execution lease before two awaits, but execution only registered disposal inside the later callback. The preparation owner now owns the lease across resource cleanup, session admission, and execution; the later duplicate ownership is removed. Its existing cleanup stack releases the session preparation hold, joins the session owner's settlement receipt, deletes the continuation after admission unwinds, then releases the lease. This preserves openclaw#180877 without a timer or retry. This fixes a concrete leak on the cron preparation path used by the fleet run. The decision-only path reported in openclaw#205435 is **not yet proven** to have this cause, so that issue remains open. This does not solve openclaw#195478: active turns still retain their admitted plugins; only abandoned cron holds are removed. ## Evidence - Base `a92d5919a899`: the new cron owner regression fails because one real retained plugin work reference remains after cancelled session admission; execution never starts (45 ms test time). - Readiness owner regression fails on the base with `plugin-reload` and passes on the candidate. Recovery/failed-health cases remain covered. - Real isolated source Gateway, with `plugins.reload` unresolved behind an admitted held request: base HTTP **200 → 503 → 200**; candidate HTTP **200 → 200 → 200**. Base run 23.11 s, candidate run 50.34 s. Both Gateways and state were cleaned. - Gateway consumer batch: 8 files / 179 tests passed, including real HTTP readiness during a held drain and after its forced drain failure. - Production delta measured with `tokei`: **+8 code lines** (971 → 979 across the three changed production modules). - Initial focused batch: **15 files / 271 tests passed** in 376.50 s wall time. After the cleanup-order repair, the final three cron owner files passed **21/21 tests**, including openclaw#180877's external ordering assertion and the cancelled-continuation regression (12 ms; 45 ms on the failing base). - `check:changed` passed core production/test typechecks, formatting, and guards. Its dead-export scan reported three untouched exports (`readUpdateDatabaseEngineConfig`, `DoctorContributionPending`, `formatUpdateSnapshotCapacity`); no suppression or unrelated code repair is included. - Final scoped checks passed: formatting, oxlint (zero warnings/errors), core production types, and the services-cron test type graph. Final checks plus the three-file test run took 69.40 s; Vitest itself took 43.60 s. - Local ClawSweeper reviewed `a92d5919a899` → `25e3fdb6b90c` at default service tier: complete, **patch is correct**, zero findings, security cleared. The offline review did not receive execution receipts; the observed runs are summarized above. ### Readiness decision Serving-health readiness is the requested contract for this repair: an ordinary reload does not report the whole serving Gateway as unavailable. New agent runs still wait on the existing replacement gate, visible in status. Recovery and failed activation remain unhealthy. This resolves the local review's advisory product-direction question without changing admission policy. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #205435, #195478 ## What Problem This Solves A plugin reload after an update could make the whole Gateway fail `/readyz` for its 60-second drain, even though the previous plugin generation was still serving. A cancelled cron run could also abandon its selected plugin-generation lease before execution started, leaving future reloads waiting on work that had ended. ## User Impact Ordinary plugin reload drains no longer make the Gateway not-ready. Failed activation or recovery still fails readiness. Cancelling a prepared cron run releases its selected generation. No settings, stored formats, drain budgets, retries, or active-turn pinning rules change. ## Why This Change Was Made The readiness owner treated every reload status as a core outage. It now distinguishes an ordinary reload from failed or recovering activation. Cron preparation acquired its selected execution lease before two awaits, but execution only registered disposal inside the later callback. The preparation owner now owns the lease across resource cleanup, session admission, and execution; the later duplicate ownership is removed. Its existing cleanup stack releases the session preparation hold, joins the session owner's settlement receipt, deletes the continuation after admission unwinds, then releases the lease. This preserves #180877 without a timer or retry. This fixes a concrete leak on the cron preparation path used by the fleet run. The decision-only path reported in #205435 is **not yet proven** to have this cause, so that issue remains open. This does not solve #195478: active turns still retain their admitted plugins; only abandoned cron holds are removed. ## Evidence - Base `caf2a4d4f7dc`: the new cron owner regression fails because one real retained plugin work reference remains after cancelled session admission; execution never starts (45 ms test time). - Readiness owner regression fails on the base with `plugin-reload` and passes on the candidate. Recovery/failed-health cases remain covered. - Real isolated source Gateway, with `plugins.reload` unresolved behind an admitted held request: base HTTP **200 → 503 → 200**; candidate HTTP **200 → 200 → 200**. Base run 23.11 s, candidate run 50.34 s. Both Gateways and state were cleaned. - Gateway consumer batch: 8 files / 179 tests passed, including real HTTP readiness during a held drain and after its forced drain failure. - Production delta measured with `tokei`: **+8 code lines** (971 → 979 across the three changed production modules). - Initial focused batch: **15 files / 271 tests passed** in 376.50 s wall time. After the cleanup-order repair, the final three cron owner files passed **21/21 tests**, including #180877's external ordering assertion and the cancelled-continuation regression (12 ms; 45 ms on the failing base). - `check:changed` passed core production/test typechecks, formatting, and guards. Its dead-export scan reported three untouched exports (`readUpdateDatabaseEngineConfig`, `DoctorContributionPending`, `formatUpdateSnapshotCapacity`); no suppression or unrelated code repair is included. - Final scoped checks passed: formatting, oxlint (zero warnings/errors), core production types, and the services-cron test type graph. Final checks plus the three-file test run took 69.40 s; Vitest itself took 43.60 s. - Local ClawSweeper reviewed `caf2a4d4f7dc` → `25e3fdb6b90c` at default service tier: complete, **patch is correct**, zero findings, security cleared. The offline review did not receive execution receipts; the observed runs are summarized above. ### Readiness decision Serving-health readiness is the requested contract for this repair: an ordinary reload does not report the whole serving Gateway as unavailable. New agent runs still wait on the existing replacement gate, visible in status. Recovery and failed activation remain unhealthy. This resolves the local review's advisory product-direction question without changing admission policy. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 2f246fd)
Related: #205435, #195478 A plugin reload after an update could make the whole Gateway fail `/readyz` for its 60-second drain, even though the previous plugin generation was still serving. A cancelled cron run could also abandon its selected plugin-generation lease before execution started, leaving future reloads waiting on work that had ended. Ordinary plugin reload drains no longer make the Gateway not-ready. Failed activation or recovery still fails readiness. Cancelling a prepared cron run releases its selected generation. No settings, stored formats, drain budgets, retries, or active-turn pinning rules change. The readiness owner treated every reload status as a core outage. It now distinguishes an ordinary reload from failed or recovering activation. Cron preparation acquired its selected execution lease before two awaits, but execution only registered disposal inside the later callback. The preparation owner now owns the lease across resource cleanup, session admission, and execution; the later duplicate ownership is removed. Its existing cleanup stack releases the session preparation hold, joins the session owner's settlement receipt, deletes the continuation after admission unwinds, then releases the lease. This preserves #180877 without a timer or retry. This fixes a concrete leak on the cron preparation path used by the fleet run. The decision-only path reported in #205435 is **not yet proven** to have this cause, so that issue remains open. This does not solve #195478: active turns still retain their admitted plugins; only abandoned cron holds are removed. - Base `caf2a4d4f7dc`: the new cron owner regression fails because one real retained plugin work reference remains after cancelled session admission; execution never starts (45 ms test time). - Readiness owner regression fails on the base with `plugin-reload` and passes on the candidate. Recovery/failed-health cases remain covered. - Real isolated source Gateway, with `plugins.reload` unresolved behind an admitted held request: base HTTP **200 → 503 → 200**; candidate HTTP **200 → 200 → 200**. Base run 23.11 s, candidate run 50.34 s. Both Gateways and state were cleaned. - Gateway consumer batch: 8 files / 179 tests passed, including real HTTP readiness during a held drain and after its forced drain failure. - Production delta measured with `tokei`: **+8 code lines** (971 → 979 across the three changed production modules). - Initial focused batch: **15 files / 271 tests passed** in 376.50 s wall time. After the cleanup-order repair, the final three cron owner files passed **21/21 tests**, including #180877's external ordering assertion and the cancelled-continuation regression (12 ms; 45 ms on the failing base). - `check:changed` passed core production/test typechecks, formatting, and guards. Its dead-export scan reported three untouched exports (`readUpdateDatabaseEngineConfig`, `DoctorContributionPending`, `formatUpdateSnapshotCapacity`); no suppression or unrelated code repair is included. - Final scoped checks passed: formatting, oxlint (zero warnings/errors), core production types, and the services-cron test type graph. Final checks plus the three-file test run took 69.40 s; Vitest itself took 43.60 s. - Local ClawSweeper reviewed `caf2a4d4f7dc` → `25e3fdb6b90c` at default service tier: complete, **patch is correct**, zero findings, security cleared. The offline review did not receive execution receipts; the observed runs are summarized above. Serving-health readiness is the requested contract for this repair: an ordinary reload does not report the whole serving Gateway as unavailable. New agent runs still wait on the existing replacement gate, visible in status. Recovery and failed activation remain unhealthy. This resolves the local review's advisory product-direction question without changing admission policy. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 2f246fd) Release adaptation: Merge runtime lease ownership and settlement-ordered continuation cleanup into the existing prepareCronRunContext in run-prepare.ts, without the later owner split (3ad2cce). The regression drives the stable preparation path with its existing harness, aborts at continuation initialization, and observes real lease holds and admission unwind. Stable readiness stays in its existing owner. The later same-file 6d86389 only relocates the readiness type; 1ed6fd2 (#207091) adds provider rate-limit reset handling. Neither is needed. Co-authored-by: RomneyDa <[email protected]>
Related: #180758
What Problem This Solves
A completed isolated Agents API cron turn deleted its exact-run continuation session while still owning admission for that session. Native deletion drains the admitted turn, creating a self-dependency: the owner cannot settle until deletion returns. Defer deletion until admission unwinds, retain the prepared runtime generation during cleanup, and dispose that runtime afterwards through the existing resource stack.
Evidence
Observed native Gateway/cron capture.
Built main (
32276e16fb7807083d4452f2a9ec50084f6c95ae) and the candidate with Node 24.22.1 in secretless Linux Docker. Each case starts a real built Gateway, then runs shippedcron add,cron run --wait, andcron runs. The actual OpenAI SDK, Agents API harness, native session controller, continuation cleanup, and durable cron history are used. Only external HTTP responses are synthetic, provided by a local TLS endpoint; no hosted key is used. No lifecycle function, timer, drain budget, or clock is replaced.All four runs finish with
status: ok,completionStatus: succeeded, and summaryCRON_NATIVE_COMPLETED. Each creates exactly one real native session; the fixture records no native input cancellation. Main logs the continuation-removal failure because the session is still settling. Candidate completes deletion and publishes history promptly.Ordinary embedded-runtime controls also succeed on both refs (2,410 / 2,844 ms), remove their exact continuation row, and produce no cleanup warning. The timing includes production cleanup and CLI/readback overhead; it is a regression discriminator, not a benchmark.
Focused checks: 9 execution-diagnostic tests pass, including native cleanup on success and provider failure. Formatting and lint pass for both changed files.
Not Fixed Here
This fixes the self-drain ordering of completed isolated native turns. It does not claim to fix every cause of a cron stall or the linked report's persistent empty-history symptom after the full wait: baseline history eventually became visible in these runs. Existing pending-delivery, descendant, media-task, and continuation-retention safeguards are unchanged.
Compatibility and Merge Danger
No configuration, storage format, provider contract, or public API changes. Reverting fully restores the old cleanup ordering: a two-way door. Blast radius is isolated cron teardown ordering and prepared-runtime lifetime; ordinary execution, delivery policy, and genuine failure reporting must remain unchanged.