Skip to content

fix: doctor continues past missing provider key and reports it as warning - #762

Merged
vladimirrott merged 5 commits into
lacs-project:mainfrom
sharmis-tp:fix/doctor-config-warning-647
Nov 17, 2026
Merged

vladimirrott merged 5 commits into
lacs-project:mainfrom
sharmis-tp:fix/doctor-config-warning-647

Conversation

@sharmis-tp

Copy link
Copy Markdown
Contributor

Summary

sysknife doctor stopped at a missing provider key before it ever contacted the daemon, and --json printed nothing. Scripts reading --json doctor got no JSON to parse, and the daemon — which may have been fine — was never checked.

Now run_doctor checks the daemon first and treats a BrainConfig::from_env() failure the way the MCP sysknife_doctor handler already does: provider and model read "unknown", and the error goes into a warnings list in both the text and JSON output. Exit code 4 is preserved for a broken config per docs/cli.md.

Related Issue

Fixes #647

Validation

  • Tests added or updated
  • Documentation updated if behavior changed
  • Security impact considered
  • Trust boundary preserved (daemon remains the only privileged executor)
  • CI passes
  • Every commit is signed off

Notes for Reviewers

The CLI now matches the MCP side's config-error handling (lines 1282-1291 in mcp_server.rs). No contract changes — the JSON gains provider, model, and warnings fields in the failure envelope where they were previously absent.

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to SysKnife, and thank you for taking #647. Moving BrainConfig::from_env() below the daemon check and reusing the MCP doctor's brain config unreadable: {e} wording with unknown placeholders makes sysknife doctor and the MCP doctor answer the same way on the same host. Your test parses stdout as JSON and pins provider, model and warnings, which is the assertion that fails when the old early return comes back. You also updated docs/cli.md where the issue pointed.

Three items before merge. The first two are small.

  1. Exit code for an older daemon. The distro-fallback note now goes into warnings (runner.rs:1065), and the exit code comes from warnings.is_empty() (runner.rs:1109). A daemon that answers but predates host_distro therefore exits 4 even with a valid config. On main that note only appears in the JSON and the exit code stays 0. tests/e2e/multi-vm-smoke.sh runs doctor --json per VM and aborts on any non-zero exit, so that setup would start failing. The issue's wording ("the error goes into a warnings list") pointed at this shape, so the miss is partly the issue's. Keep a separate config_warning: Option<String>, take the exit code from it, and print only that in the new text loops.
  2. A test for the branch the issue is about. The new test points SYSKNIFE_SOCKET at a path nothing listens on, so only the daemon-unreachable arm runs. When the daemon answers, no test checks the JSON warnings, the text warning or the exit code. apps/sysknife-cli/tests/remote_distro.rs has a fake daemon you can copy. Assert ok is true, provider is unknown, warnings names the missing key and the exit code is 4. A second test with a daemon that sends no distro and a valid config should exit 0.
  3. The test baseline. The PR adds one test, so tests/evidence/workspace-tests.json needs "tests": 2104 (it reads 2103) or the rust job fails in scripts/test_baseline.sh. UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh writes it. Run it after the tests from item 2, since they move the number again. If cargo-nextest is a hurdle, tell me and I will push the change to your branch.

Optional: the PR text says "No contract changes", and the exit code is part of that contract, so a line on it would help the next reader. Giving the test env_clear() and a temp HOME, as remote_distro.rs does, keeps a developer's own config out of it.

Your five CI runs wait for my approval because this is your first PR here. I will approve them after your next push so one run covers the final head. If you want another in the same area, #664 (--json progress lines between the JSON objects) and #561 (--dry-run exit code) are open.

@sharmis-tp

Copy link
Copy Markdown
Contributor Author

All three items addressed:

  1. Exit code for older daemon: Introduced config_warning: Option<String> in run_doctor. The exit code now derives from config_warning.is_none() instead of warnings.is_empty(). Distro-fallback notes still appear in warnings (JSON and stderr) but no longer affect the exit code — a daemon that answers with a valid config exits 0 even without host_distro.

  2. Tests for daemon-answers path: Two new tests in doctor_output.rs using a fake daemon (same protocol as remote_distro.rs):

    • daemon_answers_missing_config_key_exits_4 — daemon answers, SYSKNIFE_LLM_PROVIDER=anthropic without API key: asserts ok true, provider is unknown, warnings mentions the missing key, exit code 4.
    • daemon_answers_no_distro_valid_config_exits_0 — daemon answers without host_distro, valid ollama config: asserts ok true, exit code 0.
      Both tests use env_clear() and a temp HOME/XDG_CONFIG_HOME/XDG_DATA_HOME to isolate from developer config.
  3. Test baseline: Updated tests/evidence/workspace-tests.json from 2103 to 2105 (+2 new tests).

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fake daemon in doctor_output.rs speaks the real framing (length prefix, query_state, state_response) and lets each test decide whether host_distro is present. That makes the daemon-answers cases testable, and moving the exit code onto config_warning fixes the older-daemon case I raised.

I ran head 4863979f in a container with the network off:

  • cli_smoke ran 24 tests (23 passed, 1 ignored) and doctor_output ran 6, all passed, including daemon_answers_missing_config_key_exits_4 and daemon_answers_no_distro_valid_config_exits_0.
  • Mutants on run_doctor: reading the exit code from warnings.is_empty() turns daemon_answers_no_distro_valid_config_exits_0 red. Forcing Ok(()) and forcing config_warning to None each turn daemon_answers_missing_config_key_exits_4 red. Dropping the warnings.push turns that test and doctor_missing_provider_key_still_reports_json red. Inverting the exit branch turns both daemon tests red. A pristine run afterwards passed again.
  • docs/cli.md matches the code: exit 0 for a reachable daemon with a valid config, exit 4 otherwise.

Two items before merge.

  1. The test baseline is one short. The PR adds three tests: doctor_missing_provider_key_still_reports_json in cli_smoke.rs and two in doctor_output.rs. cargo test -p sysknife-cli --tests -- --list lists 381 tests on main and 384 on your head, so tests/evidence/workspace-tests.json should read 2106 and it reads 2105. The rust job will fail in scripts/test_baseline.sh. UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh writes the number. The first test is easy to miss because it was in the PR before the second round.
  2. The distro warning prints twice in text mode. On main, sysknife doctor prints warning: daemon distro unavailable... once, right after distro source:. On your head the new for w in &warnings loops print it a second time, in both arms. I ran the binary against a fake daemon that sends no host_distro, with a valid config: exit 0 as intended, and two identical warning lines. With the daemon unreachable it prints the warning before the failure text and again after it. My first review asked for the new text loops to print only the config warning, and I should have shown you this output then. Printing config_warning alone in both loops fixes it, and the JSON warnings array keeps both notes. A text-mode twin of daemon_answers_no_distro_valid_config_exits_0 (no --json, count the stderr lines that contain daemon distro unavailable, expect one) holds it.

security-audit is red on every branch since RUSTSEC-2026-0462 (rmcp). I opened #768 for the bump, so you have nothing to do there. After your next push I will use Update branch to bring in main (0.30.1 and the bump) and approve your five CI runs, so one run covers the final head. If cargo-nextest is a hurdle, tell me and I will push the baseline change to your branch.

Thank you for working through the daemon-answers path, which was the hard part of #647. #664 (--json progress lines between the JSON objects) and #561 (--dry-run exit code) are open if you want another in the same area.

@sharmis-tp

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review and for running the mutants.

Addressed both items:

  1. Test baseline — bumped to 2107 (2106 for the three existing tests + 1 for the new text-mode test below).
  2. Duplicate distro warning — both text-mode loops now print only config_warning, not all warnings. The JSON warnings array still carries both notes. Added daemon_no_distro_text_mode_warns_once which runs in text mode against the fake daemon with no distro and asserts the fallback warning appears exactly once in stderr.

Ready for another look.

vladimirrott
vladimirrott previously approved these changes Nov 10, 2026

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both text-mode loops now print only config_warning, and daemon_no_distro_text_mode_warns_once pins the fix with the fake daemon you already wrote. I approve the code at head 08ef7b619cb989ae6f3cb05db40d204cdc5cce52.

I put the new test through the merge gate in a container with the network off. It passes as written. With the old loops restored (s/if let Some(w) = &config_warning {/for w in \&warnings {/) it fails:

running 'daemon_no_distro_text_mode_warns_once' unmutated
rust suite: evidence of 1 executed unit(s), passing unmutated
applying the mutation and re-running
receipt recorded for #762 at 08ef7b61 (observed: clean pass, mutated fail)
observed_failure: test daemon_no_distro_text_mode_warns_once ... FAILED

One step left before merge, and it is mechanical. Your branch is behind main by six commits, and main also reads 2107 tests now, because #764 added three and #771 added one. Git merges the two "tests": 2107 lines without a conflict, so the merged tree would still say 2107 while it holds four more tests than that. I counted test attributes on each tree:

$ M=$(git merge-tree --write-tree origin/main p762); for r in 584f9f9f origin/main p762 $M; do n=$(git grep -hE '^\s*#\[(tokio::)?test' $r -- '*.rs' | wc -l); echo "$r attrs=$n evidence=$(git show $r:tests/evidence/workspace-tests.json | grep -oE '"tests": [0-9]+')"; done
584f9f9f attrs=2111 evidence="tests": 2103
origin/main attrs=2115 evidence="tests": 2107
p762 attrs=2115 evidence="tests": 2107
e09fe2f1d28ea87880b8a7f42661014702d5b019 attrs=2119 evidence="tests": 2107

The base gained four tests on each side, so the merged tree needs 2111. Merge or rebase onto main, then run UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh and push once. I said last time that I would press Update branch myself. I held off because that commit alone would leave the rust job red and cost you a second round of CI approvals, so one push from you covers both steps.

Once that lands I will check that the only new change since 08ef7b61 is the merge from main plus the evidence file, rerun the same mutation on the new head, and merge when every check is green. If the push carries any other code change, I will review it again first.

Thank you for staying with #647 through three rounds. You made doctor --json usable on the machine where it mattered most, the one with a broken config.

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One blocking item, and it's mechanical: the baseline commit 88966d5 has no Signed-off-by line, so the required dco check will fail once the runs start. Everything else at 88966d5 is what I asked for, and I'll approve as soon as that commit carries a sign-off.

The merge and the baseline are right. Your merge commit dcb3868 has the same tree git produces on its own (git merge-tree --write-tree origin/main 08ef7b61 gives e09fe2f1, and so does dcb3868^{tree}), so it resolved nothing by hand. Against main, your diff is the one I approved at 08ef7b6 plus the evidence file, and 2111 is the count I worked out in my last review.

I re-ran the mutation proof at the new head, in a container:

$ maintainer-merge verify 762 88966d58715202e8af41661ce3238576acc383a7 daemon_no_distro_text_mode_warns_once 's/if let Some(w) = &config_warning {/for w in \&warnings {/'
  rust suite: evidence of 1 executed unit(s), passing unmutated
  applying the mutation and re-running
  receipt recorded for #762 at 88966d58 (observed: clean pass, mutated fail)

The sign-off, with main's own DCO script:

$ bash scripts/check_dco.sh 9846ea2f 88966d58
dco: 88966d5 chore: update test baseline to 2111 after merge with main
     no Signed-off-by trailer from <[email protected]>

dco: 1 of 4 commits in 9846ea2..88966d5 lack a sign-off from their author.

The merge commit is exempt (the script skips merges). One way to fix it without touching the merge:

git commit --amend --no-edit -s
git push --force-with-lease

When that lands I'll check that the new head differs from 88966d5 only in the commit message, and re-approve. The workflow runs need my approval again on each push until your first merge, so a wait there is on my side. Two things could still move: if #777 merges first it also changes tests/evidence/workspace-tests.json, and the count would need one more UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh. If that happens, it's from the merge order and has nothing to do with your work.

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at d305d591409053c3f4e2929a6a653d326a2cf4a6. The sign-off is fixed, thank you. One mechanical item is left, and it comes from merge order, not from your work: the branch now conflicts with main on one line of tests/evidence/workspace-tests.json.

The amend changed only the commit message, as I hoped. The tree is the one I verified at 88966d5:

$ git rev-parse 88966d58^{tree} d305d591^{tree}
584f9d2d163a941e02a72740c8b06308493fa0fc
584f9d2d163a941e02a72740c8b06308493fa0fc
$ bash scripts/check_dco.sh 9846ea2f d305d591
dco: 4 commits in 9846ea2..d305d59 each carry their author's sign-off

The guard still bites at this head:

$ maintainer-merge verify 762 d305d591409053c3f4e2929a6a653d326a2cf4a6 daemon_no_distro_text_mode_warns_once 's/if let Some(w) = &config_warning {/for w in \&warnings {/'
  rust suite: evidence of 1 executed unit(s), passing unmutated
  applying the mutation and re-running
  receipt recorded for #762 at d305d591 (observed: clean pass, mutated fail)

The conflict is the one I warned about last time: #777 merged and moved the baseline on main from 2107 to 2108, while your branch moves it from 2107 to 2111.

$ git merge-tree --write-tree --name-only origin/main d305d591
CONFLICT (content): Merge conflict in tests/evidence/workspace-tests.json

GitHub runs no checks on a conflicted branch, which is why this head shows none. To fix it:

git fetch upstream && git merge upstream/main     # take either side of the conflict
UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh   # records the merged count
git commit -s -am "chore: update test baseline after merge with main"
git push

By arithmetic the count should land on 2112 (2108 on main plus your four), but the script decides, not me. Once that push lands I'll check that nothing outside the evidence file changed against this head, and approve.

@sharmis-tp
sharmis-tp force-pushed the fix/doctor-config-warning-647 branch from d305d59 to fc9ec9d Compare November 16, 2026 05:30
vladimirrott
vladimirrott previously approved these changes Nov 16, 2026

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at fc9ec9da5bd956727694dc4a3029456f3b418dcc. Approving it. Thank you for coming back to this; the rebase onto main dropped the merge commit and left three signed-off commits, which is a cleaner history than the one I approved.

The rebase carried no new code. I compared the patch I approved at d305d591 with this one, every added and removed line outside the evidence file:

$ diff <(git diff $(git merge-base origin/main d305d591) d305d591 -- . ':!tests/evidence' | grep -E '^[+-][^+-]') <(git diff origin/main...p762 -- . ':!tests/evidence' | grep -E '^[+-][^+-]') && echo IDENTICAL
IDENTICAL

$ bash scripts/check_dco.sh $(git merge-base origin/main p762) p762
dco: 3 commits in b83fda8..fc9ec9d each carry their author's sign-off

2118 is right for the main you rebased onto (2114 at b83fda8, plus your four tests), and the guard still bites:

$ maintainer-merge verify 762 fc9ec9da5bd956727694dc4a3029456f3b418dcc daemon_no_distro_text_mode_warns_once 's/if let Some(w) = &config_warning {/for w in \&warnings {/'
  rust suite: evidence of 1 executed unit(s), passing unmutated
  applying the mutation and re-running
  receipt recorded for #762 at fc9ec9da (observed: clean pass, mutated fail)

One mechanical item is left, and it comes from merge order: main has moved twice since b83fda8, the second time when I merged #784 today, so the evidence file conflicts again.

$ git merge-tree --write-tree --name-only origin/main fc9ec9da
3caec5a7273f629095f459707201400388490ad6
tests/evidence/workspace-tests.json

Auto-merging apps/sysknife-cli/src/runner.rs
Auto-merging apps/sysknife-cli/tests/cli_smoke.rs
Auto-merging docs/cli.md
Auto-merging tests/evidence/workspace-tests.json
CONFLICT (content): Merge conflict in tests/evidence/workspace-tests.json
git fetch upstream && git rebase upstream/main     # take either side of the conflict
UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh   # records the merged count
git commit -s -am "chore: refresh workspace test baseline"
git push --force-with-lease

The count should land on 2132 (2128 on main plus your four). When that is the only change against this head, I'll re-run the mutation and merge it.

@vladimirrott

Copy link
Copy Markdown
Member

A correction to the commands in my review: with git rebase, two of your commits touch the evidence file, so you would hit the conflict twice and need git add and git rebase --continue each time. A merge is one step:

git fetch upstream && git merge upstream/main      # take either side of the conflict
UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh   # records the merged count
git commit -s -am "chore: merge main and refresh workspace test baseline"
git push

Either way works for me; the target is still 2132.

@sharmis-tp

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (b3eb865). Evidence file lands on 2132 (2128 upstream + 4 ours). Three signed-off commits preserved.

vladimirrott
vladimirrott previously approved these changes Nov 17, 2026

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 1e04a30. Thanks for the rebase and for keeping all three commits signed off.

I rebuilt main plus the head I approved yesterday (fc9ec9d) with git merge-tree, and git diff --stat from that tree to 1e04a30 lists tests/evidence/workspace-tests.json and nothing else, at 2132 (2128 plus your 4 tests). The merge gate re-ran the warns-once guard at this head in a container:

maintainer-merge verify 762 1e04a30e690917bdbcb73c32dc004d092d01a10d daemon_no_distro_text_mode_warns_once 's/if let Some(w) = &config_warning {/for w in \&warnings {/'
  receipt recorded for #762 at 1e04a30e (observed: clean pass, mutated fail)

One more baseline step, and it is a sneaky one. I merged #785 about half an hour ago, and it also moved main to 2132. Your file and main's now hold the same number, so git merges them without a conflict (git merge-tree --write-tree --name-only origin/main 1e04a30e prints only the tree id), but the merged tree should count 2132 + 4 = 2136. Please merge main again and run UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh; it should record 2136.

The workflow runs on this PR are waiting for a maintainer to approve them, which is on my side to do. Nothing for you to fix there.

Merge origin/main into the branch and set tests/evidence/workspace-tests.json to main's count plus the 4 test(s) this branch adds.

Signed-off-by: Vladimir Rotariu <[email protected]>
The format check on the rust job failed on two hunks in apps/sysknife-cli/tests/doctor_output.rs. This commit is the output of cargo fmt --all and changes no behaviour.

Signed-off-by: Vladimir Rotariu <[email protected]>

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving at 6a19b81.

Two mechanical commits on top of the head I approved (1e04a30), neither touching your logic:

  • 3cf6bfb merges main and sets the baseline in tests/evidence/workspace-tests.json to 2140: 2136 on main plus the four tests this PR adds.
  • 6a19b81 runs cargo fmt --all. The rust job's format check failed on two hunks in apps/sysknife-cli/tests/doctor_output.rs (around lines 167 and 224), and this is the formatter's output for them. Your first-contribution workflow runs had been waiting for approval, so the failure had not shown yet. I approved the runs for both heads.

The gate receipt is recorded at 6a19b81: maintainer-merge verify 762 6a19b816... daemon_no_distro_text_mode_warns_once, with if let Some(w) = &config_warning { replaced by for w in &warnings {, printed receipt recorded for #762 at 6a19b816 (observed: clean pass, mutated fail). All 14 checks are green on this head.

Thank you for the long patience through the review rounds. Merging now.

@vladimirrott
vladimirrott merged commit e167637 into lacs-project:main Nov 17, 2026
14 checks passed
vladimirrott added a commit that referenced this pull request Nov 17, 2026
…790 (#805)

Eight merged pull requests had no Unreleased entry.

Signed-off-by: Vladimir Rotariu <[email protected]>
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.

sysknife doctor stops at a missing provider key before checking the daemon, and --json prints nothing

2 participants