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 mentions "isolated cron runs", "stable session key", "LCM context", and "compaction". Let me explore the repository to understand what this is about.
This seems to be a project related to LLM/agent systems - perhaps related to "LangChain" or similar. Let me look at the structure first.
Assistant
This is a TypeScript project. Let me look at the source code structure and understand what it's about.
Assistant
Let me search for relevant terms related to the issue - "cron", "isolated", "LCM", "session key
Assistant
Let me focus on the relevant source files. Let me search for "isolated" and "LCM" in the source code:
Assistant
Let me look at the relevant parts of the code. The issue involves "isolated" context mode, "cron", "LCM", and "session key". Let me look at
engine.tsandopenclaw-bridge.tsAssistant
Let me search for "contextMode" in engine.ts and openclaw-bridge.ts more specifically
Assistant
Let me look at the context around line 9275 in engine.ts, and also at openclaw-bridge.ts
Assistant
Let me keep reading around this area and see the rest of
prepareSubagentSpawn.Assistant
Now let me understand how
contextModeis used in the broader context. Let me look atresolveConversationIdForSessionKeyand the compaction logic more closelyAssistant
Let me look at
resolveConversationIdForSessionKeyaround line 4752.Assistant
Let me look at
openclaw-bridge.tsaround the contextMode areaAssistant
Let me search for
contextModeusage across the entire source codeAssistant
Let me look at the bootstrap method in engine.ts
Assistant
Let me look at the bootstrap method.
Assistant
Let me continue reading bootstrap method
Assistant
Let me look at the plugin index.ts for how cron and isolated sessions are handled
Assistant
Let me look at the plugin/index.ts around line 1528
Assistant
Let me look at the compaction.ts file to understand the flow
Assistant
Let me search for "archive" and "replace" in the source code
Assistant
Let me search for how the issue might manifest - how does the engine decide whether to reuse an existing conversation vs create a fresh one
Assistant
Let me look at
applySessionReplacementandrotateStaleSessionKeyConversationIfTrackedTranscriptMissingAssistant
Let me continue reading
handleBeforeResetAssistant
Let me look at
rotateStaleSessionKeyConversationIfTrackedTranscriptMissingAssistant
Let me look at the rotate method
Assistant
Let me look at the assemble method in engine.ts to see how context is assembled
Assistant
Let me look at the assemble method.
Assistant
Let me look at the
afterTurnmethod to see how context is persistedAssistant
Let me look at
afterTurnAssistant
Let me look more carefully at how the
contextModeparameter flows from the host runtime into the engine. Let me look at the plugin wiringAssistant
Let me look at how the plugin wires the engine methods
Assistant
Let me search for
prepareSubagentSpawnin the entire source codeAssistant
Let me look at the test for
prepareSubagentSpawnaround line 7012Assistant
Let me look at the test for prepareSubagentSpawn around line 645
Assistant
Let me look at how the host runtime passes the
contextModeto the LCM plugin. Let me search for how the runtime might call the LCM engine with context modeAssistant
Let me look at the bootstrap interface in openclaw-bridge.ts more carefully
Assistant
Let me look at the expansion-auth.ts file to understand how grants work
Assistant
Let me look at the specs directory for more context about the expected
Assistant
Let me look at the test file related to engine, specifically around the area that tests
contextModeor isolated behaviorAssistant
Let me look at the conversation store to understand
getOrCreateConversationand `getConversationForSessionAssistant
Let me look at conversation-store
Assistant
Let me look at the conversation store's
getOrCreateConversationAssistant
Let me look at how the plugin wires the engine to the host runtime
Assistant
Let me look at line 1464 in plugin/index.ts
Assistant
Let me look at
handleSessionEndAssistant
Let me look at `getConversationBySessionKey
Assistant
Let me look at the
SubagentSpawnPreparationtype and how it'sAssistant
Let me look at the type definition
Assistant
Let me check how the grant is used for expansion - look at the expansion tool
Assistant
Let me look at
lcm-conversation-scope.tsAssistant
Let me search for
isSubagentSessionKeyAssistant
Let me look at the plugin implementation of `isSubagentSessionKey
Assistant
Let me look at `parseAgentSessionKey
Assistant
Let me search properly
Assistant
Let me look at it
Assistant
Let me look at `shared-init.ts
Assistant
Let me check the git log for recent changes related to
Assistant
Let me check for commits related to contextMode or isolated cron
Assistant
Let me check the changeset directory for hints about
Assistant
Let me read the changeset files that seem related
Assistant
Let me look at AGENTS.md for project context
Assistant
Let me now look at the full
prepareSubagentSpawnimplementation to understand all the code paths and implementAssistant
Let me look at the test for
prepareSubagentSpawnmore carefully to understand the expectedAssistant
Let me look at the test cases for prepareSubagentSpawn at lines 645, 1187, 1670, and 7012
Assistant
Let me look at the test at line 1670
Assistant
Now I have a clear understanding of the issue. The
prepareSubagentSpawnmethod inengine.tshas acontextModeparameter that is completely ignored in the implementation. WhencontextModeis"isolated", the method should NOT create a grant that gives the child access to the parent's LCM context. Currently, it always resolves the parent's conversation and creates a grant withallowedConversationIds: [conversationId], leaking the parent's context to isolated cron sessions.Let me first create a script to reproduce the issue
Assistant
Let me fix the script
Assistant
Let me implement the fix. The issue is clear:
prepareSubagentSpawnignorescontextMode. WhencontextModeis"isolated", the method should not create a grant linking the child to the parent's conversationAssistant
Let me use the
replacecommand insteadAssistant
Let me open the file at the right line first
Assistant
Let me use sed to make the change
Assistant
Now let me insert the isolated check after line 9296
Assistant
Let me use
nlorcat -nto see exact line numbersAssistant
Line 9290 is
this.ensureMigrated();Lines 9292-9296: child/parent session key trim + check Line 9297 is}Line 9298 is blank Line 9299 isconst conversationId = await this.resolveConversationIdForSessionKey(parentSessionKey);I need to insert after line 9297 (the closing brace of the
if (!childSessionKey || !parentSessionKey)block):// Isolated sessions do not inherit the parent's LCM context. if (params.contextMode === "isolated") { return undefined; }Let me use sed to insert after line 9297.
Assistant
Let me verify the
Assistant
The change looks correct. Now let me run the existing tests to make sure nothing breaks
Assistant
All 317 tests pass. Let me also run the other test files to make sure nothing is broken
Assistant
All 1067 tests pass. Let me verify the change once more
Assistant
The fix is clean and correct. Let me verify the logic one more time by checking the complete
prepareSubagentSpawnmethod after the change:Assistant
The fix looks correct. Let me also clean up the extra blank line and then submit
Assistant
Let me verify the final state and run tests one final time
Assistant
Clean diff. Let me run the tests one final time to confirm
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →