Fix: session context persistence#11
Open
michaelansel wants to merge 1 commit intoRichardAtCT:mainfrom
Open
Conversation
Fixed two critical issues causing conversation context to reset on every message: 1. Session continuation detection: Replaced unreliable `is_new_session` flag with robust `temp_` prefix check - The `is_new_session` flag persisted incorrectly in cached session objects - Now checks if session_id starts with "temp_" to determine if it's a new session - Ensures `--resume` flag is properly used for continuing conversations 2. Backend consistency: Added backend tracking to prevent SDK/subprocess session conflicts - SDK and subprocess have separate session storage and cannot resume each other's sessions - Added `backend` field to ClaudeSession to track which backend created each session - Sessions now stick with their original backend (SDK or subprocess) for their lifetime - Prevents context loss when SDK fails and falls back to subprocess Before this fix: - First message: Creates session (subprocess fallback due to SDK error) - Second message: SDK tries to resume subprocess session → fails → context lost After this fix: - First message: Creates session with backend='subprocess' - Second message: Uses subprocess directly → context maintained ✓ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Author
|
I ran into what seems like the same problems as #6 , but Claude came up with a different solution. I think it might be worth merging the two, so I'm submitting this now as an interim hold until I have time to do the integration/comparison. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed two critical issues causing conversation context to reset on every message:
Session continuation detection: Replaced unreliable
is_new_sessionflag with robusttemp_prefix checkis_new_sessionflag persisted incorrectly in cached session objects--resumeflag is properly used for continuing conversationsBackend consistency: Added backend tracking to prevent SDK/subprocess session conflicts
backendfield to ClaudeSession to track which backend created each sessionBefore this fix:
After this fix:
🤖 Generated with Claude Code