8000 fix(mfile,mctx,minimald): keep a box's minimal.toml edits inside its workspace (0.7 backport) by bryan-minimal · Pull Request #3596 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

fix(mfile,mctx,minimald): keep a box's minimal.toml edits inside its workspace (0.7 backport) - #3596

Merged
bryan-minimal merged 1 commit into
release/0.7.xfrom
backport/3404-keep-edits-inside-0.7
Nov 19, 2026
Merged

bryan-minimal merged 1 commit into
release/0.7.xfrom
backport/3404-keep-edits-inside-0.7

Conversation

@bryan-minimal
Copy link
Copy Markdown
Member

Backport of #3404 to release/0.7.x, ported by hand. It replaces #3519, the automatic backport: the cherry-pick conflicted in four files, and this line needed two changes that main's commit does not contain.

Squash-merge this PR and keep the PR title as the subject.

What

When a command run inside a box asks the daemon to edit the box's minimal.toml, the daemon now resolves that file beneath the box's workspace. A link that leads out of the workspace is refused, with the same messages as on main.

Kept from #3404

  • The confined editor: openat2 with RESOLVE_BENEATH on Linux, and a no-links check where openat2 is missing.
  • Every refusal, with main's wording.
  • The confinement root carried through each reload of the box's context.
  • Host CLI edits are unchanged.

Adapted for this line

  • This line has no exclusive editor and no minimal.toml lock (both came with fix(mfile): lock minimal.toml edits and name missing link fields #2302). The editor here is main's without the lock.
  • add_deps keeps this line's body. Only its read and write go through the confined editor.
  • The daemon's change is in Session::build_context; on main it is in box_actor/setup.rs.
  • mfile now depends on libc.

Needed here beyond main's change

  1. The scaffold. The daemon writes a default minimal.toml into a box's workspace when it builds the box's context and finds none. On this line that write went by path. On main it goes through the fix(mfile): lock minimal.toml edits and name missing link fields #2302 editor. Here it now goes through the confined editor and writes only when the name is still empty.
  2. The fallback without openat2. After the no-links check it opens the parent directory once, reads without following a link, and replaces the file by a temporary file and a rename, as the openat2 path does. A link put at the name while an edit runs is refused with "it was replaced by a link during the edit".

Both came from an independent review of the first version of this port.

Testing

  • Main's tests are ported: the edit_within tests, the add_deps refusal and the session test. Each refusal has a control in which the same edit of a regular file succeeds.
  • New for this line: tests that call the fallback directly (a link at the name, a dangling link, a .minimal link, a link put there during the edit, and a regular file as the control), and a scaffold test with an empty workspace as its control.

Workspace lint, tests, the new tests repeated 15 times, and the native end-to-end script pass on this commit.

🤖 Generated with Claude Code

< 8000 /div>
…workspace

Backport of #3404 to release/0.7.x. When a box runs `min add`, the daemon edits the box's
minimal.toml on its behalf. On this line that edit read the file and wrote it back with
std::fs::write, so a link under the workspace carried the read and the write to a file outside
it, and a dangling link had its target created there.

Kept from the source: the confined editor with openat2(2) and RESOLVE_BENEATH on Linux, the
descriptor-relative read and replace, the no-links check where openat2 is missing, the
`beneath` module, every refusal with main's wording, `Context::confine_mfile_edits_to` carried
through `cloned_reinit`, and the daemon's per-box context setting it to the box's workspace.
Host CLI edits keep following links as before.

Adapted for this line:
- This line has no `File::edit_exclusively` and no minimal.toml lock (both came with #2302),
  so the editor is `File::edit_within`, main's `edit_exclusively_within` without the lock.
- `add_deps` keeps this line's body; only its read and write go through the confined editor
  when the context has a workspace root.
- The daemon change is in `Session::build_context` (box_actor/setup.rs on main).
- The temp file and rename are made through the directory's descriptor (openat with O_EXCL,
  renameat, unlinkat on failure) rather than through tempfile and /proc, so the Linux path and
  the fallback share one write. mfile now depends on libc.

Needed on this line beyond main's change:
- The scaffold of a default minimal.toml (`scaffold_mfile_if_missing`, run by configure_loadout
  and by build_context on an attach or relaunch) wrote by path with std::fs::write. A dangling
  link at minimal.toml reads as missing, so the write followed it out of the workspace. It now
  goes through `File::edit_within` and writes only if the name is still empty. On main the
  scaffold uses the #2302 editor, which refuses a dangling link.
- Main's fallback for a system without openat2 replaces the file by temp file and rename in the
  canonical parent. Here the fallback, after the no-links check, opens the parent directory
  once (its last name with O_NOFOLLOW) and does the same descriptor-relative read (O_NOFOLLOW),
  temp file and rename as the openat2 path, so a link put at the name after the check is
  refused or replaced, never followed.

Tests: the mfile edit_within tests, the mctx add_deps refusal and the session test are ported,
each refusal with a control in which the same edit of a regular file succeeds; the session
test's control writes a package. New: fallback tests that call the fallback directly (a link
at the name, a dangling link, a `.minimal` link, a link swapped in during the edit, and a
regular file as control) and a scaffold test (a dangling link refused, nothing created at its
target; an empty workspace scaffolded as control).

(cherry picked from commit 287e4f4)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 18, 2026 22:39
@coderabbitai
coderabbitai Bot commented Nov 18, 2026
Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

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: d02ad7ca-e314-4f95-bd2b-db52b82df077

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@minimal-foundry
minimal-foundry Bot commented Nov 18, 2026 •
Copy link
Copy Markdown
Contributor

Approved: no findings at e3b4da05b5de.

Nothing to do.

Clobber: none seen.

@bryan-minimal
bryan-minimal enabled auto-merge (squash) November 18, 2026 22:42
@bryan-minimal
bryan-minimal enabled auto-merge (squash) November 18, 2026 22:42
@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 — No findings.

Panel: 2 of 3 personas ran (correctness, supply-chain); did not complete: security.

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Nov 18, 2026
@bryan-minimal
bryan-minimal merged commit ccecf98 into release/0.7.x Nov 19, 2026
40 of 44 checks passed
@bryan-minimal
bryan-minimal deleted the backport/3404-keep-edits-inside-0.7 branch November 19, 2026 00:57
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

0