GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fork-kit/homelab: machine file section, homelab check, test-machine leases (#857) by scuttletoby · Pull Request #1096 · scuttletoby/t3code

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Owner

Part of #857: the small part the owner decided on in #1073 (machine file, homelab check, leases). The VM verbs, timers, file push and backups wait for the server design (#900).

What

A new kit, fork-kit/homelab (Python 3 stdlib, Linux and macOS):

  • Machine file: a "homelab" section of the private /etc/fork-kit/machine.json, read through the shared loader (fork-kit/common/machine_file.py), so all its rules apply: root owner, no link, no unknown key, no secrets. The section has leaseDir and machines[] (name, host, port, roles, note, optional lease {defaultMinutes, maxMinutes}). Only a machine with lease can be leased. Mistakes are refused with the key named: a duplicate name, a bad host or port, a default above the max, or a leasable machine with no leaseDir.
  • homelab check [--no-reach] [--timeout S] [--json]: one ok/FAIL line per finding (or the same findings as JSON), exit 1 if any line fails, changes nothing. It checks the section, the lease folder (it exists, is not a link, is not writable by everyone, and this user can write it) and every lease in it, then makes a TCP connect to each machine's host:port (nothing is sent).
  • homelab lease take|release|list: one lease per machine in <leaseDir>/<name>.json, changed only under a flock on <name>.lock. Each write goes to a temp file next to it and is renamed over it, so a reader never sees half a lease.
    • A lease ends by itself. After that anyone can take it, and take says whose lease ended.
    • Taking twice: by its holder, the lease is renewed (since is kept); by another holder, it is refused with exit 3, naming the holder and the end time, so a script can wait and retry.
    • release works only for the holder. Releasing a free or expired lease is fine.
    • A lease file the kit did not write (bad JSON, another machine's file, a link) is refused, never overwritten.
    • list --json is for scripts.
  • Nothing personal: the kit names no machine. Real names, hosts and addresses stay in each machine's local machine file. machine.example.json gets a homelab section with .example names (RFC 2606) and 192.0.2.x (RFC 5737), and a test pins that.

Not in this PR: the installer and bootstrap entry. The kit is used from a checkout for now (python3 -I -B fork-kit/homelab/bin/homelab ...). Registering an installer touches bootstrap.sh, kit_install.test.py and the release KITS table, so it gets its own PR. Until then the kit is listed in NO_INSTALLER of fork-ci-release.test.py. The whole fork-kit folder goes into a release, and a folder without a row fails that test.

Other touched files: .github/fork-ci-tests.txt (two new tests), review_judge.test.py OTHER_KITS (homelab is not a gate kit: the merge gate reads nothing in it), and a row in the fork-kit/README.md table. No seam lines: no upstream file changes.

State question

  • Runs again: take by the same holder renews it, release twice is fine, and check changes nothing.
  • Stops half-way: the old lease or the new one is in place, never half of one. A temp file left behind by a stopped take is removed by the next take or release of that machine, whatever its process id, and readers ignore it until then.
  • Two takers at once: the lock serializes them, so exactly one wins.
  • Old or empty state: a missing folder is reported with the command that makes it. An expired lease counts as free. A file the kit did not write is refused and kept.
  • Missing machine file: every command fails and names the path and the README.

Tests (red, then green)

fork-kit/homelab/tests/lease.test.py (24) and check.test.py (18), both unittest and both listed. Each file's RedCheck removes one guard at a time in a copy of the kit and shows that the test for it then fails (12 guards in lease, 8 in check). That is the red half of every guarded test below.

Questions the tests answer:

  • Does a free machine get a lease for its default time, written with mode 664 and no temp file left behind?
  • A lease taken twice: is another holder refused with exit 3 and the lease left unchanged? Does the same holder renew while keeping since?
  • A lease that expires: is it still held one second before its end, free at its end (list says free), and taken by another holder, with a note saying whose lease ended? Does the old holder then get a new lease, not a renewal?
  • Do two takers at once never both win? Four processes each sleep between read and write: with the lock exactly one wins, and without it all four do.
  • Are more than maxMinutes, 0 minutes, a machine that cannot be leased, an unknown machine and a bad holder name refused?
  • Does a missing lease folder give the command that makes it? Is a foreign or linked lease file refused and left as it was?
  • Can only the holder release a live lease? Is a release that runs twice, or comes after expiry, fine?
  • A missing machine file: do take, release, list and check all fail, naming the path and fork-kit/homelab/README.md? Is a file with no homelab section refused?
  • check: do machines that answer pass and a closed port fail? Does --no-reach connect to nothing? Are held leases shown? Do a broken lease file, a missing folder, a folder this user cannot write and a machine file anyone can write each fail?
  • Does each kind of section mistake get refused with its key named? Does the example section parse and name only RFC 2606/5737 values?

Run locally: both homelab files pass alone and through node .github/scripts/fork-ci-tests.cjs fork-kit/homelab/. review_judge.test.py ForkConfig passes. machine_file.test.py's example-file test passes with the new section; its other failures on this Mac come from the symlinked /var temp folder and are the same without this change. Not run locally: fork-ci-release.test.py, because this machine has no PyYAML. Its only change is the NO_INSTALLER row, and CI runs it.

Fixes nothing alone: #857 stays open for the installer and the parts that wait on #900.

Part of #857

Fix round 1

From the lens compare (#1096 kept over #1106; its good parts carried over). Head e9108e2.

Item Fixed how Test (fails on the old code, proven once)
1. lease folder anyone can write was accepted (0777: check said ok) lease.open_dir opens the folder and refuses it when its mode has o+w (sticky or not), naming chmod 2775; every command and check go through it Take.test_a_lease_folder_anyone_can_write_is_refused (0777 and 01777 refused, nothing written; 0775 fine), Check.test_a_lease_folder_anyone_can_write_fails_the_check
2. a folder swapped for a link mid-run was followed the folder is opened once (O_DIRECTORY | O_NOFOLLOW) and the lock, read, temp write, rename and unlink all use dir_fd= Take.test_a_folder_swapped_for_a_link_mid_run_is_not_followed: after the read the folder is moved and a link to another folder put in its place; the lease lands in the moved folder, the link target stays empty
3. a FIFO named <name>.lock made take and release hang the lock is opened with O_NONBLOCK and refused when it is not a plain file Take.test_a_lock_file_that_is_not_a_plain_file_is_refused_not_waited_on (take and release in a child with a 20 s limit: exit 1, no lease written; the old code hangs)
4. no check --json check --json prints {"ok", "checks": [{"ok", "what", "machine", "text"}]} (what: machineFile, leaseDir, lease, reach); exit code as before Check.test_check_json_gives_each_finding_for_scripts
5. check --timeout -1 crashed (traceback) --timeout is 1 to 60 s; anything else (0, negative, nan, inf, not a number) is a usage error, exit 2 Check.test_a_timeout_out_of_range_is_a_usage_error
6. --note took newlines and control characters, shown in others' terminals lease.take refuses a note that is not one printable line (str.isprintable) or is over 200 characters Take.test_a_note_that_is_not_one_short_printable_line_is_refused
7. lease.test.py failed under umask 002 the shared fixture sets umask(0o022) for each test and restores it the machine-file test failed under umask 002 on the old code; both files now pass under 002 and 077
also: temp files of a stopped take stayed unless the same pid took again the next take or release of that machine removes .<name>.json.<digits>.tmp of any pid, under that machine's lock (a take writes its temp file only while holding the lock, so none is in use); other files are kept Take.test_temp_files_of_a_take_stopped_half_way_are_removed_by_the_next_take

RedCheck grows with these guards: lease 12 (was 8), check 8 (was 6).

State question for the changes

  • Runs again: all of them are checks or refusals that give the same answer each time; the sweep removes what is stale and then finds nothing. check --json changes nothing.
  • Stops half-way: the sweep only unlinks whole files, one by one; a sweep stopped half-way leaves fewer stale temp files, and the next take or release finishes it. A take stopped after its temp write leaves one, swept next time.
  • Two takers at once: the sweep runs under the machine's lock, so it never removes the temp file of a take that is writing; the lock and the folder handle are taken in the same order by every command.
  • Old or broken files: an existing 0777 folder is refused until the owner runs chmod 2775 (the README asked for that already); an existing FIFO or folder named <name>.lock is refused with its path, not removed; old temp files of any pid are swept; lease files written before this round read as before (same format, version: 1).

Not done, for the owner: renew as its own verb (with take-twice by the same holder then refused), as #1106 has it. Here take by the holder renews and keeps since; say if you want the separate verb.

Ran here: lease.test.py 24 ok (also under umask 002); check.test.py: 17 ok; the one other, test_a_good_file_a_lease_folder_and_machines_that_answer_pass, needs a loopback connect that this sandbox only allows on a few ports, so I ran a scratch copy with the listener on an allowed port: all non-RedCheck tests ok. CI runs the real file.

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@scuttletoby

scuttletoby commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Opus 5.5 (lens compare) · read at: a146e81

Lens compare: this PR is kept over #1106; carry over: (1) refuse a lease folder anyone can write (mode o+w), in lease_dir and in check; (2) work through a folder fd (dir_fd=) so a folder swapped for a link mid-run is not followed; (3) open <name>.lock with O_NONBLOCK and refuse it when it is not a plain file; (4) homelab check --json for scripts; (5) bound the check timeout (1 to 60 s; #1106 keeps it in the machine file as checkTimeoutSeconds); (6) refuse a --note that is not one printable line or is longer than 200 characters (#1106 --purpose); (7) pin umask(0o022) in the test fixture; (8) optional: a renew verb and a refused take-twice by the same holder, if the owner prefers that over "take renews".

Why this one: CI is green here; #1106 is red on two jobs because it lacks the OTHER_KITS row (review_judge.test.py) and the NO_INSTALLER row (fork-ci-release.test.py) this PR has. This PR also makes lease opt-in per machine with its own defaultMinutes/maxMinutes (a build machine cannot be leased by mistake), reports a refused machine file as a FAIL line in check instead of a bare exit, checks hosts with ipaddress plus a strict DNS-name pattern, and gives "held by someone else" its own exit 3 so scripts can wait and retry. Both have red checks (RedCheck mutations) and the same temp-file-and-rename, flock and fail-closed rules.

blocker: none
major: none
minor: check passes a lease folder anyone can write. Reproduced: leaseDir mode 0777, homelab check --no-reach prints ok ... you can take leases and exits 0. Any local user can then forge or delete leases; the README asks for 2775 with a group, so check should fail on o+w (carry-over 1).
minor: homelab check --timeout -1 ends in a traceback (ValueError: Timeout value out of range) instead of a usage error; bound it (carry-over 5).
minor: lease.test.py test_a_machine_file_without_a_homelab_section_is_refused fails on a machine whose umask is 002: the test rewrites the machine file with open(..., 'w'), so it is mode 664 and the machine-file rules refuse it as group-writable before the section is read. CI passes only because its umask is 022. Pin the umask in the fixture or chmod 0o644 after that write.
minor: --note takes any text, including newlines and control characters, which lease list prints to other agents' terminals (carry-over 6).
minor: <name>.lock is opened without O_NONBLOCK or a plain-file check: a FIFO of that name in the folder makes every take and release hang. Only a folder writer can plant it, so it is minor (carry-over 3).
minor: temp files of a take stopped half-way are removed only by a later take with the same process id; others stay in the folder forever (readers ignore them, so no wrong result).

State question:

  • Runs again: take by the holder renews (keeps since), release twice is fine (exit 0, "was not leased"), check changes nothing. Tested.
  • Stops half-way: the lease file is replaced by rename after fsync, so the old or the new lease is there, never half; the stopped take's temp file is left (minor above) and ignored by readers.
  • Two at once: the per-machine flock serializes them; the four-process test shows one winner with the lock and four without.
  • Old or empty state: an expired lease counts as free and the next take names whose lease ended; a missing folder names the command that makes it; a file the kit did not write, a link, or a non-plain file is refused and kept; a missing machine file or section fails every command with the path. A lease file from another kit version (no version: 1) is refused, not overwritten.

Ran here: fork-kit/homelab/tests/check.test.py 15 ok; lease.test.py 18 ok, 1 fail from the umask minor above. For comparison #1106's two test files pass here too.

🤖 Generated with Claude Code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@scuttletoby scuttletoby mentioned this pull request Nov 27, 2026
feat(fork-kit): homelab kit with homelab check and test-machine leases #1106
Closed
@scuttletoby

scuttletoby commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Fix round 1 (head e9108e2), from the lens compare; #1106's good parts carried over:

  1. Lease folder anyone can write -> fixed: lease.open_dir refuses a folder with o+w (sticky or not) in every command, and check reports it as FAIL.
  2. Folder swapped for a link mid-run -> fixed: the folder is opened once (O_DIRECTORY | O_NOFOLLOW); lock, read, temp write, rename and unlink all go through dir_fd=.
  3. FIFO <name>.lock hung take/release -> fixed: the lock is opened O_NONBLOCK and refused when it is not a plain file.
  4. check --json -> added: {"ok", "checks": [{"ok", "what", "machine", "text"}]}.
  5. check --timeout -1 traceback -> fixed: 1 to 60 s, otherwise a usage error (exit 2).
  6. --note -> one printable line of at most 200 characters, refused otherwise.
  7. umask 002 test failure -> fixed: the fixture pins umask(0o022) per test.
  • Stale temp files of a stopped take -> the next take or release of that machine removes them for any pid, under that machine's lock.

Each has a test that failed on the old code (proven once); RedCheck now covers 12 guards in lease, 8 in check. Not done: renew as its own verb, which is an owner question (listed in the PR body). The state question for each change is in the PR body under "Fix round 1".

🤖 Generated with Claude Code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@scuttletoby scuttletoby mentioned this pull request Nov 27, 2026
Follow upstream: rebase onto v0.1.14-nightly.20261127.5345 (draft) #1138
Merged
@scuttletoby
scuttletoby force-pushed the main branch from f3ed74c to 9921016 Compare November 28, 2026 00:00
scuttletoby and others added 2 commits November 28, 2026 04:36
@scuttletoby @claude
fork-kit/homelab: machine file section, homelab check, test-machine l…
eefb5a2
…eases (#857)

The small part of #857 (owner decision #1073): the "homelab" section of the
private machine file, `homelab check`, and leases any project can take on a
shared test machine. Real machine names and hosts stay in the machine file;
the public example uses .example names and documentation addresses. The VM
verbs wait for the server design (#900). Used from a checkout for now; the
installer comes in its own pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby @claude
fork-kit/homelab: fix round 1, lease folder and check hardening (#857)
4722d1e
- refuse a lease folder anyone can write (o+w), in every command and in check
- reach lease files through one open handle on the folder (dir_fd), so a
  folder swapped for a link mid-run is not followed
- open <name>.lock non-blocking and refuse it when it is not a plain file
  (a FIFO made take and release hang)
- homelab check --json
- check --timeout: 1 to 60 s, a usage error otherwise (-1 crashed)
- --note: one printable line of at most 200 characters
- the next take or release of a machine removes its stale temp files of any
  process id, under the machine's lock
- tests pin umask 0o022 (lease.test.py failed under umask 002)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby
scuttletoby force-pushed the fork-kit/homelab-leases branch from e9108e2 to 4722d1e Compare November 28, 2026 05:09
@scuttletoby

scuttletoby commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Opus 5.5 · read at: 4722d1e

Round 2, on the restacked head. The diff against main is only the PR's 15 files (two commits); nothing from the rewritten main history leaks in. CI is green on this head.

blocker: none
major: none
minor: _read checks version, machine, holder (a string) and since/until (numbers), but not note, the holder's form or a finite until. A version-1 lease file written by hand or by other code then breaks lease list and the Held message, or prints raw control characters. Only a folder writer can plant such a file, so the risk is low. Reproduced:

no "note" key            -> lease list: KeyError: 'note' (traceback)
"until": Infinity        -> lease list / take by another: OverflowError in stamp() (traceback)
"until": NaN             -> list and check say "free"; take overwrites it
holder/note with ESC, \n -> lease list prints them as they are

Fix: in _read, require note to pass check_note, holder to match HOLDER_RE and since/until to be finite (math.isfinite). Anything else gets the existing "not a lease this kit wrote" refusal.
minor: the README says leases let "any project's agents share a test machine". The lease folder is local to each host's machine file, though, so agents on two hosts that both list the same test machine can each hold a lease on it at the same time. Add one line: a lease binds only the agents of the host whose folder holds it.

Round 1 fixes after the restack, each read in the code and with its test present:

  • round 1, fixed: a lease folder anyone can write (o+w, sticky or not). open_dir refuses it for every command, and check reports it as FAIL.
  • round 1, fixed: a folder swapped for a link mid-run. The folder is opened once with O_DIRECTORY|O_NOFOLLOW, and lock, read, temp write, rename, unlink and sweep all go through dir_fd.
  • round 1, fixed: a FIFO or other non-plain <name>.lock. It is opened O_NONBLOCK and refused unless S_ISREG; _read does the same for <name>.json.
  • round 1, fixed: check --json exists. It has the same rows and exit code as the text output.
  • round 1, fixed: --timeout must be 1 to 60 s, otherwise exit 2. NaN and inf are refused too.
  • round 1, fixed: --note must be one printable line of at most 200 characters (at take; see the first minor for files written by hand).
  • round 1, fixed: the fixture pins umask(0o022) per test, and write_machine also chmods the file to 644.
  • round 1, fixed: temp files of a stopped take. _sweep removes .<name>.json.<pid>.tmp for any pid under the machine's lock, before take and release. This is safe because a temp file is only written under that lock.

State question:

  • Runs again: take by the holder renews it and keeps since; release twice exits 0 ("was not leased"); check and list write nothing (only take and release create a lock file).
  • Stops half-way: the lease is fsynced and then renamed, so the old or the new lease is there, never half of one. The temp file is swept by the next take or release of that machine. An exception in _write removes its own temp file. A killed process drops its flock when the fd closes.
  • Existing state: a lock file made by another agent under a strict umask is fchmodded to 664 by its owner, and the lease file always gets 664, so group members can open the lock and replace the lease. A non-plain or linked lock or lease file is refused and kept.
  • Old state: an expired lease counts as free, and the next take names whose lease ended. A lease file with no version: 1, another machine's file, or bad JSON is refused and kept. A version-1 file with missing or odd fields is the first minor.
  • Empty state: a missing folder gives the install -d command. A missing machine file or section fails every command with the path and the README. A section with no machine that can be leased needs no folder.

Ran here only to prove the first minor: a throwaway probe built on homelab_fixture.Temp, outside the repo. No suite runs.

🤖 Generated with Claude Code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@scuttletoby scuttletoby added the fork:merge-ready Merge conveyor: lenses done, merge when green label Nov 28, 2026
@scuttletoby
Merge branch 'main' into fork-kit/homelab-leases
b7d2a57
@scuttletoby
scuttletoby merged commit 58b022d into main Nov 28, 2026
27 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@scuttletoby scuttletoby mentioned this pull request Nov 28, 2026
Owner question: build the homelab kit's VM verbs now, or after the host layout is decided? #900
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

fork:merge-ready Merge conveyor: lenses done, merge when green

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@scuttletoby
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.