Skip to content

crit on a clean working tree: misleading "could not reach daemon" instead of "no changed files" #438

@perbu

Description

@perbu

Summary

Running crit (or go run .) in a git repo with a clean working tree exits with:

Started crit daemon at http://localhost:61736 (PID 19104)
Error: could not reach daemon on port 61736: Get "http://127.0.0.1:61736/api/session": dial tcp 127.0.0.1:61736: connect: connection refused
exit status 1

The actual cause is no changed files detected (after applying ignore patterns), but that message never reaches the user.

Reproduction

  1. cd into a clean git repo (no uncommitted changes, branch == base branch or equivalent).
  2. Run crit (or go run .).
  3. Observe the misleading "could not reach daemon" / connection refused error.

Root cause (from a quick read of cli_serve.go / daemon.go)

In runServe (cli_serve.go:369):

  1. bindListener succeeds.
  2. signalReadiness(pipe, addr.Port) fires at line 456 — parent startDaemon returns successfully and prints "Started crit daemon at …".
  3. createSession runs concurrently (line 485) and immediately returns "no changed files detected".
  4. The initErr path (lines 498–510) calls stop(), removeSessionFile(key), and httpServer.Shutdown(...) — daemon exits.
  5. The client polls /api/session and gets "connection refused" because the listener is already gone.
  6. removeSessionFile (daemon.go:142) also deletes ~/.crit/sessions/<key>.log, so the real error is unrecoverable after the fact.

Suggested fixes (pick one or more)

  • Validate before signaling readiness: detect the no-changes condition before signalReadiness, and report via daemonFatal so the parent surfaces the real message.
  • Preserve the log on init failure: skip log cleanup (or rename to <key>.failed.log) when shutdown is triggered by initErr, so users have a forensic trail.
  • Advise the user that the software needs a plan: when there are no changed files, the friendly message should point to the alternatives — pass file arguments (`crit `), use plan mode (`crit plan ...`), or switch branches — instead of just stating the bare condition.

Environment

  • crit @ commit 95b8ab7 (main)
  • macOS / darwin 25.3.0
  • Go: built from source via `go run .`

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