Title suggestion
chat.stream_failed with "Checkpoint compaction returned an invalid anchored summary" when Codex remote compaction fails
Body
Summary
When an Agent session accumulates enough context to trigger auto-compaction (Codex provider), the run frequently ends with:
Checkpoint compaction returned an invalid anchored summary; the original context was preserved {"code":"chat.stream_failed","operation":"chat"}
The message says context is preserved, but the whole chat run fails with chat.stream_failed instead of continuing with a usable handoff. This is observed repeatedly on an unstable network connection to the Codex endpoint.
Expected behavior
- If remote compaction fails, the fallback prompt-based compaction should produce a valid summary and the conversation should continue, or at least the run should not fail with a generic
chat.stream_failed.
- The error message should be surfaced in a user-friendly way (currently the raw JSON payload is shown to the user).
Actual behavior
The chat run terminates with chat.stream_failed. The user sees the raw error payload "Checkpoint compaction returned an invalid anchored summary; the original context was preserved ...". Context is preserved but the run does not proceed.
Reproduction steps
- Use a Codex (ChatGPT subscription) provider in Locus.
- Accumulate enough context so auto-compaction triggers (≥90% of context limit, per
compact::should_codex_auto_compact).
- Run on a network with intermittent failures toward the Codex endpoint (e.g. SSL/early-EOF errors, as observed with
git pull failing with OpenSSL SSL_read: unexpected eof while reading).
- Observe the run fail with
chat.stream_failed.
Environment
- OS: Windows x86_64
- Locus source branch/revision: diagnosis based on cached checkout (pull refresh failed on the same network issue); exact wording "invalid anchored summary" was not found in the cached revision, suggesting it is from a newer build
- Provider: OpenAI Codex (ChatGPT subscription), remote compaction via
POST /responses/compact
- Unity project: 2022.3.62f3c1 (probably unrelated)
Source references used for diagnosis (cached revision)
src-tauri/src/agent/instance/mod.rs:6148 execute_codex_remote_compact — Codex remote compaction path; on error falls back to prompt-based compact (mod.rs:6379 "codex remote compact failed, falling back to prompt-based compact")
src-tauri/src/llm/codex.rs:603 compact_conversation_history — POST /responses/compact, 300s timeout (COMPACT_REQUEST_TIMEOUT at codex.rs:549); failure modes: network error, non-2xx, non-JSON, missing compaction item
src-tauri/src/compact.rs:797 is_valid_compact_summary — summary validation (too short / ellipsis / too few alphanumeric chars → invalid)
src-tauri/src/agent/instance/mod.rs:9209 — chat.stream_failed emitted for any run error
src-tauri/src/compact.rs:151 should_codex_auto_compact — triggers at 90% context limit
Suggested improvements
- When the fallback prompt-based summary is also invalid, distinguish "remote compaction failed" from "summary invalid" in the emitted error, and include the fallback status so users know context is safe.
- Avoid terminating the whole run: if compaction fails, consider continuing with the preserved context (the message already claims it is preserved).
- Surface the error in the UI instead of the raw JSON payload.
Additional notes
The same network instability (SSL early EOF) also broke git pull for the Locus source cache, so this diagnosis is based on the cached revision; please verify line numbers against the current main.
Title suggestion
chat.stream_failedwith "Checkpoint compaction returned an invalid anchored summary" when Codex remote compaction failsBody
Summary
When an Agent session accumulates enough context to trigger auto-compaction (Codex provider), the run frequently ends with:
The message says context is preserved, but the whole chat run fails with
chat.stream_failedinstead of continuing with a usable handoff. This is observed repeatedly on an unstable network connection to the Codex endpoint.Expected behavior
chat.stream_failed.Actual behavior
The chat run terminates with
chat.stream_failed. The user sees the raw error payload "Checkpoint compaction returned an invalid anchored summary; the original context was preserved ...". Context is preserved but the run does not proceed.Reproduction steps
compact::should_codex_auto_compact).git pullfailing withOpenSSL SSL_read: unexpected eof while reading).chat.stream_failed.Environment
POST /responses/compactSource references used for diagnosis (cached revision)
src-tauri/src/agent/instance/mod.rs:6148execute_codex_remote_compact— Codex remote compaction path; on error falls back to prompt-based compact (mod.rs:6379"codex remote compact failed, falling back to prompt-based compact")src-tauri/src/llm/codex.rs:603compact_conversation_history—POST /responses/compact, 300s timeout (COMPACT_REQUEST_TIMEOUTatcodex.rs:549); failure modes: network error, non-2xx, non-JSON, missing compaction itemsrc-tauri/src/compact.rs:797is_valid_compact_summary— summary validation (too short / ellipsis / too few alphanumeric chars → invalid)src-tauri/src/agent/instance/mod.rs:9209—chat.stream_failedemitted for any run errorsrc-tauri/src/compact.rs:151should_codex_auto_compact— triggers at 90% context limitSuggested improvements
Additional notes
The same network instability (SSL early EOF) also broke
git pullfor the Locus source cache, so this diagnosis is based on the cached revision; please verify line numbers against the currentmain.