Skip to content

Windows: opencode run --standalone exits without invoking plugin cleanup #66868

Backlog

Description

@WhollyMindless

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

  1. Save repro.ts and plugin.ts in an empty directory.

  2. 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

Activity

  1. added
    area/cli
    type/bug
    version/v2
    on Nov 27, 2026
  2. opencodejr commented on Nov 27, 2026

    @opencodejr
    Contributor

    Thanks for the small, self-contained repro. I ran your repro.ts and plugin.ts unchanged against OpenCode 2.4.2, but only on Linux, since that is the only OS this sandbox has. There, run --standalone did run the plugin cleanup: both paths recorded setup, cleanup-start, cleanup-end, and the script printed NOT 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.

  3. Guembri01 commented on Nov 27, 2026

    @Guembri01

    Fixed on branch standalone-plugin-cleanup (ebd7929).

    The lease was never ended by our own teardown. Standalone.start spawned opencode serve --stdio and the spawner's scope cleanup killed it with SIGTERM — TerminateProcess on Windows — so the server never saw EOF and never ran its finalizers. services/standalone.ts now completes the child's stdin first, then waits for the exit before that kill:

    yield* Effect.addFinalizer(() => Effect.gen(function*() {
      yield* Stream.run(Stream.empty, proc.stdin).pipe(Effect.ignore)
      yield* proc.exitCode.pipe(Effect.timeout("5 seconds"), Effect.ignore)
    }))

    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 setup and an async cleanup, an owner fixture starts the real CLI source, waits until the plugin is listed, and returns normally — the same teardown run --standalone performs. On dev the receipt is empty (killed before even setup reached the file); with the change it is setup, 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 stdin stream instead of the pipe does close the lease, but leaves a Node handle open and the CLI process itself stops exiting. Completing proc.stdin from the finalizer has neither problem.

    PR creation is 404 for this account right now, so it waits as a branch with the body written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cliplatform/windowstype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions