Skip to content

Commit af5668d

Browse files
author
opencode
committed
fix(panes): correct full-TUI argv and work around mini freeze
Full TUI panes closed immediately because defaultPaneArgv built `opencode tui -s <id>`, but opencode has no `tui` subcommand — `tui` was parsed as the directory argument and the process exited with `ENOENT: chdir ... -> 'tui'`. The full TUI now attaches bare as `opencode -s <id>`. Mini panes froze during long tool calls because mini's long-lived `session.wait` is aborted by Bun's default 300s fetch idle timeout (upstream anomalyco/opencode#50135, fix PR #50248 still unmerged). Mini panes now launch via `env BUN_CONFIG_HTTP_IDLE_TIMEOUT=0`, matching the pending upstream fix. - src/watch.ts: pane argv per command (mini env-wrapped, tui bare) - test/watch.test.ts: cover both argv shapes - AGENTS.md: document both behaviors
1 parent 6da2a1b commit af5668d

3 files changed

Lines changed: 43 additions & 12 deletions

File tree

‎AGENTS.md‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ with Vitest. No runtime framework. Package ships only `dist/`
1616
| `src/cli.ts` | Orchestration: tmux/opencode version gates, session creation, owned-session cleanup, watcher spawn, `--mux-watch` path |
1717
| `src/args.ts` | Flag parsing: mux flags consumed, everything else passed through to opencode; `--mux-*` unknown flags error |
1818
| `src/config.ts` | `opencode-mux.conf` (XDG-aware) loading; auto-creates with defaults; precedence flags > file > defaults; unknown keys ignored |
19-
| `src/watch.ts` | Watcher: server events → pane lifecycle; `defaultPaneArgv(sessionID, paneCommand)` = `["opencode", <paneCommand>, "-s", sessionID]` (default `paneCommand` = `"mini"`) |
19+
| `src/watch.ts` | Watcher: server events → pane lifecycle; `defaultPaneArgv(sessionID, paneCommand)` = `["env", "BUN_CONFIG_HTTP_IDLE_TIMEOUT=0", "opencode", "mini", "-s", sessionID]` for `mini`, `["opencode", "-s", sessionID]` for `tui` (default `paneCommand` = `"mini"`) |
2020
| `src/tracker.ts` | `PaneTracker` state machine: open → closing (grace) → closed; `closePanes: auto\|keep` |
2121
| `src/tmux.ts` | Tmux adapter: split-window, kill-pane, window-scoped border styles (`-w`), `currentPane` from `TMUX_PANE` |
2222
| `src/theme.ts` | Theme resolution + mtime-cached provider (`createThemeStyles`) |
@@ -56,10 +56,16 @@ with Vitest. No runtime framework. Package ships only `dist/`
5656
`GET /api/info`). `serviceGeneration()` in `cli.ts` selects the matching
5757
client; the binary's generation must always drive the choice. Keep any new
5858
server interaction working on **both**.
59-
5. **Pane command is `opencode mini -s <id>`** (both generations support it).
59+
5. **Default pane command is `opencode mini -s <id>`** (both generations
60+
support it), launched through `env BUN_CONFIG_HTTP_IDLE_TIMEOUT=0` to work
61+
around upstream opencode #50135: mini's long-lived `session.wait` is aborted
62+
by Bun's 300s fetch idle timeout, freezing the pane during long tool calls.
6063
Mini removes the tab strip/agent switcher that the full TUI cannot hide —
61-
that's deliberate. The main pane always gets the full TUI
62-
(`opencode` + pass-through args).
64+
that's deliberate. `--pane-command tui` launches the full TUI as bare
65+
`opencode -s <id>` — opencode has **no `tui` subcommand**, so
66+
`opencode tui -s <id>` would parse `tui` as the directory argument and exit
67+
immediately (`ENOENT: chdir … -> 'tui'`), closing the pane. The main pane
68+
always gets the full TUI (`opencode` + pass-through args).
6369
6. **Failures are non-fatal** for appearance: a failing `set-option` or border
6470
apply never changes exit codes or blocks attach.
6571

@@ -132,8 +138,9 @@ npm run build # tsc -p tsconfig.build.json
132138
- Theme table regen: `node scripts/generate-theme-table.mjs` (fetches the
133139
pinned `anomalyco/opencode` v2.0.5 tag) or `--from <dir>` for local assets.
134140
Idempotent — output must be byte-identical on re-run.
135-
- Keep tests representative of the *new* pane command shape when touching
136-
pane argv (`["opencode", "mini", "-s", id]`; session id is `argv[3]`).
141+
- Keep tests representative of the pane command shape when touching pane argv:
142+
mini is `["env", "BUN_CONFIG_HTTP_IDLE_TIMEOUT=0", "opencode", "mini", "-s", id]`,
143+
tui is `["opencode", "-s", id]` (there is no `tui` subcommand).
137144
- Error messages are prefixed `opencode-mux:` and reference stderr.
138145
- **Version variables**: on version bump, update both `src/version.ts` (`VERSION` constant) and the README version mention — these must always match `package.json` `version`. Forgetting either causes stale version reporting.
139146
- **Release flow**: `npm version <x.y.z>` (identity-env vars set) creates the

‎src/watch.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,29 @@ export interface Watcher {
3232
start(signal: AbortSignal): Promise<void>;
3333
}
3434

35-
/** Pane command: attach the child session in the new pane via the minimal mini UI (no tab bar, no agent switcher). */
35+
/**
36+
* Upstream workaround for opencode issue #50135: `opencode mini` keeps a
37+
* long-lived `session.wait` request open, but its client uses Bun's default
38+
* fetch idle timeout (300s), which aborts the request during long-running tool
39+
* calls — the pane then freezes/dies. Disabling the idle timeout is exactly
40+
* what the pending upstream fix (PR #50248) does, so this is harmless once it
41+
* ships. See https://github.com/anomalyco/opencode/issues/50135
42+
*/
43+
const MINI_IDLE_TIMEOUT_ENV = "BUN_CONFIG_HTTP_IDLE_TIMEOUT=0";
44+
45+
/**
46+
* Pane command: attach the child session in the new pane.
47+
*
48+
* `mini` is a real subcommand (`opencode mini -s <id>`, no tab bar / agent
49+
* switcher), launched through `env` to carry the idle-timeout workaround above.
50+
* The full TUI has **no** `tui` subcommand — `opencode tui -s <id>` makes
51+
* opencode parse `tui` as the optional directory argument and exit with
52+
* `ENOENT: chdir … -> 'tui'`, closing the pane instantly. The full TUI is
53+
* launched bare instead: `opencode -s <id>`.
54+
*/
3655
export function defaultPaneArgv(sessionID: string, paneCommand: PaneCommand = "mini"): string[] {
37-
return ["opencode", paneCommand, "-s", sessionID];
56+
const head = paneCommand === "mini" ? ["env", MINI_IDLE_TIMEOUT_ENV, "opencode", "mini"] : ["opencode"];
57+
return [...head, "-s", sessionID];
3858
}
3959

4060
/** Wires server events → tracker state machine → tmux actions. */

‎test/watch.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,19 @@ const deps = (over: Partial<Parameters<typeof createWatcher>[0]> = {}) => ({
8282

8383
describe("createWatcher", () => {
8484
it("defaultPaneArgv builds the opencode mini attach command", () => {
85-
expect(defaultPaneArgv("ses_c")).toEqual(["opencode", "mini", "-s", "ses_c"]);
85+
expect(defaultPaneArgv("ses_c")).toEqual(["env", "BUN_CONFIG_HTTP_IDLE_TIMEOUT=0", "opencode", "mini", "-s", "ses_c"]);
86+
});
87+
88+
it("defaultPaneArgv builds the bare full-TUI attach command (no 'tui' subcommand)", () => {
89+
expect(defaultPaneArgv("ses_c", "tui")).toEqual(["opencode", "-s", "ses_c"]);
8690
});
8791

8892
it("opens a pane for a matching created event and records the open phase", async () => {
8993
const tmux = makeTmux({ paneIds: ["%7"] });
9094
const tracker = new PaneTracker({ graceMs: 1_000, closePanes: "auto" });
9195
const w = createWatcher(deps({ tmux, tracker }));
9296
await w.dispatch(created("ses_c", "ses_p"));
93-
expect(tmux.splits).toEqual([{ targetPane: "%0", layout: "main-vertical", argv: ["opencode", "mini", "-s", "ses_c"] }]);
97+
expect(tmux.splits).toEqual([{ targetPane: "%0", layout: "main-vertical", argv: ["env", "BUN_CONFIG_HTTP_IDLE_TIMEOUT=0", "opencode", "mini", "-s", "ses_c"] }]);
9498
expect(tracker.snapshot().get("ses_c")).toEqual({ phase: "open", paneId: "%7", closeAt: null });
9599
});
96100

@@ -184,7 +188,7 @@ describe("createWatcher", () => {
184188
expect(tmux.splits[1]).toEqual({
185189
targetPane: "%0",
186190
layout: "main-vertical",
187-
argv: ["opencode", "mini", "-s", "ses_c"],
191+
argv: ["env", "BUN_CONFIG_HTTP_IDLE_TIMEOUT=0", "opencode", "mini", "-s", "ses_c"],
188192
});
189193
expect(tracker.snapshot().get("ses_c")).toEqual({ phase: "open", paneId: "%2", closeAt: null });
190194
});
@@ -227,7 +231,7 @@ describe("createWatcher", () => {
227231
}),
228232
);
229233
await w.adopt();
230-
expect(tmux.splits.map((s) => s.argv[3])).toEqual(["ses_running"]);
234+
expect(tmux.splits.map((s) => s.argv[s.argv.indexOf("-s") + 1])).toEqual(["ses_running"]);
231235
expect(tracker.snapshot().get("ses_running")).toEqual({ phase: "open", paneId: "%1", closeAt: null });
232236
expect(tracker.snapshot().get("ses_done")).toBeUndefined();
233237
expect(tmux.kills).toEqual([]);

0 commit comments

Comments
 (0)