Skip to content

tools/lab: host-wide lab id lock; change follows a LAN renumber; scenarios 06 LAN renumber, 07 require_public_ip - #155

Merged
Cd1s merged 4 commits into
mainfrom
lab/id-lock
Oct 18, 2026
Merged

Cd1s merged 4 commits into
mainfrom
lab/id-lock

Conversation

@Cd1s

@Cd1s Cd1s commented Oct 17, 2026

Copy link
Copy Markdown
Owner

What

Host-wide lab id lock (#152). A lab's namespaces (mrlab<id>-*), taps and QEMU are host-wide while its state lives in each checkout, so two checkouts could take the same id — a reset 1 in one checkout tore down another agent's running lab.

  • up starts a holder process (own session, host namespace) that flocks /run/mrlab/<id>.lock until down and writes pid=, checkout=, since= into it. Contenders open the file append-only, so they never touch the owner's data; only the winner rewrites it.
  • Every command that touches a lab (up down reset isp install lan ssh console api change run reboot powercut) refuses an id held by another checkout, naming the owner and PID. reset/down were the dangerous ones, not only up.
  • status shows "lock": free | ours | held | stale with owner / owner_pid.
  • A lock whose holder died without down (stale): the same checkout takes it back; another checkout needs MRLAB_FORCE=1 (MRLAB_FORCE=1 lab.sh reset <id>).
  • down empties the file while the holder still has the flock, then stops the holder (verified by name and by its fd on the lock file); the file itself stays, so a contender can never end up locking an unlinked inode.

lab.sh change follows a LAN renumber (#153). When the apply answers with confirm_ip / confirm_token, the lab records the new router address, the LAN client renews (as a wired PC whose port flaps), and the change is confirmed on the new address with the one-time token; later commands use the new address.

Scenarios. 06-lan-renumber: 192.168.1.1/24 → 192.168.1.6/24 → 192.168.2.1/24 through the API — confirmed on the new address, client lease and gateway follow, panel/API on the new address, no rollback after the 120 s window, old addresses removed. 07-require-public-ip: PPPoE behind CGNAT with wan[].require_public_ip (gap 30 s) — cron re-check redials, stops after 5 private addresses with a risk event, no further redials, public address once the ISP offers one.

README: the quick reference says ids are host-wide, how to check one (status) and how to take over a stale one; the new scenarios are listed.

Verification

  • shellcheck: tools/ci.sh's invocation (-S warning) and the stricter default on lab.sh, guest/*.sh, scenarios/*.sh: clean.
  • Two checkouts of this branch on IN (ids 7, 8 only):
    • A up 7; B up 7, reset 7, down 7, isp 7 1 dhcp, console 7 true → all refused with A's checkout and holder PID; A's lab untouched (QEMU, 4 namespaces). B status 7 shows "lock":"held" and A as the owner.
    • A down 7 → lock file empty, no holder → B up 7 succeeds.
    • B's holder killed (crash) → A up 7 refused (stale, MRLAB_FORCE hint) → MRLAB_FORCE=1 A reset 7 takes over. A's own holder killed → A up 7 takes it back without force.
    • A and B up 8 at the same time, 8 rounds (after fixing a race the first rounds found: a loser that saw the lock already held treated it as its own): every round exactly one winner and one holder, the loser refused naming the owner.
    • run 7 01-fresh-dhcp 6/6 and run 8 06-lan-renumber 14/14 in parallel; B up 8 refused meanwhile; both locks free and no holders afterwards (the scenario's exit trap runs down).
  • Scenario 07 against main 2f40ac3 (RC2 run): every check ok except one that asserted more than feat(net): require public IPv4 on PPPoE WANs #150 specifies (a CGNAT session that passes the health check is "ok" in mr doctor by design; the stop is the risk event) — that line is a recorded diagnostic now.

Closes #152

🤖 Generated with Claude Code

Cd1s and others added 4 commits October 18, 2026 07:40
…new address); scenarios 06 LAN renumber, 07 require_public_ip behind CGNAT

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…med, reset takes the id first, lock records written once and only under the flock

- change: lan.ip / cookies switch to the new address only after a "confirmed":true answer (or, with
  --no-confirm, once the router answers there); a failure leaves the lab on the old address
- reset takes the id lock before teardown, so two resets of a free id cannot destroy each other's lab
- the holder writes its record with one printf (timestamp first); a held lock with an empty record or
  a dead PID is a takeover in progress: id_guard, status and id_acquire wait for the new record
- stale records are emptied only under a short flock (MRLAB_FORCE takeover, MRLAB_FORCE down of
  another checkout's lab, own stale down)
- 07: sessions() prints one number when nothing matches; 06: unused helpers removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…new no longer stretches it)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Cd1s
Cd1s merged commit 447272e into main Oct 18, 2026
2 checks passed
@Cd1s Cd1s mentioned this pull request Oct 18, 2026
52 tasks done
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.

tools/lab: host-wide lab id lock (two checkouts can grab the same id)

1 participant