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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me explore the concept of "isolated cron runs", "session key", and "LCM context". Let me search for relevant terms.
Assistant
Let me look at the session-patterns.ts and the concept of session keys more carefully. The issue is about isolated cron runtime sessions that reuse a stable session key. Let me look at the engine to understand how sessions are resolved.
Assistant
Let me look at how session keys are resolved, and where cron sessions come into play. Let me look at the engine's session resolution logic.
Assistant
Now I need to understand the actual issue. The issue is about isolated cron runs leaking context when they reuse a stable session key. Let me look at how conversations get resolved - the
getConversationForSession. The key question is: when an isolated cron run reuses a stable session key, does it pick up the active LCM context from a prior run?Let me look at the conversation store's
getConversationForSession.Assistant
Let me search for how "run" portions and isolated sessions are detected.
Assistant
Let me look at how the engine handles a run start, and understand the session key derivation. Let me look at the main assemble/maintain flow.
Assistant
Let me look at the
assemblefunction and how the conversation is resolved and bootstrapped at the start of a run. The key is understanding where the active conversation is selected from a stable session key.Assistant
Let me look at how the conversation gets bootstrapped at run start. Let me search for the bootstrap function which creates conversations.
Assistant
Let me look at the plugin/index.ts to see how bootstrap is called and what session info is passed.
Assistant
Let me look at the docs and config for cron-related keys, and search for how cron runs are detected.
Assistant
Now, let me understand the actual issue more deeply. Let me look at the test files for engine to understand how session reuse and isolated cron runs work. Let me look at the test that mentions "stable sessionKey" and how it rotates.
Let me look at the engine.test.ts around line 5090 where cron is referenced.
Assistant
Let me check the CHANGELOG and recent commits for clues about this issue.
Assistant
Let me look at the existing logic for session file rotation and rollover detection.
Assistant
Let me search for how cron lanes / isolated runs are detected in the plugin.
Assistant
Let me look at how the plugin wires bootstrap and what session info is passed for runs.
Assistant
Let me look at handleSessionEnd.
Assistant
Let me search for cron pattern detection in the engine and how it's configured.
Assistant
Let me look at the existing tests around session reuse and session key rotation to understand the expected behavior.
Assistant
Let me look at the README and docs for cron lanes and how isolated sessions work.
Assistant
Important clue from README line 325. Let me look at how cron runs and session keys are structured. Let me look at the afterTurn path.
Assistant
Now let me understand the actual flow for an isolated cron run. The cron run is "isolated" - meaning each run is its own runtime session. Let me look at how the cron session key pattern is detected. The key thing the issue wants: detect isolated cron runs and archive the prior active conversation.
Let me look at the README more for cron run session key structure and how the host treats isolated runs.
Let me re-read README around line 320-365.
Assistant
Now let me look at the session-patterns test fully and how cron keys are structured.
Assistant
Now I have a good understanding. Let me look at how cron session keys are used in tests to make sure I don't break existing behavior.
Assistant
Let me look at how the existing tests in engine.test.ts use cron session keys (e.g. line 5105
sessionKey: "agent:main:cron:nightly"withignoreSessionPatterns: ["agent:*:cron:**"]). So those are ignored. Let me check there's no test that uses a cron key WITHOUT ignore patterns and expects reuse. Let me search engine.test.ts for cron keys without ignore.Assistant
Let me look at the context engine interface to understand the lifecycle (bootstrap, assemble, maintain, afterTurn) and confirm bootstrap is the run-start entry.
Assistant
Let me see the full ContextEngine interface including afterTurn and maintain.
Assistant
Let me look at the test helpers used in engine.test.ts to create engines and run bootstrap/assemble.
Assistant
Now let me write a reproduction test to confirm the bug.
Assistant
Let me fix the imports placement.
Assistant
I've reproduced the bug — the second run reuses the prior run's active conversation. Let me also test the variant where cron reuses a stable session file path (which may be the actual leak scenario).
Assistant
Both scenarios reproduce the bug. Now let me implement the fix. Let me look at the engine around the bootstrap insertion point and the
applySessionReplacementmethod.Assistant
Let me look at how ignoreSessionPatterns are compiled and stored in the engine constructor.
Assistant
Now let me check other test files for cron keys without ignore patterns to ensure my change won't break them.
Assistant
The lcm-command.test.ts uses cron keys for doctor cleaner tests that create conversations directly. Let me verify those don't go through bootstrap/assemble/afterTurn.
Assistant
Now let me implement the fix. Let me look at the exact bootstrap insertion point.
Assistant
Now let me look at the assemble insertion point.
Assistant
Now let me look at the afterTurn insertion point where rotateStale is called.
Assistant
Let me find the afterTurn entry method and its rotateStale call.
Assistant
Now I have a good understanding. Let me implement the fix. First, let me add a module-level compiled regex for the cron pattern. Let me look at the area near the top constants.
Assistant
Let me add the cron pattern constant after the AMBIGUOUS constant.
Assistant
Now let me add the
isIsolatedCronSessionKeyand `rotateIsolatedCronRunAssistant
Now let me add the helper methods after
isStatelessSession.Assistant
The file has shifted by 11 lines. Let me use goto then replace.
Assistant
Now let me wire the call into the three entry points. First bootstrap. Let me find the bootstrap rotateStale call (now shifted).
Assistant
The bootstrap one is at 7213. Let me look around it.
Assistant
Now the assemble entry point. Let me find the assemble rotateStale call.
Assistant
Now the afterTurn entry point at line 6488.
Assistant
Now let me also wire it into the
compactentry point for completeness. Let me look at the compact method.Assistant
Now let me wire compact too.
Assistant
Now let me run the typecheck and the reproduction test.
Assistant
I need to import
compileSessionPattern(singular). Let me update the import.Assistant
Typecheck passes. Now let me run the reproductiontest.
Assistant
Both reproduction tests pass now. Let me verify the deeper per-run key variant and that compaction within a run still works. Let me add edge case tests to the repro file.
Assistant
All 5 tests pass. Now let me run the broader test suite to ensure no existing tests broke.
Assistant
All 1072 tests pass. Now let me consider edge cases more carefully. There's an important concern: the
findAmbiguousSessionKeyRuntimeRolloverguard runs right after the rotation. After rotation, the prior conversation is archived, sogetConversationBySessionKey(which only returns active=1) returns null. The ambiguous rollover guard then returns null (no active conversation by key). Good.However, there's a subtle concern. Let me think about a scenario where an isolated cron run resumes within the same runtime session (same
sessionId), with a different session file (transcript rotation within the run). In that caserotateIsolatedCronRunConversationreturns false (same sessionId), and the existingrotateStaleSessionKeyConversationIfTrackedTranscriptMissinghandles the transcript-file rollover. Good - that path is preserved.Now let me think about a scenario where the prior cron run's session file is still present and matches the new run's session file (the stable session file path case). In my second repro test, both runs reused the same stable file path. Let me verify the bootstrap reconcile path handles this correctly — the new fresh conversation has
existingCount === 0, so it takes the first-time import path with the new file's messages. Good.Assistant
Build succeeds. Now let me consider documentation. The issue mentions the cron lanes reuse stable session keys. The README already documents that
agent:*:cron:**excludes cron sessions. But now LCM handles isolated cron runs that are NOT ignored. Let me check if I should add documentation about this behavior. Let me look at the docs around session lifecycle to see if there's a natural place to document this.Assistant
Let me add a documentation note about isolated cron run isolation in the docs/configuration.md near the session pattern section, and a corresponding note in README. Let me view the README cron section first.
Assistant
The replace tool needs the file open with the target in view. Let me use edit on the README instead with line range.
Assistant
Now let me add a corresponding note to docs/configuration.md. Let me view that section.
Assistant
I introduced a duplicate
###/newand/reset`` header. Let me fix it.Assistant
There's a duplicate "Lossless-claw treats OpenClaw reset commands differently:" at lines 334 and 336. Let me remove the duplicate.
Assistant
Now let me add a changeset, as required by the repo's release workflow (per AGENTS.md). Let me check the .changeset format.
Assistant
Now let me remove the temporary reproduction test file before submitting (since I should not add new tests to the repo).
Assistant
Now let me run the full test suite once more to confirm everything still passes after removing the temp test.
Assistant
All 1067 tests pass. Let me run the typecheck once more and the build.
Assistant
Let me review the final diff of the source changes.
Assistant
Let me verify git status to make sure the changeset file is included and no stray files remain.
Assistant
Let me improve the phase type to include "compact" for clarity since I wired it into compact too.
Assistant
Now update the compact call site to use phase "compact".
Assistant
Now let me re-run typecheck and the full test suite one final time.
Assistant
Everything passes. Let me do a final review of the complete diff.
Assistant
Everything looks good. Let me verify the final state of the repo and submit.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.