Skip to content

fix: resume interrupted Pi agent turns - #60

Merged
Chumor merged 1 commit into
Zhou-Shilin:mainfrom
Chumor:fix/resume-interrupted-pi-agent-turns
Aug 3, 2026
Merged

Chumor merged 1 commit into
Zhou-Shilin:mainfrom
Chumor:fix/resume-interrupted-pi-agent-turns

Conversation

@Chumor

@Chumor Chumor commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Fixes #58

  • Continue failed harness turns from the existing user/tool boundary
  • Retry transient failures in the background before reporting an error

Summary by CodeRabbit

  • Reliability Improvements
    • Increased the default retry limit from 2 to 5 for better handling of temporary failures.
    • Added configurable retry limits with validation to prevent invalid values.
    • Added a two-second base delay between retry attempts.
    • Improved recovery and retry handling for interrupted assistant interactions.
    • Conversation state now restores cleanly after failed interactions, allowing processing to continue.
    • Existing provider-specific retry settings remain supported.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR increases default retries from two to five across provider and simple completion configuration. Harness streams disable stream-level retries and add session-level recovery that rewinds failed turns, reruns the agent loop, and honors delay and cancellation handling.

Changes

Retry configuration and harness recovery

Layer / File(s) Summary
Retry defaults across providers and streams
app/src/main/java/com/zhousl/aether/data/pi/PiProviderMapper.kt, shared/src/commonMain/kotlin/com/zhousl/aether/data/pi/SharedPiChatClient.kt, pi-bridge/src/bridge.ts
Provider and normalized model configurations use five retries by default. Simple completions use five retries. Harness streams set stream retries to zero.
Harness turn retry recovery
pi-bridge/src/bridge.ts
Harness sessions track retry limits. Failed assistant turns rewind Pi and extension session state, recreate turn state, rerun the agent loop, and honor a two-second delay and abort signals.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HarnessPrompt
  participant retryAssistantCall
  participant continueHarnessTurn
  participant PiSession
  HarnessPrompt->>retryAssistantCall: Execute assistant turn
  retryAssistantCall->>continueHarnessTurn: Retry failed turn
  continueHarnessTurn->>PiSession: Rewind failed turn branches
  continueHarnessTurn->>continueHarnessTurn: Rerun agent loop
  continueHarnessTurn-->>retryAssistantCall: Return assistant response
  retryAssistantCall-->>HarnessPrompt: Return result or abort
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: resuming interrupted Pi agent turns.
Linked Issues check ✅ Passed The retry limit is set to five and failed harness turns resume through retryAssistantCall, addressing the linked reconnection bug [#58].
Out of Scope Changes check ✅ Passed The changes remain within scope because they implement retry handling and interrupted-turn recovery required by the PR and issue [#58].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]

This comment was marked as resolved.

@Chumor
Chumor force-pushed the fix/resume-interrupted-pi-agent-turns branch 2 times, most recently from 8ec075d to 54feb61 Compare August 3, 2026 15:06

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pi-bridge/src/bridge.ts`:
- Around line 40-47: Verify the pinned `@earendil-works/pi-agent-core` API before
changing continueHarnessTurn: confirm whether runAgentLoopContinue is an
exported symbol or replace it with the documented agentLoopContinue export.
Remove the HarnessRetryInternals cast and direct calls to private AgentHarness
methods such as createTurnState, createContext, createLoopConfig,
createStreamFn, and handleAgentEvent by using the public AgentHarness
retry-continuation surface; if no public equivalent exists, document and
validate the internal dependency across supported patch releases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a6837fb-bb9d-46ab-89c8-42420c9a9ee6

📥 Commits

Reviewing files that changed from the base of the PR and between 8ec075d and 54feb61.

📒 Files selected for processing (3)
  • app/src/main/java/com/zhousl/aether/data/pi/PiProviderMapper.kt
  • pi-bridge/src/bridge.ts
  • shared/src/commonMain/kotlin/com/zhousl/aether/data/pi/SharedPiChatClient.kt
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/src/main/java/com/zhousl/aether/data/pi/PiProviderMapper.kt
  • shared/src/commonMain/kotlin/com/zhousl/aether/data/pi/SharedPiChatClient.kt

Comment thread pi-bridge/src/bridge.ts
@Chumor
Chumor marked this pull request as draft August 3, 2026 15:20
@Chumor
Chumor marked this pull request as ready for review August 3, 2026 17:37
@Chumor
Chumor force-pushed the fix/resume-interrupted-pi-agent-turns branch 2 times, most recently from d2a195e to dc1fa0a Compare August 3, 2026 17:50
- Retry failed harness turns after rewinding the failed assistant leaf
- Raise default agent max_retries from 2 to 5 across bridge and clients
@Chumor
Chumor force-pushed the fix/resume-interrupted-pi-agent-turns branch from dc1fa0a to d1f3bc5 Compare August 3, 2026 17:54
@Chumor
Chumor merged commit e89a435 into Zhou-Shilin:main Aug 3, 2026
4 checks passed
@Chumor
Chumor deleted the fix/resume-interrupted-pi-agent-turns branch August 3, 2026 18:41
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.

[BUG] Reconnect mechanism for LLM API requests fails on Android and iOS

1 participant