Skip to content

fix(cron): preserve cron context in session entry for async completion wakes - #101078

Merged
steipete merged 19 commits into
openclaw:mainfrom
xialonglee:fix/cron-async-media-wake-loses-context
Jul 10, 2026
Merged

steipete merged 19 commits into
openclaw:mainfrom
xialonglee:fix/cron-async-media-wake-loses-context

Conversation

@xialonglee

@xialonglee xialonglee commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #99919.

An isolated cron turn can finish while image_generate, music_generate, or video_generate is still running. The completion wake previously lost the exact cron run's model, thinking level, tool policy, native CLI session binding, transcript context, and delivery policy. Multi-step jobs could therefore resume with defaults, emit an incomplete reply, or silently stop.

Why This Change Was Made

The final maintainer rewrite keeps continuation state at the owners that can enforce it:

  • The cron runtime persists a hidden exact :run: row while detached media is pending and projects normal history to the stable cron row.
  • The server-owned gateway is the only caller allowed to claim an exact continuation. Claims use lifecycle revision, session identity, owner run, and gateway-generation guards.
  • Provider/model/thinking/tool policy, native CLI bindings, prompt mode, delivery policy, and exact transcript context are restored from that row.
  • Claim release and stable-row projection are one session-accessor transaction. Failed model candidates roll back instead of contaminating the stable row.
  • Durable release failures return UNAVAILABLE, retry in a bounded unref'd worker, and repair the cached terminal result after recovery without rerunning the model.
  • Restart-stale claims fail closed to the pinned direct-delivery fallback, and terminal media bookkeeping cleans eligible hidden rows even for delete-after-run jobs with no later timer tick.

This is intentionally an exact-run protocol rather than a base-session fallback: concurrent cron runs and provider-owned CLI sessions must not share mutable continuation state.

User Impact

Async media completion now resumes the original isolated cron task with its exact runtime and delivery context. Successful generated media remains deliverable during gateway restart or persistence degradation, and hidden continuation rows are bounded by terminal cleanup and cron retention.

Evidence

  • Sanitized public AWS Crabbox cbx_aa62c4edff9f, run run_8b37e22c4a9d: 636 focused tests passed across gateway settlement, session accessor, cron identity/policy, restart recovery, media lifecycle, and cleanup.
  • Earlier broad continuation run run_068d566be879: 1,195 tests passed.
  • Exact-head GitHub Actions run 29062957840: build, production types, test types, lint, session-accessor boundary, security scans, and completed compact shards are green.
  • Fresh Codex gpt-5.5/high autoreview: no accepted or actionable findings.
  • Local static checks: oxfmt, type-aware oxlint, git diff --check, and scripts/check-session-accessor-boundary.mjs passed.

No credentialed live provider call was run on untrusted contributor code. The contributor's earlier stub-assisted behavior proof is useful supporting evidence; sanitized regression tests and exact-head CI are the merge gates.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Jul 6, 2026
@xialonglee
xialonglee marked this pull request as draft July 6, 2026 17:50
@xialonglee
xialonglee force-pushed the fix/cron-async-media-wake-loses-context branch from 340dbae to 5176542 Compare July 6, 2026 17:57
@clawsweeper

clawsweeper Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 8, 2026, 6:06 AM ET / 10:06 UTC.

Summary
This PR persists a cron bootstrap marker on session entries and uses it to restore provider, model, thinking, run kind, and base-session routing for async media completion wakes.

PR surface: Source +90, Tests +211. Total +301 across 6 files.

Reproducibility: yes. source-reproducible: current main's generated-media completion handoff omits the cron provider/model/thinking/bootstrap context that normal cron execution carries, and the linked issue plus PR body provide symptom evidence.

Review metrics: 3 noteworthy metrics.

  • Persisted session metadata: 1 optional field added, 1 reserved slot added. The durable marker controls wake routing and must survive session-store persistence and plugin slot merging.
  • Cron wake routing: 1 run-key fallback path added. Completion wakes can target persisted base cron sessions instead of ephemeral run-session keys.
  • Synthetic model override: 1 internal authorization path enabled. Restoring the cron provider/model on wake depends on a privileged in-process gateway dispatch contract.

Stored data model
Persistent data-model change detected: serialized state: src/agents/agent-command.ts, serialized state: src/config/sessions/types.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #99919
Summary: this PR is the current candidate fix for the open cron/isolated generated-media completion context-loss issue; broader generated-media delivery reports overlap but do not replace it.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] The PR adds durable SessionEntry metadata and reserves a new slot, so maintainers should accept that old rows without bootstrapContextRunKind keep existing behavior while new cron rows carry routing state.
  • [P1] The PR intentionally changes async cron completion wakes from ephemeral run-session keys to persisted base cron session entries, which affects session association for generated-media follow-up turns.
  • [P1] The PR authorizes synthetic provider/model overrides for restored cron wakes; the reviewed path constrains this to trusted in-process dispatch, but that boundary is merge-relevant.

Maintainer options:

  1. Accept the targeted cron continuation contract (recommended)
    Merge after maintainers explicitly accept the persisted cron marker, base-session routing, and trusted synthetic model override as the intended compatibility tradeoff.
  2. Add one more upgrade guardrail
    Require an exact-head regression proof that absent bootstrapContextRunKind leaves non-cron and existing session rows on their previous wake path before merge.
  3. Replace with a broader continuation design
    Pause or close this PR if the permanent owner direction is a different cron/session continuation contract rather than SessionEntry metadata.

Next step before merge

  • No automated repair remains; the next action is maintainer acceptance of the session-state, compatibility, and message-delivery merge risk.

Maintainer decision needed

  • Question: Should this PR land with the new durable cron SessionEntry marker, base-session wake routing, and trusted synthetic model override as the accepted cron async-media continuation contract?
  • Rationale: The code path appears correct, but the fix changes compatibility-sensitive persisted session state and completion routing semantics that should be accepted by a maintainer before merge.
  • Likely owner: IWhatsskill — They authored the adjacent merged cron generated-media continuation fix that this PR builds on, making them the best available history owner for the routing choice.
  • Options:

Security
Cleared: No dependency, workflow, lockfile, secret, install, package, or external code-execution surface changes were found; the synthetic override is tracked as functional merge risk.

Review details

Best possible solution:

Land the narrow cron-aware wake restoration with its regression coverage and live proof after maintainers accept the durable marker, base-key routing, and trusted synthetic override contract.

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

Yes, source-reproducible: current main's generated-media completion handoff omits the cron provider/model/thinking/bootstrap context that normal cron execution carries, and the linked issue plus PR body provide symptom evidence.

Is this the best way to solve the issue?

Yes. This is the best bounded fix because it persists the missing cron marker, restores context only for cron entries, uses the persisted base session when run keys are ephemeral, and covers the invariant with focused tests.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4ae8d735bf54.

Label changes

Label justifications:

  • P1: The PR targets a scheduled-agent continuation regression where async media completion can silently abandon multi-step cron workflows.
  • merge-risk: 🚨 compatibility: The diff adds persisted session metadata and changes how cron completion wakes resolve sessions and model overrides.
  • merge-risk: 🚨 session-state: The PR intentionally changes wake association from run-scoped session keys to persisted base cron session entries.
  • merge-risk: 🚨 message-delivery: Generated-media completion wakes decide whether the requester agent continues and sends the expected follow-up instead of dead-ending.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body includes after-fix Gateway/session-store logs showing the async image_generate wake used the configured model, persisted cron marker, and base-key fallback.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix Gateway/session-store logs showing the async image_generate wake used the configured model, persisted cron marker, and base-key fallback.
Evidence reviewed

PR surface:

Source +90, Tests +211. Total +301 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 98 8 +90
Tests 1 211 0 +211
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 309 8 +301

What I checked:

