ISSUE DESCRIPTION Isolated cron runs leak context when they reuse a stable session key…
- User
ISSUE DESCRIPTION
Isolated cron runs leak context when they reuse a stable session key
Different isolated cron runtime sessions that reuse a stable session key must not share active LCM context. Prior runs remain archived, compaction within the current run still works, and ordinary non-cron session continuity is unchanged.
Interface
No new public interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /lossless-claw, current file: none) bash-$
- Assistant
I’ll first map the repository and search for cron/session/LCM context handling and relevant tests. Then I’ll reproduce the stable-key leakage in the nearest test harness, make the narrowest lifecycle fix, and run focused plus broader tests.
- Assistant
rgis unavailable, so I’ll use recursivegrep. The changeset names suggest this codebase already has runtime rollover safeguards; I’ll inspect those implementations and tests, plus repository guidance and current git state, before changing anything. - Assistant
The likely fault is conversation identity selection rather than compaction itself: a stable key currently maps back to one active conversation. I’ll inspect the engine’s conversation acquisition/rollover path and the runtime lifecycle event shape, especially whether cron isolation metadata is already present but ignored.
- Assistant
The lifecycle adapter currently forwards only basic identity fields; I need the exact hook contracts and rollover code. I’ll extract the relevant type definitions, conversation store semantics, and the concentrated rollover test section rather than broad keyword output.
- Assistant
To preserve ordinary continuity, isolation should be opt-in based on cron identity, not every runtime UUID change. Stable cron keys appear structurally recognizable (
agent:<id>:cron:...), potentially with per-run suffixes in newer hosts. I’ll now locate allgetOrCreateConversationcall sites and the existing runtime/transcript mismatch decision function to determine the correct single interception point. - Assistant
The two acquisition sites are after-turn reconciliation and bootstrap/assemble. I’ll inspect them alongside the helper that archives on detected file rollover. The issue wording (“different isolated cron runtime sessions”) likely means runtime session IDs are different while the key is intentionally stable; current ambiguity guard preserves the old conversation if its transcript still exists—exactly the reported leak.
- Assistant
Confirmed:
getOrCreateConversationrewrites the old row’s runtime UUID whenever the stable key matches. Existing preflight helpers can archive stale rows but deliberately refuse when the old transcript remains. For isolated cron, that refusal is wrong because the old transcript should remain archived. I’ll inspect the preflight call ordering and method input contracts to add a narrowly scoped “cron + changed runtime UUID” split before acquisition, ensuring same-run calls continue using the fresh row. - Assistant
No new interface is needed: session keys already encode cron lanes, and runtime UUID distinguishes runs. I’ll verify OpenClaw bridge signatures and the exact afterTurn/assemble preflight. Then I can implement a private predicate and split helper called at the same guarded preflight points, leaving ingestion alone because afterTurn already establishes identity before ingesting the turn.
- Assistant
Cron recognition should accept any agent ID (
agent:*:cron:*structurally), including stable keys without:run:and run-qualified keys. A split only occurs when the stable cron key’s active row has a different runtime UUID; repeated calls in one run are no-ops, and non-cron keys retain existing ambiguity/continuity behavior. I’ll identify all three preflight insertion locations and create a temporary reproduction using publicbootstrapagainst two existing transcript files with the same cron key. - Assistant
The reproduce condition is clear in code: bootstrap run 2 reaches
findAmbiguous..., sees run 1’s still-existing file, and returns"ambiguous session-key runtime rollover"instead of creating a fresh conversation. I’ll implement the private split helper and call it before existing generic rollover guards in bootstrap, afterTurn reconciliation, and assemble. It will archive rather than delete, create a replacement only where the caller immediately needs one, and rely on the per-key transaction queue for race safety. - Assistant
I found afterTurn’s queued reconciliation already has a lifecycle preflight at line 6418, so no outer change is needed. I’ll edit the helper near the existing stale/ambiguous helpers, then add one call immediately before the stale helper in each of the three locations. For assemble,
createReplacement: falsewould cause lookup to miss and safely use live fallback; however the requirement says compaction within the current run still works, so assemble should create the current run row immediately. I’ll use replacement creation consistently. - Assistant
One edge case is an empty prior row:
applySessionReplacementintentionally treats it as already fresh and does not archive, which is safe because it contains no active LCM context; acquisition then updates its runtime UUID. Non-empty/context-bearing prior runs are archived. This preserves data and avoids accumulating meaningless empty archives. I’ll now make the source-only change plus a patch changeset (user-visible bug fix), without modifying tests. - Assistant
Python is not installed, and no files were changed. I’ll apply the same deterministic transformation with Node, which is the repository’s native runtime, then inspect the resulting diff.
- Assistant
The source diff is narrow and passes whitespace validation; the changeset is untracked, so it does not appear in ordinary
git diff --statyet but will be submitted. Next I’ll run typecheck and the focused engine suite. Before that, I’ll locate the existing ambiguity regression test names so I can run a targeted baseline-equivalent check and ensure ordinary non-cron behavior remains unchanged. - Assistant
Typecheck and all 317 engine tests pass, including the existing ordinary stable-key ambiguity tests, confirming non-cron continuity is unchanged. To explicitly reproduce and verify the reported case without adding/modifying repository tests, I’ll create a temporary standalone TypeScript harness outside the repository’s tracked files. I’ll reuse the test dependency factory shape minimally, run two bootstraps with distinct runtime IDs and still-existing files under one cron key, assert archive/fresh isolation, then delete the harness.
- Assistant
I’ll use
vite-node(already present through Vitest) for the standalone harness, so TypeScript and the repository’s.jsimport conventions resolve correctly. The harness will fail loudly unless run 1 is archived with its two messages intact, run 2 is active with only its own two messages, and run 2 can ingest another message into that same fresh conversation (the compaction/continuity prerequisite within a run). - Assistant
The standalone reproduction passes: run 1 and run 2 have different conversation IDs, run 1 remains archived with both messages, run 2 contains only its own messages, and a same-run follow-up stays on run 2’s conversation. I’ll now run the complete test suite and production build, then inspect final status/diff for unintended artifacts.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.