Resource leaks (OpenCode adversarial review of PR #1)
Surfaced by an OpenCode adversarial self-review, triaged by Claude Code. These accumulate over long-running Claude sessions with many background tasks.
9. lib/opencode.mjs — importExternalAgentSession finally cleanup
finally { fs.rmSync(tempDir, { recursive: true, force: true }) } with no try/catch. If rmSync throws, the error clobbers the try block's return value (JS finally semantics) and leaks the temp dir. Wrap the cleanup in its own try/catch.
10. opencode-companion.mjs — handleCancel leaves dedicated server running
Kills the task-worker via terminateProcessTree(job.pid) but does not tear down the opencode serve process dedicated to that job's session. With no other active job, the server lingers until handleSessionEnd, accumulating zombie server processes across many short background tasks.
11. lib/opencode.mjs — runServerTurn orphans server sessions
client.createSession creates a session; if captureTurn throws (event-stream timeout, sendMessage failure, etc.) the session is never deleted. Only implicit cleanup is opencode serve exiting. Confirmed by the smoke test — the failed run left ses_0c072d6d… alive on the server (which is how the findings were recovered). Delete/close the session on turn failure.
Ref: PR #1.
Resource leaks (OpenCode adversarial review of PR #1)
Surfaced by an OpenCode adversarial self-review, triaged by Claude Code. These accumulate over long-running Claude sessions with many background tasks.
9.
lib/opencode.mjs—importExternalAgentSessionfinallycleanupfinally { fs.rmSync(tempDir, { recursive: true, force: true }) }with no try/catch. IfrmSyncthrows, the error clobbers thetryblock's return value (JSfinallysemantics) and leaks the temp dir. Wrap the cleanup in its own try/catch.10.
opencode-companion.mjs—handleCancelleaves dedicated server runningKills the task-worker via
terminateProcessTree(job.pid)but does not tear down theopencode serveprocess dedicated to that job's session. With no other active job, the server lingers untilhandleSessionEnd, accumulating zombie server processes across many short background tasks.11.
lib/opencode.mjs—runServerTurnorphans server sessionsclient.createSessioncreates a session; ifcaptureTurnthrows (event-stream timeout,sendMessagefailure, etc.) the session is never deleted. Only implicit cleanup isopencode serveexiting. Confirmed by the smoke test — the failed run leftses_0c072d6d…alive on the server (which is how the findings were recovered). Delete/close the session on turn failure.Ref: PR #1.