Skip to content

Large tool results bypass auto-compaction and context_length_exceeded is retried unchanged #320

Description

@danshapiro

Summary

A delegated session can exceed the model context after one or more very large tool results even when context-simple has max_tokens: 300000, compact_threshold: 0.8, and auto_compact: true. The resulting OpenAI context_length_exceeded error is then retried five times with an unchanged oversized payload.

Environment

  • Amplifier CLI: 2026.07.11-c150034
  • amplifier-core: 1.6.0
  • Bundle: anchors 0.1.0
  • Provider: OpenAI (gpt-5.6-sol, long context enabled)
  • Delegation: fresh child with context_depth: none
  • OS: Linux / WSL2

Reproduction

  1. Start a fresh delegated child with context_depth: none.
  2. Have the child run content searches over JSONL files whose individual matching lines are very large.
  3. In the observed run, two search tool results were approximately 614,299 and 735,454 characters.
  4. Observe provider input usage grow from 57,519 tokens to 441,952 and then 827,426 despite the bundle's 300,000-token context setting and auto-compaction.
  5. After one more iteration, OpenAI returns invalid_request_error / context_length_exceeded.
  6. Observe five provider:retry events replaying the same deterministic failure.

No raw session contents are attached because they may contain private data; the sizes and usage counts above come from event metadata only.

Expected behavior

Before every provider submission, Amplifier should ensure the serialized request is within the effective provider/model context budget. Large tool results should be truncated, artifactized, or trigger compaction before the next request. A context_length_exceeded response should be non-retryable unless Amplifier first reduces the payload.

Actual behavior

Tool results can push a delegated session far beyond the configured context budget without compaction. The oversized provider request fails, then the same payload is retried five times.

Suggested safeguards

  • Enforce a configurable byte/token cap on every tool result, independent of result line count.
  • Run a final provider-specific token-budget check immediately before submission.
  • Compact or artifactize oversized tool results before sending.
  • Classify context_length_exceeded as non-retryable unless the request is changed.
  • Add a regression test with a single very large tool result and another with multiple medium-large results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions