1M-context session becomes unrecoverable: ECONNRESET on large uncached requests, and /compact fails with the same error

Status Closed — not planned
Maintainer reply None cached
Activity 4 comments · opened Jul 5, 2026 · closed Sep 23, 2026

Summary

Sessions with very large 1M-context conversations (~520k tokens) repeatedly fail with API Error: Unable to connect to API (ECONNRESET) when the prompt cache has gone cold, and — critically — /compact fails with the same error, because compaction itself requires sending the full context. This leaves the session unrecoverable: the user's only option is abandoning it and starting a new session, losing all conversational state.

Environment

  • Claude Code v2.1.197, macOS (Darwin 25.2.0)
  • Model: claude-fable-5[1m] (1M context beta)
  • No VPN, no proxy, no ANTHROPIC_BASE_URL override
  • status.claude.com showed all systems operational during the failures

Symptoms

  • Affected session context: ~520k tokens; last successful request showed cache_creation_input_tokens: 496847 (i.e., nearly the entire context re-ingested uncached after the ~5 min cache TTL lapsed).
  • Requests hang for many minutes ("Cogitated for 8m 7s") then die with ECONNRESET or "socket connection was closed unexpectedly"; occasional overloaded_error (529) and 500s in the same windows.
  • Errors came in bursts across multiple days (2026-07-04 16:08–16:27, 20:50, 21:32–22:03 UTC; 2026-07-05 18:14+ UTC).
  • Small sessions (~45k tokens, mostly cache hits) in the same environment at the same time worked flawlessly. Direct connectivity checks to api.anthropic.com during a failure window were clean (5/5 connects, ~27ms).
  • Attempting to recover with /compact failed: Error during compaction: API Error: Unable to connect to API (ECONNRESET).

Why this is a product bug and not just transient API weather

  1. Auto-retry re-pays the full ~500k-token uncached ingestion on every attempt, keeping the session in the failure-prone state for many minutes per retry cycle.
  2. /compact — the documented remedy for oversized context — requires the exact same giant request that is failing. When a session most needs compaction, compaction is least likely to succeed.

Suggested improvements

  • Make compaction resilient for huge contexts: chunked/incremental summarization, or compaction that can resume across failed attempts instead of resending the entire context each time.
  • Surface a clearer error/hint when repeated ECONNRESETs correlate with very large uncached prompts (e.g., suggest compacting before the context grows past the point where compaction itself can fail).
  • Consider keeping the prompt cache warm (or warning on cache expiry) for sessions above some context size, since a cold cache is what turns each request into a multi-minute vulnerable window.

Impact

User lost an active large working session and had to reconstruct state in a fresh session by hand. Retries did eventually succeed for normal messages, but each cycle cost many minutes, and the recovery path (/compact) was unusable.

View original on GitHub ↗

3 Comments

junaidtitan · 3 months ago

You've landed on the exact catch-22: the session is too big to compact via the API, but compaction requires sending the full context — so the one tool that should rescue you is itself what's failing.

The difference with cozempic (github.com/Ruya-AI/cozempic) is that it operates on the JSONL file on disk, not through an API request. The prune itself requires no network call — it reads the local file, strips the categories that make sessions balloon (accumulated tool outputs, redundant system-prompt injections, stale progress ticks, duplicate content from prior compaction cycles), writes a trimmed version, and that's it. Your ~520k token session should come down substantially — probably into the 150–250k range depending on what's in there, though the exact number depends on your session composition.

Workflow (with Claude stopped):

pip install cozempic
cozempic current --diagnose          # see the breakdown
cozempic treat current               # dry-run first
cozempic treat current --execute     # apply

What this doesn't fix: the cache TTL issue you described is real and Anthropic needs to address it. A pruned session will still go fully uncached after 5 minutes of inactivity, and the next request still has to re-ingest — it just has to re-ingest 150k tokens instead of 520k, which is a qualitatively different ask from the API and much less likely to hit the ECONNRESET threshold. The suggestion in your issue to warm the cache or warn on expiry is the right systemic fix; the pruning just gets you out of the hole this time.

Your suggestion to make /compact resilient for huge sessions (chunked/incremental) is worth following separately — that's a CC architectural issue that cozempic can't fix.

If you're still stuck mid-session and need to recover, I'd be interested to hear whether the file-side approach actually gets you unstuck.

ZiyueYang-Cradle · 2 months ago

Filed #79989 with new data that sharpens this: across five affected sessions in one night (232k / 261k / 328k / ~905k / ~905k tokens) plus your ~520k, every failure is >200k tokens and nothing ≤200k ever fails — the threshold looks like the standard/long-context boundary itself, hit on the first fully-uncached ingestion after prompt-cache expiry (which is why it strikes after idle periods). Also validated a recovery workaround 5×: generate the summary offline from the JSONL on disk, then mint a new session file containing only a synthetic isCompactSummary entry — resumes at ~7k tokens on the first attempt. Details + isolation experiments (incl. why transcript surgery and appended-boundary tricks don't work) in #79989.

tamilov · 1 month ago

Hi @Rterrell25, I came across this while looking into recovery from long AI sessions. When that 1M context session became unrecoverable and you had to abandon it, what did you actually have to reconstruct by hand in the new session? Did the repo and files give you most of the state back, or were important decisions and intent only present in the conversation? Roughly how long did recovery take?

Showing cached comments. Read the full discussion on GitHub ↗