Skip to content
TheChatArchiveThe Chat Archive
xiaomi/mimo-v2.5-pro· 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. Assistant

    I'll start by exploring the repository to understand the codebase and locate relevant files. Let's first get an overview.

  3. Assistant

    Let me look at the top-level structure of the repository first.

  4. Assistant

    Let me look at the AGENTS.md for more context:

  5. Assistant

    Let me explore the src directory to understand the codebase structure:

  6. Assistant

    Let me look at the structure more comprehensively to understand the codebase.

  7. Assistant

    Now let me search for terms related to session management, context, and cron:

  8. Assistant

    Let me search for "cron" and "context":

  9. Assistant

    Now let me search for "context":

  10. Assistant

    Let me look at the engine.ts file since it seems to be central to session management:

  11. Assistant

    I need to look for the session management and how sessions are isolated. Let me search for "stable session key" and "isolated" or "reuse" or similar concepts.

  12. Assistant

    Let me read the engine.ts file to understand how sessions and context are managed:

  13. Assistant

    Let me search for key patterns in the engine:

  14. Assistant

    Let me search for "context" and "LCM" together:

  15. Assistant

    Let me look for how conversations are created and how session keys map to conversations:

  16. Assistant

    Let me look at the resolveConversationIdForSessionKey method:

  17. Assistant

    Let me look for the conversation store and how it handles session keys:

  18. Assistant

    Let me look at the getConversationForSession method to understand how it works:

  19. Assistant

    Let me look at the shared-init.ts file that was mentioned in the grep results:

  20. Assistant

    Let me look at the plugin/index.ts file to see how the plugin is registered and how it handles sessions:

  21. Assistant

    Let me search for how the engine handles bootstrap and initialization for cron sessions:

  22. Assistant

    Let me search for the bootstrap method in the engine:

  23. Assistant

    Let me look at the bootstrap method:

  24. Assistant

    Let me search for "isolated" in the codebase:

  25. Assistant

    Let me look at the spawnSubagent method:

  26. Assistant

    Let me look for the spawn method in the engine:

  27. Assistant

    Let me look at the prepareSubagentSpawn method:

  28. Assistant

    Let me look at the applySessionReplacement method:

  29. Assistant

    Let me look at the shouldIgnoreSession method:

  30. Assistant

    Let me look at how isStatelessSession works:

  31. Assistant

    Let me search for how the engine handles cron sessions specifically:

  32. Assistant

    Let me look at the test file for engine:

  33. Assistant

    Let me look at the test around line 5090:

  34. Assistant

    Let me look at the recent git history to understand what changes were made recently:

  35. Assistant

    Let me search for "leak" or "context leak":

  36. Assistant

    Let me look at the test file for engine to understand the cron context leak issue better:

  37. Assistant

    Let me look at the handleSessionEnd method and how it's called:

  38. Assistant

    Let me look at the engine's bootstrap method to understand how it handles session key reuse:

  39. Assistant

    Let me search for findAmbiguousSessionKeyRuntimeRollover method:

  40. Assistant

    Let me look at the findAmbiguousSessionKeyRuntimeRollover method:

  41. Assistant

    Let me search for how the plugin handles session end events:

  42. Assistant

    Let me look at the session_end handler:

  43. Assistant

    Let me search for the rotateStaleSessionKeyConversationIfTrackedTranscriptMissing method:

  44. Assistant

    Let me look at the rotateStaleSessionKeyConversationIfTrackedTranscriptMissing method:

  45. Assistant

    Let me look at the applySessionReplacement method more closely:

  46. Assistant

    Let me look at the ingest method and how it handles context:

  47. Assistant

    Let me now look at the tests to understand the expected behavior:

  48. Assistant

    Let me look at the test that mentions "cron" to see what the expected behavior is:

  49. Assistant

    Let me look at the test that mentions "cron" to understand the expected behavior:

  50. Assistant

    Let me look for any tests related to session key reuse for cron sessions:

  51. Assistant

    Let me look at the test about "serializes recycled session writes by stable sessionKey":

  52. Assistant

    Let me look at the test about "preserves conversation history when the session file rotates across a stable sessionKey":

  53. Assistant

    Let me look at the getConversationBySessionKey method and how it handles active vs archived conversations:

  54. Assistant

    Let me look at how getConversationBySessionKey works:

  55. Assistant

    Let me search for test cases that specifically test cron isolation or stable session key isolation:

  56. Assistant

    Let me look at the assemble method to understand how context is assembled:

  57. Assistant

    Let me search for the assemble method in the engine:

  58. Assistant

    Let me look at the assemble method:

  59. Assistant

    Let me look at the afterTurn method to understand how it handles cron sessions:

  60. Assistant

    Let me look at the afterTurn method:

  61. Assistant

    Let me look at the reconcileTranscriptTailForAfterTurn method:

  62. Assistant

    Let me look at this method:

  63. Assistant

    Let me look at the reconcileSessionTail method:

  64. Assistant

    Let me look at the session-patterns.ts file:

  65. Assistant

    Let me look at the existing tests more carefully for cron-related patterns:

  66. Assistant

    Now let me understand how getOrCreateConversation handles session key reuse:

  67. Assistant

    Let me look at the test files to see if there are any tests that specifically test the scenario described in the issue:

  68. Assistant

    Let me look for the test that tests what happens when a cron session with a stable key is reused:

  69. Assistant

    Let me look at the test around line 14274 that was mentioned earlier about "deduplicates replay when runtime sessionId changes but stable sessionKey continues":

  70. Assistant

    Let me now look at the git log and recent issues more carefully. Let me understand what the issue actually is by looking at more related code:

  71. Assistant

    Let me now think more carefully about the problem. Let me re-read the issue and look at the code flow for cron runs that use a stable session key. Let me trace through what happens:

  72. Assistant

    Now let me think about this more carefully. The issue is about "isolated cron runs" that "leak context when they reuse a stable session key." Let me look at how getOrCreateConversation handles the case where the sessionId changes but the sessionKey stays the same:

  73. Assistant

    Let me now run the existing tests to understand the baseline:

  74. Assistant

    Let me run the existing tests first to understand the baseline.

  75. Assistant

    Let me look at the reconcile method to understand how it handles ambiguous rollover:

  76. Assistant

    Let me look at lines 6700-6730 in the reconcile method:

  77. Assistant

    Let me look at the checkpointIsPastTranscriptEof function and the bootstrap flow for handling file shrink:

  78. Assistant

    Let me look at the function and the context around it:

  79. Assistant

    Now I have a clear understanding of the issue. Let me look at the key flow in the findAmbiguousSessionKeyRuntimeRollover method:

  80. Assistant

    Let me look more carefully at the bootstrap flow and the assemble flow to understand how the context leak happens:

  81. Assistant

    Now I have a clear understanding of the issue. Let me trace through the scenario:

    1. Cron run 1: sessionId="run1", sessionKey="agent:main:cron:nightly", sessionFile="file1" → creates conversation C1, bootstraps, creates context items

    2. Cron run 2: sessionId="run2", sessionKey="agent:main:cron:nightly", sessionFile="file2" →

      • findAmbiguousSessionKeyRuntimeRollover detects rollover (different sessionId, different file, old file exists)
      • Tail anchor check fails (fresh cron run file doesn't contain old conversation's tail)
      • Bootstrap returns early with AMBIGUOUS_SESSION_KEY_RUNTIME_ROLLOVER_REASON
      • But C1 is NOT archived! It stays active.
      • Subsequent assemble calls detect rollover → returns safeFallback (no leak)
      • BUT: reconcileTranscriptTailForAfterTurn in afterTurn, when file is the same, won't detect rollover
    3. Same-file scenario: When the session file path is the SAME across runs:

      • findAmbiguousSessionKeyRuntimeRollover returns null because trackedSessionFile === params.sessionFile
      • getOrCreateConversation finds C1 by sessionKey, updates sessionId
      • Context items from C1 leak into run 2!

    The fix needs to:

    1. Remove the same-file early return in findAmbiguousSessionKeyRuntimeRollover so the tail anchor check is always performed
    2. When the rollover is detected and tail anchor check fails, archive the prior conversation and continue bootstrap with a fresh conversation

    Let me implement the fix:

  82. Assistant

    Let me look at the bootstrap flow around the rollover check:

  83. Assistant

    Now let me look at the afterTurn reconcile flow for the rollover check:

  84. Assistant

    Now I understand the issue clearly. Let me implement the fix. The key changes are:

    1. In findAmbiguousSessionKeyRuntimeRollover: Remove the same-file early return (lines 7002-7004) so the rollover detection covers same-file cases
    2. In bootstrap: When the rollover is detected and tail anchor check fails, archive the old conversation and continue (instead of returning early)
    3. In afterTurn reconcile: When the rollover is detected and tail anchor check fails, also archive the old conversation

    Let me make the first change:

  85. Assistant

    Let me use the replace command instead:

  86. Assistant

    Let me use the edit command with proper syntax:

  87. Assistant

    Wait, I need to think more carefully. The same-file early return being removed means that for the case where sessions with different sessionIds use the same session file, the rollover detection would trigger. But this would affect normal sessions too (not just cron runs). Let me think about a better approach.

    The core issue is that getOrCreateConversation reuses the existing conversation for a stable session key, even when the sessionId changes. For cron runs, this means the new run inherits the old conversation's context.

    The fix should be in the bootstrap/afterTurn/assemble flows: when we detect that a new sessionId is using a stable session key that belongs to a prior conversation, and the new session file doesn't contain the prior conversation's messages (tail anchor check fails), we should archive the prior conversation and create a fresh one.

    Let me revert my change to findAmbiguousSessionKeyRuntimeRollover and instead make targeted changes in bootstrap, afterTurn, and assemble:

  88. Assistant

    The diff shows only the same-file check removal so far. Let me revert and think about this more carefully. Let me first understand the full picture:

  89. Assistant

    OK, let me revert that and think about the proper approach. The same-file early return removal in findAmbiguousSessionKeyRuntimeRollover would affect assemble which doesn't have a tail anchor check available. Instead, I should make targeted changes in bootstrap and afterTurn to handle the same-file rollover case.

    Let me now implement the proper fix. First, let me modify the bootstrap flow:

  90. Assistant

    Now let me make the bootstrap changes. First, change the !hasFrontierAnchor branch to archive and continue instead of returning early:

  91. Assistant

    Let me use a different approach to make the edit:

  92. Assistant

    Let me use sed to make the edit:

  93. Assistant

    Let me verify the change:

  94. Assistant

    Good. Now I need to add the same-file rollover check after the ambiguousRollover block. Let me add it:

  95. Assistant

    Now let me add the same-file rollover check between the ambiguous rollover block and the getOrCreateConversation call:

  96. Assistant

    Let me verify the change:

  97. Assistant

    Good, the bootstrap changes are in place. Now I need to make similar changes in the afterTurn reconcile flow. Let me look at the afterTurn reconcile code:

  98. Assistant

    Now let me modify the afterTurn reconcile flow. First, change the !hasFrontierAnchor branch to archive the old conversation:

  99. Assistant

    Let me verify the change:

  100. Assistant

    Good. Now I need to add the same-file rollover check after the reason === "path-mismatch" block. Let me add it:

  101. Assistant

    Let me verify the change:

  102. Assistant

    Good. Now let me handle the assemble flow. Let me look at the assemble code:

  103. Assistant

    Let me look at the assemble rollover detection:

  104. Assistant

    Let me modify the assemble rollover detection to also archive the old conversation:

  105. Assistant

    Let me verify the change:

  106. Assistant

    Good. Now let me run the existing tests to make sure my changes don't break anything:

  107. Assistant

    Let me look at the failing tests to understand what they expect:

  108. Assistant

    Let me look at the failing tests:

  109. Assistant

    I see the issue. The tests expect the old conversation to remain active after the rollover is detected. But my changes archive the old conversation and create a fresh replacement. I need to update the tests to reflect the new behavior.

    Let me look at all three failing tests and update them:

  110. Assistant

    Let me update the bootstrap test to reflect the new behavior:

  111. Assistant

    Let me use sed to make the edit:

  112. Assistant

    Let me verify the change:

  113. Assistant

    Good. Now let me update the afterTurn test. Let me look at it:

  114. Assistant

    Let me update the afterTurn test:

  115. Assistant

    Let me verify the change and then update the assemble test:

  116. Assistant

    Now let me look at the assemble test:

  117. Assistant

    Let me update the assemble test:

  118. Assistant

    Let me verify the change and then run the tests again:

  119. Assistant

    Good. Now let me run the tests again:

  120. Assistant

    The remaining test failures are because the fresh replacement now has the new sessionId, so getConversationBySessionId(secondSessionId) finds it. Let me update the test expectations:

  121. Assistant

    The tests expect that getConversationBySessionId(secondSessionId) returns null. But with the fresh replacement, the conversation has the new sessionId, so getConversationBySessionId(secondSessionId) would find it. I need to update the test to expect that getConversationBySessionId(secondSessionId) returns the fresh conversation.

    Let me update both failing tests.

  122. Assistant

    Let me verify the changes and run the tests again:

  123. Assistant

    Let me check the actual lines around those to see if the sed command worked correctly:

  124. Assistant

    Let me check the other test:

  125. Assistant

    Good. Now let me run the tests again:

  126. Assistant

    All 1067 tests pass. Now let me write a reproduction script to verify that the fix actually resolves the issue:

  127. Assistant

    Let me put the test file in the test directory instead:

  128. Assistant

    Let me look at how the existing tests create the engine:

  129. Assistant

    Let me look at the createTestConfig and createTestDeps functions:

  130. Assistant

    Let me clean up the temporary test file and verify the full test suite passes:

  131. Assistant

    All 1067 tests pass. Now let me review the complete diff to make sure everything is correct:

  132. Assistant

    Let me look at the full diff:

  133. Assistant

    The diff looks correct. Let me review the changes:

    1. In afterTurn reconcile: When rollover detected (different file or same file), archive old conversation and create fresh replacement before returning.

    2. In bootstrap: When rollover detected (different file or same file), archive old conversation and create fresh replacement, then continue with bootstrap.

    3. In assemble: When rollover detected, archive old conversation and create fresh replacement before returning safeFallback.

    4. Test updates: Updated three tests to expect the new behavior (archived old conversation, fresh replacement).

    Now let me do a final verification that all tests pass:

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