Skip to content

fix(cron): subagents lose memory access when a cron job runs in their parent chat - #166417

Merged
jalehman merged 2 commits into
mainfrom
fix/cron-keep-session-revision
Oct 7, 2026
Merged

jalehman merged 2 commits into
mainfrom
fix/cron-keep-session-revision

Conversation

@jalehman

@jalehman jalehman commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: subagents permanently lose memory access, and the parent's in-flight memory calls are revoked, when a cron job runs in an existing chat session.

User Impact

User impact: a scheduled check-in or other cron job that targets an existing conversation no longer cuts that conversation's subagents off from Knowledge or other memory-slot tools. Previously each cron run made every existing child fail with "trusted agent/session authority is required" until it was respawned.

Why This Change Was Made

A session's lifecycle revision names its incarnation. Spawned children record the parent's revision as their memory lineage, and memory-audience leases treat a changed revision as a new incarnation. resolveCronSession minted a fresh revision on every run, including runs that reuse the same live session in place, so every cron run looked like a session reset to those owners. The pre-run persist commits the entry before turn admission, so even a run rejected with "already has an active turn claim" rotated it.

Reused in-place sessions now keep their revision. A revision is still minted for new sessions, stale resets, forced rollovers, differing source sessions, rows without a revision, and exact-run cron: sessions. Those run in a hidden :run: row whose continuation ownership and the gateway's base-superseded check use the base revision as the per-run generation.

Because a reused revision is shared with the session's other writers, persistence ownership now also requires the session id of the run's last committed row: a same-revision session-id replacement is rejected instead of adopted. Concurrent in-place runs that keep the same incarnation merge their field writes the same way chat turns already coexist with cron, and worker turn admission still serializes the turns. A reused row that had no revision (for example channel-created) gets one on its first cron run.

Evidence

Live failure: on a main Gateway, a five-minute check-in cron job targeting a dashboard session rotated its revision; all 8 subagents spawned earlier still recorded the old parent revision and every Knowledge call from them was denied.

