Skip to content

CLI service: job, sweep and preparation statuses as enums - #121

Merged
agorischek merged 1 commit into
mainfrom
cli-run-status-enums
Nov 21, 2026
Merged

agorischek merged 1 commit into
mainfrom
cli-run-status-enums

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

The code review survey asked for this as a separate PR: the CLI service's run statuses become idiomatic Rust enums.

Before

  • Job and SweepRun kept their status as a &'static str, with the outcome in optional fields beside it. That allowed contradictory states, such as a cancelled job holding a document and diagnostics at once.
  • PrepareRun kept its status as the "status" key of a Mutex<serde_json::Value>, so a typo still compiled.
  • A queued job reported running, and internally it was indistinguishable from one that was actually running.

After

  • JobState has the variants Queued, Running, Completed(Collected), Failed { diagnostics } and Cancelled(Option<Collected>), where Collected is the job's kind, document and notices. A job is Queued until it gets the collecting turn, then Running. Both still serialize as running, because clients keep polling while a job runs. value() and running() match on the variant exhaustively.
  • SweepStatus has the variants Running, Completed, Failed(error) and Cancelled(Option<error>).
  • PrepareStatus has the variants Running, Succeeded(report), Failed(error) and Cancelled(error). It sits beside the progress events in a typed Progress, and the run's revision is its own field.

The JSON is unchanged, with one exception: a cancelled job no longer reports the diagnostics of the error that its cancellation caused.

Rust only. It doesn't depend on #110.

Verification

  • cargo check, cargo clippy -D warnings and cargo fmt pass for projections-cli.
  • Service tests jobs::concurrent_posts_are_bounded_and_cancel_waits_for_process_cleanup, jobs::shutdown_cancels_native_process_before_returning, history::sweeps_take_pairs_and_stop_when_asked and history::sweeps_skip_projections_that_need_trust pass.
  • Two tests fail locally: native_collection_comparison… and sweeps_run_projections…. They need the default comparator built (npm run build), and fail the same way without this change. CI runs them.

Statuses were strings: `&'static str` for jobs and sweeps, with the outcome in optional fields beside them, and a
`serde_json::Value` with a "status" key for preparations, where a typo compiles. A queued job reported "running" and
looked like a running one. A cancelled job could hold a document and diagnostics at once.

- `JobState`: Queued, Running, Completed(collected), Failed{diagnostics}, Cancelled(collected, if any). A job is
  Queued until it has the collecting turn, then Running. Both are still `running` on the wire, since clients poll
  while a job is.
- `SweepStatus`: Running, Completed, Failed(error), Cancelled(error, if it also failed).
- `PrepareStatus`: Running, Succeeded(report), Failed(error), Cancelled(error), beside the progress events.

The JSON is the same, except that a cancelled job no longer carries the diagnostics of the error its cancellation
caused.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the typed-status refactor.

No open issues 🎉

What changed in this PR

Refactors CLI service job, sweep, and environment preparation statuses into Rust enums, tying outcomes to their valid states while preserving the existing JSON interface except for cancelled-job diagnostics.

Changes:

  • Distinguishes queued jobs from running jobs internally; both still serialize as running.
  • Replaces string and JSON-based statuses with typed states carrying results or errors.
  • Stops reporting error diagnostics for cancelled jobs.
File Description
packages/​cli/​src/​service/​sweeps.rs Adds SweepStatus with associated errors and preserves response serialization.
packages/​cli/​src/​service/​prepare.rs Introduces typed preparation status and progress, with revision stored separately.
packages/​cli/​src/​service/​jobs.rs Introduces JobState and collected results, including explicit queue and cancellation states.

Review effort: Balanced

@agorischek
agorischek merged commit 4bba7d7 into main Nov 21, 2026
63 checks passed
@agorischek
agorischek deleted the cli-run-status-enums branch November 21, 2026 00:33
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.

2 participants