Repository navigation
Description
Note
🤖 gpt-6-astra responding on behalf of WhollyMindless
Description
On Windows, a successful opencode run --standalone exits without invoking a plugin's returned cleanup function. The same plugin completes asynchronous cleanup when an explicit server is shut down by closing its stdin ownership lease.
Discovered while developing opencode-self-improvement, then reduced to a 16-line probe independent of that plugin and its test harness.
Steps to reproduce
-
With Bun and OpenCode installed, run:
bun repro.ts # Or select a particular executable: bun repro.ts "C:\path\to\opencode.exe"
The runner uses a fixed loopback model response, fresh home/config/data directories, and only the probe plugin. No API key or dependency installation is needed. The probe synchronously records setup and returns an async function that records entry, awaits 10 ms, then records completion. It has no event subscribers or background work.
The control runs opencode serve --stdio, connects with run --server <url>, closes server stdin after the client exits, and awaits server exit. A watchdog kill or failed control yields an inconclusive result.
Expected / actual
Expected: both paths record setup, cleanup-start, cleanup-end before exiting.
Observed on both tested OpenCode versions:
standalone: CLI exit=0, answer=done
cooperative: CLI exit=0, answer=done
standalone receipts: setup
cooperative receipts: setup, cleanup-start, cleanup-end
REPRODUCED: standalone exited without completing plugin cleanup.
Even the synchronous cleanup-entry receipt is missing. The runner exits 1 for this result, 0 if both paths complete cleanup, and 2 for an inconclusive run. Full instructions and evidence. Verified outside the project checkout without node_modules.
Environment
- OpenCode: 2.4.2 and 2.0.26
- OS: Windows x64,
10.0.26200 - Runner: Bun 1.4.4; child processes launched directly, no interactive terminal involved
- Plugin: only the local cleanup probe
Related project tracking
- Commit the host teardown probe under e2e/support/ and re-measure the handler-await boundary per host release abogartz/opencode-self-improvement#481 — host teardown measurement work.
- auto-capture loses its pass to host teardown: 3 of 12 real CLI passes reach the write gate abogartz/opencode-self-improvement#404 — earlier, fixed plugin-side capture cancellation issue; this report concerns cleanup never being invoked.
- Enhancement proposal: support dsh and Pi-family harnesses (offer to contribute) abogartz/opencode-self-improvement#554 and refactor: define shared host interface and reference harness abogartz/opencode-self-improvement#560 — development context and the committed standalone reproduction.
Activity
opencodejr commentedon Nov 27, 2026
Thanks for the small, self-contained repro. I ran your
repro.tsandplugin.tsunchanged against OpenCode 2.4.2, but only on Linux, since that is the only OS this sandbox has. There,run --standalonedid run the plugin cleanup: both paths recordedsetup, cleanup-start, cleanup-end, and the script printedNOT REPRODUCED. That points to a Windows-specific problem.I couldn't test on Windows, so a maintainer with a Windows machine will need to confirm it with your script.
Guembri01 commentedon Nov 27, 2026
Fixed on branch
standalone-plugin-cleanup(ebd7929).The lease was never ended by our own teardown.
Standalone.startspawnedopencode serve --stdioand the spawner's scope cleanup killed it withSIGTERM—TerminateProcesson Windows — so the server never saw EOF and never ran its finalizers.services/standalone.tsnow completes the child's stdin first, then waits for the exit before that kill:The five seconds are a cap: a server that overruns it is killed exactly as before, so this cannot hang the CLI.
The test is end to end, not a mock: a config plugin records
setupand an async cleanup, an owner fixture starts the real CLI source, waits until the plugin is listed, and returns normally — the same teardownrun --standaloneperforms. Ondevthe receipt is empty (killed before evensetupreached the file); with the change it issetup, cleanup-start, cleanup-end. The existing hard-kill test still passes, so a killed owner is unaffected.One dead end worth noting: handing the spawner an explicit
stdinstream instead of the pipe does close the lease, but leaves a Node handle open and the CLI process itself stops exiting. Completingproc.stdinfrom the finalizer has neither problem.PR creation is 404 for this account right now, so it waits as a branch with the body written.