Skip to content

feat: join-code onboarding with one-command installers, dashboard login, and signed proof of origin - #10

Merged
Denimworld12 merged 16 commits into
mainfrom
fm/hospital-chain-friend-onboarding
Oct 11, 2026
Merged

Denimworld12 merged 16 commits into
mainfrom
fm/hospital-chain-friend-onboarding

Conversation

@Denimworld12

@Denimworld12 Denimworld12 commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Intent

The captain is preparing to onboard friends onto a two-machine (and eventually multi-machine) test of this project's distributed hospital-chain training system over Tailscale. A friend already joined once as hospital-b by hand-unzipping a kit file and running two docker commands; that worked, but the setup required manually generating and emailing a kit containing a shared secret, used hardcoded hospital-a/hospital-b names, and had no way to prove on screen that a friend's machine was really the one connected, other than clicking a Start/Pause button that looks unconvincing to an audience. For an upcoming session with friends on Windows laptops (Docker Desktop and Tailscale already installed), the captain wants: each friend to set up their hospital node in close to one command instead of cloning the repo or hand-editing files; each friend to type their own hospital's name instead of using the hardcoded hospital-a/hospital-b identifiers; a basic login screen in front of the dashboard's monitoring pages, since right now anyone can open it and press Start/Pause with no accountability; and real, verifiable proof visible on the dashboard that the numbers and connections are actually coming from each friend's own physical machine, not just a button that nobody watching would believe. The captain explicitly said this phase is about making the communication/network and onboarding work properly, not about changing the training model or how hospitals' data is processed - that is explicitly out of scope for now. The captain also flagged that the single shared secret used to start a training round had been exposed in plaintext in a chat/terminal session and should no longer be something that needs to be shared and typed by hand at all. The captain's plan is to have a friend test this change for real on a Windows laptop before it is merged.

What Changed

  • Join-code enrollment and one-command installers: The directory now issues single-use, expiring join codes (stored only as SHA-256 hashes) through a new admin API and a new Join codes dashboard page. A remote hospital runs deploy/install/install.ps1 (Windows) or deploy/install/install.sh (macOS/Linux), types its own display name, and enrolls with /enroll. Its keys are generated locally and its private keys never leave it. The hub signs a TLS certificate for it, assigns a stable node id (a slug of the name plus random hex), and issues a per-hospital observer token. Display names are free text and must be unique. Removing a hospital frees its name for reuse. Every enrollment attempt is written to the audit log.
  • Dashboard login, plus relayed Start/Pause/Stop: All dashboard pages and APIs now sit behind an admin login (MEDCHAIN_ADMIN_PASSWORD). The dashboard server relays Start, Pause and Resume to the first live hospital that answers. Stop is sent to every live hospital with one shared op id, so a hospital beyond a dead neighbour still stops. Nobody has to type the shared secret any more: the hub's dashboard sends it from its own environment.
  • Signed proof of origin: Every few seconds each node posts a status message to the observer, signed with its Ed25519 update-signing key. The message reports the host's name, OS and uptime, its Tailscale device name, the measured round-trip time to each neighbour, and how many data rows it holds (the count only). The observer checks each signature against the key the directory holds for that hospital, and audits any message that fails. A new Nodes page shows the verified results. Observer writes are now checked against each hospital's own token. This branch also updates the README, docs/MULTI_LAPTOP.md, the deploy compose and env files, and the CI workflow, and adds unit tests for enrollment, the installer, the observer, auth and the relay.

Risk Assessment

✅ Low: This round's fix commit is small and well bounded. Stop now goes to every alive chain member that has a recent heartbeat, with one shared op_id per press. The nodes already ignore an op_id they have seen, and they never forward to the sender (named 'dashboard'), so the copies are harmless. Start, pause and resume behave exactly as before, now through a pure function that is unit-tested. The installer reports the refusal whatever 'docker compose down' returns, and the extended test covers that. I found no new reachable defects.

Testing

I brought the round-1 hub back up on this Mac over Tailscale, with two kit hospitals running. Then I ran deploy/install/install.sh from this commit as a friend would, three times: a fresh join-code enrollment, a re-run while still enrolled, and a re-run after the organiser clicked Remove while the node was running. All three gave the expected result. The last one is the case that wrongly said "Done" in round 1; it now reports the refusal and exits 1. The 5 install.sh unit tests also pass. The install.ps1 half of the fix could not be run on a real Windows machine here. All test containers were torn down afterwards and the worktree is clean.

  • Live validation: ✅ go - 3 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Friend runs install.sh for the first time with a join code: the node is created and started (no forced recreate), the installer says Done and the hospital joins the chain ✅ pass live 18-r2-fresh-install.txt (Creating/Created/Started, exit=0); the snapshot then showed chain hospital-a, hospital-b, harbour-view-hospita-a74d
Friend re-runs install.sh while still enrolled: the container is recreated and checks in again, the installer says Done and the hospital stays alive in the chain ✅ pass live 19-r2-rerun-still-enrolled.txt: 'Recreate/Recreated', container ID changed from 5c15a9d7… to a778506f…, exit=0, all three hospitals alive
Adversarial: organiser removes the friend's hospital while its node is running, friend re-runs install.sh; the installer must report the refusal instead of 'Done' ✅ pass live 20-r2-rerun-after-removal-while-running.txt: '[!] The organiser removed this computer from the network: ... /register answered 403', exit=1, container removed afterwards (in round 1 this printed Done…
Windows friend re-runs install.ps1 after being removed: Docker Desktop recreates the node and the installer reports the refusal ⏸️ untested no Needs a Windows machine with Docker Desktop and Tailscale to run install.ps1 against a live hub; this host is macOS. The captain's planned Windows test with a friend covers it.
Evidence: Fresh install.sh enrollment (container created, no recreate)

MedChain hospital installer 1.1.0
-------------------------------------------
  [ok] Docker is running
  [ok] Tailscale is connected: this computer is 100.89.221.7 (nikhils-mac-mini.tail880695.ts.net)
  [ok] The hub at 100.89.221.7:18100 answers
  [ok] 17 GB free

Downloading the MedChain program (medchain-node:nm3, about 2 GB the first time)...
Error response from daemon: pull access denied for medchain-node, repository does not exist or may require 'docker login'
  (could not check for a newer copy; using the one already on this computer)

Enrolling this computer. The organiser gives you a join code (it works once, for 30 minutes).
enrolled Harbour View Hospital as harbour-view-hospita-a74d (data: hospital-d.csv)

 Network medchain-harbour-view-hospita-a74d_default Creating 
 Network medchain-harbour-view-hospita-a74d_default Created 
 Container medchain-harbour-view-hospita-a74d-node-1 Creating 
 Container medchain-harbour-view-hospita-a74d-node-1 Created 
 Container medchain-harbour-view-hospita-a74d-node-1 Starting 
 Container medchain-harbour-view-hospita-a74d-node-1 Started 

