Skip to content

Context overflow after failed compaction should trigger fallback failover #18095

@gramanoid

Description

@gramanoid

Summary

When context overflow occurs and auto-compaction cannot recover (reason: "nothing to compact"), runEmbeddedPiAgent currently hard-fails even if fallback models are configured.

This prevents the fallback chain from doing its job in a common failure mode (request too large for current model).

Current behavior

  • Model returns context/window overflow (e.g. 413 / request_too_large)
  • Auto-compaction runs and fails to reduce enough context
  • Runner throws a normal error path and exits
  • No fallback model attempt is made

Expected behavior

If fallback models are configured, the runner should escalate this failure as a FailoverError so the outer loop can try the next fallback model/profile.

Why this matters

Fallback chains are specifically meant to recover from model-specific constraints (including context window limits). Hard-failing here defeats reliability for long-running sessions.

Proposed fix

In the overflow/compaction-failure branch in src/agents/pi-embedded-runner/run.ts:

  • Build a user-facing overflow message
  • If fallbackConfigured, throw FailoverError with:
    • status: 413
    • code: "context_overflow" | "compaction_failure"
    • provider, model, profileId
  • Keep existing non-fallback behavior unchanged

Also add coverage in src/agents/pi-embedded-runner/run.overflow-compaction.test.ts:

  • Assert FailoverError is thrown when compaction fails and fallback is configured.

Version

Observed on OpenClaw v2026.2.15 with local reliability patches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions