Repository navigation
fix(cron): cron runs that generate images stall and retry their completion forever - #199529
Conversation
Detached media in an exact cron run completed through a cron continuation turn that no caller could admit after #185730. The run then stalled until the watchdog killed it, and each image retried its rejected handoff until the Gateway restarted. Cron runs now wait for their media inline and receive it as the tool result. The unreachable generated-media cron continuation path is removed. Co-authored-by: obviyus <[email protected]>
…etion forever OpenClaw-Publication: ed108d3b-b25e-8819-8cde-583d1a429b0e
|
🦞👀 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 makes isolated cron runs await media generation inline and removes their obsolete completion-continuation machinery. Example: The isolated job “Cron image E2E” generates a QA lighthouse image.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete cron media deadlock with a coherent simplification; the earlier baseline finding is resolved, and the remaining CI failure also occurs on main. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe shared media lifecycle connects agent tools to generation providers and returns generated files; isolated cron turns now consume those results before normal cron settlement. flowchart LR
A[Isolated cron run] --> B[Media generation tool]
B --> C[Shared media lifecycle]
C --> D[Generation provider]
D --> E[Inline media result]
E --> A
A --> F[Normal cron settlement]
Technical reviewBest possible solution: Keep cron media generation inside the original admitted turn and retain the existing stored-marker compatibility and cleanup owners. Do we have a high-confidence way to reproduce the issue? Current-main detachment, continuation admission, and requester-settlement code establish the failing path; the author reports a matching red/green Gateway regression that was not rerun during this read-only review. Is this the best way to solve the issue? The smallest complete repair reuses foreground media execution, preserving the cron turn’s model, instructions, and authority while removing both sides of the completion deadlock. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a426bf146b1b. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -849, Tests -1549, Docs +4, Other -494. Total -2888 across 62 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel 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 HistoryReview history (1 earlier review cycle)
Reviewed November 15, 2026, 5:34 AM ET / 10:34 UTC (Revision 2). |
Cron runs no longer detach media, so the runner wait that held a run open until its detached media settled can never trigger. It was also the half of the deadlock that kept the run open until the stall watchdog fired. Remove the wait, its benchmarks and the stale mock-export baselines. Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Maintainer override: |
|
Landed in e6265d6. Cron runs that call image, music or video generation now get the media back as the tool result and finish |
…9585) ## What Problem This Solves Fixes: a cron run can be handed late background work, such as a command exit or a completion, after it has ended. Each producer decided by itself whether a cron run could receive a later turn. When two producers disagreed (media expected a later turn; the runner waited for the media), production hit a deadlock and a retry storm of about 16.5k attempts. ## User Impact A cron run receives background results only while its executor still owns it: as an inline tool result, or through `sessions_yield`, which the cron executor resumes in place. After the run ends, the Gateway refuses any new turn on its run session one time, with `cron run has ended; inspect the result in its run record`. Results stay in their durable records (process log, subagent registry, task record). Background commands that are still running when the run ends are not awaited. The run history now names them in its diagnostics, so the run does not look complete while its commands continue. Subagent behavior does not change. ## Why This Change Was Made One rule now has one owner. `isEndedCronRun` (cron run key, and no run of that session has a live execution owner) is the same check exec-notify did before. Both turn admission owners call it: - Gateway agent-turn preparation (`agent-session-prepare.ts`), next to the other session start refusals. - The session-event handoff (`enqueueSessionEventForHost`), as the acceptance check. Exec exit wakes reach a session through this path, not through `agent` RPC. The check runs at enqueue and again until the occurrence is accepted. `isOneShotRunSessionKey` (cron run key or subagent key) replaces the duplicated `subagent || cron run` checks. | Producer | Before | After | |---|---|---| | Background exec exit (`bash-tools.exec-notify.ts`) | Own `assertExitNotificationAcceptanceCurrent` cron check; own `hiddenSubagent \|\| isCronRunSessionKey` one-shot check | No cron check. One-shot uses `isOneShotRunSessionKey`. The session-event admission refuses an ended run, and the warning still says `inspect the result with process log` | | Exec exit-wake guidance (`bash-tools.exec-output.ts`) | Read the producer's cron assertion | One-shot runs promise a wake only through `sessions_yield` (`isOneShotRunSessionKey`) | | Exec default timeout (`exec-tool-timeout.ts`) | `isSubagentSessionKey \|\| isCronRunSessionKey` | `isOneShotRunSessionKey` | | Exec batching (`session-event-batch.ts`) | Bypassed batching when the exec cron assertion was present | No cron special case. A batched turn is admitted through the same gate | | `agent` RPC turns on a cron run key (for example subagent completion, manual) | No ended-run refusal | Refused with the typed `INVALID_REQUEST` above | | Media (`media-generate-background-shared.ts`) | Inline in cron runs (#199529) | Unchanged | | `sessions_send` | Cron-specific branches | Unchanged. No site means only "requester cannot receive a later turn": the follow-up path lets yielded subagent requesters receive registry turns, and the executor keeps the `:trigger` case plus a wait-failure notice that applies to cron only | The cron executor comments on the intended asymmetry: subagents are awaited because their output is the run's output; background commands are not, because they can be services. Jobs with `deleteAfterRun` still delete the run session, and that stops its commands (existing behavior). The `cronRunContinuation` marker is not changed (separate follow-up). ## Evidence - New QA-lab Gateway e2e `test/e2e/qa-lab/runtime/cron-one-shot-run.e2e.test.ts` (real Gateway, mock-openai). Each case checks that the run reaches status `ok`, that an `agent` turn on the ended run key is refused with the typed error, and that no model request occurs after the run ends: - (a) background `sleep 3; echo …`, then `sessions_yield`: the run resumes in place, and its summary contains the command output. - (b) background `sleep 30; echo …`, no yield: the run ends in less than 25 s. Its diagnostics name the running command. Its exit later logs `completion was not admitted (cron run has ended…); inspect the result with process log` exactly once and starts no turn. - (c) the cron run spawns a child and ends its turn: the run completes with the child's result (regression guard). - New-behavior assertions: the `agent` refusal (all cases), the diagnostics entry and the refusal text (b). The yield resume and the child result are existing behavior. I did not run this e2e on the base. - `test/e2e/qa-lab/media/cron-image-generation.e2e.test.ts` passes. - Unit test at the admission boundary (`agent-session-preparation.worker.test.ts`): a cron run key is admitted while a run context owns it, and refused with `INVALID_REQUEST` after the run context is released. - Focused suites pass: exec background follow-up, exec notify, session-event handoff/readmission/permissions, gateway agent-turn, cron isolated-agent (62 files), qa-lab mock-openai. - On this head (rebased on main after #199529 landed): `pnpm tsgo:core`, `pnpm check:test-types`, `pnpm tsgo:scripts`, mock-export, max-lines, line-cap and assertion-safety ratchets, format, and oxlint all pass. The only oxlint finding is the existing max-lines on `session-event-handoff.ts`, which is grandfathered and has the same line count as main. - I did not run the full `ocx build --dts` and packed-install smoke on this rebased head. Both passed on the identical pre-rebase change. <details><summary>Follow-up finding: image_generate in a hidden subagent that never yields</summary> From reading the code only; no test. `shouldDetachMediaGenerationTask` detaches for every non-cron key, so a subagent's image detaches. Its completion goes through `deliverSubagentAnnouncement` as an `agent` turn on the subagent key. Gateway admission does not refuse it: inter-session input that is not `subagent_settle` does not reactivate the child registry row (`agent-run-subagent.ts`). The result is not the refused-completion retry storm. It looks like a late orphan turn in the finished child session, whose output probably does not reach the parent. The fix is not a one-line predicate swap, so it is not in this PR. </details> **Review follow-up (b8b06bb):** live cron completions bypass the exec completion batching lane again, keyed on the cron run session key instead of the removed producer-side acceptance check (the reason #199113 excluded them). New regression `admits every completion that arrives while its cron run is live` in `bash-tools.exec-background-followup.test.ts`: two background commands finish while the run is live and both are admitted; it fails with the bypass removed and passes with it. **Review follow-up 2:** the ended-run rule counts only the executor's own run (the run carrying the job invocation), so an accepted completion follow-up on the same session cannot make an ended origin look live (the case #172690 guarded with captured origin run ids). The admission boundary test now holds a follow-up owner while the executor releases and expects the refusal; it fails on the previous predicate and passes now. `check-lint-core-4` fails only in `lint extension package stripe`, which this PR does not touch. Co-authored-by: Ayaan Zaidi <[email protected]>
…etion forever (openclaw#199529) ## What Problem This Solves Fixes: a cron run that generates images is recorded as failed after a long stall, and each image then retries a rejected completion handoff every 1–2 seconds until the Gateway restarts. ## User Impact User impact: cron jobs that use `image_generate` (or other media tools) receive the generated media as the tool result, use or send it, and finish with status `ok`. No more false `semantic_stall` failures and no endless handoff retries in the logs. One production Gateway logged about 16,500 rejected attempts per image over 4.5 hours (`cron run completion handoffs are reserved for server-owned callers`) after a weekly cron run that had already delivered its output. ## Why This Change Was Made In an exact cron run, media generation detached into a background task whose completion came back as a later continuation turn on the run session. Admitting that turn needed a server-owned flag, and openclaw#185730 removed the only caller that set it, along with the other queued paths that launched model turns. Every generated-media completion for a cron run has been refused since then. A second owner made it a deadlock: the embedded runner held a cron run open until its detached media settled, while the media completion waited for the run to settle. Only the stall watchdog broke it. A cron run is already background work and delivers its own output, so it does not need a later turn to receive its media. Cron runs now take the existing inline path: the tool waits for the provider and returns the media. That makes both halves unreachable, so they are removed instead of re-wired: the generated-media cron continuation (admission branch, continuation claim/release controller, restored continuation policy and model plumbing through agent admission and execution, internal client flag), and the runner's completion-required async-task wait with its benchmarks. About 2,600 lines are removed in total. Not changed: the `cronRunContinuation` session marker that cron runs still write. Run tool policy, retention and `chat.send` still read it. Its now-unwritten `continuing` phase can be retired in a follow-up once old rows age out. ## Evidence - **Red on base:** new QA-lab E2E `test/e2e/qa-lab/media/cron-image-generation.e2e.test.ts` (scenario `cron-image-generation`) forces an isolated cron run against a deterministic image provider. On `main` the provider is called once and the run never reaches a terminal status (two runs). - **Green with the fix:** the same E2E passes in about 20 s. The provider is called once, the run's `image_generate` tool result carries the generated image, and the run finishes `ok`. - Focused suites pass: `agent.test.ts`, the media lifecycle and image tool tests, the embedded attempt execution/stream prepare/settle/finalize/lifecycle tests, agent admission/session/execution owner tests, local-operator authority, and artifacts. - `tsgo:core`, `tsgo:scripts` and `check:test-types` pass. Mock-export, max-lines and assertion-safety ratchets pass. `oxlint` and format are clean on changed files. A full build plus the packed tarball check and an installed `openclaw --version` smoke pass. Co-authored-by: Ayaan Zaidi <[email protected]>
…nclaw#199585) ## What Problem This Solves Fixes: a cron run can be handed late background work, such as a command exit or a completion, after it has ended. Each producer decided by itself whether a cron run could receive a later turn. When two producers disagreed (media expected a later turn; the runner waited for the media), production hit a deadlock and a retry storm of about 16.5k attempts. ## User Impact A cron run receives background results only while its executor still owns it: as an inline tool result, or through `sessions_yield`, which the cron executor resumes in place. After the run ends, the Gateway refuses any new turn on its run session one time, with `cron run has ended; inspect the result in its run record`. Results stay in their durable records (process log, subagent registry, task record). Background commands that are still running when the run ends are not awaited. The run history now names them in its diagnostics, so the run does not look complete while its commands continue. Subagent behavior does not change. ## Why This Change Was Made One rule now has one owner. `isEndedCronRun` (cron run key, and no run of that session has a live execution owner) is the same check exec-notify did before. Both turn admission owners call it: - Gateway agent-turn preparation (`agent-session-prepare.ts`), next to the other session start refusals. - The session-event handoff (`enqueueSessionEventForHost`), as the acceptance check. Exec exit wakes reach a session through this path, not through `agent` RPC. The check runs at enqueue and again until the occurrence is accepted. `isOneShotRunSessionKey` (cron run key or subagent key) replaces the duplicated `subagent || cron run` checks. | Producer | Before | After | |---|---|---| | Background exec exit (`bash-tools.exec-notify.ts`) | Own `assertExitNotificationAcceptanceCurrent` cron check; own `hiddenSubagent \|\| isCronRunSessionKey` one-shot check | No cron check. One-shot uses `isOneShotRunSessionKey`. The session-event admission refuses an ended run, and the warning still says `inspect the result with process log` | | Exec exit-wake guidance (`bash-tools.exec-output.ts`) | Read the producer's cron assertion | One-shot runs promise a wake only through `sessions_yield` (`isOneShotRunSessionKey`) | | Exec default timeout (`exec-tool-timeout.ts`) | `isSubagentSessionKey \|\| isCronRunSessionKey` | `isOneShotRunSessionKey` | | Exec batching (`session-event-batch.ts`) | Bypassed batching when the exec cron assertion was present | No cron special case. A batched turn is admitted through the same gate | | `agent` RPC turns on a cron run key (for example subagent completion, manual) | No ended-run refusal | Refused with the typed `INVALID_REQUEST` above | | Media (`media-generate-background-shared.ts`) | Inline in cron runs (openclaw#199529) | Unchanged | | `sessions_send` | Cron-specific branches | Unchanged. No site means only "requester cannot receive a later turn": the follow-up path lets yielded subagent requesters receive registry turns, and the executor keeps the `:trigger` case plus a wait-failure notice that applies to cron only | The cron executor comments on the intended asymmetry: subagents are awaited because their output is the run's output; background commands are not, because they can be services. Jobs with `deleteAfterRun` still delete the run session, and that stops its commands (existing behavior). The `cronRunContinuation` marker is not changed (separate follow-up). ## Evidence - New QA-lab Gateway e2e `test/e2e/qa-lab/runtime/cron-one-shot-run.e2e.test.ts` (real Gateway, mock-openai). Each case checks that the run reaches status `ok`, that an `agent` turn on the ended run key is refused with the typed error, and that no model request occurs after the run ends: - (a) background `sleep 3; echo …`, then `sessions_yield`: the run resumes in place, and its summary contains the command output. - (b) background `sleep 30; echo …`, no yield: the run ends in less than 25 s. Its diagnostics name the running command. Its exit later logs `completion was not admitted (cron run has ended…); inspect the result with process log` exactly once and starts no turn. - (c) the cron run spawns a child and ends its turn: the run completes with the child's result (regression guard). - New-behavior assertions: the `agent` refusal (all cases), the diagnostics entry and the refusal text (b). The yield resume and the child result are existing behavior. I did not run this e2e on the base. - `test/e2e/qa-lab/media/cron-image-generation.e2e.test.ts` passes. - Unit test at the admission boundary (`agent-session-preparation.worker.test.ts`): a cron run key is admitted while a run context owns it, and refused with `INVALID_REQUEST` after the run context is released. - Focused suites pass: exec background follow-up, exec notify, session-event handoff/readmission/permissions, gateway agent-turn, cron isolated-agent (62 files), qa-lab mock-openai. - On this head (rebased on main after openclaw#199529 landed): `pnpm tsgo:core`, `pnpm check:test-types`, `pnpm tsgo:scripts`, mock-export, max-lines, line-cap and assertion-safety ratchets, format, and oxlint all pass. The only oxlint finding is the existing max-lines on `session-event-handoff.ts`, which is grandfathered and has the same line count as main. - I did not run the full `ocx build --dts` and packed-install smoke on this rebased head. Both passed on the identical pre-rebase change. <details><summary>Follow-up finding: image_generate in a hidden subagent that never yields</summary> From reading the code only; no test. `shouldDetachMediaGenerationTask` detaches for every non-cron key, so a subagent's image detaches. Its completion goes through `deliverSubagentAnnouncement` as an `agent` turn on the subagent key. Gateway admission does not refuse it: inter-session input that is not `subagent_settle` does not reactivate the child registry row (`agent-run-subagent.ts`). The result is not the refused-completion retry storm. It looks like a late orphan turn in the finished child session, whose output probably does not reach the parent. The fix is not a one-line predicate swap, so it is not in this PR. </details> **Review follow-up (b8b06bb):** live cron completions bypass the exec completion batching lane again, keyed on the cron run session key instead of the removed producer-side acceptance check (the reason openclaw#199113 excluded them). New regression `admits every completion that arrives while its cron run is live` in `bash-tools.exec-background-followup.test.ts`: two background commands finish while the run is live and both are admitted; it fails with the bypass removed and passes with it. **Review follow-up 2:** the ended-run rule counts only the executor's own run (the run carrying the job invocation), so an accepted completion follow-up on the same session cannot make an ended origin look live (the case openclaw#172690 guarded with captured origin run ids). The admission boundary test now holds a follow-up owner while the executor releases and expects the refusal; it fails on the previous predicate and passes now. `check-lint-core-4` fails only in `lint extension package stripe`, which this PR does not touch. Co-authored-by: Ayaan Zaidi <[email protected]>
…del route On main 00a9cbf, 2 of the 3 cases failed: the fixture bound the delegated handoff to DEFAULT_MODEL, which openclaw#203271 (265577c) removed, so consumeSubagentCompletionToolHandoff returned nothing and the requester turn ran with disableTools: true. The handoff is now bound to the fixture's configured primary (openai/gpt-5.5), and the retention case asserts the embedded run carries that route. createAgentRunModelSelectionHandler lost lifecycleStorePath and activeSessionAgentId in openclaw#199529 (e6265d6), which the agents-root test typecheck reported as TS2353; the fixture passes the same fields as production's call in agent-run-execution-phase.ts.
What Problem This Solves
Fixes: a cron run that generates images is recorded as failed after a long stall, and each image then retries a rejected completion handoff every 1–2 seconds until the Gateway restarts.
User Impact
User impact: cron jobs that use
image_generate(or other media tools) receive the generated media as the tool result, use or send it, and finish with statusok. No more falsesemantic_stallfailures and no endless handoff retries in the logs. One production Gateway logged about 16,500 rejected attempts per image over 4.5 hours (cron run completion handoffs are reserved for server-owned callers) after a weekly cron run that had already delivered its output.Why This Change Was Made
In an exact cron run, media generation detached into a background task whose completion came back as a later continuation turn on the run session. Admitting that turn needed a server-owned flag, and #185730 removed the only caller that set it, along with the other queued paths that launched model turns. Every generated-media completion for a cron run has been refused since then. A second owner made it a deadlock: the embedded runner held a cron run open until its detached media settled, while the media completion waited for the run to settle. Only the stall watchdog broke it.
A cron run is already background work and delivers its own output, so it does not need a later turn to receive its media. Cron runs now take the existing inline path: the tool waits for the provider and returns the media. That makes both halves unreachable, so they are removed instead of re-wired: the generated-media cron continuation (admission branch, continuation claim/release controller, restored continuation policy and model plumbing through agent admission and execution, internal client flag), and the runner's completion-required async-task wait with its benchmarks. About 2,600 lines are removed in total.
Not changed: the
cronRunContinuationsession marker that cron runs still write. Run tool policy, retention andchat.sendstill read it. Its now-unwrittencontinuingphase can be retired in a follow-up once old rows age out.Evidence
test/e2e/qa-lab/media/cron-image-generation.e2e.test.ts(scenariocron-image-generation) forces an isolated cron run against a deterministic image provider. Onmainthe provider is called once and the run never reaches a terminal status (two runs).image_generatetool result carries the generated image, and the run finishesok.agent.test.ts, the media lifecycle and image tool tests, the embedded attempt execution/stream prepare/settle/finalize/lifecycle tests, agent admission/session/execution owner tests, local-operator authority, and artifacts.tsgo:core,tsgo:scriptsandcheck:test-typespass. Mock-export, max-lines and assertion-safety ratchets pass.oxlintand format are clean on changed files. A full build plus the packed tarball check and an installedopenclaw --versionsmoke pass.