8000 fix(minimald): publish the box's address before launching its activate hooks by mitodrummer · Pull Request #2072 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

fix(minimald): publish the box's address before launching its activate hooks - #2072

Merged
mitodrummer merged 1 commit into
mainfrom
fix/finalize-publish-before-activate-hooks
Oct 7, 2026
Merged

mitodrummer merged 1 commit into
mainfrom
fix/finalize-publish-before-activate-hooks

Conversation

@mitodrummer
@mitodrummer mitodrummer commented Oct 7, 2026 •
Copy link
Copy Markdown
Member

Closes #2070

Cause

SessionActor::finalize (crates/minimald/src/session.rs) launched the box to run its on_activate hooks (launch_host_for_hooks(LaunchPhase::Activating)) before register_hostname(&record, true) published the box's loopback address and registered its *.min.internal name. That hook launch is the box's first attach. For an own-address box that declares static ingress, the attach (finish_own_ip_attach in net/gvproxy_network.rs) reads OwnAddressReporter::published_address(), finds none, and fails with no published address handed for box <name> by design (NET-010 / NET-121). So every --network own_ip --ingress … session with at least one activate hook failed at FinalizeSession. Sessions without activate hooks never launch during finalize, so they registered first and worked. Introduced by #1798.

Fix

Move register_hostname(&record, true) ahead of the activate-hook block in finalize, after the patch/hook-script marker checks, the package check, and patch materialization. The first finalize keeps wait_for_verdict = true, so it still waits (bounded) for the range verdict. The record is promoted to Active after the hooks, as before. register_hostname reads only the record's id, name, network mode, policy, and box addresses, none of which the Active write changes. The comment that said "The box's first finalize: the one registration that may wait for the range verdict" moved with the call and now explains the ordering.

Error path: if the hook launch or a hook fails (or the record write fails), finalize returns Err with the publish standing on a Materializing record. The CLI's activate cleanup then sends DestroySession, whose deregister_hostname(true) unpublishes, forgets, releases any grant, and deregisters the name. owns_hostname_route is keyed on the in-memory SessionInner::Active, which a Materializing session already has, so the deregister runs. If the client dies before it can destroy, the leftover Materializing record is reaped at the next daemon start, and grants for sessions missing from the store get swept. A retried finalize registers again, which is idempotent per session id.

Tests

  • New test-only seam launch_publish_seam (#[cfg(all(test, target_os = "linux"))]). For every own-address mock launch, it records what the production attach's OwnAddressReporter::published_address() would return at launch time. The mock launcher attaches no network, so this is how a test sees the order.
  • an_activate_hook_launch_finds_the_box_s_address_already_published: a handed own-ip box with declared ingress and an on_activate hook finalizes. Its hook launch found the hand already published (this assertion fails on the old ordering, which recorded None), the hook ran, the record is Active, and the name answers at the hand.
  • a_failed_activate_hook_s_publish_is_withdrawn_by_the_destroy: the same box with a failing hook fails finalize and is not promoted. After DestroySession, the name is NXDOMAIN, nothing routes, and published_own_address is None.

Verification

  • cargo fmt --all: clean.
  • Not compiled or run. The change was authored on macOS arm64, where minimald does not build natively. just test / just fix scope to -p minvmd -p sessions there and would not touch this change. just test-cross could not run: the Docker daemon is not running and cross is not installed. No musl target is installed for a cargo check --target …-linux-musl either. The Linux CI lanes are the first compile and test of this change. Please watch ci-linux-native-success before marking it ready.
  • No markdown touched, so just lint-prose does not apply.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Session hostnames are registered before activation hooks run, so hooks can access the session’s published address.
    • If an activation hook fails, the session remains inactive, and destroying it removes its registered hostname and published address.

…e hooks

FinalizeSession launched the box to run its on_activate hooks before
register_hostname published the box's loopback address and registered its
name. The hook launch is the box's first attach, and an own-address box that
declares static ingress refuses to attach without a published address (NET-010,
NET-121), so every own_ip session with --ingress and an activate hook failed with
"no published address handed for box <name>".

Register (and publish) first, keeping the first finalize's bounded wait for the
range verdict, then run the hooks, then promote the record to Active. A finalize
that fails after the publish leaves it on the Materializing record; the client's
activate cleanup destroys the session, and destroy withdraws the publish, the
name, and any grant.

Adds a test seam recording what each own-address launch reads as the published
address, and tests that the activate-hook launch finds the hand already
published and that a failed hook's publish is withdrawn by the destroy.

Closes #2070

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai
coderabbitai Bot commented Oct 7, 2026 •
Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 57630541-c89e-48bf-86dc-b62cc0d17116
📥 Commits

Reviewing files that changed from the base of the PR and between 143cce4 and 4ac77cb.

📒 Files selected for processing (2)
  • crates/minimald/src/session.rs
  • crates/minimald/src/session/tests.rs

Included review availability: This review used your included allowance. 3 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.


📝 Walkthrough

Walkthrough

Finalization now registers the hostname before launching activation hooks. Linux-only tests cover the published address observed at launch, successful activation, and cleanup after an activation hook fails.

Changes

Own-address Finalization

Layer / File(s) Summary
Register hostname before hooks
crates/minimald/src/session.rs
Session::finalize registers the hostname before launching activation hooks. The later registration was removed.
Observe launch address and verify outcomes
crates/minimald/src/session.rs, crates/minimald/src/session/tests.rs
A Linux test seam records the published address observed for each session launch. Linux tests check successful finalization and cleanup after a failing activation hook.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: norrietaylor

Merge Risk: ⚪ Minimal · up to 4ac77

The change is mergeable after normal Linux CI checks; no concrete blocking issue was established.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, uses the required Conventional Commit format, and clearly describes publishing the box address before activate hooks.
Description check ✅ Passed The description is complete and relevant. It explains the cause, fix, error path, tests, and verification results. It does not use the template headings exactly and omits the checklist, but it include…
Linked Issues check ✅ Passed Issue [#2070] requires FinalizeSession to publish an own-address box and register its name before launching on_activate hooks. Session::finalize now calls register_hostname(&record, true) befo…
Out of Scope Changes check ✅ Passed The changed production code implements [#2070]'s required ordering and documents its error-path behavior. The Linux-only launch observation seam and the two tests directly verify successful activation…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit watched the address appear,
Before the hooks began their work.
The launch found what it needed there,
A failing hook left cleanup clear.
Then carrots danced beside the burrow.

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

@mitodrummer
mitodrummer marked this pull request as ready for review October 7, 2026 20:23
@mitodrummer
mitodrummer requested a review from a team as a code owner October 7, 2026 20:23
@minimal-foundry
minimal-foundry Bot commented Oct 7, 2026 •
Copy link
Copy Markdown
Contributor

Approved: no findings at 4ac77cb140a5.

Nothing to do.

Clobber: none: git log on crates/minimald/src/session.rs shows the moved register_hostname call came from the PR's own earlier placement, not a revert of anyone's recent fix.

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

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Oct 7, 2026
@mitodrummer
mitodrummer added this pull request to the merge queue Oct 7, 2026
Merged via the queue into main with commit cd0d88d Oct 7, 2026
36 checks passed
@mitodrummer
mitodrummer deleted the fix/finalize-publish-before-activate-hooks branch October 7, 2026 21:42
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

2 participants

0