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 understanding the repository structure and the issue description.
The issue is about "isolated cron runs leak context when they reuse a stable session key". Let me explore the repository to understand the codebase.
Key points from the issue:
- 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
- Ordinary non-cron session continuity is unchanged
This seems to be related to some session management system. Let me explore the repository structure.
Assistant
This looks like a TypeScript/JavaScript project. Let me explore more to understand the structure, especially around "cron", "session", "context", and "LCM".
Assistant
Let me search for "cron", "session", "LCM", and "context" references.
Assistant
Let me look at the core engine and LCM-related files more thoroughly.
Assistant
Let me search for "stable" session key and look at the LCM context handling.
Assistant
Let me search for "isolated" and "contextMode" in the engine:
Assistant
Let me look at this area in the engine.ts file.
Assistant
Let me try the open command differently.
Assistant
Let me continue scrolling to see the rest of
prepareSubagentSpawn.Assistant
Let me search for the LCM context handling and how "isolated" context mode is used:
Assistant
Let me look at the openclaw-bridge.ts file to see how contextMode is used
Assistant
Let me try the open command differently.
Assistant
Now let me look at the compaction.ts file to understand LCM context handling
Assistant
Let me search for the key functions related to session handling and isolation:
Assistant
Let me look at the relevant functions in engine.ts - bootstrap, ingest, and the session handling
Assistant
Let me look at the bootstrap function
Assistant
Let me search for key functions related to lifecycle and session rotation
Assistant
Let me look at the
rotateStaleSessionKeyConversationIfTrackedTranscriptMissingandfindAmbiguousSessionKeyRuntimeRolloverfunctions:Assistant
Continue reading
findAmbiguousSessionKeyRuntimeRollover:Assistant
Let me look at the lifecycle functions and how the cron session handling works:
Assistant
Let me continue viewing the
handleSessionEndfunctionAssistant
Let me look at the test files related to engine and cron:
Assistant
Let me search for tests related to stable session keys and cron isolation
Assistant
Let me search for tests related to the issue in the test
Assistant
Let me look at the tests for stable sessionKey handling
Assistant
Let me search for tests related to "isolated" context mode and subagent spawn
Assistant
Let me look at the lcm-integration test file for tests about
Assistant
Let me look at the
prepareSubagentSpawnfunction in the engine:Assistant
Let me look at the
resolveConversationIdForSessionKeyfunctionAssistant
Let me look at this function
Assistant
Let me look at the conversation store to understand session key resolution
Assistant
Let me look at the conversation store for session key handling
Assistant
Let me look at these key functions
Assistant
Let me look at the assemble function to understand how contextMode might be relevant:
Assistant
Let me find where
prepareSubagentSpawnis called:Assistant
Let me look at the plugin for contextMode usage
Assistant
Let me look at the plugin initialization:
Assistant
Let me search for where
contextModeis passed through the systemAssistant
Let me look at the full bootstrap function more carefully:
Assistant
Let me look at
getOrCreateConversationin the conversation storeAssistant
Let me see this function
Assistant
Let me search for how cron sessions interact with the LCM engine
Assistant
Let me look at plugin/index.ts around line 1528
Assistant
Let me search for where the "isolated" context mode might be used in the broader context
Assistant
Let me look at the git log to see recent changes related to this issue:
Assistant
Let me look at the changes in the recent commit related to session rollover:
Assistant
Let me look at the changeset directory:
Assistant
Let me read the changeset about stale session key rollover:
Assistant
Let me read a few more changesets:
Assistant
Let me look at the test at line 3716:
Assistant
Let me look at the fork-related handling in the engine:
Assistant
Let me search for the assemble function and where it handles fork bounded:
Assistant
Let me look at the assemble function around line 8894:
Assistant
Let me look at how the
createConversationmethod works in the conversation store:Assistant
Let me look at
createConversation:Assistant
Let me look at how
prepareSubagentSpawnis called in the broader context:Assistant
Let me look at the test around line 645:
Assistant
Let me look at the specs directory:
Assistant
Let me look at the architecture docs:
Assistant
Now I have a good understanding. Let me look at how the
applySessionReplacementfunction is used for archiving:Assistant
Let me look at
applySessionReplacementfully:Assistant
Now I understand the issue. Let me look at the
prepareSubagentSpawnfunction once more and plan my fix:The issue is clear:
prepareSubagentSpawnacceptscontextModebut doesn't use it. WhencontextModeis"isolated", the child session should not share LCM context with prior runs that used the same stable session key. Currently, bootstrap/ingest for the child will find the existing active conversation by session key and reuse it, leaking context.The fix: In
prepareSubagentSpawn, whencontextModeis"isolated", archive any existing active conversation for the child session key.Let me first create a reproduction script to confirm the issue
Assistant
Let me first check the existing test infrastructure to understand how to run tests
Assistant
Let me run the existing tests to establish a baseline and understand how tests work
Assistant
Now I understand the issue well. Let me implement the fix in
prepareSubagentSpawn. The function currently acceptscontextModebut doesn't use it. WhencontextModeis"isolated", we need to archive any existing active conversation for the child session key so that subsequent bootstrap/ingest creates a fresh conversationAssistant
Now let me implement the fix. The change is in
prepareSubagentSpawn: whencontextModeis"isolated", archive any existing active conversation for the child session keyAssistant
Let me try using replace instead:
Assistant
Good. Now let me run the existing tests to make sure nothing is broken
Assistant
All tests pass. Now let me create a quick verification script to confirm the fix works for the reported
Assistant
Let me check the test helpers to ensure our verification script uses the right imports
Assistant
Let me look at the test helpers
Assistant
Let me search more broadly for helper functions
Assistant
The helper functions are local to the test file. Let me create a proper test to verify the fix. First let me look at what functions are available
Assistant
Let me verify the fix by running the tests and checking if there are tests related to
contextMode:Assistant
Let me look for the specific prepareSubagentSpawn tests that ran:
Assistant
All tests pass. Let me run the full test suite one more time to confirm:
Assistant
Let me also check Type
Assistant
Let me review the changes
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.