Skip to content

fix(cli): emit daemon progress as its own JSON event - #771

Merged
vladimirrott merged 1 commit into
lacs-project:mainfrom
yuee3:fix/json-progress-events
Nov 10, 2026
Merged

vladimirrott merged 1 commit into
lacs-project:mainfrom
yuee3:fix/json-progress-events

Conversation

@yuee3

@yuee3 yuee3 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Closes #664.

Bug

--json documents NDJSON — "one JSON object per event" — but the execute callback passed the daemon's progress frames straight to log.println. With a daemon double streaming two frames, execute_plan printed:

{"plan":{"intent":"test","preference_changes":[],"steps":[{"action":"GetMemoryInfo","params":{},"risk":"low","summary":"GetMemoryInfo"}],"summary":"test plan"}}
{"summary":"mock preview","risk_level":"low","current_state":{},"proposed_change":{},"expected_side_effects":[],"reboot_required":false,"rollback_available":false,"warnings":[],"request_hash":"mock-request"}
Authorization passed for GetMemoryInfo
Executing GetMemoryInfo...
{"status":"succeeded","summary":"mock done","warnings":[],"job_id":null,"needs_reboot":false,"rollback_ref":null,"transaction_id":"GetMemoryInfo"}

Anything that parses every line dies on the fourth — including the sysknife --dry-run --json "…" | jq '.plan.steps[].action' example in docs/cli.md.

Change

The JSON arm prints {"event":"progress","line":"…"} instead. The human renderer is untouched; the only other edits are the --json row and the schema block in docs/cli.md, plus the recorded test count. No refactor, no new dependency.

Evidence

Test written first, run against the unfixed arm:

thread '…execute_plan_json_emits_progress_as_its_own_event' panicked at runner.rs:4355:
--json printed a line that is not JSON (expected value at line 1 column 1): "Authorization passed for GetMemoryInfo"

After the fix:

{"plan":{…}}
{"summary":"mock preview",…}
{"event":"progress","line":"Authorization passed for GetMemoryInfo"}
{"event":"progress","line":"Executing GetMemoryInfo..."}
{"status":"succeeded",…}

The test drives execute_plan with opts.json = true against a daemon double (the existing mock now takes a progress_lines list), then asserts every emitted line parses and that the daemon's text survives as a progress event — so silently swallowing progress fails it too.

Checks

  • UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh → 2107 tests run: 2107 passed, 8 skipped, baseline 2106 → 2107 (WSL ext4, non-root)
  • cargo nextest run -p sysknife-cli → all green
  • cargo fmt --check clean, cargo clippy --workspace --all-targets --locked -- -D warnings clean

Duplicate check

No open PR mentions #664; git log has no change to this arm since it was written. The issue's claim was released by @anyingiit and reopened to other contributors on 2026-11-05; I noted my take there before starting.

`--json` promises NDJSON, but the execute callback passed the daemon's
progress frames straight to `log.println`. A run printed

    {"plan": {…}}
    {"summary": "mock preview", …}
    Authorization passed for GetMemoryInfo
    Executing GetMemoryInfo...
    {"status": "succeeded", …}

so any consumer that parses every line — the `jq` pipeline documented
under Examples — dies on the first progress frame.

Print them as `{"event": "progress", "line": …}` instead. The human
renderer is untouched.

The regression test drives `execute_plan` with `opts.json = true` against a
daemon double streaming two progress frames, then parses every emitted
line. Reverting the JSON arm to `log.println(line)` fails it on the first
frame.

Signed-off-by: yuee3 <[email protected]>
@yuee3
yuee3 requested a review from vladimirrott as a code owner November 10, 2026 02:09

@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 05adac4d. Approving.

You picked the right layer for the test. It drives execute_plan itself against the daemon double, so it covers the one call site that streams progress (execute_step_checked in the main loop), and teaching the mock to send job_progress frames per action means the next --json test gets that for free. The second assertion matters too: a fix that dropped progress text would also produce valid NDJSON, and your any(line == "Executing GetMemoryInfo...") check rejects it.

What I checked:

  • The frame shape. DaemonResponse::JobProgress { job_id, line } in crates/sysknife-daemon/src/dispatcher.rs matches what the mock sends, and client.rs strips ANSI before on_line sees it, so the new object carries plain text.

  • Callers. execute_step_checked in runner.rs is the only place the CLI hands progress to a JSON-aware callback; the MCP server calls execute_with_outcome and collects the lines into its own result. The E2E stories run --dry-run --json, which never executes, so they see no new event.

  • The fix reverted. I ran your test in a container at this head, then again with the JSON arm put back to log.println(line);:

    receipt recorded for #771 at 05adac4d (observed: clean pass, mutated fail)
    observed_failure: test runner::tests::plan_preflight_tests::execute_plan_json_emits_progress_as_its_own_event ... FAILED
    
  • The other direction, with the arm replaced by let _ = line; so progress vanishes and every printed line stays valid JSON:

    running 1 test
    thread 'runner::tests::plan_preflight_tests::execute_plan_json_emits_progress_as_its_own_event' (7182) panicked at apps/sysknife-cli/src/runner.rs:4368:13:
    the daemon's progress text is not in the output: []
    test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 349 filtered out; finished in 0.00s
    
  • CI: all required checks pass, dco included. The evidence file goes 2106 → 2107 from the same base as main, so no conflict.

Nothing blocks. I'll add the CHANGELOG entry myself when it lands.

Once this merges, tell me if you want another one. The CLI's output contract keeps turning up small gaps like this one, and you've now fixed two of them.

@vladimirrott
vladimirrott merged commit 9846ea2 into lacs-project:main Nov 10, 2026
14 checks passed
@yuee3

yuee3 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — yes, I'd like another one.

Do you have a specific direction in mind, or are there known output-contract gaps left after #757 that I should pick up? Either way is fine; if there's no shortlist I can sweep the CLI's output surfaces (--json per subcommand, --dry-run vs execute, exit codes, stdout/stderr split) and propose candidates with a reproduction first.

@vladimirrott

Copy link
Copy Markdown
Member

@yuee3 Yes, I have one: #561. --dry-run exits 0 for a plan that --max-risk would refuse, so a pre-flight check built on --dry-run --json passes plans the real run rejects. It's the exit-code side of the contract you fixed in #757 and here. I left the details on the issue.

Your sweep is welcome as well. If you find a gap and can reproduce it, open an issue with the reproduction and I'll label it. Keep it separate from #561 so neither waits on the other.

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 --json prints the daemon's progress lines raw between the JSON objects, so jq fails on any executed run

2 participants