Skip to content

fix(cron): a cron run that hands off to a child times out even when the child answers in seconds - #197695

Merged
obviyus merged 2 commits into
mainfrom
fix/cron-owed-child-settle
Nov 12, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/cron-owed-child-settle

Conversation

@obviyus

@obviyus obviyus commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: an isolated cron job fails with "cron: job execution timed out" when its agent hands work to a child that owes it a result (sessions_spawn, default expectsCompletionMessage: true) and then ends with NO_REPLY, even when the child answers within seconds. The failure counts toward the job's error backoff. With --announce delivery the child's answer is also never sent.

User Impact

Supervisor-style cron jobs that hand off to a child now finish ok right after the child answers. With delivery none the run records the child's answer quietly; with --announce the child's answer is delivered. A child slower than the job timeout still times the run out, and runs whose agent replies itself are unchanged.

Why This Change Was Made

The run waits for the child's result before it finishes (#162474). When the child finished, the completion handoff asked whether the cron run's session was busy. Since #175837, a cron run holds its session turn for its whole run, including this wait, so the answer was always "busy". The handoff then started a new parent turn, which had to wait for that same held turn. The run waited for the child, the child's handoff waited for the run, and the job timeout broke the tie. The queued parent turn then ran right after the timeout.

Before #175837 this check asked whether the parent's agent run was live (isEmbeddedAgentRunActive). #175837 moved it to the session controller as part of a broad migration; its body and reviews do not discuss cron handoffs. Now a cron run counts as busy for this handoff only while its agent attempt is live. After the attempt ends, the existing handoff applies: the completion is recorded and the cron run reads the child's result itself (completion_handoff_pending, which already says "an idle cron turn settles this completion").

What #175837 needs stays in place: the cron run still holds its session turn, and this path never starts a turn, so no second parent turn can run beside it. While the cron agent attempt is live, the completion still steers into or queues behind it, as before. The shared requester activity check used elsewhere is unchanged. No new text, nothing stored changes.

Related work:

Evidence

A built Gateway in a secretless node:24.22.1 container, with a stand-in model and a stand-in Telegram Bot API. Each scenario is an isolated cron agentTurn with a 40 s timeout whose agent calls sessions_spawn and then answers exactly NO_REPLY, unless noted. Two runs on main ce76ed2 and two on this PR; two more runs on the earlier main 37e568b match main.

Scenario main (2 runs) this PR (2 runs)
owed child answers in 5 s, --no-deliver error: job execution timed out at 40 s, consecutiveErrors 1; the parent is woken only after the timeout ok in 8-13 s, silent, consecutiveErrors 0; finishes under 1 s after the child answers; child answer recorded as the run summary
same, --announce to Telegram error (timeout); nothing sent ok in 6-8 s; the child's answer is sent once
owed child slower than the timeout (60 s) error (timeout) error (timeout), unchanged
owed child whose model call fails error (timeout) error: "cron child-session handoff completed without a final assistant payload" (existing text) after about 16 s
child answers while the parent's agent attempt is still live ok; the completion reaches the live attempt same
parent replies itself, --announce to Telegram, no spawn ok; reply sent once same
fire-and-forget child ok same
collector child never collected error (timeout) same

An instrumented copy of main (log lines only) shows the blocking point: the child answered at 10:10:23.116, the handoff saw the cron run's session as busy at 10:10:23.354 and started a parent turn, the run's child wait returned unsettled at the 40 s timeout (10:10:53.585), and the queued parent turn ran at 10:10:54.888.

Regression: one row in subagent-announce-delivery.test.ts (a cron run holding its turn after its attempt ended) fails on the base (path: direct, a requester turn is dispatched) and passes on this branch; paid for by inlining a test helper (tests net -1). Focused announce suites pass. Production +7 lines in one file.

Run details: #197695 (comment)

@clawsweeper

clawsweeper Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Proof runs (built Gateway, node:24.22.1, stand-in model and Telegram Bot API). Driver and per-run artifacts kept in the loop proof folder.

