Provider stream can emit empty aborted with AbortSignal=false (Pi 0.83.0 compatibility)
Summary
With @agegr/pi-web 0.8.6 using @earendil-works/pi-* 0.83.0, the main Agent intermittently persists an empty assistant turn:
type=error, reason=aborted, stopReason=aborted
content=[], totalTokens=0, AbortSignal.aborted=false
Request aborted before processing provider output.
This occurred across openai-codex/gpt-5.3-codex-spark, openai-codex/gpt-5.4-mini, and deepseek/deepseek-v4-flash, all with SSE. It is related to earendil-works/pi#4945, but the stream terminates by itself instead of hanging until user abort, and it is not Codex-only.
Evidence
I added metadata-only tracing around the RPC abort command, Agent.abort(), the run AbortController, the signal abort event, and the original provider EventStream terminal/result.
Natural failures consistently showed:
- no RPC/UI abort command;
- no
Agent.abort()orAbortController.abort(); - signal false at request, terminal, and result;
- provider EventStream itself emitted
error(reason=aborted); - zero content and zero reported tokens;
- failure before tool execution, independent of browser/SSE client disconnect.
In a recent batch of 6 new sessions, 5 first attempts ended this way. Retrying the identical zero-output stream recovered DeepSeek and GPT Mini once each; Spark also produced consecutive empty aborts.
Compatibility gap
Pi's retry classifier only retries stopReason=error; aborted correctly means caller cancellation under normal semantics. Because this provider/transport failure arrives mislabeled as aborted, pi-web currently ends and persists an empty reply without recovery.
Two complementary fixes seem appropriate:
- Pi upstream should avoid emitting
abortedwhile the request signal is false; classify the pre-output transport/provider failure aserrorso standard retry applies. - pi-web can defensively retry a strictly qualified empty abort before any content/tool event, with a bounded retry count and a fresh signal check.
I have a local pi-web wrapper implementing that strict boundary, with tests for real cancellation, partial output, tool calls, retry exhaustion, and iterator/setup failures. I can provide the patch if useful.
Environment: Windows 10.0.19044, Node 24.15.0, pi-web 0.8.6, Pi packages 0.83.0.
AI-assisted report: prepared from locally collected, redacted diagnostic metadata at the user's explicit request. No prompts, responses, credentials, or raw session logs are included.
Post-deployment update from the bounded compatibility workaround (metadata only):
- 9 new sessions: 5 direct successes, 1 recovered by retry, 3 still ended empty
aborted. - Two
openai-codex/gpt-5.3-codex-sparksessions exhausted all 3 total attempts. Every attempt remained pre-output; final result waserror/aborted, signal=false, 0 tokens/content, and no local abort event. - One
deepseek/deepseek-v4-flashsession retried once. Attempt 2 emitted an assistantmessage_startwith a thinking block but no text/tool event, then endederror/abortedwith 0 tokens/content. The conservative guard treated the thinking block as committed and did not make attempt 3. - One
openai-codex/gpt-5.4-minisession recovered on attempt 2; the other five sessions completed directly.
This confirms that bounded downstream retry can reduce the symptom but does not fix the upstream semantic problem. In particular, consecutive empty aborts occur with a false request signal, and a provider may start hidden reasoning before returning an empty aborted terminal. The upstream distinction between caller cancellation and provider/transport failure is still needed.
AI-assisted update, based only on redacted event metadata; no prompts, responses, credentials, or raw logs are included.
Additional data point + concrete suggestion, from a downstream wrapper that hit this exact issue.
Confirmed on 0.8.7 / pi 0.84.0: the provider stream can still emit error(reason=aborted) with content=[], totalTokens=0, and signal.aborted=false — i.e. the transport/provider fails before any output and leans on the aborted mislabel. This is not Codex-only: it also appears on deepseek, aliyun (qwen/deepseek), and glm.
Suggested fix (upstream, better than a downstream wrapper):
- In pi / pi-ai: when a provider event-stream terminates with
abortedwhile the request signal isfalseand there is zero output/content/tokens, classify it aserror(retryable) instead ofaborted. Then the standard retry path handles it. - In pi-web: optionally, a defensive bounded retry of a strictly-qualified empty abort (no content/tool/usage yet) before surfacing it.
We kept a downstream wrapper (withEmptyAbortRetries) that does the strict-boundary retry (retries ≤2 with a fresh signal check, never retries after real output/tool/usage or on genuine cancellation). It is small and tested, but it exists only because upstream doesn't handle this. If upstream adopts either fix, the wrapper can be deleted.
Happy to share the wrapper's test cases / diff for reference.
Thanks for the detailed diagnostics. After checking the current behavior, we believe pi-web is handling the aborted stop reason according to the normal contract: it represents caller cancellation and should not be retried.
The affected runs show AbortSignal.aborted=false and no local abort, so the semantic mismatch is in the upstream Pi/provider stream layer. Once this pre-output transport failure is classified as error (or retried before being surfaced), the existing Pi retry path should recover it.
We will wait for the upstream Pi update rather than add a broad pi-web retry. A narrow downstream retry can remain only as a defensive workaround.