8000 feat(minimal2,minimald): default to native minimald on Linux; --minvmd to opt into the VM by norrietaylor · Pull Request #571 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content
{"props":{"contextRegion":{"crumbs":[{"crumb_type":"organization","label":"gominimal","is_root":false,"href":"/gominimal"},{"crumb_type":"repository","label":"minimal","is_root":false,"href":"/gominimal/minimal"}],"localNavigation":[{"id":"code","icon":"code","label":"Code","href":"/gominimal/minimal","selectedLinks":["repo_source","repo_downloads","repo_commits","repo_releases","repo_tags","repo_branches","repo_packages","repo_deployments","repo_attestations"],"popoverTarget":false,"commandId":"repositories:go-to-code","reactNav":{"appTarget":"code-view","anchor":"code-view-repo-link"},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"issues","icon":"issue-opened","label":"Issues","href":"/gominimal/minimal/issues","selectedLinks":["repo_issues","repo_labels","repo_milestones"],"count":240,"popoverTarget":false,"commandId":"repositories:go-to-issues","reactNav":{"appTarget":"repo","anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"pull-requests","icon":"git-pull-request","label":"Pull requests","href":"/gominimal/minimal/pulls","selectedLinks":["repo_pulls","checks"],"count":30,"popoverTarget":false,"commandId":"repositories:go-to-pull-requests","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"discussions","icon":"comment-discussion","label":"Discussions","href":"/gominimal/minimal/discussions","selectedLinks":["repo_discussions"],"popoverTarget":false,"commandId":"repositories:go-to-discussions","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"actions","icon":"play","label":"Actions","href":"/gominimal/minimal/actions","selectedLinks":["repo_actions"],"popoverTarget":false,"commandId":"repositories:go-to-actions","reactNav":{"appTarget":"repo","anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"security-and-quality","icon":"shield","label":"Security and quality","href":"/gominimal/minimal/security","selectedLinks":["security","overview","alerts","policy","token_scanning","code_scanning"],"count":0,"popoverTarget":false,"commandId":"repositories:go-to-security","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"insights","icon":"graph","label":"Insights","href":"/gominimal/minimal/pulse","selectedLinks":["repo_graphs","repo_contributors","dependency_graph","dependabot_updates","pulse","people","community"],"popoverTarget":false,"commandId":"repositories:go-to-insights","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}}],"localNavigationUpdateChannel":null,"selectedLink":"repo_pulls"},"owner":null,"headerLogo":{"href":"/","aria-label":"Homepage "},"notifications":{"indicatorMode":"disabled","websocketChannel":null,"fetchIndicatorSrc":"/notifications/indicator","fetchIndicatorEnabled":false},"issues":{"href":"/issues"},"pulls":{"href":"/pulls"},"contributedRepos":{"href":"/repos"},"copilot":{"show":false,"showAgentsButton":false,"showRelaunchAnnouncement":false,"copilotChatUrl":null,"copilotApiUrl":"https://api.githubcopilot.com"},"search":{"show":true,"showCommandPalette":false,"isSearchPage":false,"isJumpToSearch":false,"searchContext":{"scope":"repo:gominimal/minimal","current_repo_name":"minimal","current_repo_nwo":"gominimal/minimal","current_repo_org":"gominimal","user_id":"gominimal"}},"commandPalette":null,"enterpriseBar":{"show":false},"globalTransactionalMessage":[],"payloadsUrl":"/_global-navigation/payloads.json?can_toggle_site_admin_and_employee_status=0\u0026is_admin_mode_on=0\u0026is_ui_opted_out=0\u0026show_ui_opt_out=0\u0026v=8","contextRegionUrl":"/_global-navigation/context-region.json"}}

feat(minimal2,minimald): default to native minimald on Linux; --minvmd to opt into the VM - #571

Merged
norrietaylor merged 5 commits into
mainfrom
feat/linux-native-default-backend
Jun 25, 2026
Merged

norrietaylor merged 5 commits into
mainfrom
feat/linux-native-default-backend

Conversation

@norrietaylor
@norrietaylor norrietaylor commented Jun 24, 2026 •
Copy link
Copy Markdown
Member

Summary

On Linux the CLI unconditionally autospawned minvmd (autospawn::ensure_minvmd_running) while resolve_socket_path resolved the native minimald socket — self-inconsistent, and unusable on hosts where minvmd is the non-libkrun stub. This makes native minimald (DM2) the Linux default and the minvmd microVM (DM1) an explicit --minvmd opt-in. macOS is unchanged (minvmd is the only backend there).

Changes

  • crates/minimal2
    • --minvmd global flag on GlobalArgs.
    • autospawn::ensure_daemon_running(use_minvmd, minimal_dir) dispatches: macOS → minvmd; Linux → native minimald by default, minvmd when --minvmd. Replaces the 6 direct ensure_minvmd_running() call sites.
    • New ensure_minimald_running() (Linux): if the SSH socket isn't already accepting, spawns minimald run --detach --instance-num 0.
    • resolve_socket_path(minimal_dir, use_minvmd) — Linux+--minvmd resolves the minvmd bridge UDS; otherwise the native providers/local-0/ssh.sock.
  • crates/minimald
    • minimald run --detach: re-execs in a new session (setsid via pre_exec), stdio→null, and returns once the SSH socket accepts connections or an 8s timeout elapses. Mirrors minvmd run --detach.

Behavior

  • minimal2 activate on Linux → native minimald (DM2), no VM.
  • minimal2 --minvmd activate on Linux → minvmd microVM (DM1); requires /dev/kvm + libkrun.
  • macOS: --minvmd is a no-op (minvmd always).
  • Behavior change: the prior Linux default (always minvmd) becomes native. Intended.

Verification

Docker rust:1.95 + protobuf-compiler, --locked, CARGO_INCREMENTAL=0:

  • cargo fmt --all -- --check — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo build -p minimald -p minimal2 — clean
  • cargo test -p minimal2 — pass (incl. a new resolve_socket_path backend-split test)

Follow-up

A native-detach integration proof (spawn minimald run --detach, drive a CLI round-trip without minvmd) is worth a netns-lane test; not included here.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a global --minvmd option to select the daemon backend on supported platforms.
    • Added --detach to daemon listening to start in the background and wait until the daemon is ready.
  • Bug Fixes
    • Improved daemon startup/connection so commands target the correct socket/backend, including correct SSH proxy wiring.
    • Ensures the daemon instance is spawned when the expected socket isn’t reachable.
  • Tests
    • Added unit tests for backend-specific socket path resolution.

…d to opt into the VM

On Linux the CLI unconditionally autospawned minvmd, yet resolved the native
minimald socket — self-inconsistent, and broken on hosts where minvmd is the
non-libkrun stub. Make native minimald (DM2) the Linux default and the minvmd
microVM (DM1) an explicit opt-in.

- minimal2: `--minvmd` global flag. Linux default autospawns native minimald;
  `--minvmd` autospawns minvmd. macOS is unaffected (minvmd is the only backend).
- minimal2: `ensure_daemon_running()` dispatches by platform + flag;
  `resolve_socket_path()` takes the backend so Linux+--minvmd resolves the bridge
  UDS, not the native path.
- minimald: add `run --detach` — re-execs in a new session (setsid), stdio to
  null, and returns once the SSH socket accepts connections. Mirrors
  `minvmd run --detach`; used by the native autospawn path.

Verified in Docker (rust:1.95, --locked): fmt, workspace clippy -D warnings,
build -p minimald -p minimal2, test -p minimal2 (incl. the backend socket-path test).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0143kv2BRrRqGxmVwwHskQtS
@coderabbitai
coderabbitai Bot commented Jun 24, 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: Pro

Run ID: 18dbeff9-ebd5-48ed-a4d7-3075dc7316e3

📥 Commits

Reviewing files that changed from the base of the PR and between e9cd215 and e15b946.

