Skip to content

Treat pi's manual compaction refusal as a skipped compaction, not a failed turn - #1807

Merged
SawyerHood merged 2 commits into
mainfrom
bb/draft-pr-for-1721-pi-compact-on-a-small-session-thr_5wpegxnkvx
Aug 18, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/draft-pr-for-1721-pi-compact-on-a-small-session-thr_5wpegxnkvx

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

Pi has a keepRecentTokens floor (20k tokens by default). When a session has nothing before that floor, /compact refuses before it calls the model with Compaction failed: Nothing to compact (session too small). Pi reports that refusal through the same compaction_end.errorMessage field as a real failure. The pi event translator (packages/agent-runtime/src/pi/event-translation.ts) turned every manual compaction_end error into turn/completed status=failed. The server maps a failed root turn to run.failed, so the thread moved to error, the composer showed "Retry by sending a follow-up message", and bb thread tell (steer mode) answered HTTP 409: Thread is not active. Nothing was wrong with the session.

Report: https://get-bb.github.io/reports/issues/1721.html

What changed

  • packages/agent-runtime/src/pi/event-translation.ts: a manual compaction_end with pi's pre-flight refusal messages (Nothing to compact (session too small), Already compacted) is a no-op. The translator emits provider/warning { summary: "Context compaction skipped", details: <pi message> } and a normal turn/completed status=completed. Real failures (for example Summarization failed: ...) still emit status=failed. Manual compaction still owns its maintenance turn.
  • packages/thread-view/src/build-event-projection.ts, operation-projection.ts: a provider/warning inside a compaction turn settles the pending compaction row as Context compaction skipped with the warning detail. The row was otherwise pending forever, because no thread/compacted or item/completed follows a refusal. The warning is not rendered a second time as a standalone row.
  • Tests: event-translation.test.ts gets the no-op case for both refusal messages and the pinned failure case now uses a real failure message. timeline-interruption.test.ts gets the projection case (with a providerWarning factory in the harness).

Deviation from the report

The report suggested provider/error{message:"Context compaction skipped"} as the cheapest way to close the compaction row. That renders a red "Provider error" row and an error-status compaction row, which is not informational. This PR uses provider/warning instead and settles the row with a completed status. No wire contract changed, so HOST_DAEMON_PROTOCOL_VERSION is unchanged.

Update after SlopCop review

  • Added the compaction-skipped provider warning category (packages/domain). The pi translator emits it for a refused manual compaction, and the thread view settles the pending compaction row only for that category. An unrelated warning inside a compaction turn keeps its own row and leaves the compaction pending (new test keeps a pending compaction and renders an unrelated warning in the same turn, fails before / passes after).
  • Bumped HOST_DAEMON_PROTOCOL_VERSION to 135 (134 was taken by Keep replayed Codex usage snapshots out of unknown turn ids #1804) (plus the contract test), because the daemon event stream and the warning category enum changed.
  • Regenerated packages/plugin-sdk/bundled-types for the new enum member.
  • Verified: turbo typecheck for domain, agent-runtime, thread-view, host-daemon-contract, plugin-sdk, server, app — 7 successful; turbo test for domain (145), host-daemon-contract (52), thread-view (378), agent-runtime (320) — all pass.

How I verified

  • Before the change: the two new translator tests failed (status: "failed" with the pi error), and the new thread-view test failed (row stayed pending).
  • pnpm exec turbo run typecheck --filter=@bb/agent-runtime --filter=@bb/thread-view — 2 successful.
  • pnpm exec turbo run test --filter=@bb/agent-runtime --filter=@bb/thread-view — agent-runtime 320 passed, thread-view 377 passed.

Fixes #1721

AGENT GENERATED: by Claude Opus 5

@bb-slop-cop

bb-slop-cop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and product behavior.

});
} else if (compactionNoopDetail !== undefined) {
events.push({
type: "provider/warning",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — Increment the host daemon protocol version

This code changes the daemon event stream. Existing remote daemons can keep protocol 132 and send the old failed result after deployment.

Increment HOST_DAEMON_PROTOCOL_VERSION and update its contract test. The mismatch will cause the required daemon update.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in f07e5b4: bumped HOST_DAEMON_PROTOCOL_VERSION to 134 with a lineage note and updated the contract test.

// A provider warning inside a compaction turn means the provider declined
// to compact (for example pi's "Nothing to compact"): the row settles as a
// skipped compaction instead of staying pending forever.
if (decoded.type === "provider/warning") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — Match only the compaction-skip warning

This branch matches every turn-scoped provider warning, not only the Pi skip warning.

A separate warning can become “Context compaction skipped,” and the code then removes the original warning row.

I reproduced this result with a model-fallback warning. The timeline hid the warning and used its detail as compaction detail.

Match the exact skip signal or use a dedicated compaction outcome event.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in f07e5b4: added a dedicated compaction-skipped warning category; the pi translator emits it, and the timeline settles the compaction row only for that category. Added a test where an unrelated warning during compaction keeps its own row and leaves the compaction pending.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

This pull request makes a small Pi /compact refusal harmless. It keeps the thread usable and shows a skipped-compaction row.

I found two high-impact defects.

  1. The change alters daemon events, but it does not increment the host daemon protocol version. Remote machines can keep the old behavior.
  2. The timeline treats every turn warning as a compaction skip. It can hide a real warning and corrupt the compaction row.

I left inline comments with exact locations and fixes.

The performance cost from the new string check is negligible. Repeated skips can cause quadratic scans, but the normal 1,500-event limit bounds this cost.

I found no security issue. The provider detail remains text, and the change adds no material denial-of-service path.

The codebase has no duplicate production refusal matcher. The architecture problem comes from using a general warning as a compaction lifecycle event.

Validation passed:

  • All 697 tests passed in @bb/agent-runtime and @bb/thread-view.
  • Both package type checks passed.
  • All GitHub checks passed.
  • A live Pi test at the pull request SHA left the thread idle after /compact.
  • The browser showed “Context compaction skipped” with the refusal detail. It did not show a failed compaction.
  • An independent GPT-5.6 review gate confirmed both defects.

SawyerHood added a commit that referenced this pull request Aug 18, 2026
…sion

Address SlopCop review on #1807:
- Add the `compaction-skipped` provider warning category. The pi
  translator emits it for a refused manual compaction, and the thread
  view settles the pending compaction row only for that category. Other
  warnings inside a compaction turn keep their own row.
- Bump HOST_DAEMON_PROTOCOL_VERSION to 134 so enrolled daemons update.
- Regenerate the bundled plugin SDK types.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/draft-pr-for-1721-pi-compact-on-a-small-session-thr_5wpegxnkvx branch from ca1cc22 to f07e5b4 Compare August 18, 2026 19:34
SawyerHood and others added 2 commits August 18, 2026 21:17
…ailed turn

Pi reports "Nothing to compact (session too small)" and "Already
compacted" through the same compaction_end.errorMessage field as a real
failure. The pi translator turned every manual compaction error into
turn/completed status=failed, so the server moved the thread to error.

Classify those pre-flight refusals as a no-op: emit a provider/warning
("Context compaction skipped") and a normal turn/completed. In the
thread view, a provider warning inside a compaction turn settles the
pending compaction row as "Context compaction skipped" with the
provider detail, and the warning is not rendered a second time.

Fixes #1721

Co-Authored-By: Claude <[email protected]>
…sion

Address SlopCop review on #1807:
- Add the `compaction-skipped` provider warning category. The pi
  translator emits it for a refused manual compaction, and the thread
  view settles the pending compaction row only for that category. Other
  warnings inside a compaction turn keep their own row.
- Bump HOST_DAEMON_PROTOCOL_VERSION to 134 so enrolled daemons update.
- Regenerate the bundled plugin SDK types.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/draft-pr-for-1721-pi-compact-on-a-small-session-thr_5wpegxnkvx branch from f07e5b4 to ced94d8 Compare August 18, 2026 21:18
@SawyerHood
SawyerHood merged commit 79a6058 into main Aug 18, 2026
17 of 18 checks passed
@SawyerHood
SawyerHood deleted the bb/draft-pr-for-1721-pi-compact-on-a-small-session-thr_5wpegxnkvx branch August 18, 2026 21:31
ymichael added a commit that referenced this pull request Aug 19, 2026
… skipped compaction

Main commit 79a6058 landed this fix in the old pi event translator, which
this branch deletes. The delta translator now recognizes pi's known refusal
messages on a manual, non-aborted compaction_end and emits a turn-scoped
provider.warning{compaction-skipped} plus a completed turn boundary instead
of failing the turn. Domain, thread-view, and protocol-version pieces of the
original commit merged cleanly during the rebase. Plan live-QA finding 1 is
resolved.

Co-Authored-By: Claude Fable 5 <[email protected]>
ymichael added a commit that referenced this pull request Aug 19, 2026
… skipped compaction

Main commit 79a6058 landed this fix in the old pi event translator, which
this branch deletes. The delta translator now recognizes pi's known refusal
messages on a manual, non-aborted compaction_end and emits a turn-scoped
provider.warning{compaction-skipped} plus a completed turn boundary instead
of failing the turn. Domain, thread-view, and protocol-version pieces of the
original commit merged cleanly during the rebase. Plan live-QA finding 1 is
resolved.

Co-Authored-By: Claude Fable 5 <[email protected]>
ymichael added a commit that referenced this pull request Aug 19, 2026
… skipped compaction

Main commit 79a6058 landed this fix in the old pi event translator, which
this branch deletes. The delta translator now recognizes pi's known refusal
messages on a manual, non-aborted compaction_end and emits a turn-scoped
provider.warning{compaction-skipped} plus a completed turn boundary instead
of failing the turn. Domain, thread-view, and protocol-version pieces of the
original commit merged cleanly during the rebase. Plan live-QA finding 1 is
resolved.

Co-Authored-By: Claude Fable 5 <[email protected]>
ymichael added a commit that referenced this pull request Aug 19, 2026
… skipped compaction

Main commit 79a6058 landed this fix in the old pi event translator, which
this branch deletes. The delta translator now recognizes pi's known refusal
messages on a manual, non-aborted compaction_end and emits a turn-scoped
provider.warning{compaction-skipped} plus a completed turn boundary instead
of failing the turn. Domain, thread-view, and protocol-version pieces of the
original commit merged cleanly during the rebase. Plan live-QA finding 1 is
resolved.

Co-Authored-By: Claude Fable 5 <[email protected]>
ymichael added a commit that referenced this pull request Aug 19, 2026
… skipped compaction

Main commit 79a6058 landed this fix in the old pi event translator, which
this branch deletes. The delta translator now recognizes pi's known refusal
messages on a manual, non-aborted compaction_end and emits a turn-scoped
provider.warning{compaction-skipped} plus a completed turn boundary instead
of failing the turn. Domain, thread-view, and protocol-version pieces of the
original commit merged cleanly during the rebase. Plan live-QA finding 1 is
resolved.

Co-Authored-By: Claude Fable 5 <[email protected]>
ymichael added a commit that referenced this pull request Aug 19, 2026
… skipped compaction

Main commit 79a6058 landed this fix in the old pi event translator, which
this branch deletes. The delta translator now recognizes pi's known refusal
messages on a manual, non-aborted compaction_end and emits a turn-scoped
provider.warning{compaction-skipped} plus a completed turn boundary instead
of failing the turn. Domain, thread-view, and protocol-version pieces of the
original commit merged cleanly during the rebase. Plan live-QA finding 1 is
resolved.

Co-Authored-By: Claude Fable 5 <[email protected]>
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.

pi /compact on a small session surfaces as a failed turn and puts the thread in error state

1 participant