opencode-pty icon indicating copy to clipboard operation
opencode-pty copied to clipboard

[Bug] npm 0.4.0: notifyOnExit is a silent no-op on OpenCode 2.x — V2 exit-notifier fix (PR #61) unreleased for 7 weeks

Open yulong-ge opened this issue 3 weeks ago • 1 comments

Summary

On the current npm release (0.4.0, latest as of today), notifyOnExit: true is a complete silent no-op under OpenCode 2.x: the PTY exits, no <pty_exited> message is ever delivered, nothing is logged anywhere, and the agent never wakes. The user has to manually nudge the session, which defeats the whole feature.

A full fix has been sitting on main since PR #61 (merged 2026-09-19) — one day after v0.4.0 was tagged — but no release has been cut since, so every install path ("plugin": ["opencode-pty"], opencode-pty/v2 shim, etc.) ships the broken build.

Environment

  • opencode-pty 0.4.0 (npm latest; dist audited below)
  • OpenCode 2.2.6 (TUI), macOS arm64, Bun runtime
  • Plugin loaded via a local V2 shim re-exporting opencode-pty/v2 (see #85 for why the subpath can't be a plugin spec directly)

Reproduction

  1. Load the V2 entry under OpenCode 2.x.
  2. pty_spawn({ command: "sleep", args: ["3"], notifyOnExit: true }), end the agent turn.
  3. Process exits after 3s → nothing happens. No message in the session, no log line from the plugin, no error.

With the fix wired (see workaround), the same spawn delivers <pty_exited> and wakes the agent ~immediately after exit.

Root cause in 0.4.0

Three breaks compound, each verified against node_modules/opencode-pty/dist and at runtime:

  1. V2 setup installs an empty adapter. dist/src/v2/index.js calls createV2Adapter() with no options, so installHostAdapter never sets a notifier (adapters/index.js only calls manager.setNotifier when adapter.notifier is truthy). manager.notifier stays null.
  2. The fallback NotificationManager never gets a client. initManager(client) is exported but called by no code path in the package. NotificationManager.sendExitNotification returns immediately when this.client is null — silently.
  3. OpenCode 2.x provides no client to wire anyway. Runtime-probed on 2.2.6: the V1 server(input) hook is never invoked; the V2 setup(ctx) context has no client key (it exposes app, location, options, agent, aisdk, command, credential, event, experimental, generate, model, provider, integration, mcp, permission, plugin, reference, rpc, skill, storage, tool, vcs, websearch, worktree, session, shell); the tool execution context only has sessionID, agent, messageID, id, progress, signal. So no external caller can supply an SDK client either.
  4. All failures are swallowed. sendExitNotification wraps everything in catch { /* Ignore */ }, so breaks 1–3 leave zero diagnostics — from the outside this looks like "the model ignored the notification".

main fixes all of this in PR #61 via V2SessionNotifier bound to ctx.session.prompt ({ sessionID, id, text }, idempotent id, errors logged) — but it's unreachable for npm users.

Workaround for 0.4.0 users (verified on OpenCode 2.2.6)

In a local shim, after calling the package's V2 setup, install a notifier through the plugin context's native session domain:

import { setManagerNotifier } from "opencode-pty/plugin/pty/manager"
import { NotificationManager } from "opencode-pty/plugin/pty/notification-manager"

// ctx is the V2 setup context; builder reuses the stock <pty_exited> formatter
const builder = new NotificationManager()
setManagerNotifier({
  async sendExitNotification(session, exitCode) {
    await ctx.session.prompt({
      sessionID: session.parentSessionId,
      text: builder.buildExitNotification(session, exitCode),
      delivery: "queue", // verified accepted on 2.2.6; omit to match main's steer default
    })
  },
})

Flat { sessionID, text } is the accepted shape on 2.2.6 — nested { sessionID, prompt: { text } } fails with SchemaError(Missing key at ["text"]), and { path: { sessionID }, body: … } fails with SchemaError(Missing key at ["sessionID"]).

Ask

Please cut v0.4.1 from current main. That single release also resolves #86 (V2 tool registration lives in the same unreleased PR) and closes the loop on #54's ask — this is the second time a notification fix is merged but stranded ahead of a release.

Cross-references

  • #61 (the unreleased fix), #86 (V2 tools — same PR, same release gap), #85 (V2 entry not loadable as plugin spec), #80 (V2 permissions not wired — same createV2Adapter({}) family), #54 (silent swallow family; its "please release" note applies doubly here), #57 (V1 model clobbering — main's V2 notifier also addresses this by construction)

yulong-ge avatar Nov 07 '26 11:11 yulong-ge

Closing: the underlying fix is already on main (PR #61), and that was the core of this report. The remaining ask was only a patch release (v0.4.1) — a maintainer call, not a bug to track. The verified 0.4.0 workaround above covers anyone hitting this in the meantime.

yulong-ge avatar Nov 07 '26 11:11 yulong-ge