Live after-fix proof (fsn1 Gateway, dd619529b24 plus this PR and #166419), using a fresh dashboard session P on agent main:

Step Result
P spawns subagent C; C calls knowledge_status ok; C records parent revision 57e9cab9…
cron add --session session:<P> --message ... then cron run cron turn ran in P and replied; P revision still 57e9cab9… (on main this run rotated it)
C calls knowledge_status again ok, same scope; no memory-audience denials logged
Control: sessions.reset on P (revision becomes 7ac8ced6…), then C calls knowledge_status rejected: Knowledge access unavailable: trusted agent/session authority is required.

The test cron job was removed and the test sessions archived afterwards.

  • New session.test.ts table: fails on main (expected '75e3c9da-…' to be 'existing-revision' for fresh in-place reuse) and passes with this change; the other rows pin that new, stale, forced, differing-source, revision-less, and exact-run cases still mint.
  • run-session-state.test.ts now runs the existing session-id replacement race with both a minted and a reused revision; the reused case fails without the ownership change. pnpm test src/cron/isolated-agent/run-session-state.test.ts --maxWorkers=1: 28/28, 32 s wall (26 s Vitest, mostly transform). pnpm test src/cron/isolated-agent: 45 files, 519 tests pass.
  • pnpm test src/cron/isolated-agent/session.test.ts --maxWorkers=1: 25/25, 44 s wall warm (Vitest 32.5 s, about 1% test time; the rest is transform/import).
  • pnpm test src/cron: no failures in the isolated-agent session code. session-registry-maintenance.test.ts and trigger-script.preparation.test.ts fail locally on this macOS host with or without this change; owner-hardening.test.ts failed once under load and passes alone.
  • node scripts/check-changed.mjs --base 2ae568e850a: passed (typecheck, lint, dead-export, guards).

🤖 Generated with Claude Code

resolveCronSession minted a fresh lifecycleRevision on every run, even when
the run reused the same still-fresh session in place. The revision names a
session incarnation: spawned children record it as their parent lineage and
memory-audience generation leases treat any change as revocation. A cron job
targeting an existing chat session therefore cut every child off from memory
and revoked the parent's in-flight audience on each run, including runs that
later failed turn admission, because the pre-run persist lands first.

Reused in-place incarnations now keep their revision. A new revision is still
minted for new sessions, stale resets, forced rollovers, differing source
sessions, rows without a revision, and exact-run cron sessions, whose base-row
revision is the per-run generation that hidden `:run:` continuation ownership
and the gateway's base-superseded check compare against.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 7, 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.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 2:28 AM ET / 06:28 UTC (Revision 3).

ClawSweeper review

What this changes

Cron runs that reuse an existing conversation preserve its lifecycle revision, while persistence rejects replacement sessions and detached runs retain separate generations.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary and has no identified blocking defect. The updated live evidence addresses memory continuity and reset revocation, and the previously reported session-ID ownership defect is fixed.

Priority: P1
Reviewed head: e9d93280c982de4dc8c2b9a974349dad189416a4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant live continuity and revocation evidence, meaningful regressions, and no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured after-fix Gateway results exercise cron preparation in an existing parent conversation, show its child retaining Knowledge access, and show parent reset rejecting subsequent child access. Source inspection and the replacement-race regression resolve the earlier session-ID concern. The setup includes the related memory PR; existing stored fields remain compatible without migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured after-fix Gateway results exercise cron preparation in an existing parent conversation, show its child retaining Knowledge access, and show parent reset rejecting subsequent child access. Source inspection and the replacement-race regression resolve the earlier session-ID concern. The setup includes the related memory PR; existing stored fields remain compatible without migration.
Evidence reviewed 9 items Pinned introduced changes: Reviewed the merge-base-to-head delta and complete affected production modules and tests. The actual checkout and original PR head are e9d9328; endpoint drift was not attributed to this PR.
Current main still needs the repair: Fetched main still assigns a random lifecycle revision unconditionally, including fresh in-place session reuse. No merged replacement is established by the supplied related context.
Latest release comparison: The v2026.9.8 session implementation also unconditionally mints lifecycleRevision. Its source was read through GitHub’s contents endpoint because the local tag object was unavailable.
Findings None None.
Security None None.

How this fits together

Scheduled agent turns prepare and persist conversation state before executing. Subagents use the parent conversation’s session identity and lifecycle revision to establish memory access.

flowchart TD
  A[Scheduled agent turn] --> B[Read conversation state]
  B --> C{Reuse same incarnation?}
  C -->|Yes| D[Keep lifecycle revision]
  C -->|No or detached| E[Mint run generation]
  D --> F[Check current session identity]
  E --> F
  F --> G[Persist and admit turn]
  G --> H[Memory access follows live lineage]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +17, Tests +39. Total +56 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 20 3 +17
Tests 2 76 37 +39
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 96 40 +56

Review metrics

None.

Technical review

Best possible solution:

Preserve conversation incarnation identity during ordinary scheduled reuse while keeping reset, replacement, and detached-run ownership boundaries intact.

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

Yes: current main unconditionally rotates the parent revision, while memory lineage requires the child’s recorded parent revision to match. The body reports this failure on a real Gateway; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: repairing revision creation at the cron session owner and checking the captured session ID is a focused solution that preserves existing reset and continuation contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured after-fix Gateway results exercise cron preparation in an existing parent conversation, show its child retaining Knowledge access, and show parent reset rejecting subsequent child access. Source inspection and the replacement-race regression resolve the earlier session-ID concern. The setup includes the related memory PR; existing stored fields remain compatible without migration.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured after-fix Gateway results exercise cron preparation in an existing parent conversation, show its child retaining Knowledge access, and show parent reset rejecting subsequent child access. Source inspection and the replacement-race regression resolve the earlier session-ID concern. The setup includes the related memory PR; existing stored fields remain compatible without migration.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.
  • remove merge-risk: 🚨 security-boundary: Current PR review selected no merge-risk labels.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A cron turn in an existing conversation can permanently deny its active subagents memory access until they are respawned.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured after-fix Gateway results exercise cron preparation in an existing parent conversation, show its child retaining Knowledge access, and show parent reset rejecting subsequent child access. Source inspection and the replacement-race regression resolve the earlier session-ID concern. The setup includes the related memory PR; existing stored fields remain compatible without migration.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured after-fix Gateway results exercise cron preparation in an existing parent conversation, show its child retaining Knowledge access, and show parent reset rejecting subsequent child access. Source inspection and the replacement-race regression resolve the earlier session-ID concern. The setup includes the related memory PR; existing stored fields remain compatible without migration.

Evidence

What I checked:

  • Pinned introduced changes: Reviewed the merge-base-to-head delta and complete affected production modules and tests. The actual checkout and original PR head are e9d9328; endpoint drift was not attributed to this PR. (src/cron/isolated-agent/session.ts:279, e9d93280c982)
  • Current main still needs the repair: Fetched main still assigns a random lifecycle revision unconditionally, including fresh in-place session reuse. No merged replacement is established by the supplied related context. (src/cron/isolated-agent/session.ts:279, 5d4484b6ba69)
  • Latest release comparison: The v2026.9.8 session implementation also unconditionally mints lifecycleRevision. Its source was read through GitHub’s contents endpoint because the local tag object was unavailable. (src/cron/isolated-agent/session.ts:275, fc23bc864e45)
  • Previous ownership finding resolved: Revision ownership now also compares the current session ID with the last committed entry. The alternative initial-generation claim checks that same identity, so same-revision replacement rejects before returning a row to persist. The existing race test now covers both minted and reused revisions. (src/cron/isolated-agent/run-session-state.ts:233, e9d93280c982)
  • Updated production behavior evidence: The captured PR body reports a real Gateway running this PR together with fix(memory): Knowledge calls fail mid-turn after unrelated session activity #166419: a child’s Knowledge call succeeds before and after a cron turn in its parent, the parent revision stays unchanged, and resetting the parent causes the child’s next call to be rejected. This addresses the earlier continuity and revoked-lineage proof requests. Same-revision stale preparation is additionally resolved by the explicit persistence guard and focused regression; no remaining plausible bypass was identified. The combined setup is integration evidence, not an isolated measurement of either PR. Captured context identity: ab533908d8f175c4b7f36c8044b0c1fd8701683592d06903dec57e87e7c9a9eb. (e9d93280c982)
  • Authority remains checked at memory use: Memory lineage resolution compares parent session ID and lifecycle revision. Retained audiences hold generation leases, and the provider adapter checks the caller’s audience currency before invoking provider operations. This PR preserves an incarnation without removing those checks. (src/plugins/memory-audience.ts:213, e9d93280c982)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • jalehman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-07T03:16:38.507Z sha 58d3017 :: needs real behavior proof before merge. :: [P2] Check the captured session ID when reusing its revision
  • reviewed 2026-10-07T06:07:35.505Z sha e9d9328 :: needs real behavior proof before merge. :: none

…ision

A reused in-place lifecycle revision is shared with the session's other
writers, so revision equality alone no longer proves the run still holds the
incarnation it last committed. A same-revision session-id replacement would
pass the ownership shortcut and be adopted by stale cron preparation. Ownership
now also requires the session id of the run's last committed row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Oct 7, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 7, 2026
@jalehman
jalehman merged commit fa57fad into main Oct 7, 2026
137 of 138 checks passed
@jalehman
jalehman deleted the fix/cron-keep-session-revision branch October 7, 2026 07:07
@jalehman

jalehman commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
… parent chat (openclaw#166417)

* fix(cron): keep session lifecycle revision when reusing an incarnation

resolveCronSession minted a fresh lifecycleRevision on every run, even when
the run reused the same still-fresh session in place. The revision names a
session incarnation: spawned children record it as their parent lineage and
memory-audience generation leases treat any change as revocation. A cron job
targeting an existing chat session therefore cut every child off from memory
and revoked the parent's in-flight audience on each run, including runs that
later failed turn admission, because the pre-run persist lands first.

Reused in-place incarnations now keep their revision. A new revision is still
minted for new sessions, stale resets, forced rollovers, differing source
sessions, rows without a revision, and exact-run cron sessions, whose base-row
revision is the per-run generation that hidden `:run:` continuation ownership
and the gateway's base-superseded check compare against.

* fix(cron): require the committed session id when a run reuses its revision

A reused in-place lifecycle revision is shared with the session's other
writers, so revision equality alone no longer proves the run still holds the
incarnation it last committed. A same-revision session-id replacement would
pass the ownership shortcut and be adopted by stale cron preparation. Ownership
now also requires the session id of the run's last committed row.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: S 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