Skip to content

fix: exit non-zero when doctor, stop --all or snapshot delete fail - #22

Merged
Asdivyansh merged 2 commits into
SilosLabs:mainfrom
TheDreamSaver:fix/exit-codes-on-failure
Nov 16, 2026
Merged

Asdivyansh merged 2 commits into
SilosLabs:mainfrom
TheDreamSaver:fix/exit-codes-on-failure

Conversation

@TheDreamSaver

Copy link
Copy Markdown
Member

Fixes #21

Problem

doctor, stop --all and snapshot delete reported failure but exited 0. A script or CI step running them couldn't tell anything had gone wrong, and stop --all even printed "Sandbox shut down cleanly." after a container failed to stop.

Change

  • doctor: a new reportResults() prints as before, then sets process.exitCode = 1 if any check failed. That covers both the "not configured" early return and the full run. Warnings alone still exit 0.
  • stop --all:
    • stopAllAgents() now returns which containers failed. runStop collects those, plus a proxy that couldn't be stopped.
    • On any failure it prints Could not stop: … instead of "shut down cleanly" and exits 1. The rest of the shutdown (config, network cleanup) still runs.
    • A failed docker ps is now reported instead of being treated as "no containers".
  • snapshot delete: exits 1 when docker rmi fails.
  • Docs: docs/cli-reference.md notes the exit behaviour for all three.

All three use process.exitCode rather than process.exit(), so output flushes and cleanup still runs.

Tests

The new cases in tests/cli.test.ts run the real CLI (node --import tsx src/cli.ts) with a temp HOME, a real config written through writeConfig, and a fake docker on PATH. The fake fails on demand: everything, rmi, or rm of one container.

Case main this branch
doctor, Docker down, not configured exit 0 exit 1
stop --all, silo-b can't be removed exit 0, "shut down cleanly" exit 1, "Could not stop: silo-b"
snapshot delete missing exit 0 exit 1
stop --all, everything stops exit 0 exit 0
snapshot delete present exit 0 exit 0

The three failure cases fail on main and pass here. npm run typecheck, npm test (357 passing) and npm run build are green, and the branch merges cleanly with #13.

Not in this PR:

  • integrations test, which also exits 0 when an integration is unreachable. That function needs the bigger fix tracked as "integrations test checks what it claims".
  • run on an LLM error. It needs a live sandbox to reproduce, so it belongs with the run robustness work.

These commands reported failure but still exited 0, so a script or CI job
couldn't tell that anything went wrong:

- doctor printed "N critical issue(s) found" and exited 0.
- stop --all carried on past a container it couldn't remove (and a proxy it
  couldn't stop), then printed "Sandbox shut down cleanly." and exited 0.
- snapshot delete printed "not found or could not be deleted" and exited 0.

Each now sets process.exitCode = 1 on failure, so output still flushes and
the rest of stop's shutdown still runs. stop names what it couldn't stop
instead of claiming a clean shutdown. doctor warnings alone still exit 0.

CLI tests run the real entry point with a fake docker on PATH and a temp
HOME; the three failure cases fail on main and pass here.
Fixes SilosLabs#21
On Linux, conf keeps its config under $XDG_CONFIG_HOME when that is set,
regardless of HOME, and CI runners set it. Every CLI test therefore read and
wrote the runner's real config directory: the config written for the
snapshot/stop tests leaked into the doctor test's HOME, failed to decrypt
(its key is derived from a different HOME) and doctor aborted with
"Unsupported state or unable to authenticate data". macOS ignores
XDG_CONFIG_HOME, so this only showed up in CI.

Point XDG_CONFIG_HOME inside each temp HOME for every spawned CLI.
@TheDreamSaver

Copy link
Copy Markdown
Member Author

The first CI run failed only on the new doctor test, and only on Linux. On Linux, conf stores the config under $XDG_CONFIG_HOME when it's set, and GitHub's runners set it. So every throwaway HOME in tests/cli.test.ts shared the runner's real config directory: the config written for the stop/snapshot tests leaked into the doctor test and failed to decrypt there, because the key is derived from HOME. macOS ignores XDG_CONFIG_HOME, which is why it passed locally.

c8d412d pins XDG_CONFIG_HOME inside each temp HOME for every spawned CLI, including the existing exit-code tests from #18. CI is green now.

@Asdivyansh
Asdivyansh merged commit da9b2d5 into SilosLabs:main Nov 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doctor, stop --all and snapshot delete exit 0 when they fail

2 participants