Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
ADR 0050: Bounded provider stream recovery and diagnostics
- Status: Accepted (amended by D259 and D378 / ADR 0206, which replaced the retry arithmetic below with one shared bounded budget; classification per D186)
- Date: 2026-08-04
Context
The provider retry layer covered failures while establishing a request, but a
provider can also terminate after the assistant stream has started: the runtime
classified the common terminated message as a generic PROVIDER_ERROR, ended
the turn, and left regenerate to build a new runtime and reseed the transcript.
Repeated mutation failures had a related cost, as the model could keep repairing
an obsolete patch instead of taking a fresh snapshot of the target file.
Decision
- Classify
terminated, premature stream closure, and equivalent incomplete stream messages as retryableSTREAM_FAILED, preserving only safe, low-cardinality provider status/code fields inAppError.details. - Configure pi-ai request setup with a provider-level retry and an interruptible delay, forwarding the durable session id for adapters with request affinity.
- After a stream has started, retry transient
STREAM_FAILED,NETWORK_ERROR, orTIMEOUTin the same turn after an abortable backoff: the failed assistant leaves the next model context with its visible message id reused, so partial content is replaced rather than duplicated; a further failure is terminal. - Attach
phase,providerWaitMs,streamMs, provider status/code, andretryAttemptas diagnostics only — redacted, bounded, and never carrying credentials or raw provider bodies. - Mutation instructions select
Editfor one small unique replacement andWritefor a coherent whole-file rewrite; after a mismatch the agent follows the line-anchored contract's fresh-read or complete-reveal recovery, and the third counted failedEditor shell patch command returns pi-agent-core's terminating tool hint with the exact mismatch.
Consequences
- One transient stream termination no longer forces regenerate or a new transcript/runtime boundary; a recovered turn keeps one assistant bubble and one terminal lifecycle.
- Provider errors stay diagnosable from agent timing and session logs without exposing secrets.
- Persistent outages, authentication errors, context failures, and repeated stream failures stay visible and actionable instead of looping.
Alternatives
- Retry every provider error in the same turn: authentication, model-selection, and context errors are not fixed by replaying the request.
- Create a new assistant bubble per attempt: partial attempts would look like multiple answers and complicate transcript reconciliation.