Skip to content

fix(agent): compact an overflow whose interruption was not recorded - #7211

Merged
M4n5ter merged 2 commits into
apache:mainfrom
YongGoose:fix/overflow-lost-interruption
Nov 24, 2026
Merged

M4n5ter merged 2 commits into
apache:mainfrom
YongGoose:fix/overflow-lost-interruption

Conversation

@YongGoose

Copy link
Copy Markdown
Member

Supersedes #7143, which GitHub closed when rust-preview was deleted after the switch to main. Rebased onto main (73f2333), where cargo nextest run -p maka-agent-engine -E 'test(/reconcile::/)' passes (20 tests, including the new one). The other results below are from rust-preview.

Summary

Refs #7111 (the race reported in this comment, not the summary failure the issue is about).

A Main request that overflows records ModelSourceFailureCaptured and leaves the attempt open. The driver then writes ModelInterrupted from the failed stream, and fold accepts ContextOverflow recovery only on an interrupted attempt. If that interruption is never written, reconcile finds an open attempt with no live model work and runs the restart path, which assesses first. The native adapter assesses the captured overflow as ContextOverflow, fold rejects it, and the Run fails instead of compacting:

Agent Run failed after a driver error … error=invalid event transition: context overflow requires an original interrupted model attempt

The interruption can go missing in two ways, both found by reading the code:

  • The completion handler's publish loses a revision race. Engine::publish returns Ok(false) on RevisionConflict, and nothing retries it.
  • The driver retires after the stream fails. The retiring branch removes the model work without writing the interruption, and the next driver starts from durable state.

A captured source failure proves the stream ended, so there is nothing left to observe. Reconcile now interrupts such an attempt before assessing it, the same order the live driver uses. The normal path is unchanged: the completion handler still writes the interruption with the real error text before reconcile runs again.

Verification

  • New reconcile::tests::an_overflow_whose_interruption_was_not_recorded_still_recovers builds that state (overflow captured, no interruption, no live work) and applies reconcile's actions through fold. Without the fix it panics with InvalidTransition("context overflow requires an original interrupted model attempt"); with the fix the attempt ends as a compactable overflow.
  • End to end, I temporarily made the engine drop the ModelInterrupted publish for overflow errors (simulating Ok(false)) and ran context_overflow_after_partial_output_compacts_and_continues:
  • cargo nextest run -p maka-agent-engine --lib: 34 passed.
  • cargo nextest run -p maka-agent-native --lib: 204 passed, two runs.
  • cargo clippy -p maka-agent-engine --all-targets and cargo fmt --all -- --check are clean.

I could not trigger the race without the temporary patch on cc879c1cd (macOS, 15 cores): 36 parallel runs of the test alone, one nextest run and six full-suite runs (one process per test, 15 at a time) were all clean for this test. cell_notifications_deduplicate_child_knowledge_per_step_cut, also noted in #7111, failed in 5 of those 6 full-suite runs; this PR does not change it.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude Code traced the failure, wrote the fix and the test, and ran the reproductions above.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

A Main request that overflows records its source failure and leaves the
attempt open; the driver then writes ModelInterrupted from the failed
stream, and only an interrupted attempt may take ContextOverflow recovery.
When that interruption is not written (the publish loses a revision race
and returns Ok(false), or the driver retires before writing it),
reconcile sees an open attempt with no live model work and assesses it
first. The assessment records ContextOverflow, fold rejects it with
"context overflow requires an original interrupted model attempt", and
the Run fails instead of compacting.

A captured source failure proves the stream ended, so there is nothing
left to observe. Reconcile now interrupts such an attempt before
assessing it, the same order the live driver uses.

Refs apache#7111

Generated-by: Claude Code
@github-actions github-actions Bot added the effort/S Under 100 readable lines label Nov 23, 2026
…ted source failure

Two small peer follow-ups to the captured source-failure interrupt path:
- Skip deciding unadmitted tool calls while an attempt has a captured
  source failure awaiting recovery assessment, matching the existing
  interrupted-attempt guard so an overflowed response cannot execute
  unadmitted tools before Interrupt -> Assess -> Reject.
- Reuse the decoded ModelError diagnostic from ModelLevel.failure when
  available instead of replacing it with a generic string.

Generated-by: Maka (Gemini)
@M4n5ter
M4n5ter force-pushed the fix/overflow-lost-interruption branch from bd5bf60 to 77a83ad Compare November 24, 2026 02:29

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix — handling this in reconcile::next_action fits the level-triggered reconcile loop much better than adding retry state to Completion::Model.

I pushed a small follow-up commit to this branch for two peer details in the same function:

  1. Hold unadmitted tool calls in the tool loop (reconcile.rs) when attempt.source_failure.is_some() && attempt.recovery.is_none() (matching the existing attempt.interrupted.is_some() guard), so a streaming ToolCall emitted before an overflow whose interruption was lost cannot slip into Action::Decide before Interrupt -> Assess -> Reject.
  2. Reuse the decoded ModelError from model.failure for the Action::Interrupt diagnostic when available (falling back to "Original model source failed"), preserving the real error message if the attempt later terminates as Failed.

LGTM once CI turns green!

@M4n5ter
M4n5ter merged commit 14897e5 into apache:main Nov 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/S Under 100 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants