Skip to content
TheChatArchiveThe Chat Archive
MiniMaxminimax/minimax-m3· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Isolated cron runs leak context when they reuse a stable session key…

  1. 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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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-$

  2. MiniMax Assistant

    I'll start by exploring the repository structure to understand the codebase.

  3. MiniMax Assistant

    Let me look at the engine.ts file around contextMode handling since that's where isolated sessions are mentioned.

  4. MiniMax Assistant

    Let me look at how cron sessions interact with the conversation store.

  5. MiniMax Assistant

    Let me search for related terms like "isolated cron", "leak", and "stable session key":

  6. MiniMax Assistant

    Let me look at conversation-store.ts to understand how conversations are stored:

  7. MiniMax Assistant

    Now let me search for "isolated" or "cron" handling in the engine:

  8. MiniMax Assistant

    So the engine.ts has only one mention. Let me look at how prepareSubagentSpawn is used:

  9. MiniMax Assistant

    Let me look at the tests for engine.test.ts to see how the engine handles session keys:

  10. MiniMax Assistant

    Let me look at the recent commits/changesets to understand the issue context:

  11. MiniMax Assistant

    Now let me look at fork-related commits to understand the pattern used:

  12. MiniMax Assistant

    Let me look at how contextMode is used in prepareSubagentSpawn and how it relates to isolated cron runs:

  13. MiniMax Assistant

    The contextMode parameter is accepted but never actually used in the engine code. Let me look at how cron sessions interact with LCM and find the area where the "leak" would happen:

  14. MiniMax Assistant

    Let me look at how prepareSubagentSpawn is called and how contextMode might affect the conversation selection:

  15. MiniMax Assistant

    Now let me see how contextMode is referenced in tests to see if any test scenarios exist for isolated:

  16. MiniMax Assistant

    Let me look at the engine tests for prepareSubagentSpawn since this is likely related to our concern:

  17. MiniMax Assistant

    Now let me look at the test file for prepareSubagentSpawn tests to find related cases:

  18. MiniMax Assistant

    Now let me understand the cron session lifecycle better. Cron jobs in OpenClaw typically have session keys like agent:main:cron:<job>:run:<run-id>. Let me look at how the conversation store handles them:

  19. MiniMax Assistant

    Now I understand the flow. Each getOrCreateConversation(sessionId, { sessionKey }) looks up by sessionKey and gets an existing conversation if found.

    The issue is:

    • A cron job may have a stable session key like agent:main:cron:nightly
    • But each cron run uses a different sessionId like agent:main:cron:nightly:run:run-123
    • When the second cron run tries to get/create a conversation with the SAME sessionKey agent:main:cron:nightly, it finds the PREVIOUS run's conversation
    • Then it would update the session_id and reuse the conversation - but this means context from previous run is "leaked"

    Let me search for cron handling in conversation store and engine:

  20. MiniMax Assistant

    Let me look at lcm-doctor-cleaners.ts to understand cron sessions handling:

  21. MiniMax Assistant

    Now let me understand the issue better. The issue says: "Different isolated cron runtime sessions that reuse a stable session key must not share active LCM context."

    This suggests that cron jobs with session keys like agent:main:cron:daily-digest:run:run-123 should NOT share active context across runs, but should archive prior runs. Let me look at how session keys are handled:

  22. MiniMax Assistant

    Now I see. The default cron pattern is agent:*:cron:** which means cron sessions are excluded entirely. So in the default case, the issue wouldn't occur.

    But wait - what if the user doesn't ignore cron sessions? Let me re-read the issue: "Different isolated cron runtime sessions that reuse a stable session key must not share active LCM context."

    Let me look at how OpenClaw session keys for cron runs work - the session keys might be like agent:main:cron:<job-name> (stable) but with different session IDs for each run.

    Let me look at how OpenClaw session keys actually work. First, let me understand what "isolated cron" means:

  23. MiniMax Assistant

    Now I have a clearer picture. The "stable session key" is a session key that survives across runs of the same logical session (e.g., main agent session, etc.). Cron runs normally have session keys that vary.

    Let me look at how prepareSubagentSpawn is used - if it's used for cron runs, then the issue could be in there:

  24. MiniMax Assistant

    Now let me look at how cron sessions get started in plugin/index.ts:

  25. MiniMax Assistant

    Let me look at resolveConversationIdForSessionKey and how it handles sessionKey:

  26. MiniMax Assistant

    Now let me look at ingest to understand how it handles sessionKey for active conversations:

  27. MiniMax Assistant

    Now let me look at the ingest method that handles session keys:

  28. MiniMax Assistant

    Let me look at the ingestSingle function:

  29. MiniMax Assistant

    Now I understand the issue better. When ingestSingle calls getOrCreateConversation(sessionId, { sessionKey }), it will:

    1. Check if a conversation exists for the sessionKey
    2. If yes, reuse that conversation (and just update sessionId)
    3. Otherwise, look up by sessionId, or create a new one

    For cron runs that share the same sessionKey, the second run will reuse the first run's conversation, which means context "leaks" between runs.

    Let me search for how the issue is being addressed or what test cases exist:

  30. MiniMax Assistant

    Let me look at the docs/architecture.md to understand the conversation lifecycle:

  31. MiniMax Assistant

    Now let me look at how session continuity is described:

  32. MiniMax Assistant

    OK, so the current behavior:

    • LCM prefers sessionKey for stable identity
    • When same sessionKey appears with new sessionId, it updates the stored sessionId
    • This is by design for main sessions

    Now for cron runs, the issue is:

    • Cron runs may reuse a stable sessionKey like agent:main:cron:daily-digest
    • Each run is a separate isolated runtime, so they should not share active context
    • But currently LCM does share context because it follows sessionKey continuity

    The fix should be to detect when an "isolated" session is being used (via the contextMode: "isolated" parameter in prepareSubagentSpawn, which I notice is defined but not yet used), and treat the conversation lookup differently - either archive the previous conversation and create a new one, or otherwise not share active context.

    Let me look at getOrCreateConversation to think about the right fix:

  33. MiniMax Assistant

    Now I understand the issue clearly:

    In getOrCreateConversation(sessionId, { sessionKey }):

    1. If a conversation exists for sessionKey, it returns that existing one (and updates sessionId)
    2. This means a new isolated cron run will get the OLD conversation (with stale context) as its active context
    3. Context "leaks" from prior runs to current

    The fix needs to be:

    • When the runtime tells us this is an isolated session (via contextMode: "isolated" parameter passed to prepareSubagentSpawn)
    • We need to archive the prior conversation for that sessionKey and create a new one
    • This means the previous run's data is preserved (archived), and the new run starts fresh

    Let me check how prepareSubagentSpawn is called - we need to add this logic there since contextMode is the parameter that signals this:

  34. MiniMax Assistant

    OK so prepareSubagentSpawn is part of the context engine API but isn't called anywhere except in tests. The fix needs to live in the engine.

    Let me think about the approach. The issue says:

    • "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."

    So the fix needs to:

    1. Detect when an isolated cron run is happening (likely via contextMode: "isolated" in prepareSubagentSpawn)
    2. Archive the prior conversation for that sessionKey
    3. Create a new conversation for the current run
    4. Keep compaction working within the current run

    Let me look at how prepareSubagentSpawn is wired to OpenClaw's runtime to confirm the flow:

  35. MiniMax Assistant

    So the engine is registered with OpenClaw, and prepareSubagentSpawn is part of the API. The fix needs to be inside the prepareSubagentSpawn to:

    1. Detect contextMode: "isolated"
    2. Archive any existing conversation for that sessionKey
    3. Create a new conversation for the new run

    Let me look at the full prepareSubagentSpawn:

  36. MiniMax Assistant

    Now let me think about the approach:

    The issue says "isolated cron runtime sessions that reuse a stable session key". This means cron runs that share the same sessionKey but are isolated (i.e., should not share context).

    The fix should be in prepareSubagentSpawn to detect contextMode: "isolated". When isolated:

    • Archive any prior conversation for the child sessionKey
    • Create a new conversation for the new child run
    • This way the new run starts with fresh context

    Let me look at the existing tests for prepareSubagentSpawn:

  37. MiniMax Assistant

    Let me look at the imports and helpers to understand the structure:

  38. MiniMax Assistant

    Now I have enough context to think about the fix. Let me think about the design:

    The Issue: When prepareSubagentSpawn is called with contextMode: "isolated" and childSessionKey that has been used in a prior run, LCM currently reuses the prior conversation (because resolveConversationIdForSessionKey finds it by sessionKey). This causes the new run to inherit the old run's context.

    The Fix: When contextMode === "isolated":

    1. Archive the existing conversation for childSessionKey if it exists and has data
    2. Create a new conversation for this run
    3. Subsequent ingest calls using childSessionKey will see no active conversation and create a fresh one (since getOrCreateConversation won't find an active one by sessionKey after archiving)

    Wait, but ingest for the child uses childSessionKey. Let me look at how ingest works for child sessions:

  39. MiniMax Assistant

    Hmm, let me look at the engine tests to understand the actual call patterns. When a cron run is isolated, what does OpenClaw do?

  40. MiniMax Assistant

    Let me look at the spec files:

  41. MiniMax Assistant

    Now let me think about this more concretely. Looking at the code path:

    1. When a cron run starts, OpenClaw calls prepareSubagentSpawn (or some equivalent) with the child session key (which is the cron session key) and contextMode: "isolated".

    2. After spawn, the engine receives ingest calls for the cron run using this child session key.

    3. ingest calls getOrCreateConversation(sessionId, { sessionKey: childSessionKey }).

    4. getOrCreateConversation looks up by sessionKey first - if a conversation exists, it reuses it.

    So the fix is:

    • In prepareSubagentSpawn, when contextMode === "isolated" AND there's an existing active conversation for the child session key, archive it.

    Let me also check the SubagentSpawnPreparation rollback - it just revokes the expansion grant. So when we archive, we should make sure the next ingest creates a new conversation.

    Let me verify this theory by reproducing the issue first. Let me set up a test environment:

  42. MiniMax Assistant

    Let me write a small reproduction script:

  43. MiniMax Assistant

    Now let me create a small test reproduction script to verify the bug:

  44. MiniMax Assistant

    Let me check how test files import to get a sense of structure:

  45. MiniMax Assistant

    Let me write a temporary repro test:

  46. MiniMax Assistant

    Let me check how the test config is set up properly:

  47. MiniMax Assistant

    Now let me update my repro test to use the test helpers properly:

  48. MiniMax Assistant

    I've reproduced the bug. As expected:

    • After running 2 isolated cron runs with the same childSessionKey
    • Only ONE active conversation exists (with session_id = cron-run-1 from the FIRST run!)
    • No archived conversation exists

    This confirms the bug: The second prepareSubagentSpawn doesn't archive the prior conversation. When the second ingest happens later, it would use the same conversation (with the new session_id from getOrCreateConversation).

    Wait, in this test, no second ingest was called yet. Let me also check what happens with a second ingest:

  49. MiniMax Assistant

    The bug is confirmed:

    • The first cron run stored "first cron message" in conversation_id=2 with session_id="cron-run-1"
    • The second cron run reuses conversation_id=2 (just updating session_id to "cron-run-2")
    • Now the conversation has BOTH the "first cron message" AND the "second cron message"
    • The first run's context "leaked" into the second run's active context

    This is exactly what the issue describes. Now let me implement the fix.

    The fix is in prepareSubagentSpawn: when contextMode === "isolated" AND a conversation exists for the child sessionKey, archive the prior conversation so the new run starts fresh.

    Let me look at the existing prepareSubagentSpawn more carefully:

  50. MiniMax Assistant

    Now let me look at the existing helper methods like applySessionReplacement and archiveConversation to make sure I use the right approach:

  51. MiniMax Assistant

    Now let me look at how sessionOperationsQueues is used to ensure proper serialization:

  52. MiniMax Assistant

    Let me think about the fix carefully:

    The issue says:

    • "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"

    So the fix should:

    1. ONLY apply when contextMode === "isolated"
    2. Archive the prior active conversation for that sessionKey
    3. Let the current run create a new conversation naturally

    Let me implement the fix:

  53. MiniMax Assistant

    Now let me implement the fix. The key change is in prepareSubagentSpawn:

    When contextMode === "isolated":

    1. Check if there's an existing conversation for childSessionKey
    2. If yes, archive it
    3. Continue with the existing flow (which doesn't create a conversation - it just resolves the parent)

    Let me look at the entire prepareSubagentSpawn again and write the fix:

  54. MiniMax Assistant

    Now let me implement the fix:

  55. MiniMax Assistant

    Let me look at how the session queue is used in ingest:

  56. MiniMax Assistant

    Good. Now I understand. Now let me implement the fix in prepareSubagentSpawn:

  57. MiniMax Assistant

    Now let me apply the fix. I'll modify the prepareSubagentSpawn method to archive the prior conversation when in isolated mode:]<]minimax[>[<tool_call> ]<]minimax[>[<invoke name="edit --file src/engine.ts 9290:9300 << 'EOF' this.ensureMigrated();

    const childSessionKey = params.childSessionKey.trim();
    const parentSessionKey = params.parentSessionKey.trim();
    if (!childSessionKey || !parentSessionKey) {
      return undefined;
    }
    
    // Isolated subagent runs (e.g. cron jobs that reuse a stable session key) must
    // not inherit active LCM context from a prior run. Archive any existing active
    // conversation for the child session key so the current run bootstraps a fresh
    // conversation. Prior history stays archived and remains recallable; ordinary
    // non-cron session continuity is unchanged because `contextMode === "fork"`
    // (or undefined) follows the existing stable-session-key behavior.
    if (params.contextMode === "isolated") {
      await this.archiveIsolatedChildConversation(childSessionKey);
    }
    
    const conversationId = await this.resolveConversationIdForSessionKey(parentSessionKey);
    if (typeof conversationId !== "number") {
      return undefined;
    

    EOF]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>

  58. MiniMax Assistant

    Let me apply the fix using the proper command format:

  59. MiniMax Assistant

    Now I need to add the archiveIsolatedChildConversation method. Let me find a good place to add it - near the isFreshLifecycleConversation and applySessionReplacement helpers:

  60. MiniMax Assistant

    Let me add the helper method right before isFreshLifecycleConversation:

  61. MiniMax Assistant

    Now let me also consider if we need session queue serialization for this operation. The prepareSubagentSpawn itself is already serialized per child session key through the sessionOperationQueues... wait, let me check if it is:

  62. MiniMax Assistant

    prepareSubagentSpawn doesn't use withSessionQueue. So I should ensure the archive operation is serialized along with subsequent ingest/operations on the same child session. Let me look at withSessionQueue to see how to integrate it:

    The flow is:

    1. prepareSubagentSpawn archives prior conversation
    2. Then ingest for the new run will be called - which uses withSessionQueue keyed by sessionId+sessionKey
    3. The ingest needs to see that no prior active conversation exists

    There's a potential race condition: if prepareSubagentSpawn and the subsequent ingest happen concurrently, we might have inconsistent state. Let me add serialization:

  63. MiniMax Assistant

    Let me also consider: The current ingest already serializes operations per session queue key. The session queue key is derived from sessionKey (if present) else sessionId. For isolated cron runs, the sessionKey is the same between runs (that's the issue). So when both runs are in flight concurrently, the second prepareSubagentSpawn would queue behind the first's ingest operations.

    But wait, the issue says the archive should happen on prepareSubagentSpawn. The prepareSubagentSpawn doesn't currently use the session queue. Let me think about this more carefully.

    Actually, looking at it more carefully: when an isolated cron run is being prepared:

    1. The PRIOR run should already be completed (you don't have two cron runs of the same job in flight)
    2. So we should serialize on the child sessionKey to ensure no race between prepareSubagentSpawn and the prior run's ingest

    Actually, looking at the OpenClaw host contract, prepareSubagentSpawn is called when the subagent is being spawned. The prior run should have already been ended (via onSubagentEnded). So serializing within prepareSubagentSpawn itself using the session queue should be safe.

    Let me also use withSessionQueue to serialize properly:

  64. MiniMax Assistant

    Now let me run the repro test to see if the fix works:

  65. MiniMax Assistant

    The fix works. Now:

    • Conversation 2 (first run) is archived with active=0 and archived_at set
    • Conversation 3 (second run) is the new active conversation
    • The new active conversation only contains the second run's message - no leak!

    Now let me make sure I haven't broken any existing tests. Let me first remove the temp test file and run all engine tests:

  66. MiniMax Assistant

    All 317 engine tests pass. Let me run the full test suite to be safe:

  67. MiniMax Assistant

    All 1067 tests pass. Now let me think about edge cases:

    1. First isolated cron run - no prior conversation exists. The archiveIsolatedChildConversation returns early.
    2. Subsequent isolated cron run with prior conversation - prior is archived, new one is created naturally by ingest.
    3. Fork subagent run - contextMode === "fork" or undefined - existing behavior preserved.
    4. No contextMode set - existing behavior preserved.
    5. Concurrent isolated runs with same sessionKey - serialized via session queue.
    6. Compaction within current run - untouched by our change. The current run's messages are stored in the new conversation and can be compacted normally.

    Let me think about another edge case - what about a NON-isolated run (fork) that comes after an isolated run? The fork would reuse the most recent active conversation (which is the latest isolated run's new conversation). That should be fine.

    What about an isolated run coming after a fork? The fork has its own conversation. The isolated run should archive it. Let me verify this works.

    Actually, let me also think about: what if the runtime also passes a childSessionId and childSessionKey is not stable? In that case, getConversationForSession({ sessionKey }) would not find anything because the previous run was keyed by a different sessionKey. So no archive happens - which is correct.

    Let me also verify the test that demonstrates the new behavior should be added. Looking at the existing tests for prepareSubagentSpawn:

  68. MiniMax Assistant

    I should not modify existing tests, but I want to verify the change works. Let me write a temporary test to make sure it works and remove before submission:

  69. MiniMax Assistant

    All 4 scenarios pass:

    1. ✅ Isolated cron reuses session key → prior archived
    2. ✅ Fork mode reuses session key → no archive (continuity preserved)
    3. ✅ First isolated cron run → no-op (no prior conversation)
    4. ✅ Default mode (no contextMode) → no archive (existing behavior)

    Now let me verify the typecheck passes:

  70. MiniMax Assistant

    Typecheck passes. Now let me clean up the temp test file:

  71. MiniMax Assistant

    Good, no temp files remain. Let me run the full test suite one more time to make sure everything still passes:

  72. MiniMax Assistant

    All 1067 tests pass. Now let me also add a changeset for this change:

  73. MiniMax Assistant

    Let me also check if there are any docs that should be updated:

  74. MiniMax Assistant

    Let me look at the existing changeset for fork-bootstrap-contract.md to see if there's relevant doc text I should match:

  75. MiniMax Assistant

    Let me check if there's anything in docs/configuration.md or skills related to isolated/cron sessions:

  76. MiniMax Assistant

    I should update the session-lifecycle reference to document this isolated cron behavior. Let me look at the full file:

  77. MiniMax Assistant

    Now let me update this documentation to mention the isolated subagent behavior. I'll add a new section:

  78. MiniMax Assistant

    Let me also update the docs/architecture.md:

  79. MiniMax Assistant

    Now let me run all the tests one more time to be sure:

  80. MiniMax Assistant

    All tests pass. Let me check the typecheck and the diff:

  81. MiniMax Assistant

    Let me run the build to make sure everything compiles:

  82. MiniMax Assistant

    Build succeeds. Let me run the full test suite one more time:

  83. MiniMax Assistant

    All 1067 tests pass. Let me also verify my fix one more time by reading the engine code:

  84. MiniMax Assistant

    Now let me go through the checklist:

    Checklist review:

    1. If an error was reported in the issue description, I have successfully reproduced it.

      • ✅ Yes. I created a reproduction test that showed:
        • First cron run with childSessionKey="agent:main:cron:daily-digest" creates conversation
        • Second cron run with same childSessionKey reused the prior conversation (only 1 active, no archive)
        • The active conversation contained BOTH the first run's message AND the second run's message - confirming the leak
    2. If an error was reported in the issue description, I have confirmed that my fix resolves the error.

      • ✅ Yes. After applying the fix:
        • First cron run creates conversation_id=2 with cron-run-1
        • Second cron run archives conversation_id=2 and creates conversation_id=3 with cron-run-2
        • The active conversation (id=3) only contains the second run's message
        • Prior conversation (id=2) is archived and still recallable
    3. I have thought about edge cases and made sure my fix handles them as well.

      • ✅ Yes. Verified:
        • First isolated cron run (no prior conversation): no-op archive ✓
        • Subsequent isolated cron run with prior conversation: archives prior ✓
        • Fork mode (contextMode === "fork"): no archive (continuity preserved) ✓
        • Default mode (no contextMode): no archive (existing behavior preserved) ✓
        • Concurrent calls: serialized via withSessionQueue ✓
        • Compaction within current run: untouched by fix, still works ✓
        • Recall of prior runs: preserved through standard session-family recall ✓
    4. I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.

      • ✅ Yes. All 1067 existing tests pass after the change. The relevant test files (engine.test.ts with 317 tests) all pass.

    Let me also verify no temp files were left:

  85. MiniMax Assistant

    Let me clean up /tmp temp files:

  86. MiniMax Assistant

    All temp files are cleaned up. Let me do final verification of the changes:

  87. MiniMax Assistant

    All my changes:

    1. src/engine.ts (43 lines added):

      • Added archive logic to prepareSubagentSpawn when contextMode === "isolated"
      • Added new private method archiveIsolatedChildConversation
      • Uses withSessionQueue to serialize with concurrent ingest/compact operations on the same child session key
    2. docs/architecture.md (11 lines added):

      • Added a new subsection "Isolated subagent spawns" documenting the behavior
    3. skills/lossless-claw/references/session-lifecycle.md (22 lines added):

      • Added a new "Isolated subagent spawns" section explaining the cron-style run behavior
      • Added a bullet in the "Safe operator guidance" section
    4. .changeset/isolated-cron-context-leak.md (new file):

      • Patch changeset describing the change for release notes

    Let me do one final check - run the tests and typecheck together:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.