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 explore the repository structure to understand what we're working with.

  3. GLM Assistant

    Let me understand the issue better. The issue is about isolated cron runs leaking context when they reuse a stable session key. Let me look at the cron sessions more closely.

    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
    • Ordinary non-cron session continuity is unchanged

    So there's a concept of "cron" sessions. The cron runs reuse a stable session key but should be isolated. Let me look at the session keys structure.

    Let me look at the lcm-doctor-cleaners.ts which mentions agent:main:cron:*.

  4. GLM Assistant

    Let me look at the engine's session handling, especially around session keys, archiving, and how conversations are loaded by session key.

  5. GLM Assistant

    Now I understand the structure. The key concept: conversations are resolved by session key (active=1). When a cron run reuses a stable session key like agent:main:cron:nightly, the active conversation is reused, leaking context between runs.

    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 solution: When a cron session starts a new run (new runtime session id), the prior active conversation (from a previous cron run with the same session key) should be archived, and a fresh active conversation created. This is essentially session replacement at the start of a cron run.

    Let me look at how the engine starts a session / bootstraps. Let me look at the bootstrap flow and the lifecycle hooks (handleBeforeReset, etc.). Let me look for where the engine is told a run is starting.

    Let me look at the plugin index.ts to understand the lifecycle hooks available.

  6. GLM Assistant

    Now I understand the lifecycle. There are hooks: before_reset, session_end, before_prompt_build. Let me understand how cron runs work. The issue says "isolated cron runs leak context when they reuse a stable session key."

    Let me think about the cron session keys. The pattern is agent:main:cron:nightly:run:run-123 from the session-patterns test. So a cron run key includes a :run:run-123 segment. But the issue says "reuse a stable session key."

    Wait, let me re-read. "Different isolated cron runtime sessions that reuse a stable session key must not share active LCM context."

    Hmm, so maybe the issue is that cron runs reuse a stable session key (without the run segment), but they should be isolated. Or, the issue could be that they DO have unique run segments but the active conversation matching by session_key continues.

    Wait, but the test in session-patterns.test.ts has agent:main:cron:nightly:run:run-123. Let me look at how cron sessions are actually keyed. Let me check the parseAgentSessionKey function.

  7. GLM Assistant

    Let me look at the issue from the perspective of the existing tests and code. Let me look at the regression test to understand the testing approach. Let me look at how cron sessions are tested. Let me search the test files.

  8. GLM Assistant

    Now let me understand the issue better. The key is "isolated cron runs leak context when they reuse a stable session key." So cron runs reuse a stable session key. The cron session key is something like agent:main:cron:nightly. Each run gets a new runtime session id but reuses the stable session key. The issue is that since the session key matches an existing active conversation, the new run reattaches to the old conversation, leaking context.

    Let me look at how bootstrap resolves the conversation. Let me look at the bootstrap flow which calls getOrCreateConversation / resolveConversationIdForSessionKey.

  9. GLM Assistant

    Let me look at the findAmbiguousSessionKeyRuntimeRollover function and rotateStaleSessionKeyConversationIfTrackedTranscriptMissing, which seem to handle runtime rollover cases.

  10. GLM Assistant

    Now I have a good understanding. There are existing guards for runtime rollover when session keys are reused. But the cron case is different: cron runs reuse a stable session key but each run is isolated. The existing rotateStaleSessionKeyConversationIfTrackedTranscriptMissing only rotates when the tracked transcript file is missing. Let me check the config to see if there's a cron-specific pattern config.

  11. GLM Assistant

    Let me check git history and the changesets for context on the issue.

  12. GLM Assistant

    So there's existing logic. Let me look at the lcm-command test and config test for cron-related content.

  13. GLM Assistant

    Let me look at the docs/specs for cron context and the AGENTS.md.

  14. GLM Assistant

    Now I understand the structure. Let me look at the exact call sites of the rollover checks in bootstrap, assemble, and afterTurn.

  15. GLM Assistant

    Let me look at the engine constructor and field declarations to add a cron pattern field.

  16. GLM Assistant

    Let me look at the afterTurn call to rotateStaleSessionKeyConversationIfTrackedTranscriptMissing.

  17. GLM Assistant

    Now let me look at the test helpers to understand how to create an engine and write a reproduction script.

  18. GLM Assistant

    Let me look at the ingest, ingestBatch, and assemble entry points to understand conversation resolution.

  19. GLM Assistant

    Let me look at ingestSingle which uses getOrCreateConversation at line 8105.

  20. GLM Assistant

    Let me check when ingest is called in the lifecycle and whether there's a session-start hook.

  21. GLM Assistant

    Let me check the context engine interface to understand which methods are part of the agent-run lifecycle.

  22. GLM Assistant

    Let me check the ContextEngine interface definition to see which methods are part of the agent-run lifecycle.

  23. GLM Assistant

    Let me check the compact path and whether it has rollover guards.

  24. GLM Assistant

    Now I have a clear understanding. Let me write a reproduction test to confirm the leak. Let me create a temporary test file.

  25. GLM Assistant

    The leak is confirmed: run 2 reattached to C1 (sessionId updated to cron-run-2, conversationId still 1, still active). Now let me implement the fix.

    First, add the cron pattern field and constructor initialization:

  26. GLM Assistant

    Now let me add the cron pattern constant and field. First, let me look at the imports for compileSessionPatterns and matchesSessionPattern:

  27. GLM Assistant

    Let me find the AMBIGUOUS_SESSION_KEY_RUNTIME_ROLLOVER_REASON constant to place the cron pattern near it.

  28. GLM Assistant

    No python. Let me use the edit command. First, open the file at the relevant line.

  29. GLM Assistant

    Now let me add the cron pattern field and constructor initialization. Let me find the field declarations again (they shifted by 10 lines).

  30. GLM Assistant

    Now add the constructor initialization for cronSessionPatterns:

  31. GLM Assistant

    Now let me add the isCronSessionKey helper near isStatelessSession. Let me find it.

  32. GLM Assistant

    I introduced a duplicate return line. Let me fix it.

  33. GLM Assistant

    Now let me modify rotateStaleSessionKeyConversationIfTrackedTranscriptMissing to add the cron branch. Let me find it again.

  34. GLM Assistant

    Now let me add the cron branch right after the activeByKey sessionId check.

  35. GLM Assistant

    There's a duplicate leftover from the edit. Let me fix lines 6992-6993.

  36. GLM Assistant

    The code looks clean now. Let me run the typecheck and the reproduction test.

  37. GLM Assistant

    Typecheck passes. Now let me run the reproduction test.

  38. GLM Assistant

    The same-file scenario now works (C1 archived, C2 fresh). Let me add a different-file scenario test case to verify that path too.

  39. GLM Assistant

    Both scenarios pass. Now let me find and run the existing tests related to ambiguous rollover and stale session keys to ensure no regressions.

  40. GLM Assistant

    These ambiguous-rollover tests use keys like agent:main:test:... which don't match the cron pattern, so they should be unaffected. Let me run the full engine test suite and related tests.

  41. GLM Assistant

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

  42. GLM Assistant

    All 1069 tests pass. Now let me verify the "compaction within the current run still works" requirement with a quick check, and also verify non-cron continuity. Let me add temporary checks to the repro.

  43. GLM Assistant

    Compaction did run on the fresh conversation (compacted: true); the ok: false is just the unrealistic tokenBudget: 1 with the stub summarizer. Let me fix the assertion to verify compaction resolved and operated on the fresh conversation.

  44. GLM Assistant

    All three repro tests pass. Now let me add a changeset following the repository convention, since the repo uses changesets.

  45. GLM Assistant

    Now let me update the documentation to mention cron isolation behavior. Let me check the configuration.md behavior notes section.

  46. GLM Assistant

    Let me consider whether the ingest path also needs the cron guard. Let me look at ingestSingle to see if it's worth protecting against non-compliant call ordering.

  47. GLM Assistant

    The fix in rotateStaleSessionKeyConversationIfTrackedTranscriptMissing covers bootstrap, assemble, and afterTurn — the agent-run lifecycle entry points. Per the host contract, bootstrap runs first, so the fresh conversation exists before ingest/compact. I'll keep the change minimal to avoid interactions with internal replay paths.

    Now let me remove the temporary reproduction test (I must not add new tests to the repo) and run the full suite to confirm no regressions.

  48. GLM Assistant

    All 1067 tests pass and typecheck is clean. Let me also verify the build works.

  49. GLM Assistant

    Build succeeds. Let me review the final diff to ensure everything is clean.

  50. GLM Assistant

    The diff looks clean. Let me check git status for untracked files (changeset, build artifact).

  51. GLM Assistant

    Let me verify the bootstrap call ordering is still correct (rotateStale before findAmbiguous and getOrCreateConversation) after the edits.

  52. GLM Assistant

    The ordering is correct: in bootstrap, rotateStale (line 7196, with the cron branch) runs before findAmbiguous (7203) and getOrCreateConversation (7236). The cron branch archives the prior conversation and creates a fresh one, so the subsequent checks find the fresh conversation bound to the current run.

    Let me do a final full test run to be completely sure everything passes.

  53. GLM Assistant

    All tests pass (1067/1067), typecheck is clean, and the build succeeds. Let me review the final complete set of changes.

  54. GLM Assistant

    All changes are in place and verified. Let me submit.

    Summary

    Issue: Isolated cron runs that reuse a stable session key (e.g. agent:main:cron:nightly) leaked active LCM context — a new cron runtime session (new sessionId) reusing the lane's stable key reattached to the prior run's active conversation (via getOrCreateConversation/getConversationForSession keyed by session_key), so the new run inherited the prior run's summaries/context items.

    Root cause: The existing runtime-rollover guards only rotated the prior conversation when its tracked transcript file was missing (rotateStaleSessionKeyConversationIfTrackedTranscriptMissing) or fail-closed when the file still existed but differed (findAmbiguousSessionKeyRuntimeRollover). For cron lanes, a new runtime session is always a new isolated run regardless of transcript-file state (the lane may reuse the same path or keep old run files), so neither guard applied — the new run simply reattached to the prior active conversation.

    Fix (in src/engine.ts):

    • Added an intrinsic cron-lane pattern agent:*:cron:** (compiled once at construction, independent of user-configured ignore/stateless patterns — no new public interface).
    • Added isCronSessionKey() helper.
    • Added a cron branch in rotateStaleSessionKeyConversationIfTrackedTranscriptMissing (called by bootstrap, assemble, and afterTurn): when a cron key's active conversation is owned by a different runtime session, archive the prior run's conversation (it stays archived for recall) and bind a fresh conversation to the current run — unconditionally, regardless of transcript-file existence/path. This runs before the ambiguous-rollover fail-closed check, so cron runs never hit it.

    Result:

    • Prior runs remain archived (and recallable via lcm_grep/lcm_describe/lcm_expand).
    • The current run owns a fresh active conversation, so no context leaks forward.
    • Compaction within the current run resolves and operates on the fresh conversation.
    • Non-cron session continuity is unchanged (the cron branch only matches agent:*:cron:**; existing ambiguous-rollover/stale-rollover tests for non-cron keys still pass).

    Verification: Reproduced the leak with a temporary test (same-file and distinct-file scenarios), confirmed the fix resolves it and that compaction targets the fresh conversation, then removed the temporary test. Full suite (1067 tests) passes, tsc --noEmit is clean, and the build succeeds. Added a changeset and a docs section.

    Checklist

    • Reproduced the error — temporary repro test confirmed run 2 reattached to run 1's active conversation (same conversationId, sessionId overwritten, still active).
    • Confirmed the fix resolves the error — after the fix, run 2 gets a fresh conversationId, run 1 is archived (active=false), for both same-file and distinct-file cases; compaction resolves the fresh conversation.
    • Edge cases — same-sessionId re-bootstrap (no rotation), first run (no prior → no rotation), cron in ignore/stateless patterns (excluded/read-only), multiple accumulated priors (only active rotated), non-cron keys (unchanged), assemble/afterTurn createReplacement:false semantics.
    • Ran existing tests — full suite (1067/1067) passes; typecheck and build pass; the non-cron ambiguous/stale-rollover tests are unaffected.

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