📒 Files selected for processing (1)
  • crates/minimal2/src/main.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/minimal2/src/main.rs

📝 Walkthrough

Walkthrough

The PR adds detached startup support to minimald and updates minimal2 to select between backend-specific daemon sockets and startup paths using a new --minvmd flag.

Changes

Daemon backend selection and detached startup

Layer / File(s) Summary
Detached daemon startup
crates/minimald/src/main.rs
ListenArgs gains detach; spawn_detached re-executes the daemon in a new session, strips --detach, waits for the SSH socket, and async_main skips guest setup when detach is set.
Backend selection helpers
crates/minimal2/src/autospawn.rs, crates/minimal2/src/client.rs
resolve_socket_path accepts use_minvmd, and ensure_daemon_running selects between ensure_minvmd_running() and native minimald startup before the Linux socket test checks the backend-specific path.
CLI backend wiring
crates/minimal2/src/main.rs
GlobalArgs adds --minvmd; connect_daemon resolves sockets with the backend choice, and the daemon-facing commands switch to ensure_daemon_running(...) with updated error paths.

Sequence Diagram(s)

sequenceDiagram
  participant async_main as "async_main"
  participant spawn_detached as "spawn_detached"
  participant cli_listen_on as "cli.listen_on"
  participant unix_stream_connect as "UnixStream::connect"

  async_main->>spawn_detached: listen_args.detach == true
  spawn_detached->>spawn_detached: re-exec binary without --detach
  spawn_detached->>spawn_detached: setsid and redirect stdio to null
  spawn_detached->>cli_listen_on: poll SSH socket path
  cli_listen_on->>unix_stream_connect: connect(socket)
  unix_stream_connect-->>spawn_detached: success or retry
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • gominimal/minimal#345: Adds the minvmd bridge socket path that resolve_socket 8000 _path(..., use_minvmd) now selects.
  • gominimal/minimal#354: Refactors daemon startup into ensure_daemon_running(...) and updates minimal2 to call it.
  • gominimal/minimal#400: Introduces minimald --detach, which matches the new detached autospawn path.

Suggested reviewers

  • 0chroma

Poem

A bunny flipped the startup switch,
--minvmd and --detach now hitch.
One socket waits, one daemon hums,
Soft paws tap while the new flow comes. 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: Linux now defaults to native minimald, with --minvmd opting into the VM backend.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
crates/minimal2/src/client.rs (1)

188-194: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the full override-derived paths.

The current ends_with checks do not prove that minimal_dir_override was honored; a default socket path with the same suffix would still pass.

Strengthen the test
-        assert!(native.ends_with("providers/local-0/ssh.sock"), "{native:?}");
-        assert!(bridged.ends_with("minimald.sock"), "{bridged:?}");
+        assert_eq!(native, dir.join("providers/local-0/ssh.sock"));
+        assert_eq!(bridged, dir.join("minimald.sock"));
🤖 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/minimal2/src/client.rs` around lines 188 - 194, The
linux_socket_path_honors_backend_with_override test only checks suffixes, so it
can pass even if minimal_dir_override is ignored. Update the assertions in
resolve_socket_path’s test to verify the complete override-derived paths for
both the native and bridged cases, using the same symbols resolve_socket_path
and linux_socket_path_honors_backend_with_override so the test proves the
override is actually applied.
🤖 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/minimal2/src/autospawn.rs`:
- Around line 153-159: The native daemon autospawn path is resolving the socket
with minimal_dir in ensure_daemon_running, but ensure_minimald_running/startup
still launches minimald without that same state directory, causing a mismatch
when --minimal-dir is used. Update the autospawn flow so the resolved
minimal_dir is forwarded into the spawned backend path used by
ensure_minimald_running (and the minimald launch logic it calls), keeping the
socket resolution and daemon startup aligned.
- Around line 177-185: Serialize the native autospawn path in
minimal2::autospawn before invoking minimald run --detach, since concurrent
callers can both pass the UnixStream::connect check and spawn duplicate daemons.
Add a per-socket or state-dir lock around the connect-and-spawn logic in the
autospawn flow, then re-check the socket after acquiring the lock to avoid
racing. Keep the fix localized to the autospawn code that uses socket_path and
Command::new("minimald").

