You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(cli): opencode run drops a Stop hook's continuation #1191
Under opencode run (non-interactive), a Stop hook's continuation never reaches the session. The bridge generated into .opencode/plugin/<plugin>-hooks.js runs the Stop script on session.idle, reads its {"decision":"block","reason"}, then calls client.session.promptAsync(...) without awaiting it. opencode run exits once the session is idle, so the prompt is lost.
Affected file(s)
The OpenCode and Kilo hooks bridge generator (opencode-hooks-bridge.ts and the opencode-events.js asset it ships).
Expected behaviour
A Stop script that blocks continues the turn once, under opencode run as under opencode serve or the TUI.
Observed behaviour
opencode run: the session ends on the model's last message; opencode export <session> shows no follow-up message.
opencode serve plus opencode run --attach: the follow-up arrives (the reason is the next user message).
The Stop script itself answers correctly: run by hand with a Stop payload, memory.cjs hook prints the block.
Repro: a project with aidd-context translated flat for opencode, a committed aidd_docs/memory/vcs.md, then opencode run "remove one line of aidd_docs/memory/vcs.md with your edit tool".
AI tool
OpenCode (Kilo shares the bridge, not tested)
Additional context
Only the non-interactive mode is affected: scripts and CI. Fix candidates: await the prompt before the handler returns, or keep the run alive until a pending continuation is sent.
Measurements on the latest versions (2026-11-11, non-interactive run, 3 runs per cell). The model is asked to write bad, the Stop follow-up demands ok.
Follow-up fired without waiting
Plugin dispose awaits the follow-up
OpenCode 1.19.5
0/3 (follow-up lost)
3/3
OpenCode V2 v2.2.7
3/3
3/3 (not needed)
Kilo 7.8.27
3/3
0/3
Cause (OpenCode 1.x). In run, session.idle fires while the session loop is still busy. session.prompt() then returns in about 14 ms with the previous turn's reply, without calling the model, and run exits.
Workaround that holds on 1.19.3 and 1.19.5. The plugin returns a dispose that awaits the pending follow-up prompt. The "already continued" guard must be a module-level Set, because the plugin instance is recreated.
Kilo 7.8.27 and OpenCode V2 do not need it. Kilo emits session.drained and run waits for the queue to empty. V2 runs the follow-up to completion after session.execution.succeeded. On Kilo, do not defer or await the follow-up in dispose: it fails with an UnknownError. Call promptAsync right in the session.idle handler.
Also confirmed by a separate session: opencode serve + run --attach delivers the follow-up as the next user message.
Limits: run only, no TUI, small and free models, 3 runs per cell. The explanation for Kilo and V2 (the run loop waits for queued input) is deduced, not read from the code.
Reproduced on both hosts with the artifact hook (#1317, branch feat/1149-artifact-hook), macOS, headless:
Host
run
serve + run --attach
opencode 1.19.3
Stop blocks, follow-up never persisted (session DB: 1 user message)
delivered once
kilo 7.7.5
same loss
delivered, but twice per plugin
Kilo double block (new): when two queued prompts are separated by a silent session.idle, the bridge resets session.continued on that idle. The next Stop goes out with stop_hook_active: false, so a plugin that already blocked once blocks again. Seen: 5 user messages for 2 plugins. It did not loop endlessly, because the model fixed the files on the second pass. Expected: one continuation per plugin per user turn.
Two plugins at the same idle: aidd-dev and aidd-pm both blocked. Both reasons were delivered as consecutive user messages, none lost.
Also: .catch(() => {}) on promptAsync hides any delivery error. Logging it to stderr would have made this visible.
Evidence: hook call logs with payload, stdout and rc per call, plus the session DB counts. Kept locally, available on request.
The OpenCode bridge now returns a dispose that awaits the pending Stop follow-up, and the "already continued" guard is a module-level Set, so it survives the plugin being recreated. The Kilo bridge sends the follow-up with promptAsync in the session.idle handler and resets continued only on a message that is not a follow-up, which removes the double block. Delivery failures are reported instead of swallowed. Landed in next with #1253 (364ca04).
Activity
blafourcade commentedon Nov 11, 2026
Measurements on the latest versions (2026-11-11, non-interactive
run, 3 runs per cell). The model is asked to writebad, the Stop follow-up demandsok.disposeawaits the follow-upCause (OpenCode 1.x). In
run,session.idlefires while the session loop is still busy.session.prompt()then returns in about 14 ms with the previous turn's reply, without calling the model, andrunexits.Workaround that holds on 1.19.3 and 1.19.5. The plugin returns a
disposethat awaits the pending follow-up prompt. The "already continued" guard must be a module-levelSet, because the plugin instance is recreated.Kilo 7.8.27 and OpenCode V2 do not need it. Kilo emits
session.drainedandrunwaits for the queue to empty. V2 runs the follow-up to completion aftersession.execution.succeeded. On Kilo, do not defer or await the follow-up indispose: it fails with anUnknownError. CallpromptAsyncright in thesession.idlehandler.Also confirmed by a separate session:
opencode serve+run --attachdelivers the follow-up as the next user message.Limits:
runonly, no TUI, small and free models, 3 runs per cell. The explanation for Kilo and V2 (the run loop waits for queued input) is deduced, not read from the code.blafourcade commentedon Nov 21, 2026
Reproduced on both hosts with the artifact hook (#1317, branch feat/1149-artifact-hook), macOS, headless:
runserve+run --attachKilo double block (new): when two queued prompts are separated by a silent
session.idle, the bridge resetssession.continuedon that idle. The next Stop goes out withstop_hook_active: false, so a plugin that already blocked once blocks again. Seen: 5 user messages for 2 plugins. It did not loop endlessly, because the model fixed the files on the second pass. Expected: one continuation per plugin per user turn.Two plugins at the same idle: aidd-dev and aidd-pm both blocked. Both reasons were delivered as consecutive user messages, none lost.
Also:
.catch(() => {})onpromptAsynchides any delivery error. Logging it to stderr would have made this visible.Evidence: hook call logs with payload, stdout and rc per call, plus the session DB counts. Kept locally, available on request.
blafourcade commentedon Nov 25, 2026
The OpenCode bridge now returns a
disposethat awaits the pending Stop follow-up, and the "already continued" guard is a module-levelSet, so it survives the plugin being recreated. The Kilo bridge sends the follow-up withpromptAsyncin thesession.idlehandler and resetscontinuedonly on a message that is not a follow-up, which removes the double block. Delivery failures are reported instead of swallowed. Landed in next with #1253 (364ca04).