Skip to content

Auto-compaction does not prevent CAPI 5 MB failure from accumulated normal tool history #4183

Description

@jay-tau

Describe the bug

A long, tool-heavy Copilot CLI session can remain within the model's context-token capacity but become permanently unable to make another model call because the serialized CAPI Responses request reaches the independent 5 MB body limit.

Automatic compaction does not prevent this failure. After the first failure, sending a short follow-up such as continue immediately fails with the same error because it reuses the same oversized session history:

Execution failed: Error: The request is too large to send through CAPI Responses.
Try shortening the conversation or prompt. (5.0 MB request; 5.0 MB limit)

This occurred after the autonomous task had completed its final verification; only the final response remained. The durable workspace output was intact, but the conversation could no longer proceed.

Unlike #4097 and #3767, this session had no oversized binary patch, image, document, or single giant tool result. It crossed the limit through accumulation of many ordinary tool/assistant events.

Affected version

GitHub Copilot CLI 1.0.71

Steps to reproduce the behavior

  1. Start an interactive Copilot CLI session on Linux using gpt-5.6-sol and Autopilot.

  2. Run a long engineering task that performs many shell/file operations and repeated validation cycles. Do not attach images/documents or process a large binary patch.

  3. Allow the session to accumulate several hundred agent turns and ordinary-sized tool results.

  4. Near the end of the run, observe that the next model request fails with:

    The request is too large to send through CAPI Responses.
    Try shortening the conversation or prompt. (5.0 MB request; 5.0 MB limit)
    
  5. Enter a tiny follow-up prompt such as continue.

  6. Observe the identical failure; the session is wedged.

Sanitized diagnostics from the affected session's events.jsonl:

file size:                 29,571,914 bytes
valid JSONL records:       9,139
malformed records:         0
largest individual record: 68,560 bytes
records >= 100 KB:         0

tool.execution_start:      2,475
tool.execution_complete:   2,475
assistant.message:         2,467
assistant.turn_start:        813
assistant.turn_end:          813

The two terminal session.error records contain the exact 5 MB CAPI error above. I am not attaching the event log because it contains private conversation and tool history.

Long-context model contract

If the selected model supports a long context window, Copilot CLI should let the user use that capacity. Copilot's CAPI transport/envelope must not become a smaller, undocumented effective context limit that terminates an otherwise valid session.

Internal request-body constraints should be handled transparently through byte-aware compaction, folding/eviction of old tool payloads, or another transport strategy. The user should not need to abandon a session merely because Copilot's serialized request reaches 5 MB while the model still has context capacity. /context and the model's advertised window should represent the practical usable limit; if a lower product limit is unavoidable, it must be surfaced and managed before the session becomes unrecoverable.

In short: when the model supports the context, Copilot CLI should not get in the way of using it.

Expected behavior

Automatic compaction should account for the serialized CAPI request size as well as model-token utilization. A normal long session containing many individually bounded events should not reach a permanent 5 MB transport failure while the model still has context capacity.

Specifically:

  • Estimate or measure the serialized request bytes before dispatch.
  • Trigger compaction below the CAPI 5 MB limit even when token utilization has not reached the normal compaction threshold.
  • If model-backed compaction itself cannot be sent, use a recovery path that locally drops/folds old tool results while preserving a summary and tool-call/result integrity.
  • After a size rejection, allow /compact, rewind/fork, or another recovery mechanism to unstick the existing session rather than resending the same oversized request indefinitely.
  • Consider capping/folding cumulative ordinary tool results, not only singular oversized attachments or patches.

GitHub's documentation states that Copilot CLI automatically compresses history as the conversation approaches the token limit. The resolution on #2008 additionally states that background compaction starts at 80% and blocks at 95%. This case shows that token-triggered compaction and the CAPI byte limit can still diverge.

Additional context

  • OS: Linux x86_64 container
  • Terminal: VS Code integrated terminal attached to the container
  • Shell: bash
  • Model: gpt-5.6-sol
  • Mode: Autopilot
  • The task was a long CUDA optimization workflow with many small shell/file reads and validation commands.
  • No individual persisted event was remotely close to 5 MB; the largest was about 69 KB.
  • Repeating continue failed immediately with the same error.

Related but distinct:

This report is the cumulative-many-bounded-events case and appears to be a regression/general gap in v1.0.71.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:context-memoryContext window, memory, compaction, checkpoints, and instruction loadingarea:modelsModel selection, availability, switching, rate limits, and model-specific behavior

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions