Skip to content

fix(cron): cron runs that generate images stall and retry their completion forever - #199529

Merged
obviyus merged 3 commits into
mainfrom
openclaw/keen-crayfish
Nov 15, 2026
Merged

obviyus merged 3 commits into
mainfrom
openclaw/keen-crayfish

Conversation

@obviyus

@obviyus obviyus commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

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 #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.

obviyus and others added 2 commits November 15, 2026 13:59
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
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling extensions: qa-lab size: XL labels Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: c7ad30be1908d717e2129f52e14c108ec51384b8
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-methods/cron-creator-authority-admission.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/skill-library-authoring.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Image generation detaches, leaving the run waiting for a completion handoff that cannot finish.
  • After: The original turn receives “Generated 1 image” and finishes with status ok.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The repair is focused and source-supported, with useful reported Gateway coverage and no remaining actionable finding; proof confidence remains limited to the supplied deterministic regression.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the contributor proof gate; its supplied evidence reports an isolated Gateway regression with deterministic model and image providers, without attached live-run output.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Cron jobs that generate media can stall, report failure, and keep retrying completion even after producing their output.
Reason: The maintainer-authored direction restores a concrete workflow through existing execution machinery and removes the path it replaces.

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
Reviewed head: c7ad30be1908d717e2129f52e14c108ec51384b8

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Cron media detachment and completion wait changes intended behavior with a stated reason (f6365d0: Keep cron generation detached while waiting for image, music, and video completion before final closeout.)
  • Exact continuation claims, restoration, and settlement changes intended behavior with a stated reason (fix(cron): preserve cron context in session entry for async completion wakes #101078: Preserve the originating cron run’s model, policy, native session, transcript context, and delivery custody across detached completion.)
  • Notification-driven async wait and benchmarks changes intended behavior with a stated reason (perf(agents): wake media completion waits from owner changes #182925: Replace periodic completion polling with media-owner and deadline notifications while retaining completion-wait semantics.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -849, Tests -1549, Docs +4, Other -494. Total -2888 across 62 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 26 27 876 -849
Tests 30 106 1655 -1549
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 5 22 516 -494
Total 62 159 3047 -2888

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The reported production failure stalls media-generating cron jobs and repeatedly retries rejected completion handoffs.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-15T08:56:14.891Z sha ce46c86 :: needs changes before merge. :: [P2] [P2] Remove the retired mock from its ratchet baseline

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]>
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 15, 2026
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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. labels Nov 15, 2026
@clawsweeper clawsweeper Bot removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 15, 2026
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: checks-node-changed-compact-large-22 (and the openclaw/ci-gate aggregate that reports it) fails only in src/gateway/talk/handlers/client-native-control.test.ts (4 cases of "controls a real native consultation without client control"). The same 4 cases fail locally on this PR's merge base 31d24f1104e6 without this change (ocx test src/gateway/talk/handlers/client-native-control.test.ts: 4 failed / 10 passed), and failed again after one rerun --failed (job 132783601418). This PR does not touch Talk. Exact-head ClawSweeper review is ready; the cron image E2E (test/e2e/qa-lab/media/cron-image-generation.e2e.test.ts) is red on main and green on this head.

@obviyus
obviyus merged commit e6265d6 into main Nov 15, 2026
238 of 243 checks passed
@obviyus
obviyus deleted the openclaw/keen-crayfish branch November 15, 2026 10:48
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in e6265d6. Cron runs that call image, music or video generation now get the media back as the tool result and finish ok, instead of stalling until the watchdog and then retrying a refused completion handoff indefinitely. Proof: the new cron image QA-lab E2E is red on main and green on this head. Follow-ups: bounded completion retries for every session type, and one shared rule for background work in one-shot runs.

obviyus added a commit that referenced this pull request Nov 15, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…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]>
amittell added a commit to amittell/openclaw that referenced this pull request Nov 25, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: qa-lab gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts security-sensitive-changed 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.

1 participant