Skip to content

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

Closed
YongGoose wants to merge 1 commit into
apache:rust-previewfrom
YongGoose:fix/overflow-lost-interruption
Closed

YongGoose wants to merge 1 commit into
apache:rust-previewfrom
YongGoose:fix/overflow-lost-interruption

Conversation

@YongGoose

Copy link
Copy Markdown
Member

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

@github-actions github-actions Bot added the effort/S Under 100 readable lines label Nov 22, 2026
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
@YongGoose
YongGoose force-pushed the fix/overflow-lost-interruption branch from 86b26fa to 84ee88d Compare November 22, 2026 07:18
@M4n5ter
M4n5ter deleted the branch apache:rust-preview November 23, 2026 00:07
@M4n5ter M4n5ter closed this Nov 23, 2026
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