Skip to content

[Bug]: OpenCode shell commands survive restart after their server exits #37848

Open

Description

@StiensWout

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

Not sure

Steps to reproduce

  1. Start an OpenCode thread and ask it to run a long-lived shell command.
  2. Terminate T3 Code without a graceful shutdown while the command is running.
  3. Terminate the leftover OpenCode server process while leaving its shell child running.
  4. Restart T3 Code with the same home directory.

Expected behavior

Restarting T3 Code cleans up shell commands left behind by its previous OpenCode server.

Actual behavior

The shell command keeps running after restart, and its cleanup record is deleted so later restarts cannot stop it.

Impact

Major degradation or frequent failure. Users whose T3 Code crashes and whose OpenCode server exits before restart can be left with untracked shell commands consuming resources until they exit or are stopped manually.

Version or commit

main at ca432d7ed6. The cause is at packages/provider-opencode/src/server/OpenCodeServerLedger.ts:254.

Environment

Linux x64, the repository's own tests.

Logs or stack traces

expected true to be false
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/packages/provider-opencode/src/server/OpenCodeServerLedger.test.ts b/packages/provider-opencode/src/server/OpenCodeServerLedger.test.ts
index 3fcb52c898..56e865723a 100644
--- a/packages/provider-opencode/src/server/OpenCodeServerLedger.test.ts
+++ b/packages/provider-opencode/src/server/OpenCodeServerLedger.test.ts
@@ -143,6 +143,27 @@ describe.each(observedPlatforms)("OpenCodeServerLedger observing as %s", (platfo
     }).pipe(provideHost),
   );
 
+  it.live("stops surviving shell children when the recorded server exits before restart", () =>
+    Effect.gen(function* () {
+      const fs = yield* FileSystem.FileSystem;
+      const path = yield* Path.Path;
+      const stateDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-opencode-ledger-" });
+      const gate = path.join(stateDir, "gate");
+      NodeChildProcess.execFileSync("mkfifo", [gate]);
+      const server = yield* spawnGroup(SERVE_ARGS, `sleep 600 & read _ < '${gate}'; exit 0`);
+      yield* recordFromDeadServer(stateDir, server);
+      yield* fs.writeFileString(gate, "\n");
+      yield* server.exited;
+      expect(groupExists(server.pid)).toBe(true);
+
+      const restarted = yield* OpenCodeServerLedger.make({ stateDir });
+      yield* restarted.reapOrphans;
+
+      expect(yield* fs.readDirectory(path.join(stateDir, "opencode-servers"))).toEqual([]);
+      expect(groupExists(server.pid)).toBe(false);
+    }).pipe(provideHost),
+  );
+
   it.live("records a group whose spawned wrapper already exited", () =>
     Effect.gen(function* () {
       const fs = yield* FileSystem.FileSystem;
cd packages/provider-opencode && pnpm exec vp test run --config ../../vite.config.ts src/server/OpenCodeServerLedger.test.ts -t 'stops surviving shell children'

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 17, 2026
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

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions