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 method near
shouldIgnoreSession/isStatelessSession.Assistant
I see the bug clearly now - the closing brace for the if-block got removed. Let me fix it properly.
Assistant
Let's use sed directly which is more reliable here.
Assistant
No hidden characters. Let's just use sed insertion directly.
Assistant
Now let's add the helper methods, using sed with a marker approach.
Assistant
Good, line 3572 is the return statement, line 3573 is the closing brace
}. I'll insert new methods after line 3573.Assistant
Now let's insert calls to
archiveStaleIsolatedCronConversationat the four call sites. First,ingestSingle:Assistant
Let's clean the comment ordering:
Assistant
Now let's add the same guard to
bootstrap()(before rotateStale check) andassemble()andreconcileTranscriptTailForAfterTurnInSessionQueue. Let's find bootstrap's location now.Assistant
Now let's add to
assemble():Assistant
That sed trick worked. Now let's add the same to
reconcileTranscriptTailForAfterTurnInSessionQueue:Assistant
Now let's typecheck and re-run the reproduction test.
Assistant
Typecheck passes. Now let's rerun the reproduction test.
Assistant
Leak is fixed. Now let's verify that: (1) prior run is archived not deleted, (2) compaction within the current run still works, (3) ordinary non-cron continuity is unchanged. Let's extend the repro script to check these.
Assistant
Both scenarios pass. Now let's check compaction within the current cron run still works. Let's check
compact()usesgetConversationForSessiondirectly and doesn't need archive check since new conversation already exists once ingest ran first.Assistant
Add
tokenBudgetandcurrentTokenCountparams to the test.Assistant
Good enough — compaction actually ran (compacted: true, tokensBefore 10628 → tokensAfter 2322), it just couldn't reach the unrealistic tight target of 200 tokens. Compaction is clearly functioning within the isolated run. Let's clean up the temp test files.
Assistant
Now let's run the existing full test suite to make sure nothing broke.
Assistant
All 1067 tests pass. Let's also add a changeset file, following repo convention, and double check the
git diff.Assistant
Good — queue key prefers
sessionKeywhen present, so all operations sharing a stable cron session key are serialized through one queue, avoiding races. This confirms the fix is safe and consistent with existing concurrency design.Now let's look at the final diff for review.
Assistant
Typecheck is clean (no output = success). Let's run the full test suite once more for final confirmation.
Assistant
All 1067 tests still pass. Let's do a final review of
git statusandgit diffto ensure everything is in order.Assistant
Now let me review the checklist explicitly.
Checklist review
-
If an error was reported in the issue description, I have successfully reproduced it. Yes. I built a temporary reproduction script that simulated an isolated cron session key (
agent:main:cron:nightly) being reused across two independent runtime sessions (run-1,run-2) viaingest()/assemble(). Before the fix,run-2's assembled context leakedrun-1's message content (SECRET_RUN1), confirming the exact "leak context" behavior described in the issue. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. Yes. After adding
archiveStaleIsolatedCronConversation(triggered frombootstrap,ingestSingle, , and the transcript-reconcile path whenever a session key matches the established convention and is resumed under a different runtime session id), the same reproduction no longer leaked: 's assembled context no longer contained , the prior conversation was archived () rather than deleted, its messages remained intact/readable, and the new run got its own fresh active conversation. I also verified compaction still functions correctly within the new isolated run (compaction ran and reduced tokens as expected), and that ordinary non-cron session keys retain their existing continuity behavior (a session key without the segment still reattaches a new runtime session id to the same active conversation, preserving history).
-
Assistant
-
I have thought about edge cases and made sure my fix handles them as well. Considered: (1) false-positive pattern matches on session keys that merely contain "cron" as a substring within a segment (e.g.
crontab,cron-discussion) — the regex(^|:)cron(:|$)requires an exact:cron:-delimited segment, avoiding those false positives, consistent with the existingcron_sessionsdoctor-cleaner convention. (2) Repeated ingest calls within the same run (same sessionId) — the guard is a no-op once the new conversation is active under the same sessionId, so no double-archiving or performance issue within a run. (3) Concurrency — session-key-based operation queueing ( prefers the stable ) already serializes all operations for the same cron key, so there's no race between the archive check and conversation creation. (4) Ordinary/non-cron continuity — the same reused-sessionId-under-stable-key scenario for non-cron keys is untouched (verified via a dedicated regression test I wrote and ran, not committed). (5) The fix is applied at every entry point that resolves a conversation from a session key (, / via , , and 's transcript reconciliation), so isolation holds regardless of which API surface a host uses to talk to a cron lane.
-
Assistant
Clean. The change set is minimal, focused, and fully validated. I'm ready to submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.