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
Now let's add the helper function. First, let's add a regex constant and a function near the AMBIGUOUS constant:
Assistant
Now let's insert the new private method right before this function:
Assistant
Now let's insert the check in ingestSingle before its
getOrCreateConversationcall:Assistant
Typecheck passes. Now let's run existing test suite (engine.test.ts is huge, let's run full test suite but with timeout consideration).
Assistant
All 1067 tests pass. Now let's write a reproduction script to verify the fix actually solves the issue scenario.
Assistant
The fix works. Let's now verify it fails without the fix by temporarily reverting and re-running, to confirm this test actually demonstrates the bug (not a false positive).
Assistant
Good, the repro test file remains (untracked, not stashed), while engine.ts changes are stashed away. Let's run the test now against the original (unfixed) code.
Assistant
Confirmed: without the fix, run2 reuses conversationId=1 (same as run1) — this is exactly the leak described in the issue. Now let's restore our fix.
Assistant
Now let's re-run the repro test to confirm it passes again with the fix restored, plus run the full test suite once more.
Assistant
All edge cases pass: isolated cron runs don't leak, compaction works within a run, checkpoint hits are respected, and ordinary non-cron session continuity is preserved. Let's also test the ingest() path directly (not just bootstrap), plus test the "prior tracked transcript file still exists" scenario explicitly since that's the exact ambiguous-rollover trigger case.
Assistant
All 4 tests pass. Now let's clean up the temporary test file and run the full existing test suite one final time.
Assistant
All 1067 tests still pass. Let's review the final diff to make sure everything looks clean.
Assistant
Let's add a changeset entry following repository convention.
Assistant
Now let's run the full test suite and typecheck one more time to make sure everything is in order before final submission.
Assistant
All 1067 tests pass and typecheck is clean. Let's do a final review of the git diff to make sure only intended changes are present.
Assistant
Clean. Now let's go through the checklist as requested.
Checklist review
-
If an error was reported in the issue description, I have successfully reproduced it. Yes. I wrote a temporary reproduction test simulating two isolated cron runs (
bootstrap()andingest()calls) sharing the same stable session key (agent:main:cron:nightly). On the original code, run 2 reused run 1's conversation row (sameconversationId, prior run's conversation leftactive: true) — confirming the context leak described in the issue. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. Yes. After applying the fix, the same reproduction shows run 2 gets a distinct, fresh conversation, the prior run's conversation is archived (
active: false), and no cross-run message content leaks into the new run's assembled messages. Verified via bothbootstrap()-first andingest()-first entry paths.
-
Assistant
I've completed my work. Let me finalize the checklist review before submitting.
Checklist
-
If an error was reported in the issue description, I have successfully reproduced it. I wrote a temporary vitest reproduction (later removed) that ran two "isolated cron" invocations (
bootstrap()/ingest()) sharing the stable session keyagent:main:cron:nightlywith distinctsessionId/session files. On the original code, the second run reused the first run'sconversationIdand left the first run's conversation rowactive: true— confirming the leak. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. After the fix, the second run gets a brand-new conversation row, the first run's conversation is archived (
active: false), and no cross-run message content appears in the new run's messages. Verified through both thebootstrap()entry path and theingest()entry path independently. -
I have thought about edge cases and made sure my fix handles them as well.
- Repeated
bootstrap()/ingest()calls within the same run (samesessionId) are a no-op for the new guard (verified checkpoint-hit still returnsbootstrapped: falseand the conversation stays active/unarchived). - Compaction (
compact()) within an active isolated cron run still resolves and operates on the correct (fresh) conversation — verified directly. - Ordinary, non-cron sessions that reuse a stable session key across a recycled runtime
sessionId(the existing UUID-recycling continuity case) are completely unaffected, since the new guard only activates for session keys matching the*:cron:*convention — verified via a same-file "continuation" scenario that still preserves the original conversation row. - First-ever cron run for a given key (no prior active conversation) is unaffected — no spurious archiving occurs.
- The guard was added at both write-entry points that can attach/create a conversation (
bootstrap()andingestSingle()), so the leak can't slip through if a host callsingest()beforebootstrap()for some reason. - Detection generalizes beyond the hardcoded doctor-cleaner example (
agent:main:cron:*) to any agent id and to per-run-suffixed keys likeagent:main:cron:nightly:run:run-123.
- Repeated
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Ran
npm run typecheck(clean) and the full suitenpm test(1067 tests / 49 files, all passing) both before finalizing and after adding the changeset.
Final diff is limited to
src/engine.ts(newisCronSessionKeyhelper +isolateCronRunIfSessionKeyReusedguard wired intobootstrap()andingestSingle()) plus a new changeset file documenting the patch, consistent with this repo's contribution conventions.-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →