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" that leak context when they reuse a stable session key. This seems to be related to a system called "lossless-claw" based on the directory name.
Let me explore the repository first.
Assistant
This looks like a TypeScript/JavaScript project. Let me explore the source code structure and understand the issue better.
The issue is about "isolated cron runs" that "leak context when they reuse a stable session key". The key areas seem to be:
- 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
Let me explore the source code structure first.
Assistant
Let me search for keywords related to the issue.
Assistant
Let me search more specifically for "isolated" and "stable" and "session key" concepts.
Assistant
Let me look at the key source files to understand the "isolated" cron concept and context leaking.
Assistant
Let me look at the contextMode handling in engine.ts and openclaw-bridge.ts.
Assistant
Let me look at these more carefully. The issue is about isolated cron runs leaking context when they reuse a stable session key. Let me look at the engine.ts around line 9275.
Assistant
Maybe the file is too large. Let me use grep to find the relevant sections.
Assistant
Now let me look at line 9275 and surrounding code in engine.ts to understand contextMode parameter. Also let me look at the openclaw-bridge.ts for more context.
Assistant
Let me search for where
contextModeis actually used in the code, especially for the "isolated" modeAssistant
Let me look at the openclaw-bridge.ts around line 188.
Assistant
Let me look at the full openclaw-bridge.ts and understand the structure more.
Assistant
Now let me look at the plugin/index.ts to understand how the engine is hooked up and how isolated mode is used.
Assistant
No matches. Let me look at the plugin/index.ts more broadly for contextMode related handling.
Assistant
Let me search the whole src directory for these terms.
Assistant
Let me look at the full onSubagentEnded function and below
Assistant
Let me look at how sessions/key resolution happens and how isolation works.
Assistant
Let me search for the assemble function to understand how context is accumulated
Assistant
Let me look at the assemble function.
Assistant
Let me search for where contextMode is actually used/implemented to understand the expected behavior.
Assistant
Let me look at the prepareSubagentSpawn function again more carefully. It receives
contextModebut may not be using it.Assistant
Let me look at how
createDelegatedExpansionGrantworks and understand the delegation system betterAssistant
Let me look at the expansion-auth.ts to understand how grants work and what
allowedConversationIdsdoesAssistant
Let me try using the terminal to read it
Assistant
Let me search for how sessions are created and how "archive" works, as well as how
applySessionReplacementand related functions workAssistant
Let me look at the
lifecycleRolloverfunction more carefully which seems to be the main function for handling session lifecycle changesAssistant
Let me look at the
bootstrapfunction to understand how sessions are initialized and how context flows.Assistant
Let me look at the bootstrap function to understand how sessions and conversations are initialized
Assistant
Let me look at how
getOrCreateConversationworks and how sessions and conversations are linkedAssistant
Let me look at the conversation store's getOrCreateConversation and getConversationForSession functions
Assistant
Let me search for where sessions are initialized for cron runs and how isolation is implemented
Assistant
Let me look at the test files to understand the testing patterns and see if there are related tests
Assistant
Let me look at the relevant test cases to understand how stable sessionKeys work and what the expected behavior is when sessions are reused. Let me start with the "serializes recycled session writes by stable sessionKey" test
Assistant
Let me look at the test "rotates to a fresh conversation when a stable sessionKey resumes on a new transcript after the old file disappears"
Assistant
Let me look at the plugin/index.ts to understand how the engine integrates with the runtime
Assistant
Let me search for where
prepareSubagentSpawnis called in the whole codebaseAssistant
Let me check if there is any reference to "isolated" in any of the plugin implementation code.
Assistant
Let me look at the tests for
prepareSubagentSpawnto understand itsAssistant
Let me now look at the test for prepareSubagentSpawn that resolves by sessionKey around line 701
Assistant
Let me look at the git log to see if there are any recent commits related to this issue
Assistant
Let me look at what happens if
prepareSubagentSpawncreates a new conversation for the child whencontextModeis "isolated". Let me look at the conversation store's createConversation.Assistant
Let me search for where
prepareSubagentSpawnis called outside of tests.Assistant
Let me look at what
resolveConversationIdForSessionKeydoesAssistant
Let me look at
lcm-conversation-scope.tsAssistant
Now let me understand the full flow better by looking at how
handleSessionEndis called and how the session lifecycle works.Assistant
Let me look at the
applySessionReplacementfunctionAssistant
Let me also check if the
conversationStorehas anarchiveConversationAssistant
Let me check the
archiveConversationmethodAssistant
Let me look at how
conversationStoreis accessed in the engineAssistant
Now let me implement the fix. Let me look at the exact lines of
prepareSubagentSpawnagainAssistant
Now I'll implement the fix. The key change is in
prepareSubagentSpawn: whencontextModeis"isolated", the child should get its own fresh conversation instead of sharing the parent's contextAssistant
Let me open the file first
Assistant
Good, the file is open. Let me navigate to the right lines.
Assistant
Let me use sed to apply the change
Assistant
Let me use the edit command with the
--fileoptionAssistant
Let me check the actual file to see what happened
Assistant
It seems the edit didn't apply to the right lines. Let me check git diff to see what happened
Assistant
Oh no! The edit command interpreted the line numbers relative to the visible window, replacing the import lines at the top instead of
prepareSubagentSpawn. Let me revert this immediately.Assistant
Good, reverted. Now let me apply the change correctly. Let me find the exact line numbers
Assistant
Let me use a script to apply the changes correctly. I'll use Python for a safe edit.
Assistant
Let me write a script file instead to avoid shell escaping issues
Assistant
Let me try using node since this is a JS/TS project
Assistant
Let me use a Node.js script to apply the fix
Assistant
The fix was applied successfully. Let me verify the changes.
Assistant
The changes look correct. Let me verify the full function structure.
Assistant
Good, the changes look correct. Let me now run the TypeScript compiler to check for errors.
Assistant
There's a TypeScript error. Let me check the actual config property name for
Assistant
Let me check the config property names
Assistant
Let me look at how maxDepth is configured elsewhere
Assistant
I need to fix the
maxDepthproperty. The config doesn't havemaxExpandDepth. Let me fix it.Assistant
Let me verify TypeScript compilation again
Assistant
TypeScript compilation passes. Now let me run the relevant tests to make sure my changes don't break anything.
Assistant
All 317 tests pass. Let me also run the other related test files.
Assistant
Let me check the schema to understand the UNIQUE constraints on the
Assistant
Let me check the migration or schema files
Assistant
Let me check the UNIQUE index on conversations
Assistant
Let me create a quick test script to verify the behavior manually
Assistant
Let me just verify the changes with grep
Assistant
Let me now run the full test suite to make sure nothing is broken.
Assistant
All 1067 tests pass across 49 test files. Let me review the final diff to confirm it looks correct.
Assistant
The changes look correct. Let me go through my checklist:
Checklist
-
If an error was reported in the issue description, I have successfully reproduced it.
- The issue describes a behavior (context leaking in isolated cron runs), not a specific error. I identified the root cause:
prepareSubagentSpawninsrc/engine.tsaccepts acontextModeparameter ("isolated"|"fork") but completely ignores it. The function always resolves the parent's conversation and includes it in the delegation grant, so isolated cron runs always inherit the parent's active LCM context.
- The issue describes a behavior (context leaking in isolated cron runs), not a specific error. I identified the root cause:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.