Skip to content

opencode run -s <missing-session-id> exits 0 with zero stdout instead of failing #27559

Closed as not planned

Description

@paymog

Summary

opencode run -s <session-id> with a session id that doesn't exist locally exits with code 0 and produces zero stdout, after only writing a NotFoundError to stderr. For consumers that script around opencode and rely on exit codes to decide success vs. failure, this looks indistinguishable from a successful no-op run.

Version

opencode 1.14.19 (Linux x64, installed via packaged binary in a Daytona sandbox).

Repro

# Use any session id that doesn't exist on this machine:
echo "hi" | opencode run --format json -m amazon-bedrock/us.anthropic.claude-sonnet-4-6 --variant low -s ses_doesnotexist 2>stderr.log
echo "exit=$?"
cat stderr.log

Observed:

exit=0
NotFoundError: NotFoundError
 data: {
  message: "Session not found: ses_doesnotexist",
},

      at <anonymous> (/$bunfs/root/chunk-1q2thjd0.js:684:105806)
      at ~effect/Effect/successCont (/$bunfs/root/chunk-t65044z0.js:25:7738)
      ...

Expected

opencode run -s <missing> should exit with a non-zero status (e.g. 2 for "not found" or 1 for any error). Ideally also emit a single JSON event on stdout when --format json is set, so JSON-stream consumers can detect the failure without parsing stderr.

Why it matters

We script around opencode run --format json -s <prior-session> to resume agent conversations. Stale ids happen routinely (sandboxes get recycled, machines change, sessions get cleaned up). With exit code 0 + zero stdout + stderr-only error, the only way to distinguish "session resume failed" from "agent ran and intentionally produced no output" is to grep stderr for NotFoundError, which is brittle.

Context

Found while debugging a repeated silent failure in our agent orchestrator. Diagnosis writeup: https://linear.app/goldsky/issue/INFRA-3766 (internal, but referenced for traceability).

Suggested fix

In the run command's session-lookup path, treat "session not found" as a fatal error: return non-zero. Optionally accept --no-fail-on-missing-session for callers that prefer today's behavior.

Happy to PR if useful — pointer to the relevant lookup site appreciated.

Activity

  1. github-actions commented on May 14, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If these are the same underlying exit-code handling issue, it may make sense to consolidate.

  2. github-actions commented on Jul 14, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions