Repository navigation
Wait for Pi RPC agent settlement before replying - #15
Merged
Merged
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Handled prompts start no agent run, causing the unconditional settlement wait to hang indefinitely.
Review effort: Balanced
Findings: 1
What changed in this PR
Updates Pi RPC completion handling to wait for full agent settlement before replying through Telegram.
Changes:
- Waits for
agent_settledand preserves fast responses. - Resets reply candidates across retries and sanitizes event history.
- Adds lifecycle tests and updates protocol documentation.
| File | Description |
|---|---|
pi_gateway/pi_rpc.py |
Implements settlement-based prompt completion. |
tests/test_pi_rpc_settled.py |
Tests retries, stale events, aborts, and failures. |
README.md |
Documents settlement requirements. |
docs/04-pi-rpc-integration.md |
Updates RPC lifecycle documentation. |
AGENTS.md |
Records the revised protocol assumption. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| events: list[dict[str, Any]] = [] | ||
| final_text = "" | ||
| async for event in self.events_until_agent_end(timeout=None): | ||
| async for event in self.events_until_agent_settled(timeout=None): |
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.

$## Summary\n- Wait for Pi
agent_settled, not the firstagent_end, so automatic compaction, overflow recovery, retries, and follow-ups finish before Telegram replies.\n- Reset reply candidates for each retry, drain stale command events before sending new prompts without dropping fast responses, and keep event-history sanitization.\n- Add synthetic RPC lifecycle tests for compaction/retry, fast completions, stale events, aborts, and reader failures.\n\n## Verification\n- Python 3.11 and 3.14: ruff, mypy, pytest (32 passed, 7 subtests),uv build.\n- compileall andgit diff --check.\n\nRequires a Pi version emittingagent_settled; no incorrectagent_endfallback.