Cron owed-child completion after timeout. Built Gateway, secretless node:24.22.1 container bugloop-cron-owed-child,
stand-in chat-completions model, stand-in Telegram Bot API (apiRoot), isolated cron agentTurn, --timeout-seconds 40.
Driver cron-drive.mjs (from proofs/197571), runner run.sh. Runs under runs/.
Trees: main = 37e568b (old base), main2 = ce76ed2 (current base, includes #197658), cand = 096c33d (ce76ed2 + fix).

Blocking edge (runs/probe-1, instrumented copy of main 37e568b, log lines only):
  10:10:23.116 child answers
  10:10:23.354 announce: requester=cron run session, requesterActive=true (the run's held session turn)
  10:10:23.356 announce starts a parent-turn call (queues behind the run's held turn)
  10:10:53.585 cron descendant wait returns {aborted:true, unsettled:true} (job timeout)
  10:10:54.888 queued parent turn runs (NO_REPLY), after the run already failed

Scenario                         main 37e568b x2 / main2 ce76ed2 x2            cand 096c33d x2
ann (owed child 5 s, NO_REPLY,   error timed out 40 s, ce 1; parent woken      ok 8.2 s / 13.4 s, silent, ce 0, summary = child answer,
     --no-deliver)               after the timeout                             run ends 0.2-0.9 s after the child answers; no extra parent turn
dlvann (same, --announce tg)     error timed out 40 s, nothing sent            ok 5.8 s / 7.7 s, child answer delivered once to Telegram
dlv (parent replies, announce)   ok, parent report delivered once              same
live (child answers during the   ok ~8.7 s, completion steered into the live   same (unchanged)
     parent's live attempt)      attempt, parent saw the result
slow (owed child 60 s)           error timed out 40 s                          same
fail (owed child model 400)      error timed out 40 s (main2: parent woken     error "cron child-session handoff completed without a final
                                 after the timeout)                            assistant payload" in ~16 s (existing text; ~15 s failure grace)
ff (fire-and-forget)             ok < 1 s                                      same
coll (collector, never collected) error timed out 40 s                         same

Focused tests (worktree, cand): subagent-announce-direct-delivery, subagent-announce-delivery, subagent-announce.timeout: 141 passed.

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The PR lets a cron run consume its child’s completion after the parent’s agent attempt ends, even while the run still holds its session turn.

Example: A cron run has a 40-second timeout, spawns a child, ends with NO_REPLY, and receives the child’s answer after 5 seconds.

  • Before: The run times out, increments its error count, and sends no announcement.
  • After: The run finishes successfully with the child’s answer and announces it once when delivery is enabled.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-supported repair with a reported red/green regression and shipped Gateway plus real Telegram proof; model output is deterministic fixture input.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The exact-head built Gateway exercises cron, sessions_spawn, child completion, and real Telegram Test Server delivery, with a real-user recorder observing one announcement after successful settlement; deterministic stand-in model responses isolate the scheduling trigger, and earlier Gateway runs cover silent delivery, live-parent, slow-child, failed-child, and fire-and-forget controls.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A scheduled supervisor run fails and loses its announcement even though its delegated child answered before the deadline.
Reason: The maintainer-authored PR restores established cron child settlement while preserving controller serialization and existing delivery policy.

Regression provenance

Regression provenance — suspected predecessor, not a causality claim: source commit ae6f813e73bb by Peter Steinberger; no PR verified.

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

Merge readiness

✅ Ready for maintainer review

This PR fixes a current cron completion deadlock with a narrow change; source review and shipped Gateway/Telegram evidence support merging, with no actionable findings.

Priority: P1
Reviewed head: 5bdea6d4a554f6e052eebd1677f8c75998dc72d3

Before merge

None.

Findings

None.

Agent review details

How this fits together

Child completion enters the subagent announcement owner, which either steers an active parent attempt or leaves settlement to cron; cron records the child’s result and applies the job’s delivery policy.

flowchart TD
  A[Cron run holds session turn] --> B[Parent spawns child and ends attempt]
  B --> C[Child completion]
  C --> D[Announcement owner checks live attempt]
  D --> E[Cron consumes settled child result]
  E --> F[Record summary and optional announcement]
Loading

Technical review

Best possible solution:

Keep cron settlement in its existing owner and use live agent-attempt activity solely to decide whether the child completion needs a parent handoff.

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

The held controller turn, child-settlement wait, and requester dispatch establish the circular wait in source, corroborated by the contributor’s before/after Gateway traces; no target code was executed during this review.

Is this the best way to solve the issue?

This is the smallest complete repair: it reuses the existing attempt query and cron handoff, adds one distinct regression case, and introduces no new owner, state, option, or fallback.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5dd83baa10f3.

Provenance checked

  • Cron completion activity check changes intended behavior with a stated reason (36e277d: The session-controller migration unified session admission, steering, and settlement; the resolver import changed the activity meaning used by this existing condition.)
  • Announcement test fixture simplification keeps the original intent (20b3430: The earlier test consolidation reduced repeated fixture and assertion boilerplate while preserving lifecycle contracts; the inlined assertions and removed unused responses retain those contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit afa73f3 adds src/agents/subagents/announce/subagent-announce-direct-delivery.ts:84 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: afa73f35c911; files: src/agents/subagents/announce/subagent-announce-direct-delivery.ts)

PR surface

Source +7, Tests -1. Total +6 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 13 6 +7
Tests 1 14 15 -1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 27 21 +6

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 proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: The current regression makes delegated cron runs time out despite completed children, suppresses announcements, and incorrectly triggers error backoff.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (2 earlier review cycles)
  • reviewed 2026-11-12T10:50:41.537Z sha 096c33d :: needs maintainer review before merge. :: none
  • reviewed 2026-11-12T11:12:47.293Z sha 5bdea6d :: needs maintainer review before merge. :: none

Reviewed November 12, 2026, 6:49 AM ET / 11:49 UTC (Revision 3).

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 12, 2026
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Live Telegram proof for the delivered case.

Setup. Built Gateway (pnpm build, dist/entry.js) in a secretless node:24.22.1 Docker container, one tree each: main ce76ed2 (this PR's base) and this PR's head 5bdea6d. Real Telegram Test Server: a leased bot and a real user account (TDLib userbot) recording the bot's DM. Each run starts a fresh Gateway and adds an isolated cron agentTurn with --announce --channel telegram --to <the user's DM> and --timeout-seconds 40, then runs it with openclaw cron run --wait.

The model is a stand-in on purpose: loop proofs carry no secrets or real model keys. Everything else is live: Gateway, cron, sessions_spawn, the child session, announce, and the Telegram Bot API to a real chat that a real user account sees.

  • ANN: the parent calls sessions_spawn (the child owes its result), then ends with exactly NO_REPLY. The child answers LANE_DONE_ANN_<tag> after 5 s.
  • DLV (control): the parent replies PARENT_REPORT_DLV_<tag> itself. No child.

Result (2 runs per tree)

main ce76ed2 run 1 / run 2 PR 5bdea6d run 1 / run 2
ANN cron run error: "cron: job execution timed out (last phase: model-call-started)", 40.07 s / 40.09 s ok in 11.7 s / 11.4 s, summary = child's answer
ANN in the Telegram DM nothing LANE_DONE_ANN_CAND1 / LANE_DONE_ANN_CAND2, once each
DLV control ok, report delivered once ok, report delivered once

On main the child answers 5 s in, but the parent only gets the child's result about 35 s later, after the job has already timed out. It then answers NO_REPLY again and nothing is sent. Main run 1, from the stand-in's request log:

11:35:37 parent  sessions_spawn
11:35:37 parent  NO_REPLY
11:35:43 child   answered LANE_DONE_ANN_MAIN1
11:36:13 parent  NO_REPLY (input has the child's result)   <- after the 40 s timeout

On the PR the run ends 1.2 s / 1.5 s after the child answers, with no extra parent turn. The DM gets exactly one message per case:

cand-1: bot message +16.4 s  LANE_DONE_ANN_CAND1
        bot message +63.7 s  PARENT_REPORT_DLV_CAND1
main-1: bot message +63.1 s  PARENT_REPORT_DLV_MAIN1     (no ANN message)

Telegram counts per run (bot messages in the DM): main ANN 0 / 0, PR ANN 1 / 1, DLV 1 on all four runs. No NO_REPLY text reached the chat in any run.

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 12, 2026
@obviyus
obviyus merged commit 9215601 into main Nov 12, 2026
179 checks passed
@obviyus
obviyus deleted the fix/cron-owed-child-settle branch November 12, 2026 11:52
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 9215601.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…he child answers in seconds (openclaw#197695)

fix(cron): let an owed child's answer settle the cron run before its timeout

An isolated cron run that spawned a child owing its result and ended with NO_REPLY held its session turn for the whole run (openclaw#175837). When the child answered, the result handoff saw the cron run's session as busy and queued a parent turn that could only start after the run released that turn, while the run's own descendant wait returned only at the job timeout. So the run timed out as an error even when the child answered within seconds, and announce-delivered runs sent nothing. A cron-run requester now counts as busy for this handoff only while its agent attempt is live; after the attempt ends, the existing handoff lets the cron run read the child's result itself. That path never starts a turn, so there are still never two parent turns at once. No text changes.

Evidence: a built Gateway with the shipped cron driver and a stand-in model where the parent spawns an owed child that answers in about 5 s and then ends with NO_REPLY, with a 40 s job timeout. On main the run timed out at 40 s with an error; with this change it finishes ok and silent within about a second of the child's answer. With --announce to a live Telegram Test Server DM, main timed out at about 40 s and sent nothing, and this change succeeded in about 11.5 s with the child's answer delivered once, in two runs each. A child slower than the timeout still times out, a failed child now reports the existing handoff error, and a child answering while the parent attempt is live, a parent that replies itself, a fire-and-forget child and a collector child behave the same on both. One row in the existing delivery table fails on main, at -1 net test lines. Details: openclaw#197695 (comment).

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…he child answers in seconds (openclaw#197695)

fix(cron): let an owed child's answer settle the cron run before its timeout

An isolated cron run that spawned a child owing its result and ended with NO_REPLY held its session turn for the whole run (openclaw#175837). When the child answered, the result handoff saw the cron run's session as busy and queued a parent turn that could only start after the run released that turn, while the run's own descendant wait returned only at the job timeout. So the run timed out as an error even when the child answered within seconds, and announce-delivered runs sent nothing. A cron-run requester now counts as busy for this handoff only while its agent attempt is live; after the attempt ends, the existing handoff lets the cron run read the child's result itself. That path never starts a turn, so there are still never two parent turns at once. No text changes.

Evidence: a built Gateway with the shipped cron driver and a stand-in model where the parent spawns an owed child that answers in about 5 s and then ends with NO_REPLY, with a 40 s job timeout. On main the run timed out at 40 s with an error; with this change it finishes ok and silent within about a second of the child's answer. With --announce to a live Telegram Test Server DM, main timed out at about 40 s and sent nothing, and this change succeeded in about 11.5 s with the child's answer delivered once, in two runs each. A child slower than the timeout still times out, a failed child now reports the existing handoff error, and a child answering while the parent attempt is live, a parent that replies itself, a fire-and-forget child and a collector child behave the same on both. One row in the existing delivery table fails on main, at -1 net test lines. Details: openclaw#197695 (comment).

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 9215601)

Release adaptation: Use existing active attempt handle rather than session turn activity for cron child settlement. Baseline 1 failed/110 passed; fixed 111 passed.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 7d536a79ce11952bf2db832bcec55f50983f581a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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