Skip to content

Timeout-compaction doesn't escalate when compaction fails to reduce context #64962

@OpenCodeEngineer

Description

@OpenCodeEngineer

Bug

When timeout-compaction runs but does not actually reduce the context (e.g., the compaction model produces output but fails to summarize effectively), the system doesn't escalate to a different approach. It logs [timeout-compaction] compaction did not reduce context and falls through to normal error handling, which means the user gets a "Context overflow" error.

Observed log

[timeout-compaction] compaction did not reduce context for azure/grok-4-1-fast-reasoning; 
falling through to normal handling

Root cause

In run.ts, the timeout-compaction path:

  1. Detects timeout + high context usage
  2. Triggers compaction with the current model
  3. If compaction "succeeds" (no error) but context is still over threshold → falls through
  4. No escalation to compact_then_truncate, no model switch, no session rotation

The system treats "compaction ran but didn't help" as unrecoverable, when there are still options:

  • Try a different model with better summarization capability
  • Escalate to compact_then_truncate (aggressive mode)
  • Force session rotation with a handoff summary

Expected behavior

After compaction completes but context is still over threshold:

  1. Try the next compaction fallback model (if available — see Compaction fails permanently when Azure content filter blocks summarization — no model fallback #64960)
  2. If no more models: escalate to compact_then_truncate mode
  3. If that still doesn't reduce enough: force a fresh session with a handoff summary from the last assistant message
  4. Log a clear warning: "session force-rotated due to irrecoverable context overflow"

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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