Repository navigation
CLI service: job, sweep and preparation statuses as enums - #121
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
🟢 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The code review survey asked for this as a separate PR: the CLI service's run statuses become idiomatic Rust enums.
Before
JobandSweepRunkept 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.PrepareRunkept its status as the"status"key of aMutex<serde_json::Value>, so a typo still compiled.running, and internally it was indistinguishable from one that was actually running.After
JobStatehas the variantsQueued,Running,Completed(Collected),Failed { diagnostics }andCancelled(Option<Collected>), whereCollectedis the job's kind, document and notices. A job isQueueduntil it gets the collecting turn, thenRunning. Both still serialize asrunning, because clients keep polling while a job runs.value()andrunning()match on the variant exhaustively.SweepStatushas the variantsRunning,Completed,Failed(error)andCancelled(Option<error>).PrepareStatushas the variantsRunning,Succeeded(report),Failed(error)andCancelled(error). It sits beside the progress events in a typedProgress, 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 warningsandcargo fmtpass forprojections-cli.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_askedandhistory::sweeps_skip_projections_that_need_trustpass.native_collection_comparison…andsweeps_run_projections…. They need the default comparator built (npm run build), and fail the same way without this change. CI runs them.