Waiting for the hub to place this hospital (up to 60s)...

Done. This computer is running hospital harbour-view-hospita-a74d.
  - Keep it plugged in and awake, with Docker and Tailscale running.
  - The organiser sees this computer's name and live numbers on the dashboard's Nodes page within a minute.
  - Your hospital's files and keys are in ~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2 (don't share that folder).

  Watch it:  docker compose --project-directory "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2" -f "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2/deploy/node.yml" logs -f
  Leave:     docker compose --project-directory "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2" -f "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2/deploy/node.yml" exec node python -m node.leave
  Stop:      docker compose --project-directory "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2" -f "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2/deploy/node.yml" down
exit=0
Evidence: Re-run while still enrolled: container recreated (new ID), Done, exit 0
container before: 5c15a9d70f6176fd008ca8a329743818593ab0454bde6875b44b2f91b35fadc2 started 2026-10-11T12:53:11.003842759Z

MedChain hospital installer 1.1.0
-------------------------------------------
  [ok] Docker is running
  [ok] Tailscale is connected: this computer is 100.89.221.7 (nikhils-mac-mini.tail880695.ts.net)
  [ok] The hub at 100.89.221.7:18100 answers
  [ok] 17 GB free

Downloading the MedChain program (medchain-node:nm3, about 2 GB the first time)...
Error response from daemon: pull access denied for medchain-node, repository does not exist or may require 'docker login'
  (could not check for a newer copy; using the one already on this computer)
  [ok] This computer is already enrolled (harbour-view-hospita-a74d); keeping its keys

 Container medchain-harbour-view-hospita-a74d-node-1 Recreate 
 Container medchain-harbour-view-hospita-a74d-node-1 Recreated 
 Container medchain-harbour-view-hospita-a74d-node-1 Starting 
 Container medchain-harbour-view-hospita-a74d-node-1 Started 

Waiting for the hub to place this hospital (up to 60s)...

Done. This computer is running hospital harbour-view-hospita-a74d.
  - Keep it plugged in and awake, with Docker and Tailscale running.
  - The organiser sees this computer's name and live numbers on the dashboard's Nodes page within a minute.
  - Your hospital's files and keys are in ~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2 (don't share that folder).

  Watch it:  docker compose --project-directory "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2" -f "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2/deploy/node.yml" logs -f
  Leave:     docker compose --project-directory "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2" -f "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2/deploy/node.yml" exec node python -m node.leave
  Stop:      docker compose --project-directory "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2" -f "~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2/deploy/node.yml" down
exit=0
container after:  a778506f51ca02713eea4edb7582a19b6f3fb65fdd517c92a13d1d13be500ba5 started 2026-10-11T12:53:25.077976502Z
Evidence: Remove while running, then re-run: recreated, refused with 403 reason, exit 1, container gone
== organiser presses Remove on the dashboard while the friend's node is running
{"node_id":"harbour-view-hospita-a74d","removed_from_chain":true,"forgotten":true,"epoch":4,"told":{"hospital-a":"applied","hospital-b":"applied","harbour-view-hospita-a74d":"applied"}}
container state: running started 2026-10-11T12:53:25.077976502Z
== friend re-runs install.sh

MedChain hospital installer 1.1.0
-------------------------------------------
  [ok] Docker is running
  [ok] Tailscale is connected: this computer is 100.89.221.7 (nikhils-mac-mini.tail880695.ts.net)
  [ok] The hub at 100.89.221.7:18100 answers
  [ok] 17 GB free

Downloading the MedChain program (medchain-node:nm3, about 2 GB the first time)...
Error response from daemon: pull access denied for medchain-node, repository does not exist or may require 'docker login'
  (could not check for a newer copy; using the one already on this computer)
  [ok] This computer is already enrolled (harbour-view-hospita-a74d); keeping its keys

 Container medchain-harbour-view-hospita-a74d-node-1 Recreate 
 Container medchain-harbour-view-hospita-a74d-node-1 Recreated 
 Container medchain-harbour-view-hospita-a74d-node-1 Starting 
 Container medchain-harbour-view-hospita-a74d-node-1 Started 

