Repository navigation
fix: doctor continues past missing provider key and reports it as warning - #762
Conversation
vladimirrott
left a comment
There was a problem hiding this comment.
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.
- Exit code for an older daemon. The distro-fallback note now goes into
warnings(runner.rs:1065), and the exit code comes fromwarnings.is_empty()(runner.rs:1109). A daemon that answers but predateshost_distrotherefore 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.shrunsdoctor --jsonper VM and aborts on any non-zero exit, so that setup would start failing. The issue's wording ("the error goes into awarningslist") pointed at this shape, so the miss is partly the issue's. Keep a separateconfig_warning: Option<String>, take the exit code from it, and print only that in the new text loops. - A test for the branch the issue is about. The new test points
SYSKNIFE_SOCKETat a path nothing listens on, so only the daemon-unreachable arm runs. When the daemon answers, no test checks the JSONwarnings, the text warning or the exit code.apps/sysknife-cli/tests/remote_distro.rshas a fake daemon you can copy. Assertokis true,providerisunknown,warningsnames 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. - The test baseline. The PR adds one test, so
tests/evidence/workspace-tests.jsonneeds"tests": 2104(it reads 2103) or therustjob fails inscripts/test_baseline.sh.UPDATE_TEST_BASELINE=1 scripts/test_baseline.shwrites 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.
|
All three items addressed:
|
vladimirrott
left a comment
There was a problem hiding this comment.
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_smokeran 24 tests (23 passed, 1 ignored) anddoctor_outputran 6, all passed, includingdaemon_answers_missing_config_key_exits_4anddaemon_answers_no_distro_valid_config_exits_0.- Mutants on
run_doctor: reading the exit code fromwarnings.is_empty()turnsdaemon_answers_no_distro_valid_config_exits_0red. ForcingOk(())and forcingconfig_warningtoNoneeach turndaemon_answers_missing_config_key_exits_4red. Dropping thewarnings.pushturns that test anddoctor_missing_provider_key_still_reports_jsonred. Inverting the exit branch turns both daemon tests red. A pristine run afterwards passed again. docs/cli.mdmatches the code: exit 0 for a reachable daemon with a valid config, exit 4 otherwise.
Two items before merge.
- The test baseline is one short. The PR adds three tests:
doctor_missing_provider_key_still_reports_jsonincli_smoke.rsand two indoctor_output.rs.cargo test -p sysknife-cli --tests -- --listlists 381 tests on main and 384 on your head, sotests/evidence/workspace-tests.jsonshould read 2106 and it reads 2105. Therustjob will fail inscripts/test_baseline.sh.UPDATE_TEST_BASELINE=1 scripts/test_baseline.shwrites the number. The first test is easy to miss because it was in the PR before the second round. - The distro warning prints twice in text mode. On main,
sysknife doctorprintswarning: daemon distro unavailable...once, right afterdistro source:. On your head the newfor w in &warningsloops print it a second time, in both arms. I ran the binary against a fake daemon that sends nohost_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. Printingconfig_warningalone in both loops fixes it, and the JSONwarningsarray keeps both notes. A text-mode twin ofdaemon_answers_no_distro_valid_config_exits_0(no--json, count the stderr lines that containdaemon 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.
|
Thanks for the thorough review and for running the mutants. Addressed both items:
Ready for another look. |
vladimirrott
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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-leaseWhen 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.
88966d5 to
d305d59
Compare
vladimirrott
left a comment
There was a problem hiding this comment.
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 pushBy 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.
d305d59 to
fc9ec9d
Compare
vladimirrott
left a comment
There was a problem hiding this comment.
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-leaseThe 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.
|
A correction to the commands in my review: with 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 pushEither way works for me; the target is still 2132. |
…ning Signed-off-by: Suzuki Taro <[email protected]>
Signed-off-by: sharmis-tp <[email protected]>
… test Signed-off-by: sharmis-tp <[email protected]>
fc9ec9d to
1e04a30
Compare
|
Rebased onto current main (b3eb865). Evidence file lands on 2132 (2128 upstream + 4 ours). Three signed-off commits preserved. |
vladimirrott
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.jsonto 2140: 2136 on main plus the four tests this PR adds. - 6a19b81 runs
cargo fmt --all. Therustjob's format check failed on two hunks inapps/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.
Summary
sysknife doctorstopped at a missing provider key before it ever contacted the daemon, and--jsonprinted nothing. Scripts reading--json doctorgot no JSON to parse, and the daemon — which may have been fine — was never checked.Now
run_doctorchecks the daemon first and treats aBrainConfig::from_env()failure the way the MCPsysknife_doctorhandler already does:providerandmodelread"unknown", and the error goes into awarningslist in both the text and JSON output. Exit code 4 is preserved for a broken config perdocs/cli.md.Related Issue
Fixes #647
Validation
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 gainsprovider,model, andwarningsfields in the failure envelope where they were previously absent.