Repository navigation
fix(cron): stale cron timeout aborts a later run in the same session - #163704
Conversation
…ssion The cron timeout cleanup aborts whatever run holds the session, so a replacement turn in agent:main:main is aborted after the cron run ended. These tests fail until cleanup is bound to the cron invocation run id. Refs openclaw#163568
Cron timeout cleanup aborted, force-cleared, and retired MCP for whatever run held the session. When the cron run had already ended in a shared session, that hit an unrelated turn. Record the invocation run id on the execution and skip cleanup when other work now holds the session. Fixes openclaw#163568
|
Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 5:58 PM ET / 21:58 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR binds scheduled agent timeout cleanup to the original run so it leaves a later conversation turn in the same session untouched. Merge readiness✅ Ready for maintainer review This PR remains useful: current main lacks the run-identity fence. The prior test-cost follow-up is complete, the runtime proof covers the reported cancellation boundary, and no blocking patch finding remains. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway scheduler starts scheduled agent turns and tracks their execution progress. Timeout cleanup consults the active agent registry before aborting work and retiring session tools. flowchart TD
A[Scheduled job] --> B[Agent invocation]
B --> C[Execution identity and progress]
C --> D[Timeout cleanup]
E[Current session run] --> D
D --> F{Different run active?}
F -->|Yes| G[Preserve current turn]
F -->|No| H[Abort and drain scheduled work]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +23, Tests +84. Total +107 across 6 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep timeout cleanup bound to its scheduled invocation while preserving normal cleanup when that invocation still owns the session. Do we have a high-confidence way to reproduce the issue? Yes: current-main cleanup can target a replacement run by session ID, and the contributor supplies a before/after Gateway reproduction using delayed completion delivery. This review did not execute that scenario. Is this the best way to solve the issue? Yes: propagating the existing invocation identity and checking the live run registry is a narrow repair that preserves active-cron cleanup without changing scheduling or public configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0356bacb8c66. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review The remaining test-cost report is complete in the PR body: one-worker wall times for both changed test files, plus exact-head CI job/shard seconds and individual regression timings, clearly distinguished from per-file CI wall time. Source and tests remain at |
|
🦞👀 Re-review progress:
|
|
Exact-head CI has one failing test job: checks-node-changed-compact-large32-1, with A secretless Linux Docker replay of the entire The spawn fixture imports No CI reruns, source pushes, or base updates were performed to obtain green. The maintainer decides whether to use the inherited-failure exception. |
|
Additional maintainer-observed proof, with the contributor head unchanged at
All task containers, dependency/build volumes, and the temporary credential file were removed. No source changes, rebase, push, or CI rerun were needed for the test-cost completion. ClawSweeper's latest review is |
|
Maintainer override for the one red check, |
|
Landed as 99f1f78. Thanks @jayzhou2309! |
…penclaw#163704) Fixes openclaw#163568. A cron agentTurn's stale timeout cleanup no longer aborts a later turn that now owns the same shared session. The cron invocation records its runId, and timeout cleanup skips cancellation when another turn occupies the session. A genuine timeout still cleans up.
…penclaw#163704) Fixes openclaw#163568. A cron agentTurn's stale timeout cleanup no longer aborts a later turn that now owns the same shared session. The cron invocation records its runId, and timeout cleanup skips cancellation when another turn occupies the session. A genuine timeout still cleans up. (cherry picked from commit 99f1f78) Co-authored-by: RomneyDa <[email protected]>
Closes #163568
What Problem This Solves
Fixes: a cron job's timeout aborts an unrelated run when the cron turn already finished in a shared session such as
agent:main:main, and another turn now owns that session.User Impact
User impact: a stale cron timeout no longer cancels, force-clears, or tears down MCP tools for the operator's current chat turn. A cron run that is still active at its timeout is aborted and cleaned up exactly as before.
Why This Change Was Made
The cron execution record carried only the session id, so the timeout cleanup in
src/gateway/server-cron.tsacted on whatever run held the session when the timer fired. The record now carries the cron invocation's run id, which every attempt, retry, and fallback of that turn registers its embedded handle under. Before it aborts, cleanup checks whether a different run (or an active reply run) now holds the session. If so it logs a warning and leaves the session alone. This is the run-identity fence the ClawSweeper review and the thread describe.Out of scope: why the cron completion stayed pending after its run ended, and the later transcript writer-claim failure. Both are still unconfirmed. This does not overlap #143355 (timeout reason for background exec) or #137274 (retry settlement fence), and it does not touch
agent-watchdog.ts.Evidence
timed-out agent run cleanuptests insrc/gateway/server-cron.test.tscall the cron service's realcleanupTimedOutAgentRunwith the real run registry andabortAndDrainEmbeddedAgentRun. OnlyretireSessionMcpRuntimeis mocked.abortis called once (1 failed, 1 passed). On the fix 6bdc59b it passes, the replacement stays registered, and MCP is not retired.src/cron/isolated-agent/run.invocation-context.test.tsasserts thatonExecutionStartedreports the same run id the embedded runner receives. It fails on the test commit and passes on the fix.pnpm teston the touched area:server-cron.test.ts129/129,run.invocation-context,timer.timeout-watchdog, andagent-watchdog36/36, andruns.test.tsplusruns.force-clear-terminal.test.ts27/27.oxlintandoxfmt --checkare clean on the 6 changed files, andgit diff --checkis clean.node scripts/run-tsgo.mjspasses fortsconfig.core.jsonand the gateway-server and services-cron test configs.Real behavior proof (live Gateway, before and after)
The agent ran the Gateway from source (
node scripts/run-node.mjs gateway run) in a scratch HOME on the base commit ed754fa and then on the fix 6bdc59b. Node 26.8.2,logging.level: "debug", no real credentials. Two local stand-ins replace external services:models.providers.mock,api: "openai-completions"). It answers the cron turn at once and answers any turn containingSLOWTURNafter 30 s.channels.a2a.peers.hermes) that accepts the request and never answers. This keeps the cron execution pending after its run has ended, the same state the issue shows. The A2A send gives up after about 30 s.The script runs the same steps on both commits:
openclaw cron add --name stale-timeout-probe --at 2h --session session:agent:main:main --message "cron ping" --timeout-seconds 15 --announce --channel a2a --to a2a:hermes --keep-after-runopenclaw cron run <job>. The cron turn finishes in about 1 s, then its announce waits on the peer.openclaw gateway call chat.send --params '{"sessionKey":"agent:main:main","message":"SLOWTURN operator question","idempotencyKey":"operator-<label>"}'chat.history.Before (ed754fa). The cron timeout aborts the operator turn, which started after the cron run ended (UTC, ids shortened):
After (6bdc59b). Cleanup leaves the session alone and the operator turn finishes:
Each result held on two runs of the script per commit. On both commits the cron job still ends with
cron: job execution timed out (last phase: model-call-started), the error the issue reports. Why the completion stays pending is out of scope, as stated above.What this run did not cover:
retireSessionMcpRuntimehas nothing to retire. Theserver-cron.test.tsowner case covers it.Test cost
Measured locally. Per-test times come from full-file runs on the fix with
--reporter=verbose:timed-out agent run cleanuptests take 54 ms and 92 ms.run.invocation-contexttest takes 184 ms.pnpm test src/gateway/server-cron.test.tsruns 129 tests in 38.0 s on the fix and 127 tests in 33.1 s on the base. A second run on the fix took 26.6 s, so the file's wall time varies more between runs than the new tests add.Maintainer test-cost completion (exact head
6bdc59b268e2ccc25af381506ab40ac0b748b3a8)Measured once in a secretless Linux arm64 Docker container (Node 26, pnpm 12.5.1), sequentially after installation/build; elapsed wall time includes the pnpm test wrapper and process startup:
pnpm test src/gateway/server-cron.test.ts --maxWorkers=1pnpm test src/cron/isolated-agent/run.invocation-context.test.ts --maxWorkers=1Available exact-head CI cost from run 37046107141:
agentic-control-plane-runtime-cronshard reports 29.47 Vitest seconds / 30.83 wrapper seconds across 12 files and 250 tests. The two new cleanup cases report 0.068 s and 0.089 s.core-runtime-cron-parallel-isolated-agentshard reports 94.27 Vitest seconds / 96.03 wrapper seconds across 38 files and 394 tests. The new invocation identity case reports 0.197 s.These are job/shard durations and individual test durations, not CI per-file wall times or estimates of marginal CI cost. CI does not report isolated wall time for either file. No CI jobs were rerun for this measurement.
No overlap with Pash/Sarah changes. Contributor commits and the contributor's before/after Gateway evidence above are retained unchanged.
AI disclosure
An AI agent (Claude Code) reproduced the wrong-run cancellation with the failing tests, wrote the fix, and ran the checks above:
pnpm exec vitest runon the new tests on the test commit and on the fix,pnpm teston the touched test files,pnpm exec oxlint,pnpm exec oxfmt --check,git diff --check, andnode scripts/run-tsgo.mjs. It also ran the live Gateway proof above against a local mock model and a mock A2A peer, on the base commit and on the fix.🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309.