Skip to content

Wait for Pi RPC agent settlement before replying - #15

Merged
alejandro-ao merged 1 commit into
mainfrom
fix/rpc-agent-settled
Oct 1, 2026
Merged

alejandro-ao merged 1 commit into
mainfrom
fix/rpc-agent-settled

Conversation

@alejandro-ao

Copy link
Copy Markdown
Owner

$## Summary\n- Wait for Pi agent_settled, not the first agent_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 and git diff --check.\n\nRequires a Pi version emitting agent_settled; no incorrect agent_end fallback.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 09:40
@alejandro-ao
alejandro-ao merged commit 96a33a3 into main Oct 1, 2026
3 checks passed

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Handled prompts start no agent run, causing the unconditional settlement wait to hang indefinitely.

Review effort: Balanced
Findings: 1 High severity

Open (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_settled and 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.

Comment thread pi_gateway/pi_rpc.py
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):
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