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. The issue is about "isolated cron runs leak context when they reuse a stable session key". This seems to be related to a system called "lossless-claw" or similar. Let me explore the repository structure first.
The issue mentions:
- Isolated cron runtime sessions
- Stable session keys
- LCM context (likely "Language Context Management" or similar)
- Prior runs remain archived
- Compaction within the current run still works
- Ordinary non-cron session continuity is unchanged
Let me explore the repo to understand its structure.
Assistant
Let me search for relevant terms to understand the issue better
Assistant
Let me just run one command at a time.
Assistant
Let me focus on the source files. Let me look at the engine.ts file first since it's likely the main engine.
Assistant
Let me look at the engine.ts and related files more closely. First, let me understand what the issue is about "isolated cron runs" and "stable session keys
Assistant
Let me look at the compaction.ts and related context files.
Assistant
Let me look at the plugin/index.ts for the cron-related code and also search for isolated context.
Assistant
Let me look at the engine.ts around line 9275 to understand the context mode, and also look at the openclaw-bridge.ts.
Assistant
Let me look at the test files related to this issue - particularly looking for tests that might describe the problem.
Assistant
Let me look at the engine.ts around line 1335 and also search for how "isolated" context mode interacts with sessions
Assistant
Let me search for the contextMode handling and subagent spawn with "isolated" mode
Assistant
Let me look at the openclaw-bridge.ts to understand how contextMode "isolated" is used.
Assistant
Let me look at the engine.ts to understand how conversations are resolved for sessions, especially with contextMode "isolated
Assistant
Let me search for the function that resolves a conversation ID for a session key, and also look at how contextMode "isolated" is handled in subagent spawning.
Assistant
Let me see the resolveConversationIdForSessionKey function.
Assistant
Let me search for "contextMode" in the source to understand how it's
Assistant
Let me see the full prepareSubagentSpawn function.
Assistant
Let me verify how
prepareSubagentSpawnis called and whatcontextModeis expected to do.Assistant
Let me look at the engine tests for prepareSubagentSpawn to understand the expected behavior
Assistant
Let me look at the tests around line 7012 and 1670
Assistant
Now let me look at the test around line 1670.
Assistant
Let me search for tests that test the isolated context mode.
Assistant
Let me search for "isolated" in the broader plugin code to understand how sessions work.
Assistant
Let me search the entire repository for the term "contextMode" more
Assistant
Let me look at the session patterns and how they interact with cron runs
Assistant
Let me look at the engine bootstrap and ingest functions to understand how they handle session
Assistant
Let me look at the createConversation logic and how sessions get their conversation context.
Assistant
Let me look at the conversation store to understand how conversations are resolved for session keys.
Assistant
Let me look at the ingest and bootstrap functions to understand how the conversation context is used
Assistant
Let me look at the bootstrap function.
Assistant
Let me search for "contextMode" in the broader ecosystem to understand its purpose
Assistant
Let me look at the git log to understand recent changes and context of
Assistant
Let me look at the rotate and ambiguous session key handling functions
Assistant
Let me look at the
rotateStaleSessionKeyConversationIfTrackedTranscriptMissingfunction.Assistant
Let me look at
applySessionReplacementAssistant
Let me see the full
applySessionReplacementAssistant
Let me see the rest of `handleSessionEnd
Assistant
Let me look at the
isFreshLifecycleConversationfunction and also search for how "fork" vs "isolated" context mode is appliedAssistant
Let me look at the git log more carefully for any related changes
Assistant
Let me look more broadly at how the context might be leaked. Let me look at
handleSessionEndand also theonSubagentEndedfunction.Assistant
Let me look at what the tests actually test regarding contextMode and isolated mode
Assistant
Let me look at the plugin/index.ts to understand how the engine is used
Assistant
Let me search for wirePluginHandlers and understand the plugin event flow
Assistant
Let me look at the wirePluginHandlers function to see how it handles events.
Assistant
Let me look at the expansion-auth module to understand expansion
Assistant
Let me look at the full test for prepareSubagentSpawn more
Assistant
Let me look at lines 1187-1200 for the prepareSubagentSpawn test
Assistant
Now let me look at the full test for prepareSubagentSpawn at lines 7012-7040
Assistant
Let me run the existing tests to understand the current state
Assistant
Let me look at the LCM expansion tools to understand how grants are used
Assistant
Let me look at how the assemble function handles
Assistant
Let me look at the rest of the
Assistant
Let me look at
handleSessionEndto understand when/why sessions are archivedAssistant
Let me look at
handleSessionEndfrom the beginningAssistant
Let me search for any branches or issues related to this
Assistant
Let me search the git log for related keywords
Assistant
Let me create a reproduction script to understand the issue better
Assistant
Let me run this script to see what happens:
Assistant
Let me create the script in the repo instead
Assistant
Now run it
Assistant
Let me fix the repro script with proper config
Assistant
Let me look at the engine constructor
Assistant
Let me look at how the tests create engines - specifically the test helpers
Assistant
Let me look at the test helper functions
Assistant
Let me look at createTestConfig and createTestDeps functions
Assistant
Let me see the createTestConfig and createTestDeps functions
Assistant
Now let me update the repro script using the test patterns
Assistant
Now run it
Assistant
I've confirmed the issue. The
prepareSubagentSpawnfunction ignores thecontextModeparameter, causing child subagents to always get access to the parent's conversation. WhencontextModeis "isolated", the child should NOT get this access.Now let me implement the fix:
Assistant
Let me look at how delegated sessions are identified
Assistant
Let me look at the expansion-auth.ts for delegated session functions
Assistant
Let me look at createDelegatedExpansionGrant
Assistant
Let me search for
isDelegatedSessionKeyin the codebaseAssistant
Let me look at how the LCM expand tool checks for delegated sessions
Assistant
Now let me implement the fix. When
contextModeis "isolated", the child should NOT receive the parent's expansion grant. Let me modify theprepareSubagentSpawnfunctionAssistant
Let me try a different approach with the replace command
Assistant
Let me use replace with the exact code to insert the isolated mode
Assistant
Let me use the heredoc syntax properly for multi-line replacement
Assistant
Let me verify the change was applied correctly
Assistant
The replace doesn't seem to have worked. Let me try again with more specific lines
Assistant
Let me find the exact line numbers and use edit
Assistant
Let me look at the full function to see if my edit accidentally duplicated lines
Assistant
Let me use edit with exact line numbers to insert the isolated check
Assistant
Let me use sed to insert the lines directly
Assistant
Let me use sed to insert the code
Assistant
Let me verify the change was applied correctly
Assistant
Now let me run the repro script to verify the fix:
Assistant
Let me verify that the non-isolated (fork/default) mode still works
Assistant
The fix works correctly. Now let me run the existing tests to ensure nothing is broken:
Assistant
All 1067 tests pass. Let me clean up the temporary files:
Assistant
Let me verify the final changes with a git diff
Assistant
There's a minor formatting issue - extra blank line. Let me clean it up:
Assistant
Let me verify the final state
Assistant
Let me check the exact content and fix the blank line issue more carefully
Assistant
Let me check the diff now
Assistant
Let me run the tests one final time to ensure everything is working:
Assistant
All tests pass. Let me also verify there are no other places in the codebase where
contextModeneeds to be handled but isn't. Let me double-check theopenclaw-bridge.tsinterface matches
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.