diff --git a/server/src/llm/providers/claude_code.rs b/server/src/llm/providers/claude_code.rs index b3fd1e4..a945af9 100644 --- a/server/src/llm/providers/claude_code.rs +++ b/server/src/llm/providers/claude_code.rs @@ -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 = 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); diff --git a/server/src/matrix/bot.rs b/server/src/matrix/bot.rs index 36d9b6a..b65c830 100644 --- a/server/src/matrix/bot.rs +++ b/server/src/matrix/bot.rs @@ -881,6 +881,7 @@ async fn handle_message( } else { remaining }; + slog!("[matrix-bot] session_id from chat_stream: {:?}", session_id); (reply, session_id) } Err(e) => { @@ -903,6 +904,7 @@ async fn handle_message( let conv = guard.entry(room_id).or_default(); // Store the session ID so the next turn uses --resume. + slog!("[matrix-bot] storing session_id: {:?} (was: {:?})", new_session_id, conv.session_id); if new_session_id.is_some() { conv.session_id = new_session_id; } @@ -919,13 +921,12 @@ async fn handle_message( }); // Trim to the configured maximum, dropping the oldest entries first. - // When trimming occurs, clear the session ID so the next turn starts - // a fresh Claude Code session (the old session's context would be - // stale since we've dropped entries from our tracking). + // The session_id is preserved: Claude Code's --resume loads the full + // conversation from its own session transcript on disk, so trimming + // our local tracking doesn't affect the LLM's context. if conv.entries.len() > ctx.history_size { let excess = conv.entries.len() - ctx.history_size; conv.entries.drain(..excess); - conv.session_id = None; } // Persist to disk so history survives server restarts.