Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· 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. GLM Assistant

    Let me start by exploring the repository structure to understand what we're working with.

  3. GLM Assistant

    This is a TypeScript project. Let me explore the source structure and understand the codebase.

  4. GLM Assistant

    I need to make single tool calls. Let me run them one at a time.

  5. GLM Assistant

    Let me look at the engine's context/session management logic more deeply.

  6. GLM Assistant

    Let me look at how the engine looks up active context/conversation by session key.

  7. GLM Assistant

    Let me look at the conversation store's getConversationForSession to understand how conversation lookup by session key works.

  8. GLM Assistant

    Let me look at the conversation store's full structure and the archive logic.

  9. GLM Assistant

    Now let me understand the issue better. The key is: "Isolated cron runs leak context when they reuse a stable session key". Different isolated cron runtime sessions reuse a stable session key. They must not share active LCM context. Prior runs remain archived. Compaction within current run still works. Ordinary non-cron session continuity is unchanged.

    So the cron session key is like agent:main:cron:nightly (stable) but each run is a different "runtime session" (different sessionId?). The issue is that the second cron run reuses the stable session key and ends up reusing the same active conversation/context from the prior run, leaking context across runs.

    I need to find where the engine decides whether to reuse or archive a conversation. The key concept seems to be: when a cron run completes, the conversation should be archived so the next run starts fresh. But the issue says "Different isolated cron runtime sessions that reuse a stable session key must not share active LCM context."

    So when a new cron run starts with the same session key as a prior run that has already completed, we should archive the old conversation and create a new one. But how do we detect a "new run"?

    Let me look at the conversation-scope.ts which might track scopes.

  10. GLM Assistant

    Let me look at the conversation-store index and the full schema. Let me check the migration to understand the conversations table.

  11. GLM Assistant

    There's a unique index on session_key WHERE active=1. So only one active conversation per session key can exist. The issue is that the second cron run, reusing the same session key, finds the prior active conversation and reuses it instead of archiving the prior and starting fresh.

    So I need to detect when a new cron run begins with a stable session key and archive the prior active conversation for that key, then create a new one.

    Now, how do we detect a "new run"? The runtime session ID changes between runs even though the session key stays the same. So when a new cron run starts with a different sessionId but the same sessionKey, we should archive the old conversation and create a new one.

    But wait - the existing getOrCreateConversation updates the sessionId of the existing conversation if it differs:

    if (byKey.sessionId !== sessionId) {
      this.db.prepare(`UPDATE conversations SET session_id = ?, ...`).run(sessionId, byKey.conversationId);
      byKey.sessionId = sessionId;
    }
    return byKey;
    

    So it reuses the conversation but updates the sessionId. That's the leak - the new cron run inherits the prior run's context.

    So I need to: when the sessionKey is a "cron" (isolated) session, and the existing active conversation has a different sessionId, archive the old conversation and create a new one instead of reusing.

    But the issue says "Different isolated cron runtime sessions that reuse a stable session key must not share active LCM context." The key concept: "isolated cron runtime sessions". This means sessions that are cron-based should be isolated per-run. The detection should be based on the session key pattern (cron).

    Let me look at how the engine is invoked - the afterTurn/bootstrap flow. Where does the conversation get resolved when a new turn comes in?

    Let me look at the isStatelessSession and shouldIgnoreSession and how cron is detected.

  12. GLM Assistant

    Let me look at the config and the existing tests to understand the expected behavior for cron sessions.

  13. GLM Assistant

    Let me look at the config to see how cron/isolated sessions are configured.

  14. GLM Assistant

    Let me search for "isolated" in the codebase.

  15. GLM Assistant

    Let me look at the openclaw-bridge.ts to understand the contextMode concept and how sessions are passed.

  16. GLM Assistant

    Let me look at the "ambiguous session key runtime rollover" logic in the bootstrap flow.

  17. GLM Assistant

    Let me look at the full ingest flow to see if it does rollover detection.

  18. GLM Assistant

    Let me look at applySessionReplacement.

  19. GLM Assistant

    Let me search the test file for tests about session rollover / reuse / replacement.

  20. GLM Assistant

    Let me check the default ignoreSessionPatterns in the config.

  21. GLM Assistant

    Let me check recent git history and changesets to understand the context.

  22. GLM Assistant

    Let me look at the test at line 14274 about runtime sessionId changes.

  23. GLM Assistant

    Let me look at the bootstrap flow where the ambiguous rollover check happens.

  24. GLM Assistant

    Let me look at the full ingest method.

  25. GLM Assistant

    Let me look at the test helpers to write a reproduction script.

  26. GLM Assistant

    Now let me write a reproduction script. Let me create a test file that simulates two isolated cron runs reusing a stable session key.

  27. GLM Assistant

    Let me search for cron detection helpers in the codebase.

  28. GLM Assistant

    Let me look at the plugin/index.ts to understand how sessions are passed and whether there's a "cron lane" concept.

  29. GLM Assistant

    Let me look at how the host wires bootstrap/afterTurn and how session identity is determined for cron lanes.

  30. GLM Assistant

    Let me check the openclaw plugin manifest and docs for cron lane definitions.

  31. GLM Assistant

    Let me write a reproduction test to confirm the leak. Let me create a temporary test file.

  32. GLM Assistant

    Let me place the reproduction test in the test directory and run it.

  33. GLM Assistant

    I've reproduced the leak. Now let me look at the afterTurn and assemble flows to understand where they resolve conversations.

  34. GLM Assistant

    Let me look at the assemble flow.

  35. GLM Assistant

    Let me look at where afterTurn ingests messages (the ingestBatch call in afterTurn).

  36. GLM Assistant

    Let me look at the reconcile logic for a conversation with no checkpoint.

  37. GLM Assistant

    Let me look at the compact flow to see if it resolves conversations by sessionKey.

  38. GLM Assistant

    Let me look at the lifecycle event handling and how the host passes lane info.

  39. GLM Assistant

    Now let me look at the exact location to insert the new helper method.

  40. GLM Assistant

    Let me check the AmbiguousSessionKeyRuntimeRollover type definition.

  41. GLM Assistant

    Now let me implement the fix. I'll add helper methods before rotateStaleSessionKeyConversationIfTrackedTranscriptMissing.

  42. GLM Assistant

    Now let me insert these helpers into the engine. I'll edit at line 6907.

  43. GLM Assistant

    Let me add a blank line between the methods for proper formatting.

  44. GLM Assistant

    There's a duplicate comment line. Let me fix it.

  45. GLM Assistant

    Now let me add a blank line before the rotateStale comment.

  46. GLM Assistant

    There's a duplicate line in the comment. Let me fix it.

  47. GLM Assistant

    The helpers are in place. Now let me add the calls in each entry point. Let me start with the bootstrap flow.

  48. GLM Assistant

    There's a duplicate rotateStale line. Let me fix it.

  49. GLM Assistant

    Bootstrap section is now correct. Now let me add the cron rotation to the afterTurn reconcile path.

  50. GLM Assistant

    There's a duplicate withTransaction line. Let me remove it.

  51. GLM Assistant

    The edit tool keeps duplicating lines. Let me use sed to remove the duplicate line.

  52. GLM Assistant

    Now the afterTurn reconcile is correct. Now let me add the cron rotation to the assemble flow.

  53. GLM Assistant

    Now let me add the cron rotation to ingest and ingestBatch. Let me find their current locations.

  54. GLM Assistant

    Let me update the ingest method to add the cron rotation.

  55. GLM Assistant

    Now let me add the cron rotation to ingestBatch. Let me find the exact lines now.

  56. GLM Assistant

    Now let me add the cron rotation to compact. Let me find the compact conversation resolution.

  57. GLM Assistant

    Now let me run the typecheck and the reproduction test.

  58. GLM Assistant

    Typecheck passes. Now let me run the reproduction test.

  59. GLM Assistant

    The fix works. Let me extend the repro test to verify prior runs remain archived (lossless) and ordinary non-cron continuity is unchanged.

  60. GLM Assistant

    All tests pass. Now let me run the existing engine test suite to make sure I didn't break anything.

  61. GLM Assistant

    All 317 engine tests pass. Let me run the full test suite to check for any regressions.

  62. GLM Assistant

    All 1070 tests pass. Now let me add a changeset, as this is a user-facing behavior fix. Let me check the changeset format.

  63. GLM Assistant

    Now let me remove the temporary reproduction test before submitting.

  64. GLM Assistant

    Now let me review the final diff to ensure correctness.

  65. GLM Assistant

    Let me restore the blank line in the bootstrap section for readability.

  66. GLM Assistant

    That inserted the blank line in the wrong place. Let me fix it.

  67. GLM Assistant

    Let me run the typecheck and full test suite once more to confirm everything is clean.

  68. GLM Assistant

    Let me check for any other entry points that resolve conversations by session key that I might have missed.

  69. GLM Assistant

    Let me verify the bootstrap method's early-return checks happen before the cron rotation (so ignored cron sessions aren't affected).

  70. GLM Assistant

    Bootstrap correctly checks shouldIgnoreSession and isStatelessSession before the cron rotation. The fix is complete. Let me do a final review of the full diff.

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