fix(pi): wait for terminal assistant response in RPC mode#118
Merged
roninjin10 merged 7 commits intocodeplaneapp:mainfrom Mar 27, 2026
Merged
fix(pi): wait for terminal assistant response in RPC mode#118roninjin10 merged 7 commits intocodeplaneapp:mainfrom
roninjin10 merged 7 commits intocodeplaneapp:mainfrom
Conversation
…apture Pi was working at the CLI level, but Smithers was finalizing RPC sessions on the first assistant turn_end. That is no longer correct when Pi emits a tool-use turn followed by additional turns and a final assistant answer. The result was that tool-using Pi sessions were truncated before the real final response, which made long-running implementation tasks look idle or schema-only even when Pi was continuing internally. This change fixes the RPC completion logic so Smithers waits past tool-use turns and can finalize from the true terminal assistant state. It also adds the canonical Pi-first trace event model, persistence path, and tests needed to make that trace capture observable and durable.
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.
Problem
When
PiAgentruns in RPC mode, Smithers could finalize the session on the first assistantturn_endeven when PI was still continuing internally through tool use and subsequent turns.Observed behavior
This made PI-backed tasks unreliable in the exact cases where RPC mode is most useful: longer, tool-using sessions.
Fix
turn_endevents whosestopReasonistoolUseagent_endDocs / samples
examples/pi-hello-world.tsxexamples/pi-tools-workflow.tsxthat uses PI tool calls (readandbash)models.json/pi --list-models)Why this approach
PI tool-use sessions are multi-turn conversations. Treating the first assistant
turn_endas final is too eager. The minimal safe fix is to keep the RPC session open across tool-use turns and only finalize once PI reaches a true terminal assistant state.Validation
bun test tests/pi-support.test.tsbun run cli run examples/pi-hello-world.tsxbun run cli run examples/pi-tools-workflow.tsxAdded focused coverage for:
turn_endand only finish on the final assistant answerObserved sample results:
examples/pi-hello-world.tsxreturned{"message":"hello world"}examples/pi-tools-workflow.tsxsuccessfully used tools and returned the expected structured output, including:phrase: "saffron-orbit-lantern"lineCount: 3cwdBasename: "examples"Scope
This PR intentionally contains only:
No trace capture or observability changes are included in this branch.
🤖 Generated with pi / smithers