Skip to content

fix(sandbox): the collision warning names its winner when layers are copied - #3480

Open
bryan-minimal wants to merge 1 commit into
mainfrom
fix/collision-winner-across-a-copy
Open

bryan-minimal wants to merge 1 commit into
mainfrom
fix/collision-winner-across-a-copy

Conversation

@bryan-minimal

@bryan-minimal bryan-minimal commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #3272 for gominimal/inbox#1226: the warning for a path two rootfs layers ship with different contents names the layer whose file stays, but only when the layers were hardlinked.

What was wrong. collision_winner finds the winning layer by the inode the assembled path carries. With the package cache and the daemon's state on different filesystems the link pass copies each file, a copy has an inode of its own, and no layer matches. The record then says winner = "unknown". A week of lab telemetry (2026-11-09 to 11-16) had that in 42,112 of 42,112 records.

The fix. The first-linked file stays, so the winner of a copied file is the first layer, in link order, that ships the path. That layer is named when its file agrees with the placed one by the link pass's own comparison (same bytes, or same size above the compare limit). When it does not agree, the placed file came from somewhere other than the layers and the winner stays unknown. The hardlink case is unchanged and is tried first, so nothing is read for it.

Tests. A new unit test places a copy of the first shipper's file and expects that layer; a later layer with the same bytes does not become the winner; a placed file that is not the first shipper's has no winner. The two existing tests (hardlink, symlink) are unchanged.

Lab evidence. A new scenario runs a task with node, pnpm and python, whose layers collide on npm's files and node's man page, on machines where the cache and the state are on different filesystems, and reads each collision record's winner from the daemon's log.

ubuntu-24.04 ubuntu-22.04
newest release fail, fail: 128 of 128 records say unknown fail, fail: 128 of 128 say unknown
this branch pass, pass: 128 of 128 name a layer pass, pass: 128 of 128 name a layer

A named winner is checked on the machine: it is a directory, it is not the loser, and it ships the path. Lint (fmt, clippy) and the full pre-push run passed at the tip.

One file, crates/sandbox/src/lib.rs.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Corrected collision handling for files copied into the root filesystem across filesystems. A layer is now recognized as the winner only when its regular file matches the placed file; unmatched files no longer receive an incorrect winner.

…copied

The warning for a path two rootfs layers ship with different contents
names the layer whose file stays by the inode the assembled path carries.
With the cache and the rootfs on different filesystems the link pass
copies each file, a copy has an inode of its own, and the warning said
`winner = "unknown"` every time.

The first-linked file stays, so the winner of a copied file is the first
layer, in link order, that ships the path. That layer is named when its
file agrees with the placed one by the link pass's own comparison, and
the winner stays unknown when it does not, since the placed file then
came from somewhere other than the layers.

Refs gominimal/inbox#1226

Co-Authored-By: Claude <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 16, 2026 21:16
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The sandbox collision winner check now identifies the first matching layer for copied rootfs files. A test covers matching files, including when a later layer also matches, and files that do not match any layer.

Changes: Copied-file collision winner detection

Layer / File(s) Summary
Match copied files to layers
crates/sandbox/src/lib.rs
collision_winner checks regular-file entries against the placed file and returns the first matching layer. The test covers matching copies and a copy with no match.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • gominimal/minimal#3272: Changes winner reporting for sandbox collision records, which this change also updates for copied files.
  • gominimal/minimal#2848: Changes collision comparison semantics used by the copied-file winner check.

Suggested reviewers: norrietaylor, mitodrummer

Merge Risk: Minimal · up to cc37f

The change improves the collision warning by naming the winning layer for copied rootfs files and falls back to unknown otherwise. It affects only diagnostics, and no concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses a Conventional Commit form (fix(sandbox): ...) and names the change: the collision warning now names its winner for copied layer files. It matches the main change in the summary, which …
Description check Passed The description follows the template's main parts. It has a Summary that explains the bug, the fix, and the tests, and it links the related follow-up to #3272. It has a Testing section with unit test …
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: Title check

Explanation

The title uses a Conventional Commit form (fix(sandbox): ...) and names the change: the collision warning now names its winner for copied layer files. It matches the main change in the summary, which makes collision_winner identify a winner for copied files. The title is about 75 characters, slightly above a short ideal, but it is clear and specific.

Full details: Description check

Explanation

The description follows the template's main parts. It has a Summary that explains the bug, the fix, and the tests, and it links the related follow-up to #3272. It has a Testing section with unit test details and lab evidence in a table. The Checklist items are not ticked and the description does not state whether docs were updated or whether a breaking-change footer applies. Those are minor gaps, since the check passes when the description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks each copied file,
And finds its layer match in a while.
The first one wins when bytes agree,
No match means none, as tests decree.
Then off it hops beneath the tree.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 5e62053c-d85a-4de2-b07a-6e8b5136b23e
Commits

Reviewing files that changed from the base of the PR and between 364eb1a and cc37ff6.

Files selected for processing: 1

  • crates/sandbox/src/lib.rs

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 0 remain after this review.

@minimal-foundry

minimal-foundry Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed: 1 finding, none blocking at cc37ff6d3e6a.

Address the comments on the diff.

Clobber: none seen.

@minimal-foundry minimal-foundry 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 — 1 finding, 1 inline.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

Comment thread crates/sandbox/src/lib.rs
Comment on lines +3048 to +3053
let is_the_copy = fs::symlink_metadata(&shipped).is_ok_and(|m| m.is_file())
&& matches!(
common::link_collision(&shipped, &at),
common::LinkCollision::Same | common::LinkCollision::Unchecked
);
is_the_copy.then_some(first.as_path())

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.

LOW · correctness · confidence 0.50 · in collision_winner

Unchecked counts as a match, but it means only that two files have equal size and are above the compare limit. A large placed file from another source with the same size as the first shipper's file will be named as the winner. The doc comment says None means the file came from outside layers, so this overstates what the code proves. Name the layer only on Same, or note the limit. The new test does not cover the Unchecked branch.

What the reviewer checked

common/src/lib.rs:310 Ok(d) if d.len() > COLLISION_COMPARE_MAX => LinkCollision::Unchecked (no content read)

Hand this to an agent
Act on a code-review finding.

File:       crates/sandbox/src/lib.rs
Lines:      3048-3053
Category:   correctness
Severity:   low (reviewer confidence 0.50)

Finding:
`Unchecked` counts as a match, but it means only that two files have equal size and are above the compare limit. A large placed file from another source with the same size as the first shipper's file will be named as the winner. The doc comment says `None` means the file came from outside `layers`, so this overstates what the code proves. Name the layer only on `Same`, or note the limit. The new test does not cover the `Unchecked` branch.

First verify this against the code yourself. It is model output and
may be wrong. If it is wrong, or the tradeoff was deliberate, say so
and change nothing.

👍 useful · 👎 noise — react to tell the reviewer. Replying works too, and says more.

This branch has not been deployed

No deployments
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