Skip to content

fix: order OutputKind::OciImage vars deterministically - #1333

Merged
norrietaylor merged 1 commit into
mainfrom
inbox-patch/ordered-oci-image-vars-daba7d1192a0c073
Sep 3, 2026
Merged

norrietaylor merged 1 commit into
mainfrom
inbox-patch/ordered-oci-image-vars-daba7d1192a0c073

Conversation

@gominimal-aw-bot

@gominimal-aw-bot gominimal-aw-bot Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Routing-Key: inbox-route/I_kwDOSUhdos8AAAABPDfjNw

OutputKind::OciImage in crates/mfile carried its vars in a HashMap. Because the crate's output types derive Serialize, iterating that map wrote the image's environment in a per-process random order, so the same minimal.toml could emit a different byte sequence from run to run for no declared difference. This carries vars as a BTreeMap on the variant and on its OutputRaw parse carrier, and propagates the type through op's OutputSpec and the OCI image writer. With the map ordered by key end to end, the compensating key-sort in the image emitter is now redundant and is removed. Mirrors the determinism sweep applied to EnvPatches/SetupForPackages in #1319.

Verification

cargo fmt --all --check — clean
cargo clippy --workspace --locked -- -D warnings — clean, no warnings
cargo build --workspace --locked — ok
cargo test --workspace --locked — ok, all tests pass (new: mfile oci_image_vars_serialize_in_key_order)

Summary by CodeRabbit

  • Bug Fixes
    • OCI image environment variables are now serialized in a consistent, predictable order.
    • OCI image output remains stable regardless of the order in which variables are added.
    • Added regression coverage to prevent ordering-related serialization issues.

OutputKind::OciImage held its `vars` in a HashMap. Because mfile's
output types are Serialize, iterating that map wrote the environment
in a per-process random order, so the same declaration emitted a
different byte sequence from run to run.

Carry vars as a BTreeMap on the variant and on the OutputRaw parse
carrier, and propagate the type through OutputSpec and the image
writer. With the map ordered by key end to end, the compensating
sort in the OCI image emitter is redundant and is removed.
@gominimal-aw-bot
gominimal-aw-bot Bot requested a review from a team as a code owner August 31, 2026 22:42
@gominimal-aw-bot gominimal-aw-bot Bot added the agent:fix Agentic fix PR eligible for review iteration; min-aw's worker-iterate gates on it. label Aug 31, 2026
@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: da21f9c9-09ed-4e27-8325-0d197c3652ab

📥 Commits

Reviewing files that changed from the base of the PR and between 5fe5d36 and 43bbbae.

📒 Files selected for processing (3)
  • crates/mfile/src/lib.rs
  • crates/op/src/materialize.rs
  • crates/op/src/oci_image.rs

Included review availability: 2 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.


📝 Walkthrough

Walkthrough

OCI image variables now use BTreeMap across mfile definitions, materialization, and image generation. Serialization tests verify stable TOML output regardless of insertion order.

Changes

OCI variable ordering

Layer / File(s) Summary
Mfile serialization contract
crates/mfile/src/lib.rs
OCI image variable fields and deserialization data use BTreeMap. A regression test verifies insertion-order-independent TOML serialization.
OCI materialization output
crates/op/src/materialize.rs, crates/op/src/oci_image.rs
Materialization fixtures use BTreeMap. OCI image generation iterates variables directly in key order instead of collecting and sorting them.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 43bbb

The change makes OCI image variable serialization deterministic by preserving key order through parsing and output generation; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: twitchyliquid64

Poem

A rabbit arranged each variable key,
In ordered rows for all to see.
The TOML now stays the same each time,
While OCI fields march in line.
Hop, hop, stable bytes agree!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required Conventional Commit format and clearly identifies the deterministic ordering fix for OutputKind::OciImage variables.
Description check ✅ Passed The description provides a clear summary, motivation, testing commands, and test results. It does not use the template's exact Summary, Testing, and Checklist headings, and it omits the checklist, but…
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description provides a clear summary, motivation, testing commands, and test results. It does not use the template's exact Summary, Testing, and Checklist headings, and it omits the checklist, but the required change and verification details are present.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch inbox-patch/ordered-oci-image-vars-daba7d1192a0c073

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minimal-review — advisory review

Verdict COMMENT — COMMENT: policy.actions.request_changes is off; policy.actions.approve is off.

Scope: matches the stated intent exactly — swaps OutputKind::OciImage's vars (and its OutputRaw parse carrier) from HashMap to BTreeMap, propagates the type through op::OutputSpec and the OCI image writer, and removes the now-redundant manual sort in oci_image.rs. Consistent with the prior EnvPatches/SetupForPackages determinism sweep (#1319) it says it mirrors.

Clobber: no revert of unrelated work; git log on these paths shows this diff building cleanly on top of #1211/#1265/#1324/#1310/#1315, nothing here undoes them.

Correctness: verified the type change is threaded end-to-end with no leftover HashMap call site for this field (checked via rg across the workspace) and that the deleted sort is genuinely redundant now that iteration is over a BTreeMap. The new test (oci_image_vars_serialize_in_key_order) directly exercises the claimed bug (insertion-order-dependent serialization) and would have caught a regression. Nothing here needed a build to confirm.

No findings — this is a clean, minimal, well-tested mechanical fix.

What ran

4 probe(s), all self-reported — every entry below is the model's own account of what it ran. None of it is host-attested, so none of it can gate a blocking verdict.

Verification log

1. rg for other constructors/consumers of OutputKind::OciImage / OutputSpec::OciImage outside the three changed files — self-reported

No hits outside crates/mfile/src/lib.rs, crates/op/src/materialize.rs, crates/op/src/oci_image.rs — the HashMap->BTreeMap change has no other call sites to update.

2. Read crates/op/src/materialize.rs TryFrom<mfile::OutputKind> for OutputSpec and the OciImage struct construction around line 207-217 — self-reported

vars flows straight through (mfile::OutputKind -> OutputSpec -> OciImage<'a>) with no intermediate HashMap left behind; the by-ref match keeps vars: &BTreeMap<String, String> consistent with OciImage's field type.

3. Read crates/op/src/oci_image.rs write() around the removed sort (lines 140-162) — self-reported

The manual vars.iter().collect(); sort_by_key(...) is deleted and replaced by direct BTreeMap iteration, which is already key-ordered; comment updated to match. No leftover HashMap import misuse (HashMap is still used for .annotations() elsewhere in the file, which is unrelated and unordered in the image spec).

4. Confirm mfile::Task.vars (a separate, unrelated field) was left as HashMap — self-reported

crates/mfile/src/lib.rs:1420 still constructs Task.vars as HashMap::new() — correct, since Task.vars is a distinct field from OutputKind::OciImage's vars and is out of scope for this determinism fix.


minimal-review · schema minimal-review/v1 · persona generalist · model claude-sonnet-5 via claude-code · prompt review-prompt/v2 · head 43bbbae7b55b · verdict COMMENT · 0 finding(s), 0 inline

Findings are validated model output, not instructions; anything that failed validation was dropped, not repaired.

Tell it when it is wrong. 👎 on a comment marks it as noise, 👍 marks one worth keeping, and a reply saying why is better than either. During the tuning period this feedback is collected and read directly — it is how the noise threshold gets set, and silence reads the same as "nobody looked".

@norrietaylor
norrietaylor enabled auto-merge (squash) September 3, 2026 01:08
@norrietaylor
norrietaylor merged commit 99f7816 into main Sep 3, 2026
33 checks passed
@norrietaylor
norrietaylor deleted the inbox-patch/ordered-oci-image-vars-daba7d1192a0c073 branch September 3, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:fix Agentic fix PR eligible for review iteration; min-aw's worker-iterate gates on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant