fix: session_id wiped on every trim, breaking --resume

The history trimming logic cleared session_id = None whenever entries
exceeded history_size. Since the history was always at capacity, every
new message wiped the session_id immediately after storing it. This
meant --resume was never passed to Claude Code, making every turn a
fresh conversation.

Fix: preserve session_id on trim. Claude Code's --resume loads the
full conversation from its own session transcript on disk, so trimming
our local tracking entries doesn't invalidate the session.

Also adds debug logging for session_id capture/storage (temporary).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dave
2026-03-18 11:19:00 +00:00
parent a799009720
commit 4bf01c6cca
2 changed files with 7 additions and 4 deletions

View File

@@ -120,6 +120,7 @@ impl ClaudeCodeProvider {
.map_err(|e| format!("PTY task panicked: {e}"))??;
let captured_session_id = sid_rx.await.ok();
slog!("[pty-debug] RECEIVED session_id: {:?}", captured_session_id);
let structured_messages: Vec<Message> = msg_rx.try_iter().collect();
Ok(ClaudeCodeResult {
@@ -346,6 +347,7 @@ fn process_json_event(
// Capture session_id from the first event that carries it
if let Some(tx) = sid_tx.take() {
if let Some(sid) = json.get("session_id").and_then(|s| s.as_str()) {
slog!("[pty-debug] CAPTURED session_id: {}", sid);
let _ = tx.send(sid.to_string());
} else {
*sid_tx = Some(tx);