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
I'll start by exploring the repository structure to understand the codebase and the issue at hand.
Assistant
This is a TypeScript/JavaScript project. Let me explore the source code structure and look for files related to cron, sessions, and LCM context.
Assistant
Let me look at these files related to cron, and also search for session key and LCM context related code.
Assistant
Let me look at the test files to understand the issue better.
Assistant
Let me look at the test files for anything related to cron, session, and context isolation.
Assistant
Let me look at the key source files to understand the codebase. I'll start with the engine and session patterns.
Assistant
I need to use
openwithout the/prefix or usecatto view the file.Assistant
Let me search for the specific parts related to cron sessions, session keys, and context isolation.
Assistant
Let me look at the key areas around
contextMode: "isolated"and the bootstrap/archiving logic to understand the issue better.Assistant
Now let me look at the
bootstrapmethod to understand how context is handled for sessions:Assistant
I need to continue reading the bootstrap method and understand the context isolation logic. Let me search for the specific handling of session keys and cron sessions to understand where the context leak might be happening.
Assistant
Let me look at the
getConversationBySessionKeymethod more closely:Assistant
Now I can see the issue! Let me understand the problem:
- When looking up a conversation by session key,
getConversationBySessionKeyonly looks foractive = 1conversations. - In
getOrCreateConversation, if a session key is reused (like a stable cron session key), it will find the existing active conversation by key and reuse it. - But the issue is that for isolated cron runs, when a prior run ends, its conversation should be archived, and a new cron run starting with the same session key should NOT reuse the old context.
Let me check the tests to understand the expected behavior:
- When looking up a conversation by session key,
Assistant
Let me look at the session_end lifecycle test to understand the expected behavior:
Assistant
Now let me search for tests specifically related to cron or context isolation:
Assistant
Let me look at the git log or changesets to understand the context of the issue better:
Assistant
Let me look at the AGENTS.md to understand the issue better:
Assistant
Now let me look more closely at the issue. The issue says "Different isolated cron runtime sessions that reuse a stable session key must not share active LCM context." Let me search for how cron sessions are handled and what the
shouldIgnoreSessionmethod does:Assistant
Now let me look for any existing tests related to the issue. Let me check the regression tests:
Assistant
---content---
Now I understand the context better. The issue is about isolated cron sessions that reuse a stable session key. Let me look for the specific test or code related to this scenario. Let me check if there's a test file that specifically tests for cron isolation:
<tool_call> <function=bash_terminal> <parameter=command> grep -rn "isolated.*cron|cron.*isolated|isolated.*session|session.isolated" /lossless-claw --include=".ts" | head -20 </tool_call>
Assistant
Let me retry with a simpler grep command to find relevant code.
Assistant
Now I'm getting somewhere. The
contextMode: "isolated"is used inprepareSubagentSpawn. Let me look at the openclaw-bridge.ts to understand the interface better and then look at how isolated mode should work.Assistant
Let me search for the
rotateStaleSessionKeyConversationIfTrackedTranscriptMissingandfindAmbiguousSessionKeyRuntimeRolloverfunctions to understand the existing session key handling:Assistant
Let me understand the issue better. The problem is about "isolated cron runs" that "reuse a stable session key" and leak "active LCM context".
Looking at the code, I can see:
contextMode: "isolated"is a parameter passed toprepareSubagentSpawnbut it's not currently being used- Cron sessions typically have keys like
agent:main:cron:nightly:run:run-123 - When a cron run ends, its conversation should be archived
- When a new cron run starts with the same stable session key (e.g.,
agent:main:cron:nightly), it should NOT reuse the old context
Let me look at what happens when
contextMode: "isolated"is passed - it seems like the code doesn't actually handle this case, which could be the source of the leak.Let me look at the
prepareSubagentSpawnmethod more carefully and see what it does with thecontextModeparameter.Assistant
Now let me understand the actual issue better. The
contextMode: "isolated"parameter exists inprepareSubagentSpawnbut doesn't seem to be used. Let me check how isolated sessions should behave:Assistant
Looking at this issue, I need to understand the flow better. The problem is that isolated cron sessions that reuse a stable session key are sharing LCM context when they shouldn't. Let me examine the expansion-auth module to understand how grants are tracked:
Assistant
Let me look at the test file for the expansion-auth module to understand the expected behavior for isolated mode.
Assistant
Let me continue investigating the issue. The key insight is that when
contextMode: "isolated"is used, the child session should not share any context with the parent. Let me look at how the grant is created:Assistant
Now I see the issue! When
contextMode: "isolated"is passed toprepareSubagentSpawn, the code currently doesn't check for this mode and still creates a delegated expansion grant withallowedConversationIds: [conversationId], which means the isolated session can still access the parent's conversation context.For an "isolated" context mode, the child should NOT be granted access to the parent's conversation. The
allowedConversationIdsshould be empty (or the grant shouldn't be created at all).Let me verify this by looking at how the grants are used in expansion/retrieval:
Assistant
Now I understand the issue clearly. The problem is:
- When
prepareSubagentSpawnis called withcontextMode: "isolated", the method should not grant the child access to the parent's conversation - Currently, the code ignores the
contextModeparameter and always creates a grant withallowedConversationIds: [conversationId](the parent's conversation) - For isolated mode, the
allowedConversationIdsshould be empty[]so the child cannot expand the parent's context
Let me also check if there are any tests that verify the isolated mode behavior:
- When
Assistant
There are no existing tests for the
contextMode: "isolated"feature. This confirms that the feature is incomplete - the parameter exists in the interface but is not implemented.Let me now create a test script to reproduce the issue and then fix it.
Assistant
All tests pass. Let me now create a test script to reproduce the issue and understand the expected behavior better.
Assistant
I need to check the exports from engine.ts to see how to properly create an engine instance.
Assistant
Let me look at the existing tests to see how they create engine instances:
Assistant
Let me simplify the test script to use the same approach as the test file:
Assistant
I need to run the test script I just created. Let me use the bash_terminal command.
Assistant
I've confirmed the issue. When
contextMode: "isolated"is passed toprepareSubagentSpawn, the child session is still being granted access to the parent's conversation (conversation ID 1). For isolated mode, theallowedConversationIdsshould be empty[].Now I need to fix the
prepareSubagentSpawnmethod in/lossless-claw/src/engine.tsto handle thecontextMode: "isolated"parameter properly.The fix should:
- Check if
contextModeis "isolated" - If so, set
allowedConversationIdsto an empty array[] - For "fork" mode or undefined, keep the current behavior (share context)
Let me look at the code again and make the fix.
I've confirmed the issue. When
contextMode: "isolated"is passed, the child session is still granted access to the parent's conversation. Let me fix this.<tool_call> <function=bash_terminal> <parameter=command> sed -n '9270,9345p' /lossless-claw/src/engine.ts </tool_call>
- Check if
Assistant
Let me view the relevant code section to understand the fix needed.
Assistant
Now I can see the issue clearly. The
prepareSubagentSpawnmethod always passesallowedConversationIds: [conversationId]regardless ofcontextMode. ForcontextMode: "isolated", it should be an empty array.Let me apply the fix:
Assistant
I need to use the --file option with the edit command since no file is currently open.
Assistant
Let me use sed to make the change.
Assistant
The sed command executed successfully. Let me verify the change was applied correctly by looking at the modified code section.
Assistant
The fix has been applied. Now let me verify it works by running my test script:
Assistant
The fix is working correctly. Now let me run the existing tests to make sure I didn't break anything:
Assistant
All 1067 tests pass. The fix is working correctly and doesn't break any existing functionality.
Let me clean up the test script I created and verify the final state of my changes:
Assistant
Let me verify my changes one more time by looking at the diff:
Assistant
The fix is complete. Let me verify it once more by running the full test suite:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.