Skip to content

Resource leaks: orphaned sessions, zombie servers, temp-dir leak #5

Description

@TheRealDinghyDog

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.mjsimportExternalAgentSession 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.mjshandleCancel 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.mjsrunServerTurn 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions