Skip to content

Fix Pi turn settlement after native recovery - #5341

Merged
SawyerHood merged 4 commits into
get-bb:mainfrom
yteruel31:fix/pi-interruption-settlement
Oct 12, 2026
Merged

SawyerHood merged 4 commits into
get-bb:mainfrom
yteruel31:fix/pi-interruption-settlement

Conversation

@yteruel31

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

The Pi provider finalized turns on agent_end and ignored agent_settled. Pi can still perform native overflow recovery or drain follow-up work after an agent_end without willRetry, so BB could complete the turn before that work finished. Structured assistant aborted outcomes, and errors without errorMessage, could also be reported as successful. Both behaviors are present in BB 0.46.0 and upstream base e9ad6b0.

What changed

  • Use authoritative settlement on verified stable Pi 0.84.0+ runtimes; retain the legacy event path for older or unrecognized versions.
  • Carry run-generation and checkpoint snapshots through the private extension pipe. This preserves A's outcome when an asynchronous settlement extension starts B before A's stdout settlement, and prevents native continuation attempts from opening separate BB turns.
  • Classify structured interruptions and exhausted required overflow recovery as failures. Cancelled optional compaction after a successful response does not change that response into a failure.
  • Deliver one terminal boundary, without duplicating text or token usage. Missing private settlement identities fail closed instead of completing another run.
  • Add RPC, translator, bridge subprocess-fixture, and actual Pi runtime lifecycle regressions.

No personal autonomy prompt, automatic continue, additional retry loop, tool replay, live-provider reload, public SDK, CLI, or server/host protocol change. Native retry policy and explicit Stop/permission handling remain in place.

How you verified

  • Upstream baseline: 206 tests passed, typecheck and lint passed; one existing Bun-only test skipped.
  • Ten new settlement/classification regressions fail against the unchanged production sources and pass with the fix.
  • Independent review found the extension-start ordering and optional overflow cases. Their three new regressions fail against the initially reviewed implementation and pass after correction.
  • The real Pi 0.84.0 regression uses createAgentSession, its actual extension runner and lifecycle methods, isolated in-memory settings/session/credentials, and allowModelNetwork: false. It runs the BB extension with an adapted FD transport and verifies B starts inside A's asynchronous settlement handler before A's public settlement. It asserts per-run checkpoints/outcomes, B's processing state, independent boundaries, and cumulative usage. This is an in-process runtime regression, not a live model or full CLI subprocess test.
  • pnpm exec turbo run prepare:bundled typecheck test lint --filter=bb-plugin-provider-pi --concurrency=2: 11 successful tasks; 285 tests passed, one existing Bun-only test skipped. Provider bundle preparation passed.
  • Explicit-path pnpm exec oxfmt --check and git diff --check: passed.

Settlement ownership relies on Pi's CLI-first extension loading, verified in the pinned 0.84.0 runtime. A reversed-handler test fails closed when another extension has already started an active run; arbitrary nested SDK/wrapper registration order is not claimed. The supported 1.x capability classification and bridge behavior are covered by fixtures, not a second real-runtime run.

AGENT GENERATED

@yteruel31
yteruel31 marked this pull request as ready for review October 10, 2026 19:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T19:54:41.461253Z f8c0948 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8c0948e24

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return;
}
const messages = run.end.messages ?? [];
const error = run.recoveryError ?? runSettlementError(event, messages);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid duplicating exhausted-compaction errors

When automatic overflow recovery is exhausted (reason: "overflow" and willRetry: false after a length/error/aborted assistant), this promotes the compaction failure to the synthetic settlement error. That same compaction_end has already emitted a non-retry provider.error in delta-translation.ts:740-749, and the settlement-only agent_end then emits another from the same detail at delta-translation.ts:775-790; the assembler persists both, so one failed recovery appears twice to the user. Preserve the failed terminal boundary without emitting the second diagnostic for recoveryError.

Useful? React with 👍 / 👎.

SawyerHood and others added 2 commits October 12, 2026 20:40
… errors once

When a run failed without a native retry and queued steering or follow-up
work continued inside the same settlement, only the final run's outcome
reached the thread, so the first failure was never shown. Forward that
failure as a non-terminal provider error when the continuation starts,
unless native overflow recovery handled it.

An exhausted overflow recovery was reported twice: once from the
compaction result and again from the settlement. Keep the failed boundary
and drop the second diagnostic.

Failed attempts no longer emit a token usage update when the provider
reported no usage.

Co-Authored-By: Claude Code <[email protected]>
The fake reported Pi 0.83.0 unless a test opted in, so the existing bridge
suites exercised the legacy agent_end path that no supported Pi version
takes. Default the fake to authoritative settlement and keep the legacy
path for tests that ask for it.

Co-Authored-By: Claude Code <[email protected]>
@SawyerHood
SawyerHood merged commit d011a88 into get-bb:main Oct 12, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants