Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`ai-opencode`: `RUN_FINISHED` never arrives when an adapter teardown step does not settle

Open
#1,638 1 comment 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@tombeckenham is already working on this.

Since Oct 6, 2026.

Assessment

This issue has not been assessed yet.

Description

waiting-on: maintainer

chat() holds RUN_FINISHED until the adapter's chatStream generator returns. In @tanstack/ai-opencode 0.4.14, the finally block of OpencodeTextAdapter.chatStream awaits handle.dispose(), server.dispose(), and bridge.close() in sequence. If one of them does not settle, the text streams but the run never ends, and the HTTP response stays open.

Repro

  1. Run chat() with opencodeText(...), withSandbox(...), and at least one tool, so that a tool bridge opens.
  2. Wrap the sandbox provider so that process.kill() on a spawned process returns a promise that never settles (as a sandbox API call that never returns does). Or use an opencode on PATH that ignores SIGTERM and keeps a request open on the tool bridge.
  3. Observe: TEXT_MESSAGE_END arrives, but RUN_FINISHED does not.

Proposed fix

Give each teardown step a time limit, and log a step that fails:

const bounded = (step) => Promise.race([
  Promise.resolve().then(step).catch((error) => logger.errors("opencode teardown failed", { error, source: "opencode.chatStream" })),
  new Promise((resolve) => setTimeout(resolve, 1000).unref()),
])
await bounded(() => handle?.dispose())
await bounded(() => server?.dispose())
await bounded(() => bridge?.close())

Suggestion (separate, @tanstack/ai-sandbox-local-process)

spawn uses detached: true, so a spawned process group gets no signal when its owner process dies, and the server continues to run with parent 1. One option: start one watchdog per owner with a stdin pipe that only the owner holds, register each spawned group with it, and kill the registered groups when the pipe closes.

Dominant language
TypeScript
Stars
3.2k
Forks
361
Avg merge
1d 15h
Merged PRs (30d)
210

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TanStack/ai

All issues in TanStack/ai

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.