Repository navigation
fix(cron): subagents lose memory access when a cron job runs in their parent chat - #166417
Conversation
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]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 2:28 AM ET / 06:28 UTC (Revision 3). ClawSweeper reviewWhat this changesCron 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 Review scores
Verification
How this fits togetherScheduled 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +17, Tests +39. Total +56 across 5 files. View PR surface stats
Review metricsNone. Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
…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]>
|
Merged via squash.
|
… 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.
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.
resolveCronSessionminted 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
mainGateway, 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,
dd619529b24plus this PR and #166419), using a fresh dashboard sessionPon agentmain:Pspawns subagentC;Ccallsknowledge_statusCrecords parent revision57e9cab9…cron add --session session:<P> --message ...thencron runPand replied;Prevision still57e9cab9…(onmainthis run rotated it)Ccallsknowledge_statusagainsessions.resetonP(revision becomes7ac8ced6…), thenCcallsknowledge_statusKnowledge access unavailable: trusted agent/session authority is required.The test cron job was removed and the test sessions archived afterwards.
session.test.tstable: fails onmain(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.tsnow 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.tsandtrigger-script.preparation.test.tsfail locally on this macOS host with or without this change;owner-hardening.test.tsfailed once under load and passes alone.node scripts/check-changed.mjs --base 2ae568e850a: passed (typecheck, lint, dead-export, guards).🤖 Generated with Claude Code