Skip to content

CLI --session flag rejects external session IDs that don't start with 'ses' #29964

@pencilkill

Description

@pencilkill

Bug Description

When using opencode run --session <external-id>, the Zod schema validation requires session IDs to start with ses. This blocks external orchestrators that manage session IDs in their own format (e.g. catagent-*, custom UUIDs, etc.) from passing session IDs via the --session flag.

Error observed in opencode stderr:

ERROR service=server error=Expected a string starting with "ses", got "catagent-1780062945254-girppr"

This is structurally the same class of problem as #21745 and #29868 — the Zod validation starts_with("ses") on session ID — but the trigger path is different: here it's the --session CLI flag receiving a perfectly valid string from an external tool, not an internal dispatch bug.

Steps to Reproduce

  1. Run opencode with any well-formed string that doesn't start with ses:
    echo "hello" | opencode run --format json -m deepseek/deepseek-chat -s "my-custom-session-id"
  2. Observe the Zod validation error on stderr
  3. The process exits (exit code depends on version; see opencode run -s <missing-session-id> exits 0 with zero stdout instead of failing #27559)

Expected Behavior

The --session CLI flag should accept any valid string as a session identifier. OpenCode should either:

  • Option A: Relax the Zod schema to accept arbitrary session ID strings on the --session CLI path (while keeping stricter validation for internal API routes if needed)
  • Option B: If --session is only intended for internal opencode-generated IDs, then the CLI should surface a clear error message (e.g. "Session not found: ") with a non-zero exit code, rather than a raw Zod validation error

Actual Behavior

The Zod schema validation starts_with("ses") rejects the input before any session lookup occurs, producing a raw validation error that is indistinguishable from other Zod failures.

Environment

Additional Context

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions