Skip to content

Arch Agent: retry a dropped model connection, and say why it failed - #49

Merged
asaficontact merged 1 commit into
mainfrom
fix-connection-error-cause
Oct 6, 2026
Merged

asaficontact merged 1 commit into
mainfrom
fix-connection-error-cause

Conversation

@asaficontact

Copy link
Copy Markdown
Contributor

Spec: Tawab, in the 0.1.0 desktop app on his Mac, asked "Draw this project's system overview…". The transcript showed "looked at 1 places", then "Connection error.", and no answer.

Cause:

  • pi-ai 1.0.2 turns the OpenAI and Anthropic SDKs' own retries off (maxRetries: 0) and runs its own retry loop, which defaults to 0. archdraw never set it, and pi-agent-core has no option for it.
  • So a single dropped connection on the request carrying the tool result ended the turn.
  • pi-ai also keeps only the error's message. The real reason (err.cause.cause: UND_ERR_SOCKET, ECONNRESET, ENOTFOUND…) was thrown away, and the app keeps no log, so the failure could not be diagnosed.

Change:

  • streamWithRetries (app/core/src/models.ts) sends each model request with 2 retries, the SDKs' own default.
    • Retries happen before a response starts streaming, so text is never duplicated.
    • For the OpenAI and Anthropic APIs (and OpenRouter through the OpenAI one), it passes a fetch that records why a connection failed.
  • A lasting failure now reads e.g. Connection error (other side closed, UND_ERR_SOCKET).
  • The scheduled change check and its drafts get the same retries.
  • CHANGELOG has an Unreleased entry.

Evidence:

  • app/core/test/agent-network.test.ts runs a real Conversation over a real socket against a local Responses API stand-in:
    • request 2 dropped once: it is retried, and the agent answers;
    • request 2 dropped every time: the error names the cause, after 3 attempts.
  • Both cases failed before the fix with the bare "Connection error.", as in Tawab's transcript.
  • The same two drop modes were reproduced and then fixed in the bundled server for OpenAI and Anthropic, and in the Electron desktop bundle for OpenAI (Linux, xvfb).
  • scripts/ci-local.sh passed on this head, which is rebased on main 25ac207.

Not tested:

  • real OpenAI or Anthropic endpoints;
  • real macOS;
  • Google. Its adapter refuses a custom fetch, so it gets the retries but not the cause text.

Breaks: if retries ever duplicated a reply, the transcript would show it twice. agent-network.test.ts guards the retry path.

Rollback: git revert the commit.

— Banna, one of Tawab's agents

A chat turn died at the first transient connection failure. pi-ai 1.0.2
sends every provider request with the SDK's own retries off
(maxRetries: 0) and defaults its own retry count to 0; archdraw never
set it, and pi-agent-core has no option for it. So one reset, DNS miss
or refused connection on the request that carries a tool result ended
the turn with the SDK's bare "Connection error.". pi-ai also keeps only
the error's message, so the cause (err.cause.cause: ECONNRESET,
ENOTFOUND, UND_ERR_SOCKET) was lost and the failure was undiagnosable.

streamWithRetries (models.ts) sends each model request with two retries,
the SDKs' default, and passes a fetch that records the transport cause
of a failed request (not for Google, whose adapter refuses a custom
fetch). The conversation shows "Connection error (<cause>)." when the
error remains. The scheduled change check and its drafts get the same
retries.

The test drives a Conversation over a real socket against a local
Responses API stand-in: request 1 answers with a tool call, request 2's
connection is dropped once (retried, the agent answers) or every time
(the error names "other side closed, UND_ERR_SOCKET").

Signed-off-by: Banna <banna@archdraw.dev>
Agent: Banna
@vercel

vercel Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
archdraw Ready Ready Preview Oct 6, 2026 1:47pm UTC

Request Review

@asaficontact
asaficontact merged commit 2102753 into main Oct 6, 2026
5 checks passed
@asaficontact asaficontact mentioned this pull request Oct 6, 2026

This branch was successfully deployed

1 active deployment
Preview — 1d5b6c49 Deployed Oct 6, 2026 by vercel[bot]
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.

1 participant