Skip to content

fix: fix patched build clobbering session top levels - #1185

Merged
evanspearman merged 1 commit into
gominimal:mainfrom
evanspearman:fix/patched-build-clobbers-session-top-levels
Aug 7, 2026
Merged

fix: fix patched build clobbering session top levels#1185
evanspearman merged 1 commit into
gominimal:mainfrom
evanspearman:fix/patched-build-clobbers-session-top-levels

Conversation

@evanspearman

@evanspearman evanspearman commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

In a session, min package patched-build <pkg> followed by min add <pkg> silently
does nothing: the package is never injected into the live rootfs, and the command
exits 0 with no output.

SessionChannel uses self.graph.top_levels as its record of what it has injected —
install() early-returns on it. run_patched_pkg narrowed top_levels to the single
package being built and then committed that graph as the session graph, so the next
min add <pkg> took the already-installed path. install()'s early return writes
nothing to the wire, which is why it reads as success. The add_deps tail still runs,
so minimal.toml gets the dependency while the rootfs does not.

  • run_patched_pkg scopes the build to a throwaway build_graph clone; the session
    graph keeps its own top_levels.
  • refresh() re-resolves the session's top_levels onto the reparsed graph by name
    rather than adopting the fresh parse's (which are the packages the repo declares,
    not the ones the session has). Same remap it already did for has_packages, now
    factored into a remap_refs helper.
  • install()'s already-installed path reports Already installed: <pkgs> instead of
    returning silently — on the wire it was indistinguishable from a real injection.

Testing

Besides automated tests I built a new package not merged yet and installed it successfully in the same session.

Checklist

  • Docs updated if behavior changed
  • BREAKING CHANGE: footer present if this is a breaking change

Summary by CodeRabbit

  • New Features

    • min install now clearly reports when all requested packages are already installed.
  • Bug Fixes

    • Improved package installation handling when building patched packages.
    • Package refreshes now preserve existing session and installed-package references, providing more reliable installation behavior.

Note

Fix patched builds and session refresh clobbering installed top-level packages

  • run_patched_pkg now builds against a temporary cloned graph instead of mutating the session graph's top_levels, preventing patched builds from narrowing the installed set.
  • refresh now remaps the session's installed packages and has_packages onto the newly parsed graph by name, rather than adopting the repo's declared top-levels.
  • A new remap_refs helper resolves refs from one graph against another by package name, returning an error if a package is missing.
  • install now sends a msg:Already installed: <pkg> line to the client when all requested packages are already present, instead of returning silently.

Macroscope summarized 9d1dca3.

@evanspearman
evanspearman requested a review from a team as a code owner August 7, 2026 16:22
@CLAassistant

CLAassistant commented Aug 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly identifies the main fix, although the repeated “fix” is slightly redundant.
Description check ✅ Passed The description includes Summary, Testing, and Checklist sections and explains the bug and solution, but testing evidence is limited.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/minimald/src/env.rs`:
- Around line 1208-1212: Update remap_refs to preserve an installed package only
when the existing and refreshed BuildSpecRef values have matching spec hashes,
not merely matching names. When the same package name resolves to a changed
definition, invalidate the session entry or return the established refresh
conflict so stale rootfs contents cannot be treated as installed. Add a
regression test covering a same-name package with a changed definition.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0d69fcc5-e470-491b-91bd-286ad6768996

📥 Commits

Reviewing files that changed from the base of the PR and between 8bfe0dd and 9d1dca3.

📒 Files selected for processing (1)
  • crates/minimald/src/env.rs

Comment on lines +1208 to +1212
bsrs.into_iter()
.map(|bsr| {
let name = &from.get(bsr).expect("bsrs always exist").name;
to.by_name(name).copied().ok_or_else(|| name.clone())
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve installed-package identity across refreshes.

remap_refs resolves installed packages only by name. If minimal.toml changes a package with the same name, the session maps the old rootfs contents to the new BuildSpecRef. A later install then reports Already installed for content that was never injected.

Only preserve an installed entry when its old and new spec hashes match. Otherwise, invalidate the session entry and require a rebuild or return a refresh conflict. Add a regression test with the same package name and a changed package definition.

Also applies to: 1687-1716

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/minimald/src/env.rs` around lines 1208 - 1212, Update remap_refs to
preserve an installed package only when the existing and refreshed BuildSpecRef
values have matching spec hashes, not merely matching names. When the same
package name resolves to a changed definition, invalidate the session entry or
return the established refresh conflict so stale rootfs contents cannot be
treated as installed. Add a regression test covering a same-name package with a
changed definition.

@evanspearman
evanspearman merged commit 392551a into gominimal:main Aug 7, 2026
30 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.

3 participants