Skip to content

Commit a794c70

Browse files
committed
opencode: drop chunkTimeout, add root pyrightconfig for LSP-payload fix
The chunkTimeout: 20000 setting added in b084e0f turns out to be counter-productive: anomalyco/opencode#20466 documents that SSE-chunk timeout errors hit a non-retryable code path in retry.ts, so the setting converted silent multi-minute hangs into hard failures with no SDK retry. Removed from overlay, docs, and bats; bats now asserts the key is absent. Live config required one-time manual jq del because modify_ overlays can only add/overwrite, not delete. Add pyrightconfig.json at the repo root to suppress Pyright LSP noise from PEP 723 inline-script-deps Python files (scripts/, dot_ansible/). Per anomalyco/opencode#17578 these diagnostics get appended to tool responses and inflate the SSE payload, aggravating the same Copilot proxy idle-timeout stall. Excluded via .chezmoiignore.tmpl so it stays git-tracked but never deployed to $HOME. Rewrite docs/tools/opencode.md mitigation section to cite the upstream issues (#17578, #17574, #17307, #17318, #17336, #20466, #21173), explain the LSP-payload aggravator, and expand the when-to-revisit list to cover four distinct upstream-fix scenarios.
1 parent ee923bb commit a794c70

6 files changed

Lines changed: 59 additions & 19 deletions

File tree

‎.chezmoiignore.tmpl‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ scripts/**
3636
.gitleaks.toml
3737
.gitignore
3838
39+
# Pyright config — repo-local LSP settings, not deployed (see docs/tools/opencode.md)
40+
pyrightconfig.json
41+
3942
# Zsh secrets file (API keys, tokens, proxy - never track)
4043
.config/zsh/secrets.zsh
4144

‎.chezmoitemplates/agents/opencode.overlay.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"provider": {
1212
"github-copilot": {
1313
"options": {
14-
"timeout": 600000,
15-
"chunkTimeout": 20000
14+
"timeout": 600000
1615
}
1716
}
1817
}

‎docs/tools/agent-overlays.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The `modify_` overlay model deep-merges only the keys we explicitly enforce; eve
4444
"agent": { "title": { "reasoningEffort": "low" } },
4545
"provider": {
4646
"github-copilot": {
47-
"options": { "timeout": 600000, "chunkTimeout": 20000 }
47+
"options": { "timeout": 600000 }
4848
}
4949
}
5050
}
@@ -55,8 +55,7 @@ The `modify_` overlay model deep-merges only the keys we explicitly enforce; eve
5555
- `default_agent = "build"` — primary agent on TUI/CLI startup. Override per-session via `--agent` or the picker.
5656
- `small_model = "github-copilot/gpt-5-mini"` — cheap model for title generation, summarisation, and other lightweight calls. Avoids billing Claude Opus quota for trivial tasks. Pairs with `agent.title.reasoningEffort = "low"`.
5757
- `agent.title.reasoningEffort = "low"` — cheap completions for short title generation; sibling `agent.*` entries (per-agent provider, model overrides) survive.
58-
- `provider.github-copilot.options.timeout = 600000` (10 min) — request-level timeout. Default is 5 min; bumped to give long Claude Opus generations more room before the SDK aborts the whole call.
59-
- `provider.github-copilot.options.chunkTimeout = 20000` (20 s) — abort an in-flight stream if no SSE chunk arrives for 20 s. Counter-intuitive but **this is the fix for the "Tool execution aborted" loop on Copilot's Claude Opus channel**: the Copilot proxy occasionally stalls a stream past its own ~60 s server-side idle window, after which the connection silently dies. With no `chunkTimeout` set, the SDK waits the full request `timeout` for a chunk that will never come; with 20 s the SDK cancels and retries early, getting unstuck in seconds instead of minutes. See [docs/tools/opencode.md](opencode.md#claude-opus-stream-stall-on-github-copilot) for the diagnosis from log evidence.
58+
- `provider.github-copilot.options.timeout = 600000` (10 min) — request-level timeout. Default is 5 min; bumped to give long Claude Opus generations more room before the SDK aborts the whole call. **Note**: `chunkTimeout` is intentionally NOT set here, see [docs/tools/opencode.md → Claude Opus stream stall](opencode.md#claude-opus-stream-stall-on-github-copilot) for the rationale (upstream bug [anomalyco/opencode#20466](https://github.com/anomalyco/opencode/issues/20466) — SSE-chunk-timeout errors aren't retried, so setting `chunkTimeout` would convert silent hangs into hard failures with no recovery).
6059

6160
### Codex — [`agents/codex.config.overlay.toml`](../../.chezmoitemplates/agents/codex.config.overlay.toml)
6261

‎docs/tools/opencode.md‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ When using the `github-copilot/claude-opus-4.x` channel for long-running tool ca
7272

7373
GitHub Copilot's proxy in front of the Anthropic upstream enforces an idle timeout (community-observed at ~60 s) on streaming responses. Claude Opus generating a very large single tool-call payload can stay below the chunk emission threshold long enough to trip this, after which the connection silently dies. Direct Anthropic API does not have this behaviour. Sonnet trips it less often than Opus because it generates faster.
7474

75-
There is **no client-side flag to disable the proxy's idle timeout** — it's enforced server-side. The two viable mitigations are: (1) cancel-and-retry early so the SDK isn't blocked the full request timeout waiting for chunks that will never arrive, and (2) avoid emitting one giant tool call in the first place.
75+
There is **no client-side flag to disable the proxy's idle timeout** — it's enforced server-side.
76+
77+
### Upstream tracking
78+
79+
- [anomalyco/opencode#17578](https://github.com/anomalyco/opencode/issues/17578) — exact symptom match: `Write tool SSE timeout with claude-opus-4.x via GitHub Copilot when generating long markdown files`. Reporter found that **Pyright LSP diagnostics get appended to tool responses** and inflate the SSE payload, making the stall more likely. Even writing a `.md` file can trigger a full project re-scan in repos containing Python sources without a configured venv. Fix in PR `#18894` (not merged at time of writing).
80+
- [anomalyco/opencode#17574](https://github.com/anomalyco/opencode/issues/17574), [#17307](https://github.com/anomalyco/opencode/issues/17307), [#17318](https://github.com/anomalyco/opencode/issues/17318), [#17336](https://github.com/anomalyco/opencode/issues/17336) — additional reports of the same SSE-stall pattern; `#17307` is the original issue under which `chunkTimeout` was added as a stop-gap.
81+
- [anomalyco/opencode#20466](https://github.com/anomalyco/opencode/issues/20466) — **`chunkTimeout` does not actually retry**: when the chunk-timeout fires, the resulting `SSE read timed out` error is wrapped as `NamedError.Unknown` and the `retryable()` predicate in `retry.ts` rejects it (fails the `JSON.parse()` branch). Net effect: setting `chunkTimeout` converts a silent multi-minute hang into a hard failure with **no automatic retry**, which is often worse UX than leaving it unset and relying on the SDK's request-level retry. Fix in PRs `#21727` and `#23501` (neither merged).
82+
- [anomalyco/opencode#21173](https://github.com/anomalyco/opencode/issues/21173) — analogous problem on the OpenAI Responses provider (different transport, same shape).
7683

7784
### Mitigation (managed)
7885

@@ -82,29 +89,36 @@ The overlay sets:
8289
{
8390
"provider": {
8491
"github-copilot": {
85-
"options": { "timeout": 600000, "chunkTimeout": 20000 }
92+
"options": { "timeout": 600000 }
8693
}
8794
}
8895
}
8996
```
9097

91-
- `chunkTimeout: 20000` cancels a stalled stream after 20 s of silence and lets the SDK reconnect, instead of waiting the full request `timeout`.
92-
- `timeout: 600000` (10 min) extends the request-level cap so legitimately long generations aren't aborted prematurely after the first reconnect succeeds.
98+
- `timeout: 600000` (10 min) extends the request-level cap so legitimately long generations aren't aborted prematurely.
99+
- **`chunkTimeout` is intentionally NOT set.** A previous version of this overlay set `chunkTimeout: 20000` on the assumption that early cancel-and-retry would unstick the stream faster than waiting the full request timeout. Live testing on this machine showed the setting fires correctly (`SSE read timed out` at ~20 s, visible in `~/.local/share/opencode/log/2026-04-22T105313.log` lines 183, 257) but the error is **not retried** because of upstream bug `#20466` — `retryable()` in `retry.ts` rejects the error class. Net result was "20 s hang then hard fail with no recovery", which is worse than "silent hang then SDK request-level retry". Removed pending one of the linked PRs landing.
100+
101+
### LSP-payload aggravator (Action 3 — managed at repo root)
93102

94-
This shrinks the visible "stuck" window from ~minutes to ~tens of seconds and lets retries actually make progress instead of hitting the same dead connection.
103+
Per `#17578` the SSE payload includes diagnostics from any LSP server OpenCode auto-spawns for files in the working tree. In a chezmoi-managed dotfiles repo with stray Python scripts using PEP 723 inline-script-deps (`#!/usr/bin/env -S uv run --script`), Pyright cannot resolve the inline-declared dependencies and emits dozens of `reportMissingImports` diagnostics per file, which then ride along on every tool response. To suppress this noise the chezmoi repo root carries a [`pyrightconfig.json`](../../pyrightconfig.json) that:
104+
105+
- excludes ansible role trees, chezmoi source dirs (`dot_*/`), agent transcript dirs (`.specstory/`, `.claude/`, `.cursor/`, `.opencode/`), and `backups/`,
106+
- sets `reportMissingImports = "none"` so PEP 723 scripts stop polluting the diagnostics channel.
107+
108+
This file lives at the repo root (not under any `dot_*/` source path) so it is part of the chezmoi git repo but never deployed to `$HOME`.
95109

96110
### Behavioural mitigation (not managed)
97111

98112
If a generation is still failing repeatedly, prompt the agent to:
99113

100114
1. write a minimal skeleton first via a small `write`,
101-
2. fill each section incrementally via multiple `edit` calls.
102-
103-
This avoids the giant single-tool-call payload that triggers the stall in the first place. Not enforced via global `instructions` because that bloats every session's system prompt; better to add it as a per-project `AGENTS.md` rule when the repo is known to produce large generated files.
115+
2. fill each section incrementally via multiple `edit` calls (~50–80 lines each, one logical block per call).
104116

105-
### When to remove the mitigation
117+
This avoids the giant single-tool-call payload that triggers the stall in the first place. Empirically the most reliable fix in this session — far more effective than any client-side timeout tuning. Not enforced via global `instructions` because that bloats every session's system prompt; better to add it as a per-project `AGENTS.md` rule when the repo is known to produce large generated files.
106118

107-
The `chunkTimeout` override can stay indefinitely — it's a defensive setting that doesn't hurt. Reconsider when:
119+
### When to revisit
108120

109-
- GitHub Copilot publishes that the proxy idle timeout has been raised or removed for the Anthropic channel, or
110-
- you switch to direct Anthropic API (`provider.anthropic.options.apiKey`) and stop using the Copilot channel for Claude entirely.
121+
- If `#20466` lands (one of PRs `#21727` / `#23501`), re-add `chunkTimeout` to the overlay — it will then actually retry instead of hard-failing.
122+
- If `#17578` / PR `#18894` lands, the LSP-payload aggravator goes away upstream and the root `pyrightconfig.json` becomes a belt-and-suspenders defence rather than a load-bearing fix.
123+
- If GitHub Copilot raises the proxy idle timeout, the entire section can be deleted and the overlay's `timeout` reverted to the upstream default.
124+
- If you switch to direct Anthropic API (`provider.anthropic.options.apiKey`) and stop using the Copilot channel for Claude entirely, the overlay's `provider.github-copilot` block can be dropped.

‎pyrightconfig.json‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"//": "Suppresses Pyright LSP noise from PEP 723 inline-script-deps Python files in this chezmoi repo. Auto-spawned LSPs append diagnostics to OpenCode tool responses (see docs/tools/opencode.md), inflating SSE payload size and aggravating GitHub Copilot proxy idle-timeout stalls — anomalyco/opencode#17578. This file lives at the chezmoi repo root, not under any dot_*/ source path, so it is git-tracked but never deployed to $HOME.",
3+
"exclude": [
4+
"**/.git",
5+
"**/.specstory",
6+
"**/.claude/plans",
7+
"**/.cursor/plans",
8+
"**/.opencode/plans",
9+
"**/node_modules",
10+
"**/__pycache__",
11+
"backups",
12+
"dot_ansible",
13+
"dot_*",
14+
"private_dot_*",
15+
"exact_dot_*",
16+
"tests/**/snapshots"
17+
],
18+
"reportMissingImports": "none",
19+
"reportMissingModuleSource": "none",
20+
"reportMissingTypeStubs": "none",
21+
"useLibraryCodeForTypes": true,
22+
"venvPath": ".",
23+
"venv": ".venv"
24+
}

‎tests/unit/agent_overlays.bats‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ _have_chezmoi() {
104104
# default_agent and small_model enforced by overlay.
105105
echo "$output" | jq -e '.default_agent == "build"' >/dev/null
106106
echo "$output" | jq -e '.small_model == "github-copilot/gpt-5-mini"' >/dev/null
107-
# Copilot stream-stall mitigation enforced.
107+
# Copilot stream-stall mitigation enforced (timeout only; chunkTimeout
108+
# intentionally absent — see docs/tools/opencode.md).
108109
echo "$output" | jq -e '.provider["github-copilot"].options.timeout == 600000' >/dev/null
109-
echo "$output" | jq -e '.provider["github-copilot"].options.chunkTimeout == 20000' >/dev/null
110+
echo "$output" | jq -e '.provider["github-copilot"].options | has("chunkTimeout") | not' >/dev/null
110111
# Sibling agent.build untouched.
111112
echo "$output" | jq -e '.["agent"].build.model == "x"' >/dev/null
112113
# Local plugin path preserved verbatim (machine-local).

0 commit comments

Comments
 (0)