Skip to content

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

Merged
bryan-minimal merged 3 commits into
mainfrom
fix/collision-winner-across-a-copy
Nov 18, 2026
Merged

bryan-minimal merged 3 commits 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 only when its file has the same bytes as the placed one, by the link pass's own comparison. A copied file above the compare limit (4 MiB) is not read, so its winner is reported as unknown and never guessed. When the bytes differ, 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

The table was measured before the last commit, which stopped naming a layer for an unread file above the compare limit. It was not re-run on this head. The colliding files in these scenarios (npm files and a man page) are all under the limit, so the counts are expected to hold.

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. The first layer with a regular file matching the placed file is recognized as the winner, even if later layers contain identical contents. Unmatched files and files with unchecked comparisons are no longer assigned a winner. Existing inode and symlink-target matching behavior remains unchanged.

…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. It returns no winner when the placed file does not match or the comparison is unchecked. Tests cover matching files, later matching layers, non-matching files, and unchecked comparisons.

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 identifies the first matching layer. Tests cover a later layer with the same bytes, a non-matching file, and an unchecked comparison. Existing inode and symlink-target matching remains.

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 the collision comparison semantics used by the copied-file winner check.

Suggested reviewers: mitodrummer, norrietaylor

Merge Risk: Minimal · up to 8129e

The change makes the sandbox collision warning name the winning layer for files copied across filesystems, instead of reporting unknown. It only affects warning attribution, and the added tests cover the matching, non-matching, and unchecked cases. No 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 main change: the collision warning now names its winner when layers are copied. This matches the raw summary, which describe…
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.
Description check Passed The description follows the repository template's main sections. It has a Summary that explains the bug, the fix, and the affected file. It has a Testing section that describes the unit tests and the …
Full details: Title check

Explanation

The title uses a Conventional Commit form (fix(sandbox): ...) and names the main change: the collision warning now names its winner when layers are copied. This matches the raw summary, which describes copied-file winner detection in collision_winner. The title is lower-case and has no trailing period. It is 75 characters, within a reasonable length for a title.

Full details: Description check

Explanation

The description follows the repository template's main sections. It has a Summary that explains the bug, the fix, and the affected file. It has a Testing section that describes the unit tests and the lab evidence, with a results table. Two template items are not met. The title is not part of this check, so that is not assessed here. The Checklist is absent, so the author did not confirm that docs were updated or that a BREAKING CHANGE footer is not needed. The Summary does not link a related issue with a Refs or Closes line. It mentions gominimal/inbox#1226 and follow-up to #3272 only in prose. The Testing section does not show the cargo test or clippy output as pasted evidence. It reports results in prose and a table instead. These gaps are minor, so 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,
Then finds the layer that matches its style.
If bytes disagree, no name is shown,
If checks are unchecked, no winner is known.
The first matching layer takes the prize,
While later twins pass by its eyes.

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: 80b0fbe0-1ed3-4517-858d-d10958e1f2bb
Commits

Reviewing files that changed from the base of the PR and between cc37ff6 and 8129e2b.

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

Approved: no findings at 8129e2bfe9fa.

Nothing to do.

Clobber: none.

@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 Resolved
bryan-minimal and others added 2 commits November 17, 2026 07:51
An unchecked comparison means only that two files have equal size above
the compare limit, which proves nothing about which source placed the
file. collision_winner now names the first shipping layer of a copied
file only when the link pass's comparison calls the two the same, so the
warning says unknown rather than a possibly wrong layer. A new test
covers the unchecked branch with sparse files above the limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 — approved

Verdict APPROVE — No findings.

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

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Nov 18, 2026

@norrietaylor norrietaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-reviewed the change since cc37ff6: 4803066 and the main merge (the merge tree matches the automatic merge, so it has no hand edits). collision_winner now names the first shipper of a copied file only on LinkCollision::Same. An Unchecked result (equal sizes above COLLISION_COMPARE_MAX) gives unknown instead of a possibly wrong layer, and the new sparse-file test reaches that branch and asserts it.

[low] The PR body still says the first shipper is named when its file matches "by the link pass's own comparison (same bytes, or same size above the compare limit)". Since 4803066, a match is same bytes only, and a copied file above 4 MiB always reports unknown. Please update that sentence so the squash message is accurate. The lab table's 128 of 128 was measured before this commit. It should still hold, because the colliding npm files and man page are under the limit, but it was not re-run on this head.

@bryan-minimal

Copy link
Copy Markdown
Member Author

Body corrected: the first shipper is named only when its file has the same bytes as the placed one, and a copied file above the 4 MiB compare limit reports unknown. It also now says the lab table was measured before that commit and was not re-run on this head.

@bryan-minimal
bryan-minimal added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 761849b Nov 18, 2026
41 checks passed
@bryan-minimal
bryan-minimal deleted the fix/collision-winner-across-a-copy branch November 18, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants