Skip to content

fix: report a clear cli error when no herdr server is running - #1963

Open
season179 wants to merge 2 commits into
herdrdev:masterfrom
season179:issue/1941-cli-server-not-running
Open

fix: report a clear cli error when no herdr server is running#1963
season179 wants to merge 2 commits into
herdrdev:masterfrom
season179:issue/1941-cli-server-not-running

Conversation

@season179

Copy link
Copy Markdown
Contributor

Current behavior

With no herdr server running, every socket CLI command fails with a raw debug string:

$ herdr workspace create --cwd /tmp --label test
Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }

It reads like the --cwd path is invalid, which is exactly how #1941 was reported. A stale socket file (ConnectionRefused) and every other workspace/tab/pane/agent/worktree command produce the same raw output.

What this does

Dead-socket connect failures from the guarded CLI request path (ErrorKind::NotFound | ConnectionRefused — kind-based so Windows named pipes classify the same) map to a marker error carrying a server_not_running ErrorResponse, mirroring the existing protocol_guard pattern. The edge that surfaces the error prints it exactly once:

$ herdr workspace create --cwd /tmp --label test
{"id":"cli:workspace:create","error":{"code":"server_not_running","message":"no herdr server is running at /Users/me/.config/herdr/herdr.sock; run `herdr` to start one"}}

Exit codes are unchanged (server errors 1, syntax errors 2). Printing is deferred — the marker carries the response — so callers that intentionally recover from a dead server keep their behavior with nothing printed:

  • plugin commands still fall back to the offline registry (plugin list --json → offline result, exit 0, empty stderr)
  • herdr status still reports status: not running
  • agent start transport failures print exactly one error line
  • session stop messaging unchanged

The shared classifier replaces the private copy in cli/status.rs. No wire protocol change (CLI-emitted error, like protocol_mismatch) and no server auto-start behavior.

Validation

  • just check green on macOS (zig 0.15.2 via homebrew) except one pre-existing failure unrelated to this change: live_handoff_keeps_unmanaged_agent_name_bound_to_saved_session fails identically on clean master @ 1491b7d
  • two focused regression tests: dead-server mapping (request id, code, socket path in message, marker recognizable without string matching) and a classifier negative case
  • manually verified: dead socket → single JSON error + exit 1 across command groups; status graceful; positive path against a live server unchanged; plugin offline fallback behavior identical to v0.7.5

refs #1941

socket cli commands surfaced a raw io::Error debug string
(`Error: Os { code: 2, ... }`) when nothing was listening on the
api socket, which read like a bad --cwd path. map dead-socket
connect failures to a `server_not_running` json error carrying the
resolved socket path, printed once at the edge that surfaces the
error; recovering callers (plugin offline registry fallback, agent
start polling) recognize the marker and keep their existing
behavior.

refs herdrdev#1941
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5c222dc5-0fc1-44c9-bff7-efa82ac1bc9d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@kangal-bot kangal-bot added coderabbit-review greptile-review Trigger Greptile review for contributor-approved pull requests labels Jul 28, 2026
@season179
season179 marked this pull request as ready for review July 28, 2026 04:50
@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown

Greptile Summary

Maps dead-socket CLI connect failures to a deferred server_not_running JSON error while preserving recover paths.

  • Shared kind-based classifier and ServerNotRunningReported marker in server_not_running / cli.rs
  • send_request and send_request_unchecked both map NotFound/ConnectionRefused to the marker
  • main and agent transport print the deferred response once; plugin offline fallback still treats the marker as a connection error
  • Status reuses the shared classifier; focused unit tests cover mapping and negative kinds

Confidence Score: 5/5

The PR appears safe to merge; the prior unchecked-path gap is fixed and no blocking failure remains.

send_request_unchecked now applies the same dead-server mapping as send_request, so callers get the deferred server_not_running marker; recover paths and single-print edges remain consistent.

Important Files Changed

Filename Overview
src/cli.rs Friendly dead-server mapping on both send_request and send_request_unchecked, plus classifier helpers and tests.
src/cli/server_not_running.rs Deferred marker error carrying ErrorResponse, mirroring protocol_guard style without eager print.
src/main.rs Prints carried server_not_running JSON once and exits 1 when the marker reaches main.
src/cli/agent.rs Surfaces deferred server_not_running response instead of a second generic transport line.
src/cli/plugin.rs Treats the marker as a connection error so offline registry fallback still prints nothing.
src/cli/status.rs Uses shared server_not_running_error classifier; not-running status path unchanged in behavior.

Reviews (2): Last reviewed commit: "fix: map dead-socket errors on the unche..." | Re-trigger Greptile

Comment thread src/cli.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coderabbit-review greptile-review Trigger Greptile review for contributor-approved pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants