agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

[Bug]: Resuming the OpenCode orchestrator chat fails with "peer disconnected before response"

Open launchswitch opened this issue 2 months ago • 3 comments

Resuming the OpenCode orchestrator chat fails instead of restoring the conversation. AO reports the chat failing to resume with "peer disconnected before response", and the chat never comes back.

  • Orchestrator harness: OpenCode (chat mode). Workers use Pi (TUI) and were not affected.
  • Session: the project orchestrator's chat, which had a long transcript.
  • Environment: Linux, AO desktop 0.13.0.
  • Frequency: it happened repeatedly at the time (2026-09-13, ~17:53 local).
  • Impact: the orchestrator chat was unusable and could not be resumed.

I don't have reliable repro steps beyond "resume the existing orchestrator chat".

launchswitch avatar Sep 14 '26 00:09 launchswitch

Agent-collected evidence — gathered 2026-09-13 19:40 CDT on the reporter's machine, read-only, before any local build was installed. AO desktop 0.13.0 (deb); daemon /usr/lib/agent-orchestrator/resources/daemon/ao (md5 23e5d1e53b51aa2b8092f61a5047ed8b).

Command: journalctl --user --since "2026-09-13 17:53:00" --until "2026-09-13 17:54:10"

Observed (trimmed; the overflow/close pair repeats at 17:53:45 and 17:53:55 as well):

Sep 13 17:53:11 ERROR msg="failed to queue notification; closing connection" err="notification queue overflow" capacity=1024 queued=1024
Sep 13 17:53:11 INFO  msg="connection closed" cause="notification queue overflow"
Sep 13 17:53:11 INFO  msg="http request" method=POST path=/api/v1/sessions/montamer2-2/resume-agent status=500 duration=2.08s
  error="resume agent montamer2-2: resume chat: chat conversation resume failed: ACP session/load: {\"code\":-32603,\"message\":\"Internal error\",\"data\":{\"error\":\"peer disconnected before response\"}}"

Read-only SQLite, same day (sqlite3 -readonly ~/.ao/data/ao.db): the project-scoped orchestrator conversation (5d9ca033-4a63-421a-b9db-28c9dfb7d932, 129 turns) holds 380,833 provider event rows — 349,953 attributed to montamer2-2 and 30,880 to montamer2-47. montamer2-2 is terminated (updated 2026-09-13T22:55:31Z); montamer2-47 was created in the same second.

What this supports: the failing call was POST /api/v1/sessions/montamer2-2/resume-agent, and the ACP connection was closed by the SDK's notification-queue overflow while that call was in flight (the two log lines are 40 ms apart, in the same process). The conversation attached to that session is large, so replaying it is the likely trigger — that link is a hypothesis based on transcript size, not a measurement of how many events the provider replayed.

Limits: one machine, one occurrence window, no provider-side logs. Excerpts contain no prompts or credentials.

launchswitch avatar Sep 14 '26 00:09 launchswitch

Assigned to @codebanditssss.

Rishet11 avatar Sep 14 '26 14:09 Rishet11

the main cause appears to be acp history replay backpressure during resume.

when ao resumes an opencode conversation, it calls acp session/load. opencode replays a large number of session/update notifications. ao currently normalizes each replay update synchronously on the sdk notification handler. the acp sdk has a bounded notification queue of 1024 items; for large replays, that queue fills, so the sdk closes the connection with notification queue overflow. ao then surfaces the follow-up generic error peer disconnected before response.

the fix is to keep replay notifications lightweight: buffer the raw session/update payloads while session/load is running, return quickly from the sdk callback, and normalize/process the buffered updates after session/load returns. replay capture should remain active until the buffer is fully drained and then switch to live updates atomically, so events are not lost or reordered. this is the approach proposed in pr #5372.

the failure is therefore in acp replay handling and backpressure, not the sidebar ui or sqlite data. the current main branch is still exposed while pr #5372 remains unmerged.

codebanditssss avatar Sep 15 '26 14:09 codebanditssss