Waiting for the hub to place this hospital (up to 60s)...

  [!] The organiser removed this computer from the network: the hub refuses its keys (https://100.89.221.7:18100/register answered 403: harbour-view-hospita-a74d is not a hospital this directory knows).
      What to do: Delete the folder ~/.no-mistakes/evidence/01M4NF9YC9C9ZVMYHYJVVFRSWW/friend-r2, ask the organiser for a new join code, then run the same command again.

  Fix that, then run the same command again. Nothing has been changed on this computer.
exit=1
Evidence: install.sh unit tests

5 passed in 35.39s

.....                                                                    [100%]
5 passed in 35.39s
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (16m11s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • ⚠️ dashboard/server/index.js:202 - Stop is sent the same way as Pause: relay() posts it to the first alive chain member and returns after that node answers, and the node then passes it only to its direct runner().neighbours (node/main.py:296). Stop exists for exactly the case where a neighbour is dead, and there the message can't get past the dead node. Concrete path: chain A–B–C, B's laptop dies mid-run, the organiser presses Stop. The dashboard relays to A (first by node_id), A stops and tries B, which is unreachable. C keeps running. runState puts 'running' ahead of 'stopped', so the control strip still shows the run as going, and pressing Stop again only reaches A again. The docs do say 'on every hospital it reaches', but the button can't do the job it was added for once there are more than two machines. Fix: for stop (and arguably pause/resume), have the dashboard post to every alive chain member in the relay query instead of returning after the first OK. Each node's op_id dedup already makes repeated delivery harmless if the same op_id is reused.
  • ℹ️ deploy/install/install.sh:177 - [ $code -eq 3 ] && docker compose ... down >/dev/null 2>&1 && problem ... only reports the refusal if docker compose down succeeds. If down fails (a Docker hiccup), the loop goes on as if nothing happened and the installer ends with 'Done. This computer is running hospital …' for a hospital the hub refuses. install.ps1 calls Problem no matter how down ends. Fix: [ $code -eq 3 ] && { docker compose ... down >/dev/null 2>&1; problem ...; }.

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • ℹ️ deploy/install/install.sh:175 - This gap existed before this commit. The node checks its registration only at startup (node/main.py register_with_directory), so the new refusal branch only fires after the node restarts. Live repro: the organiser removes riverside-clinic-05bd while its container is running, and the friend re-runs install.sh. node.registered still returns 0 ('registered'), and the installer prints 'Done. This computer is running hospital …' and exits 0, even though the observer is already answering the node's writes with 401. After docker restart, the same re-run correctly reports the refusal. Possible fix: have install.sh/install.ps1 restart an already-enrolled node before polling node.registered, or have the node re-register on a heartbeat. Needs a decision on whether this is in scope.
  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Organiser presses Stop while the middle hospital of an A–B–C chain is dead; the hospital beyond it (C) stops too ✅ pass live 02-stop-with-dead-middle-hospital.txt: stop results a=stopped, b=unreachable, c=stopped with one op_id; A and C show run_state stopped
Organiser presses the Stop button in the dashboard UI during a run with a dead hospital; the control strip shows the run stopped ✅ pass live 05-after-ui-stop.png, 06-ui-stop-node-states.txt
Pause and Resume still go through one hospital and spread to all; Stop's shared op_id is deduped ✅ pass live 12-pause-resume-stop-four-hospitals.txt (via hospital-a, all four paused and then running; Stop answers 'seen' on hospitals that already got it)
Removed hospital re-runs the installer after its node restarts; the installer reports the hub's refusal and exits 1 ✅ pass live 15-install-sh-rerun-after-removal-and-reboot.txt
Friend enrolls with one command, typing their own hospital name and a join code; the hospital joins the chain under that name ✅ pass live 09-install-sh-friend.txt, 10-friend-in-snapshot-with-proof.txt
Dashboard refuses snapshot and round controls without a login, and accepts only the admin password ✅ pass live 01-login-gate-api.txt, 03-login-screen.png
Nodes page shows a verified Ed25519 signature and the friend's real machine facts; spoofed proofs without a token are refused and do not change any hospital's status ✅ pass live 11-nodes-page-friend-signed-proof.png, 16-proof-spoof-attempts.txt
Friend runs install.ps1 on a Windows laptop with Docker Desktop ⏸️ untested no This host is macOS with no Windows machine or PowerShell+Docker Desktop on Windows; the captain's planned friend test on a Windows laptop covers it.
  • docker build -t medchain-node:nm3 -f node/Dockerfile . and docker build -t medchain-dashboard:nm3 -f dashboard/Dockerfile . from the worktree
  • scripts/provision.py --peers hospital-a=100.89.221.7:18001,hospital-b=…:18002,hospital-c=…:18003 --directory 100.89.221.7:18100 then the hub (deploy/hub.yml, project nm3-hub, dashboard on :18080) and three node kits (deploy/node.yml)
  • curl the dashboard API without a session, with a wrong password and with the right one (login gate)
  • Start a 300-round run, docker kill nm3-hospital-b-node-1, then POST /api/round/stop; check each node's run_state in the snapshot
  • Same again with the middle hospital dead, pressing the dashboard's Stop button in headless Chrome (chrome-devtools-axi) and accepting the confirm dialog
  • Pause, Resume and Stop across four alive hospitals (single-node relay plus flood; shared op_id dedup shows as 'seen')
  • Create a join code via /api/admin/join-codes, then MEDCHAIN_DISPLAY_NAME='Riverside Clinic' MEDCHAIN_JOIN_CODE=… bash deploy/install/install.sh </dev/null (unattended)
  • Nodes page screenshot and snapshot proofs: friend's signature verified
  • POST /api/admin/members/riverside-clinic-05bd/remove, then re-run install.sh (node still running), then restart the node container and re-run install.sh (refusal path)
  • Unauthenticated and wrong-token POST /proof to the observer naming hospital-a
  • node --test dashboard/server/relay.test.js
  • pytest -q tests/unit/test_install_sh.py

🔧 Fix applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 3 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Friend runs install.sh for the first time with a join code: the node is created and started (no forced recreate), the installer says Done and the hospital joins the chain ✅ pass live 18-r2-fresh-install.txt (Creating/Created/Started, exit=0); the snapshot then showed chain hospital-a, hospital-b, harbour-view-hospita-a74d
Friend re-runs install.sh while still enrolled: the container is recreated and checks in again, the installer says Done and the hospital stays alive in the chain ✅ pass live 19-r2-rerun-still-enrolled.txt: 'Recreate/Recreated', container ID changed from 5c15a9d7… to a778506f…, exit=0, all three hospitals alive
Adversarial: organiser removes the friend's hospital while its node is running, friend re-runs install.sh; the installer must report the refusal instead of 'Done' ✅ pass live 20-r2-rerun-after-removal-while-running.txt: '[!] The organiser removed this computer from the network: ... /register answered 403', exit=1, container removed afterwards (in round 1 this printed Done…
Windows friend re-runs install.ps1 after being removed: Docker Desktop recreates the node and the installer reports the refusal ⏸️ untested no Needs a Windows machine with Docker Desktop and Tailscale to run install.ps1 against a live hub; this host is macOS. The captain's planned Windows test with a friend covers it.
  • Brought the hub back up (docker compose -p medchain-nm3hub ... -f deploy/hub.yml up -d --wait, nm3 images, Tailscale IP 100.89.221.7) and started the hospital-a and hospital-b kit nodes
  • Logged in through POST /api/auth/login and created a join code through POST /api/admin/join-codes
  • Fresh unattended enrollment: MEDCHAIN_DISPLAY_NAME='Harbour View Hospital' MEDCHAIN_JOIN_CODE=... bash deploy/install/install.sh </dev/null
  • Re-ran bash deploy/install/install.sh while still enrolled, recording the container ID and start time before and after
  • Clicked Remove through the dashboard API (POST /api/admin/members/harbour-view-hospita-a74d/remove) while the node was running, then re-ran bash deploy/install/install.sh
  • pytest -q tests/unit/test_install_sh.py (5 passed)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…he kits

A hospital on another laptop can now join with a one-time join code instead of a
kit made and emailed by the organiser:

- directory: POST /enroll checks the code (single use, expiring, stored as its
  SHA-256, revoked after 5 wrong proofs), issues a CA-signed certificate for the
  node's own TLS key (from a CSR), a node id and a per-hospital observer token;
  /admin/join-codes creates, lists and revokes codes with the hub's admin token.
  Every attempt and code change is audited (directory store + Postgres audit_logs).
  An enrolled hospital may only register with the keys it enrolled with.
- node/enroll.py: makes the keys locally (private keys never leave), proves the
  code with an HMAC keyed by its hash, verifies the hub's HMAC'd answer, nonce and
  TLS pin, and writes a kit laid out like provision.py's (secret in
  pki/network/shared_secret via SHARED_SECRET_FILE, never printed).
- observer: accepts a hospital's own token, which only writes as that hospital,
  checked against hospital_keys (written only by the directory, never /ingest).
- provision.py: the hub kit carries the CA key; kits and make up are unchanged.
- image v1.1.0 default (ships deploy/node.yml for the enrolled kit).
…enrolled hospitals

- The directory generates an enrolled hospital's node id as a slug of its display
  name plus random hex (st-marys-leeds-3f9a); identity (TLS pins, signatures,
  chain placement) stays keyed on the id and keys.
- Display names are unique, compared case/space-insensitively, against enrolled
  hospitals and every hospital in the directory's documents; a clash is a 409 and
  the code stays valid. An enrolled hospital always appears under the name it
  enrolled with, whatever its node's config says.
- Dashboard audit log shows display names (id in the tooltip); node start-up log
  names the hospital. hospital-a..e are unchanged for make up and kits.
… a Nodes page

- node/proof.py: every 10 s each node with a signing key POSTs the observer a
  message signed with its update-signing Ed25519 key (context "proof"): host
  name, OS and version, uptime, Tailscale device (from the install script via
  MEDCHAIN_HOST_*; else the container's own, labelled), live RTT to each chain
  neighbour over the pinned TLS client, data row count, boot id + sequence.
- observer POST /proof: verifies against hospital_keys (the directory's record),
  refuses unknown keys, bad signatures, replays and >10 min skew, and audits each
  refusal (proof_rejected); stores the latest in node_proofs (not via /ingest).
- dashboard: snapshot.proofs (verified / rejected / stale / none) and a Nodes page
  with a Signature verified badge, key fingerprint and the facts. Start/Pause unchanged.
- node.enroll takes --host-name/--host-os/--host-booted-at/--tailscale-device.
…oin-codes page

- One admin account, created on first run (from MEDCHAIN_ADMIN_PASSWORD, or by the
  first visitor's setup screen while none exists; the table holds at most one),
  password stored as a bcrypt hash (cost 12).
- Sessions: random 32-byte token in an httpOnly SameSite=Strict cookie, only its
  SHA-256 in Postgres, 12 h, logout deletes it; 5 failed logins lock an address
  out for 5 minutes; cross-site Origin refused on state-changing requests.
- Every /api route (snapshot, Start/Pause, assess relay, admin) and the /ws
  snapshot stream need the session; the UI shows the login screen first. The
  existing pages are unchanged; a Log out button and a Join codes page are added.
- Join codes page relays to the directory's admin API with the hub admin token
  (shared hub-secrets volume): create (validity, data slice), shown once; list;
  revoke; and the hospitals that enrolled.
- Integration tests and CI log in (MEDCHAIN_ADMIN_PASSWORD).
…ly the foreign item

Found on the live two-node stack: an enrolled hospital's batches carry audit rows
for the updates it received (node_id = itself, sender = its neighbour), so the
batch-wide check on node_id/sender refused every such batch with 403 and the
node's writer retried forever: its metrics never reached the dashboard.

- The identity field is per kind (update_sent: sender; everything else: node_id),
  and only an item written as another hospital is refused, like an unknown kind;
  the rest of the batch is applied. A batch claiming another hospital is still 403.
- node/proof.py: a host boot time that cannot be one reports no uptime.
- The first proof-of-origin message waits one interval, after registration.
…acOS/Linux shell)

deploy/install/install.ps1 and install.sh, versioned (1.1.0, image v1.1.0) and
fetched from the release tag. Assuming Docker and Tailscale are installed and the
laptop is on the organiser's tailnet, they:
- check Docker engine running, Tailscale logged in, the hub reachable over the
  tailnet and >= 5 GB free, each failure with a plain-English fix (never a trace;
  the PowerShell one never closes the window, it returns);
- ask for the hospital's name and the join code (hidden), or take them from
  MEDCHAIN_DISPLAY_NAME / MEDCHAIN_JOIN_CODE; re-ask on a taken name (exit 3);
- read this laptop's Tailscale IP/MagicDNS name and host facts (hostname, OS,
  boot time) for the proof of origin;
- pull the published image and run python -m node.enroll inside it (free text
  passed via env, the code never on a command line), then docker compose up -d.
Re-running keeps the enrollment and keys, refreshes the address and host facts,
and restarts the node; an image already present is used if the pull fails. No
secret is printed or embedded.

Also: the Join codes page shows both install commands with the hub address
(HUB_ADDRESS, written to hub.env by provision.py); Log out sits in the nav; docs.
@Denimworld12

Copy link
Copy Markdown
Owner Author

Windows end-to-end test of PR #10 (ee0b01a)

This PR has two scenarios marked untested: the Windows installer, and the published one-command download. I tested on the machine a friend would actually use: Windows 11 Home, Docker Desktop 29.1.2, Tailscale, and stock Windows PowerShell 5.1.

Setup

  • I built medchain-node from this branch and ran an isolated hub (directory, observer, dashboard, Postgres) from this branch. I also provisioned a kit-based hospital-a, all on the laptop's real Tailscale IP.
  • I ran install.ps1 exactly as the Join codes page tells a friend to: irm <url> | iex, served locally because the real URL 404s (see 1).
  • I ran the Python unit tests (37) and the dashboard server tests (16).

Labels: ✅ = verified live on Windows. 🔎 = found by reading the code on both sides, not reproduced live.

Blocks the "one command" promise

1. Nothing at v1.1.0 is published ✅

  • raw.githubusercontent.com/Denimworld12/Hospital-Chain/v1.1.0/deploy/install/install.ps1 and install.sh return 404.
  • ghcr.io/denimworld12/medchain-node:v1.1.0 gives manifest unknown. Only v1.0.0 exists.
  • So the command on the Join codes page fails for every friend today.
  • hub.yml also doesn't pass INSTALLER_VERSION to the dashboard, so the organiser can't point the page at a test tag.
  • Fix:
    • Add INSTALLER_VERSION: ${INSTALLER_VERSION:-v1.1.0} to the dashboard env in hub.yml.
    • After merge, push v1.1.0, let the image build, and make the package public.
    • Then re-run the PowerShell command from the Join codes page once on a clean Windows laptop.

2. One dead member silently splits the chain, and the run still reports "completed" ✅

What I saw:

  • The chain was hospital-a – <a hospital whose laptop was off> – St Mary's Leeds (enrolled, alive, Signature verified).
  • I started a 20-round run from the dashboard. It answered forwarded: {"<dead>": "unreachable (ConnectError)"}.
  • hospital-a trained 20 rounds alone. St Mary's stayed run_state: idle, current_round: 0.
  • The dashboard showed state: completed, with no hint that a hospital never took part.

Why it matters:

  • The only way out is /leave, and only the hospital itself can call it. The organiser has no admin call to remove a member that's gone.
  • Join codes make joining easy, and friends' laptops do sleep, so this will happen during the demo.

Fix (suggested):

  • Add an admin "remove hospital" action: directory /admin/members/<id>/remove, plus a button on the Nodes page. It should do what /leave does on the member's behalf.
  • Flag a run as incomplete when a member never started.

Should fix (each found during the live test)

3. A failed or abandoned install burns the hospital's name for good ✅

  • I enrolled "St Mary's Leeds", deleted the MedChain folder (what a stuck friend would do), and ran the installer again with a fresh join code.
  • Result: another hospital (st-mary-s-leeds-8da8) is already called "St Mary's Leeds" three times, then No free name after three tries.
  • The hospital's own ghost record holds the name. Neither the dashboard nor the API can release it (directory/enroll.py runs consume_code and add_enrolled before the node has even started).
  • Fix: the admin remove action from 2 should also delete the enrolled record. Alternatively, let enrollment replace an enrolled record that has never registered.

4. The installer's own advice for "port is already allocated" doesn't work ✅

  • install.ps1:196 says to set $env:MEDCHAIN_PORT and get a new join code.
  • On an enrolled laptop, the re-run path (install.ps1:145-153) re-reads NODE_PORT from .env and ignores MEDCHAIN_PORT. I tested with MEDCHAIN_PORT=18023: the node stayed on 18003.
  • With a new code it then hits 3 instead.
  • Fix: on re-run, when MEDCHAIN_PORT is set, rewrite NODE_PORT and ADVERTISE_ADDR. The pins are key-based, so no re-enrollment is needed. Then fix the message.

5. install.ps1 unattended mode doesn't stop on a taken name ✅

Unlike install.sh, the PowerShell installer falls back to Read-Host even when MEDCHAIN_DISPLAY_NAME / MEDCHAIN_JOIN_CODE were set.

  • With input piped in: it read the next stdin line as the hospital name and enrolled a hospital literally named ABCD-EFGH-JKMN-PQRS-TVWX, spending the code.
  • With no input: Read-Host returns $null, so line 160 throws You cannot call a method on a null-valued expression three times, and the run ends with the misleading No free name after three tries.

Fix:

  • If MEDCHAIN_DISPLAY_NAME was supplied and the hub answers 3, call Problem "That name is taken." "Set MEDCHAIN_DISPLAY_NAME to a name no other hospital uses…" and return, as install.sh does.
  • Guard [string]$name against $null.

Interactive use, where a person types a new name, is fine.

6. Clock skew can mark a genuine node "Rejected" for good 🔎

  • observer/app.py:84,150 rejects proofs whose sent_at is more than 600 s from the hub's clock.
  • On Windows, sent_at comes from the Docker Desktop WSL VM clock, which is known to drift after the laptop sleeps.
  • Each refusal also writes an audit row, every 10 s.
  • node/security.py:114 back-dates new certificates by only 5 minutes. Any peer whose clock is more than 5 minutes slow rejects a freshly enrolled node's TLS as "not yet valid".
  • Fix: judge freshness by receive time plus (boot_id, seq) and just display the skew. Back-date certificates by about a day. Rate-limit the proof_rejected audit rows.

7. An enrolled node's observer token reaches Postgres only once 🔎

  • The token hash is written only in /enroll (directory/app.py:406, through the best-effort DbWriter). /register (:328) doesn't re-sync it.
  • If that write is dropped, or the organiser resets postgres-data, every /proof and /ingest from that node gets 401 forever.
  • Fix: in register, pass observer_token_sha256=enrolled["observer_token_sha256"], enrolled=True when the hospital is enrolled.

8. Changing MEDCHAIN_ADMIN_PASSWORD is silently ignored 🔎

  • dashboard/server/auth.js:109 uses INSERT … ON CONFLICT DO NOTHING. hub.env says "restart the dashboard after setting it", but a wrong first password stays until the Postgres volume is wiped.
  • Fix: ON CONFLICT (username) DO UPDATE SET password_hash = EXCLUDED.password_hash, and drop existing sessions.

9. Hubs made before this PR can't take join codes, and the docs don't say so 🔎

  • An old hub kit has no pki/ca.key and no enrollment: block, so /enroll answers 503. Its hub.env still says IMAGE_VERSION=v1.0.0.
  • Fix: add "re-run provision.py with the same --pki and bump IMAGE_VERSION" to docs/MULTI_LAPTOP.md, and show the 503 reason on the Join codes page.

Nits

  • No .gitattributes. With Git for Windows' default core.autocrlf=true, install.sh checks out with CRLF. tests/unit/test_install_sh.py then fails 3 of 3 with syntax error near unexpected token `$'{\r'', and all 3 pass after converting to LF. Add *.sh text eol=lf. The same applies to anyone on Windows who runs bash install.sh from a clone.
  • provision.py refuses a single kit hospital (--peers needs at least two hospitals). An organiser can't run "my hospital + friends via join codes" without making a dummy second kit, which then sits in the chain as a never-joined member (and see 2).
  • Postgres on a fixed port. hub.yml publishes Postgres on fixed 127.0.0.1:5432. On an organiser laptop that already runs PostgreSQL (this one does), make hub fails with ports are not available. This predates the PR. Consider ${POSTGRES_PORT:-5432}.
  • Weak facts for kit hospitals on the Nodes page. Kit-based hospitals show the container ID (944cc64876b0) as hostname and no Tailscale device, so the organiser's own hospital looks less convincing there than a friend's.
  • Empty folder after a failed enrollment. The installer leaves an empty MedChain folder behind while saying "Nothing has been changed on this laptop".
  • Shared lockout address. Lockout is keyed on req.socket.remoteAddress, which behind Docker port publishing is the gateway IP for every client, so one person's 5 bad tries lock out everyone.

What I verified works on Windows ✅

  • install.ps1 checks: runs under Windows PowerShell 5.1 via irm | iex. The Docker, Tailscale, hub-reachable and disk checks all print correctly, and it finds the Tailscale IP and MagicDNS name itself.
  • Wrong or spent codes: a wrong code is refused (unknown join code), and a spent code is refused (this join code has been used). Each gets clear advice and no kit is written.
  • Name check: the taken-name check ignores case and spacing (hospital A → refused).
  • Enrollment: St Mary's Leeds → st-mary-s-leeds-8da8. Keys are generated locally, .env has no SHARED_SECRET, the secret is in pki/network/shared_secret, and the join code never appears in any output.
  • Node start: healthy, joins the chain (epoch 3), and registers with the directory (200).
  • Proof of origin: the Nodes page shows Signature verified with the real host facts (LAPTOP-53DCVF1I, Windows 11, Tailscale name, boot uptime, 62 data rows).
  • Re-run: keeps the keys and enrollment. .env is rewritten with CRLF, but Compose parses it cleanly (no \r in any value).
  • Dashboard auth:
    • Without a session: 401 on snapshot, round start and join codes.
    • Cross-site login: 403. Wrong password: 401.
    • Correct login sets HttpOnly; SameSite=Strict; Max-Age=43200.
    • Join codes are created in XXXX-XXXX-XXXX-XXXX-XXXX format, and the install command shows the right hub (<tailscale-ip>:18100, a non-default port).
  • Tests: 37/37 Python unit tests (enroll, observer, install_sh, provision, settings) and 16/16 dashboard server tests (auth, snapshot) pass.

Not covered: the hidden join-code prompt (Read-Host -AsSecureString) can't be fed by a script. Someone should type it once by hand in a real PowerShell window.

Suggested order before the friend session: 1 → 2 → 5 → 4 → 3. Items 6–9 can follow.

Blocking:
- hub.yml passes INSTALLER_VERSION to the dashboard (default v1.1.0), so the Join
  codes page can point at a test tag before the release.
- The organiser can take a hospital out on its behalf: POST
  /admin/members/<id>/remove (directory, admin token) does what /leave does, and
  forgets an enrolled hospital (its credential and observer token stop working,
  its name is free). Remove button on the Nodes page (which now lists every chain
  member, proof or not), Forget on the Join codes page.
- A run is flagged incomplete in the control strip when a chain member that was
  registered before it started never took part (snapshot run.missing).

Should fix:
- Forget frees the name of an abandoned install (enrolled record deleted).
- Installers: a re-run with MEDCHAIN_PORT moves NODE_PORT/ADVERTISE_ADDR (no new
  code); the port-conflict advice says so; an empty folder a failed run made is
  removed again.
- install.ps1 unattended (MEDCHAIN_DISPLAY_NAME set) stops on a taken name like
  install.sh; no input at all (null Read-Host) stops with a plain reason.
- Proof freshness by arrival (boot id + seq), not the sender's clock; the skew is
  shown on the Nodes page; proof_rejected audit rows rate-limited per hospital and
  reason (5 min); certificates back-dated a day.
- /register re-syncs an enrolled hospital's observer token hash to Postgres.
- A changed DASHBOARD_ADMIN_PASSWORD (or user) replaces the account and ends all
  sessions; an unchanged one is left alone.
- A hub kit made before join codes: the 503 says how to upgrade it; documented.

Nits: .gitattributes (*.sh eol=lf); hub Postgres port is POSTGRES_PORT (default
5432).
@Denimworld12

Copy link
Copy Markdown
Owner Author

Thanks for testing this on a real Windows 11 laptop. Below is what changed for each point, as of b3960b6. CI is green: 8 passed, 1 skipped.

Blocks the "one command" promise

1. Nothing at v1.1.0 is published. Partly fixed.

  • deploy/hub.yml now passes INSTALLER_VERSION: ${INSTALLER_VERSION:-v1.1.0} to the dashboard. The Join codes page builds its install commands from it, so the organiser can point it at a test tag. It's listed, commented out, in deploy/hub.env.example.
  • Still to do after merge, and I can't do it from here: push the v1.1.0 tag, let the image workflow publish ghcr.io/denimworld12/medchain-node:v1.1.0 for both architectures, and make the package public. Then run the PowerShell command from the Join codes page once on a clean Windows laptop.

2. A dead member splits the chain, and the run still reports "completed". Fixed.

  • Remove a hospital: the directory has a new POST /admin/members/<id>/remove, called with the hub admin token. It does what /leave does, on the hospital's behalf: its neighbours bridge to each other.
  • Nodes page: a Remove button calls it. The page now lists every chain member, including one that never sent a proof.
  • Last two hospitals: removing one of only two is allowed. The survivor is left alone and refuses to start a run until another hospital joins (node/runner.py returns alone). A hospital calling its own /leave still can't shrink the chain below two.
  • Incomplete runs: once a run has completed or failed, the control strip shows - incomplete: <name> never took part for any chain member that was registered before the run started but never logged a round. It only checks after the run ends, so healthy hospitals aren't flagged while the start message is still travelling.
  • Not changed: the start message still can't reach past a dead member. The fix is to remove that member and start again.

Should fix

3. A failed or abandoned install burns the name. Fixed.

  • The same remove action deletes an enrolled hospital's record and revokes its observer token in hospital_keys. Its credential stops working and its name is free.
  • On the Join codes page this is Forget on "Hospitals that joined with a code".
  • It works whether or not the hospital ever joined the chain, and in a two-hospital chain.
  • The name check now only counts hospitals that may still register, so a forgotten hospital's old membership documents no longer hold its name. Tested: forget, then re-enroll with the same name.

4. MEDCHAIN_PORT was ignored on a re-run. Fixed in both install.ps1 and install.sh.

  • With MEDCHAIN_PORT set, a re-run of an enrolled laptop rewrites NODE_PORT and ADVERTISE_ADDR and keeps everything else, with no new join code.
  • Without it, the port stays as it was.
  • The "port is already allocated" advice now says to set MEDCHAIN_PORT and run the same command again.

5. install.ps1 unattended mode didn't stop on a taken name. Fixed.

  • With MEDCHAIN_DISPLAY_NAME set, a taken name now stops with "That name is taken. Set $env:MEDCHAIN_DISPLAY_NAME to a name no other hospital uses…" and never falls back to Read-Host.
  • A $null from Read-Host (no input at all) stops with "No hospital name given" or "No join code given". There's no null-reference error and no join code is spent on garbage input.

6. Clock skew could mark a genuine node "Rejected". Fixed.

  • Freshness: the observer no longer compares sent_at with its own clock. A replay is caught by the per-start boot id and sequence number.
  • Skew display: the skew is saved as clock_skew_s. The Nodes page shows "clock behind/ahead by …" when it's over a minute; the proof still counts.
  • Audit rows: proof_rejected rows are rate-limited to one per hospital and reason every 5 minutes. The dashboard's Rejected status still updates on every refusal.
  • Certificates: now start a day early, for both the CA and leaf certificates (provision.py/pki.py and enrollment).

7. The observer token reached Postgres only once. Fixed.

  • /register now passes observer_token_sha256 and enrolled=True for an enrolled hospital, so every restart re-syncs the hash.
  • Tested by dropping the record before the node starts.

8. Changing MEDCHAIN_ADMIN_PASSWORD was ignored. Fixed.

  • On start, if the account's username or password differs from the environment, the dashboard deletes every session and replaces the one account.
  • If they match, nothing changes and sessions are kept.

9. Hubs made before this PR can't take join codes. Fixed.

  • The 503 now says why: either the kit was made before join codes, or there's no CA key at the expected path. It says how to upgrade: re-run provision.py with the same --pki and --hospital directory --force, set IMAGE_VERSION=v1.1.0, then make hub. The Join codes page shows this message.
  • The same steps are in docs/MULTI_LAPTOP.md under "A hub made before join codes".

Nits

  • .gitattributes: added *.sh text eol=lf.
  • Postgres port: deploy/hub.yml publishes Postgres on 127.0.0.1:${POSTGRES_PORT:-5432}. The variable is listed in hub.env.example.
  • Empty folder after a failed enrollment: fixed in both installers. A folder the run created and left empty is removed again, so "Nothing has been changed" is true.
  • Intentionally left as-is, to keep this PR to defects:
    • Weak facts for kit hospitals on the Nodes page: kit nodes don't run the install script, so they report what their container sees, and the page labels it that way.
    • Shared lockout address behind Docker's NAT: a per-username lockout would let anyone lock the admin out. The dashboard binds to 127.0.0.1 on the hub by default.
    • provision.py refusing a single kit hospital.

How this was checked

  • Tests: unit tests cover each fix: directory removal in a 3-node chain, forget and re-enroll, token re-sync, the old-hub 503, observer skew and audit rate limits, password change, end-of-run "missing" detection, and the install.sh port and folder behaviour. All pass, along with the no-mistakes test run and CI.
  • install.ps1: the changes ran in PowerShell 7 (Linux) with docker/tailscale stubbed: unattended taken name, no input, re-run with MEDCHAIN_PORT, empty-folder cleanup. They have not been run on Windows PowerShell 5.1.
  • Still needs a person on Windows: a re-check of those paths and the hidden join-code prompt you flagged. Best done during the post-merge v1.1.0 test.

@Denimworld12

Copy link
Copy Markdown
Owner Author

Re-test of b3960b6 on Windows: every reply point checked live

Setup

  • Same laptop as before: Windows 11 Home, Docker Desktop 29.1.2, Tailscale, and Windows PowerShell 5.1, which you couldn't run.
  • I rebuilt medchain-node and the dashboard from b3960b6, re-provisioned a fresh isolated hub with the new provision.py, and ran install.ps1 the way the Join codes page says (irm … | iex, served locally because v1.1.0 isn't published).
  • Organiser side: I drove it through the dashboard API and also in Chrome, clicking the real Login, Start training round, Remove, Forget, Create a join code and Log out controls.

Every point in your reply is confirmed except one claim in item 5 (see "Still open" 1). The four "Still open" items are things the live run turned up that your reply doesn't cover.

Your reply, point by point

# Claim Live result on Windows
1 INSTALLER_VERSION reaches the Join codes page ✅ Set to a test value in hub.env. Both install commands on the page used it. v1.1.0 is still unpublished: the URL 404s, the image gives manifest unknown, and the only tag is v1.0.0. Expected, and it's on you after merge.
2 Remove and the incomplete-run flag ✅ See "Item 2 in detail" below the table.
2 Two-hospital removal leaves the survivor alone ✅ With one hospital left, Start → 409 hospital-a is alone in the chain: a run needs another hospital to join.
3 Forget frees the name ✅ See "Item 3 in detail" below the table.
4 MEDCHAIN_PORT on re-run ✅ Riverside moved 18004 → 18024 with the same signing key. .env got the new NODE_PORT and ADVERTISE_ADDR. hospital-a then dialled :18024 (epoch 6) and a 3-hospital run completed. A later re-run without MEDCHAIN_PORT kept 18024.
5 Unattended taken name stops ✅ PS 5.1, valid code: [!] That name is taken. Set $env:MEDCHAIN_DISPLAY_NAME…, and the code was not spent. The case that enrolled ABCD-EFGH-… last time (junk lines on stdin) now stops the same way.
5 No input: "No hospital name given" ✅ Clean message, no null-reference error.
5 No input: "No join code given" ❌ Hangs forever on PS 5.1. See "Still open" 1.
6 Clock skew ✅ From inside a real node container, I sent correctly signed proofs with the clock shifted -3600 s. All accepted (200 verified). The snapshot had message.clock_skew_s = 3600, which the Nodes page shows as "clock behind by 1 h". A replay of the same message got 403 replayed message (sequence 3, already had 3). Only 1 proof_rejected audit row was written, and the status went back to verified on the next genuine proof. New certificates start now - 1 day.
7 Token re-sync on /register ✅ I deleted the hospital's hospital_keys row in Postgres and restarted the node. The row came back with its token hash and enrolled=t, and /proof and /ingest returned 200 straight away.
8 Admin password change ✅ A restart without a change kept the session (200). After a change: old session 401, old password 401, new password 200.
9 Old hub 503 + upgrade path ✅ See "Item 9 in detail" below the table.
nit .gitattributes ✅ On a Windows checkout with core.autocrlf=true, install.sh is now w/lf.
nit POSTGRES_PORT ✅ The hub came up on 127.0.0.1:55433 next to a local PostgreSQL on 5432, with no override file.
nit Empty folder after a failure ✅ Wrong code, taken name and no name all left no folder behind.

Item 2 in detail

  • Setup: I stopped the middle hospital of a 3-chain without /leave, then started a run.
  • Run result: forwarded: unreachable, and the run ended missing: [Riverside Clinic, St Mary's Leeds]. That's correct: Riverside was cut off too.
  • Incomplete text: on the dashboard (Chrome) the strip reads "… / completed - incomplete: St Mary's Leeds never took part".
  • Remove: Remove, through the API and through the Nodes page button, bridged the survivors (epoch 4 and epoch 7). The next run trained everyone with missing: [].
  • Audit and errors: Remove is written to the audit log as member_removed, and an unknown id gets 404 … neither in the chain nor an enrolled hospital.
  • No false alarms: a run with everyone alive had missing: [].

Item 3 in detail

  • Same name back: after a hospital was removed, a fresh install with a new code under the same name "St Mary's Leeds" enrolled (st-mary-s-leeds-43af) and joined the chain.
  • Never-started enrollment: enrolled through node.enroll, never started, then Forget (API and the Join codes page button). The name was free immediately (ghost clinic re-enrolled).
  • Removed node is locked out: when its laptop came back, /register returned 403 … is not a hospital this directory knows and /ingest returned 401.

Item 9 in detail

  • The 503: I ran the new image on a hub kit made with main that morning (no ca.key, no enrollment:). /enroll returns 503 with the upgrade instructions.
  • The documented upgrade on a copy: --hospital directory --force --pki <same>. CA unchanged, ca.key and the enrollment: block added, and an old hospital-b certificate still verifies against the CA.

Also verified:

  • Login gates: without a session, snapshot, round start, join codes and remove are all 401. Cross-site remove → 403.
  • Spent codes: a spent code is refused.
  • No secrets in .env: no SHARED_SECRET line, and the secret is in pki/network/shared_secret.
  • Nodes page (Chrome): shows SIGNATURE VERIFIED, key, computer, OS, uptime, Tailscale device, live round-trip times and data rows for each hospital.
  • Log out: returns to the login screen, and the API then answers 401.
  • Tests: 157/157 Python unit tests (the whole tests/unit) and 18/18 dashboard server tests pass, run inside the built images.

Still open

1. install.ps1: name given, no join code, nothing to type → hangs forever on Windows PowerShell 5.1 (not fixed, despite the reply)

  • Repro: set MEDCHAIN_DISPLAY_NAME without MEDCHAIN_JOIN_CODE, with no console input. It stops at Read-Host … -AsSecureString and was still waiting after 60 s. The folder it made is left behind.
  • Cause: on 5.1, -AsSecureString reads the console directly and never returns $null, so the new $null -eq $secure guard can't fire.
  • Fix: check before prompting. if ($unattended -and -not $joinCode) { Problem "No join code given." "Set $env:MEDCHAIN_JOIN_CODE …"; return }`.
  • Severity: low, since only scripted runs hit it. But the reply says this path is handled.

2. A removed hospital that re-runs the installer is told "Done" while the hub refuses it

  • Repro: the organiser removes or forgets a hospital, and later the friend pastes the same command again (the docs say to do this after every reboot).
  • What the friend sees: [ok] This laptop is already enrolled (st-mary-s-leeds-ca3a); keeping its keys → Done. This laptop is running hospital ….
  • What the node actually gets: register … 403 … is not a hospital this directory knows and observer … 401 on every retry, forever.
  • Why it matters: the friend believes they're in, and the organiser doesn't see them.
  • Fix: after up -d, have the installer wait about 20 s for the node to register (or call the directory once). On a 403, say "The organiser removed this laptop from the network: delete $HOME\MedChain, ask for a new join code, and run the command again."

3. A run with a dead neighbour crawls for about 20 minutes and can't be stopped

  • Repro: a 2-chain with the second hospital down, then Start training round from the dashboard (default 400 rounds).
  • What happens: hospital-a trains alone and never converges. After round ~300 each round waits out the timeout, about 15 s each. At round 323 it would have needed roughly 20 more minutes.
  • Why it matters: the dashboard only offers Pause, and the incomplete flag appears only after the run ends, so the organiser is stuck. I had to restart the node.
  • Fix: end a run early when every neighbour has been unreachable for N rounds (it's already known as missing). Or add a Stop next to Pause.

4. Same display name shown twice after a Remove + re-enroll (cosmetic)

  • The topology lists "St Mary's Leeds (head): alive" and "St Mary's Leeds: left the chain".
  • The Nodes page also keeps the removed st-mary-s-leeds-ca3a row ("not in the chain") next to the new one.
  • Fix: show the node id with left or removed entries, or drop forgotten hospitals from those lists.

Not covered here

  • The interactive join-code prompt: typing it into a real window couldn't be automated from my session (no visible desktop window). A person needs to paste the Join codes command into a PowerShell window once and type a taken name, then the code, then a free name.
  • Two physical machines: everything ran on one Windows laptop's Tailscale IP. The Mac ↔ Windows path was already proven with v1.0.0 earlier today.

Verdict: items 1 (code), 2, 3, 4, 6, 7, 8 and 9 and the nits are fixed and verified on Windows. Item 5 is fixed except for the missing-code hang (Still open 1). Before the friend session:

  • Must do: publish v1.1.0 (tag, image, public package).
  • Should fix: Still open 2 and 3. They're what a friend or the organiser would actually hit on the day.

- Stop: POST /round/stop floods like Pause and cancels the run on every hospital it
  reaches (both run loops end a cancelled run as "stopped"); a Stop button next to
  Pause while a run is going; the dashboard relays it; a stopped run is also checked
  for hospitals that never took part. The way out of a run a dead neighbour keeps
  from finishing.
- A removed hospital is told so: the node reports its directory registration in
  /status (registered / retrying / refused on 401/403), python -m node.registered
  reads it, and both installers wait up to a minute after starting the node. On
  refused they stop the node and say the organiser removed the laptop and a new
  join code is needed, instead of "Done".
- install.ps1 unattended with no join code stops before prompting (on Windows
  PowerShell 5.1 Read-Host -AsSecureString never returns null, so it hung).
- After a remove + re-enroll under the same name, the topology names the departed
  entry by its node id, and the Nodes page lists a hospital outside the chain only
  while its proofs still verify.
@Denimworld12

Copy link
Copy Markdown
Owner Author

Thanks for the second Windows pass. This reply covers the four "Still open" items, as of 6d39b95. CI is green: 8 passed, 1 skipped.

1. A run with a dead neighbour crawls and can't be stopped: fixed, with Stop

What changed:

  • Node: a new POST /round/stop (shared secret, like Pause). It cancels the run on that node, and both run loops end a cancelled run as stopped, with a run_stopped audit row. It also forwards to the node's neighbours, like Pause.
  • Dashboard: a Stop button sits next to Pause while a run is going, after a confirm.
  • Reaching everyone: the dashboard sends Stop to every alive chain member, not just the first, with one shared op_id (dashboard/server/relay.js). Each node ignores copies it has already seen.
  • Hospitals beyond a dead node: they stop too, even though nothing can be passed along through the dead one. The pipeline's live test killed the middle hospital of three mid-run, then pressed Stop from both the API and the button. The run ended on both sides.
  • Afterwards: a stopped run is checked for hospitals that never took part, like a completed one, and a new run can start straight away. Start, Pause and Resume still go to one node and spread from there.

Not done: I did not add "end the run automatically after N rounds without a neighbour". That would mean changing the training round loop in node/qgadmm/, which this PR keeps out of scope. Stop is the organiser's way out; then Remove the dead hospital and start again.

2. A removed hospital that re-runs the installer is told "Done": fixed

What changed:

  • Node /status: now includes registration: registered | retrying | refused. It's refused when the directory answers 401 or 403.
  • python -m node.registered: reads that inside the container and exits 0 (registered), 3 (refused) or 1 (not yet).
  • Both installers: after starting the node, they wait up to 60 s for registration (MEDCHAIN_REGISTER_TRIES × 3 s).
    • On refused: they stop the node and say "The organiser removed this laptop from the network: the hub refuses its keys", with "Delete the folder …, ask the organiser for a new join code, then run the same command again." They exit 1, with no "Done".
    • If the hub is just slow: they finish with "it keeps trying".
  • Re-run while the removed node is still running: a node only checks in with the hub when it starts, so a long-running node still believed it was registered. On a re-run of an enrolled laptop, both installers now recreate the node's container (up -d --force-recreate) before checking, so the answer is the hub's current one. A first-time enrollment isn't restarted, and no heartbeat re-registration was added.

How it was checked:

  • install.sh: unit tests cover refused, slow, and the re-run recreating before checking. The refusal is reported even if stopping the node fails.
  • Live run: the pipeline tested remove → re-run on a running node.
  • install.ps1: the same logic ran in PowerShell 7 with a fake docker.

3. install.ps1 hangs on Windows PowerShell 5.1 with a name but no join code: fixed for real this time

You were right that last time's $null -eq $secure guard can't fire on 5.1, because there -AsSecureString reads the console and never returns $null. Now, when MEDCHAIN_DISPLAY_NAME is set and MEDCHAIN_JOIN_CODE isn't, it stops before any prompt with "No join code given. Set $env:MEDCHAIN_JOIN_CODE …", and removes the folder it created. The old guard stays for interactive use.

I've checked this in PowerShell 7 only. Since it never reaches Read-Host, 5.1 behaviour shouldn't matter, but a one-line re-check on your laptop would confirm it.

4. Duplicate names after Remove + re-enroll (cosmetic): fixed

  • Topology: a departed hospital whose display name matches a current one is shown with its node id, e.g. "St Mary's Leeds (st-mary-s-leeds-ca3a): left the chain".
  • Nodes page: a hospital outside the chain is listed only while its signed proofs still verify. A removed one's token is revoked, so it goes quiet and drops off. Chain members are always listed.

Still on the organiser after merge

  • Publish v1.1.0 (tag, image, public package).
  • One person types into the interactive join-code prompt on Windows once.

@Denimworld12
Denimworld12 merged commit 45d06f2 into main Oct 11, 2026
9 checks passed
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.

1 participant