Automatic provider retries keep the managed context pass until the run settles

Draft
ZI
1d ago
+175-5

Part of #907

What

OMP emits extension agent_end for every low-level run, including a provider error it will retry automatically. The extension event only carries messages; OMP adds its public willRetry field after the extension event. Magic Context therefore finalized the operation and released the managed pass on the first failed attempt. OMP then retried the same low-level run without a new agent_start or context pass, and before_provider_request refused the already-published pass with origin=agent_end.

Fix

  • Keep a completed, dispatched managed pass across a retryable agent_end (assistant stopReason: "error", or an explicit willRetry).
  • Finalize the deferred operation on agent_settled, which OMP emits after retries, compaction and queued work.
  • A normal agent_end still finalizes immediately.

Verification

  • New regression: retryable end -> retry admitted -> agent_settled -> next request refused. The same test fails on upstream/master with the exact origin=agent_end refusal and passes with the fix.
  • Existing #667/#673/#674 regressions: 39 pass, 0 fail, 162 assertions.
  • bun run --cwd packages/pi-plugin typecheck: pass.
  • Biome check on the two changed files: pass.

Not live-tested against an OMP 18.18.9 process. The host behavior was traced through the installed agent-session.js: extension agent_end is awaited before OMP's retry decision, and agent_settled is emitted only in the final _runAgentPrompt cleanup. The provider 429 in #907 is external; this change keeps the already-published managed pass usable for the retry.

Harness coverage (required)

  • OpenCode 1: not applicable — surface does not exist there
  • OpenCode 2: not applicable — surface does not exist there
  • Pi: not applicable — the dispatch fence is OMP-only (fenceEnabled = resolvePiHarnessKind() === "omp")
  • OMP: covered — unit regression for retryable agent_end, retry admission, and final agent_settled
  • Rust module: not applicable — no Rust surface

Keeping this draft until #907 carries design-approved, per CONTRIBUTING.


Summary by cubic

Keeps the managed context pass usable across OMP's automatic provider retries. Previously a retryable agent_end (assistant stopReason: "error" or explicit willRetry) finalized the operation, so the retry was refused with origin=agent_end even though the pass had already published.

  • The pass is now retained after a retryable agent_end and finalized when OMP emits agent_settled, after retries, compaction, and queued work.
  • A normal agent_end still finalizes immediately.
  • Adds regression coverage for retry admission, the later agent_settled refusal, and the existing normal-end behavior.