In `@crates/minimald/src/main.rs`:
- Around line 318-323: `spawn_detached` currently assumes `cli.listen_on()` is a
Unix socket, so `minimald run --detach --vsock` can time out even though the
detached child is alive. Update the `main` flow around `listen_args.detach` to
either reject `--detach` when `cli.vsock` is set or make `spawn_detached`/its
readiness check aware of vsock by polling the actual vsock listener instead of
`UnixStream::connect`. Keep the fix localized to `main`, `spawn_detached`, and
the `listen_on` readiness logic so the detached path matches the listener type.

---

Nitpick comments:
In `@crates/minimal2/src/client.rs`:
- Around line 188-194: The linux_socket_path_honors_backend_with_override test
only checks suffixes, so it can pass even if minimal_dir_override is ignored.
Update the assertions in resolve_socket_path’s test to verify the complete
override-derived paths for both the native and bridged cases, using the same
symbols resolve_socket_path and linux_socket_path_honors_backend_with_override
so the test proves the override is actually applied.
🪄 Autofix (Beta)

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: 40a23532-64ab-4a8f-acd1-ddd995684726

📥 Commits

Reviewing files that changed from the base of the PR and between c1333e0 and dec204c.

📒 Files selected for processing (4)
  • crates/minimal2/src/autospawn.rs
  • crates/minimal2/src/client.rs
  • crates/minimal2/src/main.rs
  • crates/minimald/src/main.rs

Comment thread crates/minimal2/src/autospawn.rs Resolved
Comment thread crates/minimal2/src/autospawn.rs Resolved
Comment thread crates/minimald/src/main.rs Resolved
@norrietaylor norrietaylor changed the title feat(minimal2,minimald): default to native minimald on Linux; --minvmd to opt into the VM [WIP] feat(minimal2,minimald): default to native minimald on Linux; --minvmd to opt into the VM Jun 24, 2026
@norrietaylor
norrietaylor marked this pull request as draft June 24, 2026 23:38
…ject --detach --vsock

- autospawn: forward the resolved minimal_dir into the spawned `minimald run
  --detach` as `--minimal-state-dir`, so the daemon binds the same socket
  resolve_socket_path resolved (otherwise it defaults to $XDG_STATE_HOME and the
  CLI connects to the override socket and fails). (CR thread r3470936701)
- minimald: reject `run --detach --vsock` up front. spawn_detached polls the UDS
  for readiness, but a --vsock child binds vsock instead, so the parent would
  always hit the 8s timeout while leaving an orphaned detached child.
  (CR thread r3470936703)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0143kv2BRrRqGxmVwwHskQtS
@norrietaylor
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
coderabbitai Bot commented Jun 25, 2026 •
Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

norrietaylor and others added 2 commits June 24, 2026 23:08
`cmd_mesh_status` (added in #561, after this branch forked) still called
the pre-#571 `ensure_minvmd_running()`, so `minimal mesh status` ignored
the `--minvmd` flag and always autospawned the minvmd VM. Convert it to
`ensure_daemon_running(global.minvmd, ...)` like every other command, so
it respects the native-default / `--minvmd`-opt-in backend dispatch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@norrietaylor
norrietaylor marked this pull request as ready for review June 25, 2026 07:48
@norrietaylor norrietaylor changed the title [WIP] feat(minimal2,minimald): default to native minimald on Linux; --minvmd to opt into the VM feat(minimal2,minimald): default to native minimald on Linux; --minvmd to opt into the VM Jun 25, 2026
@msample msample 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.

LGTM

@norrietaylor
norrietaylor merged commit 547ee7f into main Jun 25, 2026
21 checks passed
@norrietaylor
norrietaylor deleted the feat/linux-native-default-backend branch June 25, 2026 21:41
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.

2 participants

0