Fix Pi context usage updates during tool loops - #2024
Merged
ymichael merged 1 commit intoAug 20, 2026
Merged
Conversation
ymichael
force-pushed
the
bb/investigate-pi-context-window-reporting-thr_ii4sx6ezx2
branch
from
August 20, 2026 08:13
419095b to
f156cb3
Compare
ymichael
deleted the
bb/investigate-pi-context-window-reporting-thr_ii4sx6ezx2
branch
August 20, 2026 08:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
Pi sampled context-window usage only on SDK
agent_end, which fires after the entire agent run. A tool-heavy run contains multiple SDKturn_endevents—each after an assistant response and its tool results—so bb's context meter stayed stale throughout the tool loop even though Pi's underlying context estimate was changing. See #2023.What changed
turn_end, while retaining the existingcompaction_endupdate.agent_end; that event is still forwarded normally for completion and checkpoint handling, but the finalturn_endalready emitted the same context snapshot.agent_enddoes not duplicate the final one.HOST_DAEMON_PROTOCOL_VERSIONfrom 141 to 142 because the bundled Pi bridge's daemon-to-server event cadence changed and enrolled daemons need to update.How you verified
pnpm exec turbo run test --filter=@bb/agent-runtime --force -- src/pi/bridge/__tests__/bridge.test.ts— 27 passed. The new regression fails before the fix because only theagent_endsample is emitted.pnpm exec turbo run typecheck --filter=@bb/agent-runtime --filter=@bb/host-daemon-contract --force— passed.pnpm exec turbo run test --filter=@bb/host-daemon-contract --force -- test/contract.test.ts— 38 passed.payload-size.test.ts); the protocol contract itself passed.Fixes #2023