Likely related people:

  • IWhatsskill: Authored the merged cron yielded-media completion fix in PR fix(cron): preserve yielded media completions #92146, which changed the inactive isolated cron generated-media routing this PR narrows further. (role: recent related fix author; confidence: high; commits: 84519f7e3cf9; files: src/agents/subagent-announce-delivery.ts, src/agents/subagent-announce-delivery.test.ts, src/agents/embedded-agent-runner/run/attempt.async-tasks.ts)
  • steipete: Authored the earlier cron media completion waiting fix and appears in adjacent embedded-run capability/profile routing history. (role: prior related fix author; confidence: medium; commits: f6365d07c46c; files: src/agents/embedded-agent-runner/run/attempt.async-tasks.ts, src/agents/embedded-agent-runner/run/attempt.ts, src/agents/openclaw-tools.ts)
  • vincentkoc: Current-main blame for the reviewed subagent announcement routing path is carried by recent localization/refactor work, making this a useful routing signal but not root-cause proof. (role: recent area contributor; confidence: medium; commits: 3dbe98a1f737; files: src/agents/subagent-announce-delivery.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-08T04:14:25.774Z sha 3aa829845fe8d74ee234a0b7b33ba11de1b114c5 :: needs real behavior proof before merge. :: [P1] Restore explicit recipient session routing | [P1] Preserve transcript media in agent turns
  • reviewed 2026-07-08T04:23:18.392Z sha 3aa829845fe8d74ee234a0b7b33ba11de1b114c5 :: needs real behavior proof before merge. :: [P1] Restore explicit recipient session routing | [P1] Preserve transcript media in agent turns | [P2] Keep lifecycle end logging normalized | [P2] Keep internal wakes from marking sessions active
  • reviewed 2026-07-08T06:24:19.910Z sha 1b532f48574c34381d3047580f1cb4253b10d2ef :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-08T06:41:44.724Z sha 1b532f48574c34381d3047580f1cb4253b10d2ef :: needs real behavior proof before merge. :: [P1] Persist the cron marker with a real snapshot delta
  • reviewed 2026-07-08T07:18:44.577Z sha 1b532f48574c34381d3047580f1cb4253b10d2ef :: needs real behavior proof before merge. :: [P1] Persist the cron marker from a real delta
  • reviewed 2026-07-08T08:57:02.850Z sha 378c8150cf52c0514e3d383a479958372562bf5e :: needs changes before merge. :: [P1] Pass a concrete snapshot to persistSessionEntry
  • reviewed 2026-07-08T09:04:31.089Z sha 378c8150cf52c0514e3d383a479958372562bf5e :: needs changes before merge. :: [P1] Pass a concrete snapshot to persistSessionEntry
  • reviewed 2026-07-08T09:16:46.079Z sha a119d25d6890d6c7ca3115f0f41c09435c2e914f :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 6, 2026
@xialonglee
xialonglee force-pushed the fix/cron-async-media-wake-loses-context branch from ebc2377 to 3aa8298 Compare July 8, 2026 04:05
@xialonglee
xialonglee marked this pull request as ready for review July 8, 2026 04:07
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 8, 2026
@xialonglee
xialonglee force-pushed the fix/cron-async-media-wake-loses-context branch from 3aa8298 to 1b532f4 Compare July 8, 2026 06:09
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 8, 2026
@xialonglee

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot removed the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Jul 8, 2026
@steipete
steipete force-pushed the fix/cron-async-media-wake-loses-context branch from ecccb9b to bd10be2 Compare July 10, 2026 01:56
@steipete

Copy link
Copy Markdown
Contributor

Maintainer review and rewrite complete. The final implementation keeps each detached cron run's resumable context in a durable exact-run row, claims and releases it at the gateway owner boundary, atomically projects the settled snapshot back to the stable cron row, preserves native CLI/model/tool/delivery policy, and bounds release-write recovery without rerunning the model. Terminal media cleanup and stale gateway-generation fallback are covered as well.

Land-ready evidence:

  • Final exact PR head: bd10be23a0706b1c9c142898cc43e0f1c78cf6f7.
  • GitHub CI run 29063535464: build, production/test types, lint, session-accessor boundary, and all selected test shards passed; CodeQL and security guards passed.
  • Sanitized public AWS Crabbox run run_8b37e22c4a9d: 636 focused gateway, session-accessor, cron identity/policy, media lifecycle, and cleanup tests passed on the reviewed runtime head.
  • Earlier broad continuation run run_068d566be879: 1,195 tests passed.
  • Fresh Codex gpt-5.5/high autoreview: no accepted or actionable findings.
  • Static proof: git diff --check, oxfmt, type-aware oxlint, and scripts/check-session-accessor-boundary.mjs passed.
  • Repo-native scripts/pr review-validate-artifacts 101078 and guarded OPENCLAW_TESTBOX=1 scripts/pr prepare-run 101078 passed at the final exact head.

Known gap: no credentialed live provider call was run against untrusted contributor code. Sanitized regression proof and exact-head hosted CI are the merge gates.

Thank you @xialonglee for reporting and implementing the original async-media wake fix.

@steipete
steipete merged commit cab8040 into openclaw:main Jul 10, 2026
97 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@xialonglee
xialonglee deleted the fix/cron-async-media-wake-loses-context branch July 10, 2026 02:45
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 10, 2026
…n wakes (openclaw#101078)

* fix(cron): preserve cron context in session entry for async completion wakes (openclaw#99919)

Persist bootstrapContextRunKind on the session entry after cron agent
runs, and restore provider/model/thinking/runKind from the session
entry into directAgentParams when an async completion wake (e.g. media
generation) resumes a cron session.

Before this fix, async completion wakes lost the original cron run
context and fell back to account defaults, causing multi-step cron tasks
to silently dead-end after the first async media generation call.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(cron): authorize model override on trusted in-process dispatch for cron context restoration

* fix(cron): persist bootstrapContextRunKind on base session entry for async completion wakes

* fix(cron): route async completion wake to base cron session key instead of ephemeral run key

When the cron run-key fallback fires, record the base cron key as
effectiveSessionKey so deliverDirectSubagentAnnounce can route the
agent call to the persisted session row with its transcript and task
context instead of starting a fresh turn (openclaw#99919).

* fix(cron): add bootstrapContextRunKind to session entry slot keys and declare loadRequesterSessionEntry return type

* fix(cron): rebase onto upstream main, restore upstream agent-command behavior while keeping bootstrapContextRunKind persistence

* fix(cron): persist bootstrapContextRunKind from a pre-mutation snapshot to produce a real delta

* fix(cron): move pre-mutation snapshot inside guard so initialEntry is non-optional

* fix(cron): preserve async media continuation context

Co-authored-by: Peter Lee <[email protected]>

* fix(cron): retain continuation after base cleanup

* test(gateway): complete agent scope mock

* test(gateway): preserve agent scope exports

* test(cron): persist mocked session mutations

* test(cron): model persisted session fixtures

* fix(agents): snapshot cron continuation retries

* fix(cron): harden async continuation settlement

* test(cron): control continuation recovery clock

* fix(gateway): narrow continuation model row

* chore(changelog): defer cron continuation note

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

2 participants