Skip to content

feat(profile): thread PublishRegime through preflight to publish (#106 PR 1)#154

Merged
EffortlessSteven merged 3 commits into
mainfrom
feat/106-publish-regime-data-flow
Apr 21, 2026
Merged

feat(profile): thread PublishRegime through preflight to publish (#106 PR 1)#154
EffortlessSteven merged 3 commits into
mainfrom
feat/106-publish-regime-data-flow

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

PR 1 of the 5-PR sequence outlined by the scout on issue #106. Threads a new PublishRegime enum (FirstPublish | Update) from preflight onto each PlannedPackage so the publish retry loop can answer "is this a brand-new crate?" by reading the plan instead of re-querying the registry on every rate-limit retry.

This eliminates the is_new_crate_cached re-query waste called out by the scout's plan and unblocks PRs 2-5 (RegistryProfile, Retry-After parsing, duration estimation, per-crate tuning).

Changes

  • shipper-types: new PublishRegime enum (FirstPublish | Update) with is_new_crate() helper and round-trip serde tests.
  • PlannedPackage: gains regime: Option<PublishRegime>.
  • engine::run_preflight: now takes &mut PlannedWorkspace and stamps the detected regime onto each package after the existing registry probes; new tests cover both FirstPublish and Update stamping.
  • engine::publish_package (sequential and parallel): seeds is_new_crate_cached from p.regime when present, falling back to the legacy lazy-cached re-query when None.
  • CLI: passes &mut planned to run_preflight.
  • All call sites and constructors of PlannedPackage (production + tests + property/stress tests) updated with regime: None to remain compilable.

Backward compatibility

The new field is gated by #[serde(default, skip_serializing_if = \"Option::is_none\")]:

  • Read: legacy state.json / plan files written before this PR deserialize cleanly with regime: None.
  • Write: when regime is None, the field is omitted entirely (no \"regime\": null), so snapshots stay byte-for-byte identical for callers that never set it.
  • Behavior: the None branch in publish_package preserves the legacy is_new_crate_cached re-query path verbatim, so any embedder constructing PlannedPackage directly retains today's behavior.

Three serde tests in shipper-types lock this in:

  • planned_package_backward_compat_no_regime_field — legacy JSON deserializes cleanly with regime: None.
  • planned_package_regime_none_is_skipped_in_serializationNone is omitted on serialize.
  • planned_package_regime_some_round_trips — both variants round-trip via snake_case wire format.

Acceptance criteria (from #106 PR 1)

  • PublishRegime defined with FirstPublish and Update variants
  • PlannedPackage.regime plumbed through plan -> preflight -> publish
  • Preflight stamps regime based on registry probes (FirstPublish vs Update)
  • Publish retry loop consumes regime instead of re-querying when present
  • Backward-compat: missing regime deserializes to None and is omitted on serialize
  • No regressions in plan-id computation or release-level integration tests

Out of scope (future PRs in this sequence)

  • PR 2: RegistryProfile abstraction encoding crates.io rate-limit constants
  • PR 3: Retry-After header parsing layered above exponential backoff
  • PR 4: Preflight duration estimation in user output
  • PR 5: Per-crate tuning via .shipper.toml (defer if scope creep)
  • PublishRegime::Patch granularity (open question from the scout's plan)

Test plan

  • cargo fmt --all -- --check clean
  • cargo clippy --workspace --all-targets --all-features -- -D warnings clean
  • cargo test --workspace — all suites pass except one pre-existing Windows-parallelism flake in shipper-cli::cli_e2e::preflight_command_snapshot that also fails on main (cargo failed to rename .demo-0.1.0.crate to demo-0.1.0.crate race in shared target dir); the test passes in isolation with this diff applied.
  • New regime tests pass:
    • planned_package_backward_compat_no_regime_field
    • planned_package_regime_none_is_skipped_in_serialization
    • planned_package_regime_some_round_trips
    • publish_regime_is_new_crate_matches_variant
    • run_preflight_stamps_update_regime_on_existing_crate
    • existing run_preflight_* first-publish test extended to assert regime == FirstPublish

Refs #106

…PR 1)

Threads a new `PublishRegime` enum (`FirstPublish` | `Update`) from
preflight onto each `PlannedPackage`, so the publish retry loop no
longer re-queries `crate_exists` on rate-limit retries to recover the
"is this a brand-new crate?" answer. Preflight already knows; this PR
just stops throwing the answer away.

Per the scout's plan on issue #106 (PR 1 of 5):
- Adds `PublishRegime` to `shipper-types` with `is_new_crate()` helper.
- Adds `PlannedPackage.regime: Option<PublishRegime>`, gated by
  `#[serde(default, skip_serializing_if = "Option::is_none")]` so old
  `state.json` and plan files deserialize unchanged and snapshots
  written without the field stay byte-identical.
- `engine::run_preflight` now takes `&mut PlannedWorkspace` and stamps
  the regime onto each package after the existing registry probes.
- `publish_package` (sequential and parallel paths) seeds
  `is_new_crate_cached` from `p.regime` when present, falling back to
  the legacy lazy-cached behavior when the field is `None`.

Backward compatibility:
- `regime` is `Option<_>` with `serde(default)` and skipped on
  serialization when `None`. Plans / state files written by older
  shippers deserialize cleanly with `regime: None`, and serialization
  output is unchanged for callers that never set it.
- The `None` branch preserves the legacy `is_new_crate_cached`
  re-query path verbatim, so any embedder constructing
  `PlannedPackage` directly retains today's behavior.

Acceptance criteria (from #106 PR 1):
- [x] `PublishRegime` defined with `FirstPublish` and `Update` variants
- [x] `PlannedPackage.regime` plumbed through plan -> preflight -> publish
- [x] Preflight stamps regime based on registry probes (FirstPublish vs Update)
- [x] Publish retry loop consumes regime instead of re-querying when present
- [x] Backward-compat: missing `regime` deserializes to `None` and is
      omitted on serialize
- [x] No snapshot regressions in plan-id computation or release-level tests
@coderabbitai

coderabbitai Bot commented Apr 19, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 56 minutes and 48 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 56 minutes and 48 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ce9f3d6a-7777-419b-b094-0f5ac0778b5a

📥 Commits

Reviewing files that changed from the base of the PR and between 25e23ad and c9f985f.

📒 Files selected for processing (9)
  • crates/shipper-cli/src/lib.rs
  • crates/shipper-core/src/engine/mod.rs
  • crates/shipper-core/src/engine/parallel/publish.rs
  • crates/shipper-core/src/engine/parallel/tests.rs
  • crates/shipper-core/src/plan/mod.rs
  • crates/shipper-core/src/property_tests.rs
  • crates/shipper-core/src/stress_tests.rs
  • crates/shipper-types/src/lib.rs
  • crates/shipper-types/tests/release_levels_integration.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/106-publish-regime-data-flow

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a PublishRegime classification to distinguish between new crate publishes and version updates. This classification is determined during preflight and stored in the PlannedPackage to optimize the publish retry loop by avoiding redundant registry queries. Feedback includes a potential omission in the CLI's publish command that could bypass this optimization, a suggestion to skip redundant network calls in run_preflight when a version is already known to exist, and the removal of an unnecessary mut keyword in a documentation example to prevent compiler warnings.

let rep = engine::run_preflight(&mut planned, &opts, &mut reporter)?;
print_preflight(&rep, &cli.format);
}
Commands::Publish => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The Commands::Publish block does not appear to be updated to call run_preflight with a mutable reference (or it may not be calling it at all). Since run_preflight is now the only place where the regime field is stamped onto the plan, and run_publish relies on this field to avoid redundant registry queries during retries, the shipper publish command will miss this optimization and fall back to the legacy re-query behavior. This significantly reduces the impact of this PR for the primary user workflow.

Comment on lines 252 to 253
let already_published = reg.version_exists(&p.name, &p.version)?;
let is_new_crate = reg.check_new_crate(&p.name)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If already_published is true, it implies the crate already exists on the registry, so is_new_crate must be false. We can skip the redundant check_new_crate network call in this case to improve efficiency.

Suggested change
let already_published = reg.version_exists(&p.name, &p.version)?;
let is_new_crate = reg.check_new_crate(&p.name)?;
let already_published = reg.version_exists(&p.name, &p.version)?;
let is_new_crate = if already_published {
false
} else {
reg.check_new_crate(&p.name)?
};

///
/// ```ignore
/// let ws = plan::build_plan(&spec)?;
/// let mut ws = plan::build_plan(&spec)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The mut keyword is unnecessary here as ws is passed by immutable reference to run_resume on line 1354. This will trigger a compiler warning.

Suggested change
/// let mut ws = plan::build_plan(&spec)?;
/// let ws = plan::build_plan(&spec)?;

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d00b1888f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/shipper-cli/src/lib.rs Outdated
}
Commands::Preflight => {
let rep = engine::run_preflight(&planned, &opts, &mut reporter)?;
let rep = engine::run_preflight(&mut planned, &opts, &mut reporter)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Persist preflight-stamped regimes before exiting

run_preflight now mutates planned via &mut in the Preflight command, but that mutated plan is never written anywhere before the process exits. Because shipper publish is a separate CLI invocation that rebuilds the plan from plan::build_plan (with regime: None), the publish path cannot consume the stamped PublishRegime and still falls back to live registry re-queries on rate-limit retries. This makes the new preflight→publish threading ineffective for normal CLI workflows.

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Apr 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@EffortlessSteven EffortlessSteven merged commit d5c2d82 into main Apr 21, 2026
21 checks passed
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.

1 participant