Skip to content

feat(deploy): run one hospital node per laptop from a provisioned kit - #9

Merged
Denimworld12 merged 3 commits into
mainfrom
fm/hospital-chain-multilaptop-step2
Oct 10, 2026
Merged

Denimworld12 merged 3 commits into
mainfrom
fm/hospital-chain-multilaptop-step2

Conversation

@Denimworld12

@Denimworld12 Denimworld12 commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Intent

The captain wants to actually test the multi-laptop setup with a friend soon. Phase 1 (TLS key pinning, rejoin-without-directory, settings wrapper, observer metrics push, preflight script) is merged. This is the next piece: the actual one-file deployment a friend can run, plus docs written for a non-developer. This follows the original phase spec's Step 3 (deployment files) and Step 6 (docs), and the Step 0 audit's P4 recommendation, both already on disk - read both before starting:

What those references say (the audit report lives outside this repo):

Audit P4, "Deployment split" (Step 3):

  • deploy/node.yml: one service node, image ghcr.io/denimworld12/medchain-node:${IMAGE_VERSION}, env_file .env; mounts ./data:${DATA_PATH} (slice, checkpoints, audit.db) and ./pki:/pki:ro; ports "${NODE_PORT}:${NODE_PORT}" on all interfaces; no container_name and no Compose DNS assumptions; optional dns/extra_hosts hooks for MagicDNS trouble (H15).
  • deploy/hub.yml: directory, observer, postgres (5432 bound to 127.0.0.1 or unpublished), dashboard, and optionally the pki/provision step.
  • deploy/node.env.example and deploy/hub.env.example, each with a Tailscale block and a Hotspot block that differ only in addresses.
  • Kits stay: scripts/provision.py should emit deploy/node.yml + .env + pki/ + data/ instead of its own compose file, so "copy .env and fill it in" becomes "unzip your kit, check .env". Keys and the credential have to reach each friend somehow, and the kit is the existing private channel.
  • make up = docker compose up -d --build --wait (today's command, unchanged compose file). Also make node, make hub, make node-native. make node-native creates a venv, installs node/requirements.txt and runs python -m node with the .env. The model paths must default under the repo, not /app/models (checkpoint_dir -> DATA_PATH/checkpoints); the tabular model must exist natively (python -m node.assess.train_tabular), or the assess endpoints must degrade gracefully.
  • GHCR workflow: docker buildx with linux/amd64,linux/arm64, tag v1.0.0 and IMAGE_VERSION baked in as an env/label. Prefer native arm64 runners because the image installs torch and trains the tabular model at build time, which is slow under QEMU. Pins to verify on arm64: torch==2.5.1 (CPU index), xgboost-cpu==3.4.1, onnxruntime==1.30.0.

Audit section 4 rules that still hold: don't change the training maths; make up keeps working exactly as today; training never waits on the observer or dashboard; the directory is only for join/leave; no ngrok/relay, neighbours talk directly (Tailscale DERP relay allowed as a fallback); the target is 3 machines on a hotspot and the same run over Tailscale on different networks, with a node joining mid-run from the captain's laptop.

Audit failure modes the friend docs must account for: H14 the directory and neighbours must reach each node's port inbound (firewall); H15 Tailscale MagicDNS (*.ts.net) is often not resolvable inside Docker containers, Tailscale 100.x IPs avoid it, and preflight should test resolution from inside the container; H16 some phone hotspots isolate clients (AP isolation), so the hotspot fallback cannot work there; H5 Tailscale DERP relays and hotspots are slower than LAN (timeouts); a laptop that sleeps or restarts drops out and must rejoin; heartbeat freshness uses the observer's Postgres clock so clock skew does not mark nodes down; certificates are issued per address by provision.py.

Step 6 (docs): a guide a non-developer friend can follow to run one hospital node on their own laptop: install Docker Desktop and Tailscale, use the kit, run the preflight, start the node, keep the laptop awake, the hotspot fallback, troubleshooting.

What merged PR #8 already provides: node/settings.py (pydantic-settings) wraps the YAML loader, environment > YAML (NODE_CONFIG, optional) > defaults, with NODE_ID, BIND_HOST, NODE_PORT, ADVERTISE_ADDR (required with a directory; one NODE_PORT drives bind and advertised port), DIRECTORY_URL, DIRECTORY_CREDENTIAL_FILE, DIRECTORY_PUBLIC_KEY, DIRECTORY_TLS_PIN, OBSERVER_URL, OBSERVER_TOKEN/OBSERVER_TOKEN_FILE, OBSERVER_TLS_PIN, DATA_PATH, DATA_SLICE, CHECKPOINT_DIR, ALGORITHM, BITS, EPSILON, ROUND_TIMEOUT_S, ROUND_PAUSE_S, HTTP_CONNECT_TIMEOUT_S, HTTP_READ_TIMEOUT_S, TLS_CERT/TLS_KEY/TLS_CA, SIGNING_KEY, SHARED_SECRET, IMAGE_VERSION (MEDCHAIN_* names as aliases). TLS is pinned to each hospital's key as recorded in the directory's signed membership documents, not to the dialled hostname, so a node's address can change (hotspot) without new certificates; only the dashboard's relay still checks addresses. A node saves its membership and rejoins via its neighbours when the directory is down. observer/ is a FastAPI service taking POST /ingest batches with a bearer token into Postgres (nodes never hold Postgres credentials; Postgres on loopback). scripts/preflight.py (python scripts/preflight.py --node https://localhost: --ca pki/ca.crt) reads the local node's /status and reports each neighbour as direct, DERP-relayed or unreachable. A Makefile with make up and make lint, and scripts/provision.py kits (config, keys, a one-node compose file, README).

What Changed

  • Adds deploy/node.yml, a single-service compose file using ghcr.io/denimworld12/medchain-node:${IMAGE_VERSION}. It mounts the kit's data/ and pki/ and publishes NODE_PORT on all interfaces. Also adds deploy/hub.yml (directory, observer, Postgres on loopback only, dashboard) and .env.example templates for both, each with a Tailscale block and a hotspot block. scripts/provision.py now writes kits in this layout: a copy of deploy/node.yml, a .env, pki/, data/ and config/. This replaces the per-kit docker-compose.hospital.yaml, and provision checks each kit against the environment its container will see.
  • Adds make hub, make node KIT=... and make node-native KIT=...; make up is unchanged. make node-native builds a .venv-node, trains models/heart-risk.joblib if it's missing, and runs python -m node with the kit's .env and its local paths. Model paths in node/config.py now default to the repo's models/ folder instead of /app/models. The image now includes scripts/preflight.py, which can run inside the container without arguments (it reads NODE_PORT and TLS_CA). When there's no tailscale command it reports the path as "unknown", and when a neighbour is unreachable it prints the error.
  • Adds .github/workflows/image.yml, which builds the node image for linux/amd64 and linux/arm64, each on its own native runner. It bakes IMAGE_VERSION in as a build arg, env var and OCI label, and publishes a combined multi-arch tag to GHCR on v* tags or a manual run. Pull requests that touch the image only build it. Also adds docs/MULTI_LAPTOP.md, a guide for non-developer friends (Docker Desktop, Tailscale, kit, preflight, keeping the laptop awake, hotspot fallback, troubleshooting), and updates the README. Unit tests for preflight and provision are updated to match.

Risk Assessment

✅ Low: The round-1 fix is correct: hospital-d now appears in organiser step 1's --peers, matching step 3's make node KIT=kits/hospital-d. A full pass found no defects in the rest of the deployment: node.yml/hub.yml, the provision kit layout, Makefile node/hub/node-native, the preflight container defaults and the multi-arch GHCR workflow; make up and docker-compose.yml are unchanged.

Testing

I stood up a real hub (directory, observer, Postgres, dashboard) from deploy/hub.yml, using the node image built from this commit. Against it I ran four hospitals from provision.py kits: three through deploy/node.yml from unzipped kits, and one through make node-native. Live checks covered: - in-container preflight - a full training run - observer telemetry stored in Postgres - the dashboard (screenshot) - a mid-run join of hospital-d - rejoining while the directory is down - an address change made only in .env All of these passed. The guard messages for make node, make node-native and make hub also work, and the targeted provision/preflight unit tests pass. I did not drive Tailscale/MagicDNS, real phone hotspots, or the GHCR multi-arch publish workflow, because there is no tailnet, hotspot or tag-push authority here. make up was only checked with a dry run, so it is recorded as untested. I cleaned up all containers, the hub volumes, the test image, .venv-node, models/heart-risk.joblib and the caches.

  • Live validation: ✅ go - 11 of 15 scenarios driven live against the product
Scenario Result Live Evidence
Organiser runs provision.py and gets one zip per hospital, each with deploy/node.yml, a filled .env (Tailscale and hotspot blocks), only that hospital's keys in pki/, its data slice and config, plus a… ✅ pass live provision-lan.txt, kit-tree.txt
Organiser runs the hub from deploy/hub.yml; directory, observer, postgres (loopback only) and dashboard all come up healthy ✅ pass live hub-up.txt (needed a postgres host-port override because this host already runs Postgres on 127.0.0.1:5432; see make-hub.txt)
Friend unzips their kit and runs docker compose --project-directory . -f deploy/node.yml up -d; the node registers with the directory and joins the chain ✅ pass live run-status.txt (hospital-a/b from unzipped kits in chain a-b-c)
make node-native KIT=... builds .venv-node, trains models/heart-risk.joblib, runs the node without Docker, joins the chain, and keeps checkpoints under DATA_PATH with the assess models loaded ✅ pass live run-status.txt (hospital-c native: assess tabular/ecg true, data/checkpoints/hospital-c.ckpt.pkl)
Friend runs the preflight inside the node's container with no arguments and gets a per-neighbour report ✅ pass live preflight-in-container.txt
Adversarial: a neighbour's laptop is down, and the in-container preflight reports it as unreachable with the error and exits non-zero ✅ pass live preflight-neighbour-down.txt
Training started with the kit README's curl command spreads to every hospital and runs to completion, with each node's telemetry pushed to the observer's Postgres and shown on the dashboard ✅ pass live start-training.txt, run-status.txt, observer-postgres.txt, dashboard-after-run.png
Organiser provisions hospital-d later and starts it mid-run with make node KIT=kits/hospital-d; it is appended and joins the in-progress run ✅ pass live midrun-join.txt
Adversarial: a laptop sleeps and restarts while the directory is down; it rejoins the run from its saved membership in the kit's data/ via its neighbours ✅ pass live rejoin-without-directory.txt
Adversarial: hotspot switch by editing only .env to an address not in the node's certificate; neighbours keep delivering (TLS pinned to keys) ✅ pass live hotspot-switch.txt
make node / node-native / hub fail with a clear instruction when the kit or hub.env is missing ✅ pass live make-guards.txt
make up is still today's single-machine docker compose up -d --build --wait with docker-compose.yml unchanged ⏸️ untested no The prior payload did not establish a live result. It was checked only with make -n up (a dry run) and by noting docker-compose.yml is not in the diff. It was not run live because the full single-ma…
Over Tailscale across different networks (MagicDNS names, DERP vs direct path in preflight) ⏸️ untested no This host has no Tailscale tailnet or second machine. It needs Tailscale installed on 2 or more laptops in one tailnet, with kits provisioned for their *.ts.net names.
Real phone hotspot with 3 physical laptops (including the AP-isolation case) ⏸️ untested no This needs physical laptops on a phone hotspot. The address-change path was simulated on one host instead (hotspot-switch.txt).
GHCR multi-arch image publish (.github/workflows/image.yml) and friends pulling ghcr.io/denimworld12/medchain-node:v1.0.0 without a login ⏸️ untested no It needs a pushed v* tag (or a workflow_dispatch) on GitHub with package-write permission, then making the package public. This run is not authorised to push tags. docker manifest inspect on the ima…

Hub dashboard after the 3-hospital run (3 of 3 alive, round 79)

Evidence: provision.py kit generation output
hospital-a: /tmp/nm-kits2/hospital-a (+ hospital-a.zip)
hospital-b: /tmp/nm-kits2/hospital-b (+ hospital-b.zip)
hospital-c: /tmp/nm-kits2/hospital-c (+ hospital-c.zip)
directory: /tmp/nm-kits2/directory (+ directory.zip)
shared secret (generated): b7D9iqFsFG-_UMgSL6p8q-AzfRN2tnsM
Pass --secret with this value if you provision more hospitals for this network later.
Evidence: Kit file layout (hospital-b, directory)
directory/README.md
directory/config/directory.yaml
directory/hub.env
directory/pki/ca.crt
directory/pki/directory/hospitals.yaml
directory/pki/directory/signing.key
directory/pki/directory/signing.pub
directory/pki/directory/tls.crt
directory/pki/directory/tls.key
directory/pki/observer/tls.crt
directory/pki/observer/tls.key
directory/pki/observer/token
hospital-b/.env
hospital-b/README.md
hospital-b/config/node.yaml
hospital-b/data/hospital-b.csv
hospital-b/deploy/node.yml
hospital-b/pki/ca.crt
hospital-b/pki/directory/signing.pub
hospital-b/pki/directory/tls.crt
hospital-b/pki/hospital-b/credential
hospital-b/pki/hospital-b/signing.key
hospital-b/pki/hospital-b/signing.pub
hospital-b/pki/hospital-b/tls.crt
hospital-b/pki/hospital-b/tls.key
hospital-b/pki/observer/tls.crt
hospital-b/pki/observer/token
Evidence: Hub up (healthy services)
# host already has a Postgres on 127.0.0.1:5432; same command as make hub plus an override remapping only postgres' loopback port
 Container medchain-hub-directory-1 Running 
 Container medchain-hub-postgres-1 Recreate 
 Container medchain-hub-postgres-1 Recreated 
 Container medchain-hub-postgres-1 Starting 
 Container medchain-hub-postgres-1 Started 
 Container medchain-hub-postgres-1 Waiting 
 Container medchain-hub-postgres-1 Waiting 
 Container medchain-hub-postgres-1 Healthy 
 Container medchain-hub-postgres-1 Healthy 
 Container medchain-hub-dashboard-1 Starting 
 Container medchain-hub-observer-1 Starting 
 Container medchain-hub-observer-1 Started 
 Container medchain-hub-dashboard-1 Started 
 Container medchain-hub-observer-1 Waiting 
 Container medchain-hub-dashboard-1 Waiting 
 Container medchain-hub-postgres-1 Waiting 
 Container medchain-hub-directory-1 Waiting 
 Container medchain-hub-directory-1 Healthy 
 Container medchain-hub-postgres-1 Healthy 
 Container medchain-hub-dashboard-1 Healthy 
 Container medchain-hub-observer-1 Healthy 
rc=0
dashboard Up 5 seconds (healthy) 127.0.0.1:8080->8080/tcp
directory Up 14 seconds (healthy) 0.0.0.0:8100->8100/tcp
observer Up 5 seconds (healthy) 0.0.0.0:8200->8200/tcp
postgres Up 8 seconds (healthy) 127.0.0.1:55432->5432/tcp
Evidence: make hub failing on host port 5432 conflict
docker compose --project-directory . --env-file "/tmp/nm-kits2/directory/hub.env" -f deploy/hub.yml up -d --wait
 Network medchain-hub_default Creating 
 Network medchain-hub_default Created 
 Volume medchain-hub_postgres-data Creating 
 Volume medchain-hub_postgres-data Created 
 Volume medchain-hub_directory-data Creating 
 Volume medchain-hub_directory-data Created 
 Container medchain-hub-directory-1 Creating 
 Container medchain-hub-postgres-1 Creating 
 Container medchain-hub-directory-1 Created 
 Container medchain-hub-postgres-1 Created 
 Container medchain-hub-dashboard-1 Creating 
 Container medchain-hub-observer-1 Creating 
 Container medchain-hub-observer-1 Created 
 Container medchain-hub-dashboard-1 Created 
 Container medchain-hub-postgres-1 Starting 
 Container medchain-hub-directory-1 Starting 
 Container medchain-hub-directory-1 Started 
Error response from daemon: ports are not available: exposing port TCP 127.0.0.1:5432 -> 127.0.0.1:0: listen tcp4 127.0.0.1:5432: bind: address already in use
make: *** [hub] Error 1
directory Up Less than a second (health: starting) 0.0.0.0:8100->8100/tcp
Evidence: In-container preflight (no args)
$ docker compose --project-directory . -f deploy/node.yml exec node python scripts/preflight.py
hospital-b: chain hospital-a - hospital-b - hospital-c
  hospital-b <-> hospital-a     unknown     no tailscale command on this PATH (as inside a container): reachability only  (https://192.168.0.107:8001, last send: unknown)
  hospital-b <-> hospital-c     unknown     no tailscale command on this PATH (as inside a container): reachability only  (https://192.168.0.107:8003, last send: unknown)
exit=0
Evidence: Preflight against native node from host
$ python scripts/preflight.py --node https://localhost:8003 --ca pki/ca.crt  (host, native node)
hospital-c: chain hospital-a - hospital-b - hospital-c
  hospital-c <-> hospital-b     unknown     no tailscale command on this PATH (as inside a container): reachability only  (https://192.168.0.107:8002, last send: unknown)
exit=0
Evidence: Kit README start-training command
$ curl --cacert pki/ca.crt https://localhost:8002/health
{"status":"ok","node_id":"hospital-b"}
$ curl .../round/start (README command)
{"status":"started","run_id":"run-20261010-094343-01b7","rounds":400,"engine":"Q-GADMM (b=2)","node_id":"hospital-b","forwarded":{"hospital-a":"started","hospital-c":"started"}}
Evidence: All nodes completed run; kit data/ holds checkpoints, membership, audit.db
{'node_id': 'hospital-a', 'chain': ['hospital-a', 'hospital-b', 'hospital-c'], 'position': 1, 'run_id': 'run-20261010-094343-01b7', 'run_state': 'completed', 'current_round': 79, 'converged_round': 75, 'neighbours': [{'id': 'hospital-b', 'url': 'https://192.168.0.107:8002', 'last_send': 'delivered'}], 'assess': {'tabular': True, 'ecg': True}}
{'node_id': 'hospital-b', 'chain': ['hospital-a', 'hospital-b', 'hospital-c'], 'position': 2, 'run_id': 'run-20261010-094343-01b7', 'run_state': 'completed', 'current_round': 79, 'converged_round': 75, 'neighbours': [{'id': 'hospital-a', 'url': 'https://192.168.0.107:8001', 'last_send': 'delivered'}, {'id': 'hospital-c', 'url': 'https://192.168.0.107:8003', 'last_send': 'delivered'}], 'assess': {'tabular': True, 'ecg': True}}
{'node_id': 'hospital-c', 'chain': ['hospital-a', 'hospital-b', 'hospital-c'], 'position': 3, 'run_id': 'run-20261010-094343-01b7', 'run_state': 'completed', 'current_round': 79, 'converged_round': 75, 'neighbours': [{'id': 'hospital-b', 'url': 'https://192.168.0.107:8002', 'last_send': 'delivered'}], 'assess': {'tabular': True, 'ecg': True}}

# hospital-b kit data/ after the run (bind-mounted ./data):
audit.db
audit.db-shm
audit.db-wal
checkpoints
hospital-b.csv
hospital-b.membership.json

/tmp/nm-friend-b/hospital-b/data/checkpoints:
hospital-b.ckpt.pkl
# hospital-c (native) kit data/:
audit.db
audit.db-shm
audit.db-wal
checkpoints
hospital-c.csv
hospital-c.membership.json

/tmp/nm-kits2/hospital-c/data/checkpoints:
hospital-c.ckpt.pkl
Evidence: Observer telemetry in Postgres (79 metrics rows per node)
  node_id   | count 
------------+-------
 hospital-a |    79
 hospital-b |    79
 hospital-c |    79
(3 rows)

  node_id   | display_name |            url             | patients |          neighbours          |    engine     |         registered_at         |        last_heartbeat         |          run_id          | run_state | current_round | epoch |                   chain                    | in_chain | membership_round 
------------+--------------+----------------------------+----------+------------------------------+---------------+-------------------------------+-------------------------------+--------------------------+-----------+---------------+-------+--------------------------------------------+----------+------------------
 hospital-c | Hospital C   | https://192.168.0.107:8003 |      200 | ["hospital-b"]               | Q-GADMM (b=2) | 2026-10-10 09:43:22.889853+00 | 2026-10-10 09:48:57.966388+00 | run-20261010-094343-01b7 | completed |            79 |     3 | ["hospital-a", "hospital-b", "hospital-c"] | t        |                 
 hospital-a | Hospital A   | https://192.168.0.107:8001 |      303 | ["hospital-b"]               | Q-GADMM (b=2) | 2026-10-10 09:43:09.140437+00 | 2026-10-10 09:48:59.263387+00 | run-20261010-094343-01b7 | completed |            79 |     3 | ["hospital-a", "hospital-b", "hospital-c"] | t        |                 
 hospital-b | Hospital B   | https://192.168.0.107:8002 |      294 | ["hospital-a", "hospital-c"] | Q-GADMM (b=2) | 2026-10-10 09:43:09.147271+00 | 2026-10-10 09:48:59.769639+00 | run-20261010-094343-01b7 | completed |            79 |     3 | ["hospital-a", "hospital-b", "hospital-c"] | t        |                 
(3 rows)
Evidence: hospital-d provisioned into existing network
$ provision.py --peers ...,hospital-d=IP:8004 --directory IP:8100 --hospital hospital-d --secret <secret> --out /tmp/nm-kits2
hospital-d: /tmp/nm-kits2/hospital-d
admitted hospital-d: copy /tmp/nm-kits2/.pki/directory/hospitals.yaml to the directory machine's pki/directory/ (re-read on every registration)
rc=0
Evidence: hospital-d joins mid-run via make node
# hospital-d started mid-run with: make node KIT=kits/hospital-d
{'node_id': 'hospital-a', 'chain': ['hospital-a', 'hospital-b', 'hospital-c', 'hospital-d'], 'epoch': 4, 'epoch_start_round': 23, 'run_id': 'run-20261010-094931-b23f', 'run_state': 'running', 'current_round': 33, 'neighbours': [{'id': 'hospital-b', 'url': 'https://192.168.0.107:8002', 'last_send': 'delivered'}]}
{'node_id': 'hospital-b', 'chain': ['hospital-a', 'hospital-b', 'hospital-c', 'hospital-d'], 'epoch': 4, 'epoch_start_round': 23, 'run_id': 'run-20261010-094931-b23f', 'run_state': 'running', 'current_round': 33, 'neighbours': [{'id': 'hospital-a', 'url': 'https://192.168.0.107:8001', 'last_send': 'delivered'}, {'id': 'hospital-c', 'url': 'https://192.168.0.107:8003', 'last_send': 'delivered'}]}
{'node_id': 'hospital-c', 'chain': ['hospital-a', 'hospital-b', 'hospital-c', 'hospital-d'], 'epoch': 4, 'epoch_start_round': 23, 'run_id': 'run-20261010-094931-b23f', 'run_state': 'running', 'current_round': 33, 'neighbours': [{'id': 'hospital-b', 'url': 'https://192.168.0.107:8002', 'last_send': 'delivered'}, {'id': 'hospital-d', 'url': 'https://192.168.0.107:8004', 'last_send': 'delivered'}]}
{'node_id': 'hospital-d', 'chain': ['hospital-a', 'hospital-b', 'hospital-c', 'hospital-d'], 'epoch': 4, 'epoch_start_round': 23, 'run_id': 'run-20261010-094931-b23f', 'run_state': 'running', 'current_round': 34, 'neighbours': [{'id': 'hospital-c', 'url': 'https://192.168.0.107:8003', 'last_send': 'delivered'}]}
# hospital-d log
node-1  | 2026-10-10 09:49:37,528 INFO medchain.node: hospital-d up on :8004 (https) with 62 patients, neighbours=[], engine=Q-GADMM (b=2)
node-1  | 2026-10-10 09:49:37,588 INFO medchain.runner: membership epoch 4 now: chain hospital-a - hospital-b - hospital-c - hospital-d, neighbours ['hospital-c'] (hospital-d joined: appended at position 4 (run run-20261010-094931-b23f in progress))
node-1  | 2026-10-10 09:49:37,590 INFO medchain.node: membership epoch 4 via directory: applied
node-1  | 2026-10-10 09:49:37,602 WARNING medchain.runner: joined run run-20261010-094931-b23f at round 23 as position 4 of 4
node-1  | 2026-10-10 09:49:37,603 INFO medchain.node: join of run run-20261010-094931-b23f: joined
Evidence: Preflight flags a down neighbour as unreachable with reason (exit 1)
# directory stopped, hospital-a stopped (laptop asleep). Preflight from hospital-b's container:
hospital-b: chain hospital-a - hospital-b - hospital-c - hospital-d
  hospital-b <-> hospital-a     unreachable ConnectError: [Errno 111] Connection refused  (https://192.168.0.107:8001, last send: unreachable)
  hospital-b <-> hospital-c     unknown     no tailscale command on this PATH (as inside a container): reachability only  (https://192.168.0.107:8003, last send: delivered)
exit=1
Evidence: Rejoin via neighbours with the directory down
# hospital-a restarted (up -d) while the directory is DOWN
status: True running 86
node-1  | 2026-10-10 09:49:38,354 INFO medchain.runner: membership epoch 4 from round 23: chain hospital-a - hospital-b - hospital-c - hospital-d, neighbours ['hospital-b'] (hospital-d joined: appended at position 4 (run run-20261010-094931-b23f in progress))
node-1  | 2026-10-10 09:50:02,698 INFO medchain.node: hospital-a up on :8001 (https) with 303 patients, neighbours=[], engine=Q-GADMM (b=2)
node-1  | 2026-10-10 09:50:02,710 WARNING medchain.node: directory registration failed (https://192.168.0.107:8100/register unreachable (ConnectError: All connection attempts failed)); retrying in 1s
node-1  | 2026-10-10 09:50:02,718 INFO httpx: HTTP Request: POST https://192.168.0.107:8002/membership/rejoin "HTTP/1.1 200 OK"
node-1  | 2026-10-10 09:50:02,719 WARNING medchain.node: directory unreachable; my neighbours accepted my saved chain (epoch 4): rejoining
node-1  | 2026-10-10 09:50:02,720 INFO medchain.runner: membership epoch 3 now: chain hospital-a - hospital-b - hospital-c, neighbours ['hospital-b'] (hospital-c joined: position 3 (configured order; no run in progress))
node-1  | 2026-10-10 09:50:02,721 INFO medchain.node: membership epoch 3 via saved membership, accepted by my neighbours: applied
node-1  | 2026-10-10 09:50:02,721 INFO medchain.runner: membership epoch 4 now: chain hospital-a - hospital-b - hospital-c - hospital-d, neighbours ['hospital-b'] (hospital-d joined: appended at position 4 (run run-20261010-094931-b23f in progress))
node-1  | 2026-10-10 09:50:02,723 INFO medchain.node: membership epoch 4 via saved membership, accepted by my neighbours: applied
node-1  | 2026-10-10 09:50:02,729 INFO httpx: HTTP Request: GET https://192.168.0.107:8002/snapshot?requester=hospital-a&rejoin_round=81 "HTTP/1.1 200 OK"
node-1  | 2026-10-10 09:50:02,731 WARNING medchain.qgadmm: rejoined run run-20261010-094931-b23f at round 81 from the round-55 checkpoint (resync 384 bytes from ['hospital-b'])
node-1  | 2026-10-10 09:50:03,734 WARNING medchain.node: directory registration failed (https://192.168.0.107:8100/register unreachable (ConnectError: All connection attempts failed)); retrying in 2s
# hospital-b status
{'chain': ['hospital-a', 'hospital-b', 'hospital-c', 'hospital-d'], 'run_state': 'running', 'current_round': 87, 'neighbours': [{'id': 'hospital-a', 'url': 'https://192.168.0.107:8001', 'last_send': 'delivered'}, {'id': 'hospital-c', 'url': 'https://192.168.0.107:8003', 'last_send': 'delivered'}]}
Evidence: Hotspot-style .env switch: address change, pinned keys, training continues
# hospital-a's .env switched to the hotspot block (address host.docker.internal, not in its certificate); up -d again
2026-10-10 09:50:24,855 INFO medchain.runner: membership epoch 5 now: chain hospital-a - hospital-b - hospital-c - hospital-d, neighbours ['hospital-b'] (hospital-a re-registered at https://host.docker.internal:8001)
2026-10-10 09:50:24,857 INFO medchain.node: membership epoch 5 via directory: applied
2026-10-10 09:50:24,901 INFO httpx: HTTP Request: POST https://host.docker.internal:8100/register "HTTP/1.1 200 OK"
2026-10-10 09:50:24,914 INFO httpx: HTTP Request: GET https://192.168.0.107:8002/snapshot?requester=hospital-a&rejoin_round=135 "HTTP/1.1 200 OK"
2026-10-10 09:50:24,916 WARNING medchain.qgadmm: rejoined run run-20261010-094931-b23f at round 135 from the round-125 checkpoint (resync 384 bytes from ['hospital-b'])
{'node_id': 'hospital-a', 'epoch': 5, 'run_state': 'completed', 'current_round': 143, 'neighbours': [{'id': 'hospital-b', 'url': 'https://192.168.0.107:8002', 'last_send': 'delivered'}]}
{'node_id': 'hospital-b', 'epoch': 5, 'run_state': 'completed', 'current_round': 143, 'neighbours': [{'id': 'hospital-a', 'url': 'https://host.docker.internal:8001', 'last_send': 'delivered'}, {'id': 'hospital-c', 'url': 'https://192.168.0.107:8003', 'last_send': 'delivered'}]}
Evidence: make guard messages and make -n up
$ make node
name a kit folder that has a .env, e.g. make node KIT=kits/hospital-b
make: *** [check-kit] Error 2
rc=2
$ make node KIT=kits/hospital-zz
name a kit folder that has a .env, e.g. make node KIT=kits/hospital-b
make: *** [check-kit] Error 2
rc=2
$ make node-native
name a kit folder that has a .env, e.g. make node-native KIT=kits/hospital-b
make: *** [check-kit] Error 2
rc=2
$ make hub HUB_ENV=/nonexistent/hub.env
no /nonexistent/hub.env: run scripts/provision.py first, or copy deploy/hub.env.example there and fill it in
make: *** [hub] Error 2
rc=2
$ make -n up
docker compose up -d --build --wait
- Outcome: ⚠️ 1 info across 1 run (17m40s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ docs/MULTI_LAPTOP.md:250 - In the organiser section, step 1's provision command lists only hospital-a, -b and -c in --peers. Step 3 then says to run the mid-run joiner with make node KIT=kits/hospital-d. An organiser who follows the guide in order has no kits/hospital-d, so make node stops in check-kit with "name a kit folder that has a .env", and the planned mid-run join from the captain's laptop can't start. README.md's version of the same command already includes hospital-d=...:8004. Fix: add hospital-d (e.g. hospital-d=sam-laptop.tail1234.ts.net:8004, the organiser's own laptop) to the --peers example in step 1, or tell the reader to provision it later with --hospital hospital-d.

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

⚠️ **Test** - 1 info
  • ℹ️ deploy/hub.yml:31 - deploy/hub.yml hardcodes Postgres on 127.0.0.1:5432. On an organiser laptop that already runs a local Postgres (as this test host does), make hub fails with "ports are not available ... 5432: bind: address already in use". There is no hub.env knob or troubleshooting entry for this. It worked after remapping the port with an override file. A POSTGRES_PORT variable could be added if organisers are likely to hit this.
  • Live validation: ✅ go - 11 of 15 scenarios driven live against the product
Scenario Result Live Evidence
Organiser runs provision.py and gets one zip per hospital, each with deploy/node.yml, a filled .env (Tailscale and hotspot blocks), only that hospital's keys in pki/, its data slice and config, plus a… ✅ pass live provision-lan.txt, kit-tree.txt
Organiser runs the hub from deploy/hub.yml; directory, observer, postgres (loopback only) and dashboard all come up healthy ✅ pass live hub-up.txt (needed a postgres host-port override because this host already runs Postgres on 127.0.0.1:5432; see make-hub.txt)
Friend unzips their kit and runs docker compose --project-directory . -f deploy/node.yml up -d; the node registers with the directory and joins the chain ✅ pass live run-status.txt (hospital-a/b from unzipped kits in chain a-b-c)
make node-native KIT=... builds .venv-node, trains models/heart-risk.joblib, runs the node without Docker, joins the chain, and keeps checkpoints under DATA_PATH with the assess models loaded ✅ pass live run-status.txt (hospital-c native: assess tabular/ecg true, data/checkpoints/hospital-c.ckpt.pkl)
Friend runs the preflight inside the node's container with no arguments and gets a per-neighbour report ✅ pass live preflight-in-container.txt
Adversarial: a neighbour's laptop is down, and the in-container preflight reports it as unreachable with the error and exits non-zero ✅ pass live preflight-neighbour-down.txt
Training started with the kit README's curl command spreads to every hospital and runs to completion, with each node's telemetry pushed to the observer's Postgres and shown on the dashboard ✅ pass live start-training.txt, run-status.txt, observer-postgres.txt, dashboard-after-run.png
Organiser provisions hospital-d later and starts it mid-run with make node KIT=kits/hospital-d; it is appended and joins the in-progress run ✅ pass live midrun-join.txt
Adversarial: a laptop sleeps and restarts while the directory is down; it rejoins the run from its saved membership in the kit's data/ via its neighbours ✅ pass live rejoin-without-directory.txt
Adversarial: hotspot switch by editing only .env to an address not in the node's certificate; neighbours keep delivering (TLS pinned to keys) ✅ pass live hotspot-switch.txt
make node / node-native / hub fail with a clear instruction when the kit or hub.env is missing ✅ pass live make-guards.txt
make up is still today's single-machine docker compose up -d --build --wait with docker-compose.yml unchanged ⏸️ untested no The prior payload did not establish a live result. It was checked only with make -n up (a dry run) and by noting docker-compose.yml is not in the diff. It was not run live because the full single-ma…
Over Tailscale across different networks (MagicDNS names, DERP vs direct path in preflight) ⏸️ untested no This host has no Tailscale tailnet or second machine. It needs Tailscale installed on 2 or more laptops in one tailnet, with kits provisioned for their *.ts.net names.
Real phone hotspot with 3 physical laptops (including the AP-isolation case) ⏸️ untested no This needs physical laptops on a phone hotspot. The address-change path was simulated on one host instead (hotspot-switch.txt).
GHCR multi-arch image publish (.github/workflows/image.yml) and friends pulling ghcr.io/denimworld12/medchain-node:v1.0.0 without a login ⏸️ untested no It needs a pushed v* tag (or a workflow_dispatch) on GitHub with package-write permission, then making the package public. This run is not authorised to push tags. docker manifest inspect on the ima…
  • python scripts/provision.py --peers hospital-a=IP:8001,hospital-b=IP:8002,hospital-c=IP:8003 --directory IP:8100 --out /tmp/nm-kits2 --zip then unzip hospital-a/b zips into fresh folders
  • docker build -f node/Dockerfile --build-arg IMAGE_VERSION=v1.0.0 -t medchain-node-nmtest:v1.0.0 . (stand-in for the unpublished GHCR image)
  • make hub HUB_ENV=/tmp/nm-kits2/directory/hub.env (failed: host's own Postgres already on 5432), then the same compose command plus a postgres-port override
  • docker compose --project-directory . -f deploy/node.yml up -d from the unzipped hospital-a and hospital-b kits
  • make .venv-node/.installed models/heart-risk.joblib and make node-native KIT=/tmp/nm-kits2/hospital-c
  • docker compose --project-directory . -f deploy/node.yml exec node python scripts/preflight.py (no args) and host-side preflight against the native node
  • Kit README curl --cacert pki/ca.crt https://localhost:8002/round/start ...; /status on all nodes; psql query of observer metrics/nodes tables; dashboard screenshot
  • provision.py ... --hospital hospital-d --secret &lt;secret&gt;, copied hospitals.yaml to the hub kit, make node KIT=/tmp/nm-kits2/hospital-d started at round >= 10 of a live run
  • Stopped directory and hospital-a, ran in-container preflight, restarted hospital-a with the directory down
  • Edited hospital-a's .env to the hotspot block (host.docker.internal addresses), up -d, checked neighbours still deliver
  • make node, make node KIT=kits/hospital-zz, make node-native, make hub HUB_ENV=/nonexistent, make -n up
  • pytest -q tests/unit/test_provision.py tests/unit/test_preflight.py
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…a published image, a friend's guide

- deploy/node.yml: one `node` service from ghcr.io/denimworld12/medchain-node:${IMAGE_VERSION}, reading
  `.env`, mounting ./data at DATA_PATH, ./pki read-only and ./config (engine settings), publishing
  NODE_PORT on every interface. No container_name, no Compose DNS. Run from the kit folder with
  `docker compose --project-directory . -f deploy/node.yml up`; without that flag it stops with a
  message instead of mounting the wrong folders.
- deploy/hub.yml: directory, observer, Postgres on 127.0.0.1 only, dashboard; reads the directory kit.
- deploy/node.env.example and deploy/hub.env.example, each with a Tailscale block and a hotspot block
  that differ only in addresses, using node/settings.py's variables.
- make hub, make node KIT=..., make node-native KIT=... (its own .venv-node from node/requirements.txt,
  the kit's .env and folders in place of the container paths). The assessment models now default to
  the repository's models/ (still /app/models in the image), so the native node finds them.
- scripts/provision.py: a hospital kit is now deploy/node.yml + a filled .env + pki/ + data/ (its slice)
  + config/node.yaml, validated as the container will load it; the directory kit carries a filled
  hub.env for deploy/hub.yml. Kits use the published image (--image overrides it), so they no longer
  bundle a build context, a compose file of their own or a direct-Postgres fallback.
- scripts/preflight.py runs inside the node's container with no arguments (NODE_PORT, TLS_CA) and says
  why a neighbour is unreachable, e.g. a MagicDNS name the container cannot resolve. It ships in the image.
- .github/workflows/image.yml: linux/amd64 and linux/arm64 built on native runners, pushed by digest
  and merged into one tag on a v* tag push or a manual run; pull requests touching the image only build it.
  The Dockerfile bakes IMAGE_VERSION in.
- docs/MULTI_LAPTOP.md: the guide for a friend who has never used Docker, with the hotspot fallback
  and a troubleshooting table grounded in the multi-laptop audit; the README's multi-machine section
  describes the new kits.
…tal_joins_mid_run_then_a_middle_hospital_leaves_and_the_dashboard_follows, failing with KeyError on net[join_round - 1] (25 on gadmm_fp, 29 on qgadmm). The other 7 integration tests passed. Cause: a timing race in the test, not in this PR's code. The PR doesn't touch the node runtime, telemetry or dashboard, and the test passed on main. after_join waited for the dashboard to show 4 hospitals for the latest round (comm.hospitals_this_round). That count comes from chain_size, so one node's metrics row is enough. network_loss only includes a round once every member's metrics row has reached the observer, and each node pushes those rows from its own async queue (node/writer.py). So a lagging node's round join_round-1 row could still be in flight when the snapshot was taken. The 'hospital-d left' entry in the logs is the test's own cleanup after the crash. Fix (tests/integration/test_stack.py only): added a small loss_rounds(s) helper. after_join now also waits until network_loss includes join_round-1 and join_round, and after_leave waits for leave_round-1 and leave_round (same race). All existing assertions on the hospital counts are unchanged, so a real miscount still fails. Verified: the integration module still collects (9 tests, skipped without MEDCHAIN_STACK); ruff reports 7 warnings in test_stack.py, none on the changed lines. I could not run the live Docker stack locally: exited containers from another checkout outside this worktree use the same fixed container names, and I left them alone. CI on the PR is the real check. Not committed
@Denimworld12
Denimworld12 merged commit 49b3f75 into main Oct 10, 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