Skip to content

Error-handling gaps: teardown ordering, detached grandchild, silent log/lock leaks #6

Description

@TheRealDinghyDog

Error-handling gaps (OpenCode adversarial review of PR #1)

Surfaced by an OpenCode adversarial self-review, triaged by Claude Code. These cause silent failures in teardown/logging paths.

12. session-lifecycle-hook.mjshandleSessionEnd teardown ordering

cleanupSessionJobs and teardownServerSession run before clearServerSession. If either throws, clearServerSession never runs → stale server.json; the next SessionStart/ensureServer wastes time health-checking a dead server. Run clearServerSession in a finally, or reorder/guard each step.

13. stop-review-gate-hook.mjsrunStopReview detached grandchild survives timeout

spawnSync(..., { timeout }) runs the task subcommand, which spawns opencode serve with detached: true. On timeout, spawnSync kills the parent but the detached grandchild (separate process group) keeps running on a random port. Track and kill the grandchild, or start it in the same killable group.

14. opencode-companion.mjshandleCancel logs to possibly-undefined job.logFile

Uses job.logFile from partial-patch upsertJob state; if never written, appendLogLine(undefined, …) silently skips, losing the interrupt/cancellation log lines. Resolve the log path defensively or assert it.

15. lib/opencode-server.mjssubscribeEvents onOpen throw leaks reader lock

options.onOpen?.() — if the callback throws synchronously, the error propagates before the finally reader.releaseLock(), leaking the ReadableStream reader lock (and possibly the socket). Guard the onOpen call.

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