[BUG] Agent SDK: auto-compact completely broken on resumed sessions — reactive compaction handler is null
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
What's Wrong?
When using the Agent SDK with resumeSessionId, auto-compact never triggers and "Prompt is too long" is silently emitted as assistant text through the success path. Two independent bugs combine:
1. Proactive auto-compact uses local token counts, which are empty on resume.
The auto-compact check (RLq in the de-minified source) calls C_z, which computes qG(q) - z on the local messages array. For a resumed session, this array only contains the new prompt being sent — the full conversation lives server-side. The local count is always small, so auto-compact never triggers regardless of how large the server-side context has grown.
The pre-flight blocking limit check has the same issue — it uses qG(F) - K6, which is the local count.
2. Reactive compaction handler is permanently null.
The reactive compaction handler (wj6 in the de-minified bundle) is declared as var wj6 = null and never assigned anywhere in the 638k-line de-minified bundle. Every reactive compaction code path is gated behind wj6?. optional chaining and silently no-ops:
wj6?.isWithheldPromptTooLong(y6)→ alwaysundefined, prompt-too-long messages are never withheldwj6?.isReactiveCompactEnabled()→ alwaysundefinedif ((y6 || c6) && wj6)→ alwaysfalse,tryReactiveCompactis never called
This is the safety net for when the API rejects a request as too long. It's fully architected (withholding logic, compaction, retry loop) but completely inert.
Result: The API error is converted to an assistant message with content: "Prompt is too long" and emitted through subtype=success. The consumer sees it as regular model output, not as an error.
What Should Happen?
- For resumed sessions, the SDK should track server-reported context size (from
message_startstream events) and use that for auto-compact decisions, not just local message array size. - The reactive compaction handler should actually be instantiated.
- At minimum, "Prompt is too long" from the API should surface as an error, not as
subtype=successwith assistant text content.
Steps to Reproduce
- Use the Agent SDK to create a session
- Run multiple queries accumulating context over time
- Between queries, the session is evicted from memory and later resumed via
resumeSessionId - Eventually the server-side context exceeds the model's limit
- The SDK emits "Prompt is too long" as assistant text with
subtype=success
This manifests in any long-lived Agent SDK application that resumes sessions across process restarts. In my case, an automation tool that runs periodic analysis sessions — each cycle resumes the same session ID. After significant accumulated context, the session silently died.
Error Messages/Logs
No error in logs. The SDK reported:
type=system, subtype=init
type=system, subtype=status
type=rate_limit_event
type=assistant (1 content block: "Prompt is too long")
type=result, subtype=success, cost=$0.00
Claude Model
Opus 4.6 (1M context)
Is this a regression?
Unknown — reactive compaction may have never been wired up.
Claude Code Version
2.1.85
Platform
Anthropic API (Agent SDK)
Operating System
Linux (Debian)
Additional Information
Related: #36751 (same symptom from CLI resume path, no root cause identified). Also related: #35358 (session resume drops context).
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