# US-046 — Tracker .env awareness + first-node auto-join bootstrap

Status: in progress
Priority: High (blocks the US-044 two-machine test; auto-join dead on fresh trackers)

## Context

Reported 2026-07-06: a node auto-joining a fresh tracker prints
`(auto-join unavailable: HTTP Error 503)` and then cannot download the model
from the tracker. Two independent causes:

1. **Bootstrap chicken-and-egg.** `_handle_network_assign` handles an empty
   registry by falling back to the first *deployable* recommended preset — but
   deployability is computed from the registered pool only
   (`_deployment_summary(all_nodes, preset)`), which is empty, so nothing is
   ever deployable and the first node always gets 503. The caller's own
   `vram_mb` / `ram_mb` (already sent in the query) are ignored.
2. **Tracker ignores `.env`.** `meshnet-node` loads `.env` (cwd) and
   `~/.config/meshnet/secrets.env` at startup; `meshnet-tracker` does not. The
   repo `.env` sets `MESHNET_DOWNLOAD_DIR=/run/media/popov/DATA/llm/safetensor/models`,
   but the tracker only reads `--models-dir` / `MESHNET_MODELS_DIR`, so
   `models_dir` stays unset → `/v1/model-files/download` returns
   404 "tracker model-file source is not enabled" and assignments carry no
   `model_sources`.
3. **Symlink tars (found while verifying).** HF cache snapshots are symlink
   farms into `blobs/`; both the tracker's `/v1/model-files/download` and the
   node's `write_shard_archive` tarred the symlinks themselves
   (`tarfile` default `dereference=False`), so receivers extracted dangling
   links instead of weights.

## Fix

1. In the empty-registry branch of `_handle_network_assign`, synthesize a
   candidate `_NodeEntry` from the caller's `vram_mb`/`ram_mb` query params and
   include it in the pool used for the deployability gate (and the reported
   `deployment` summary), so a recommended preset that fits *pool + caller*
   bootstraps the network.
2. Tracker CLI loads env defaults the same way the node CLI does
   (`.env` in cwd, then `~/.config/meshnet/secrets.env`, never overriding
   already-set env vars).
3. `TrackerServer` models-dir resolution falls back
   `--models-dir` → `MESHNET_MODELS_DIR` → `MESHNET_DOWNLOAD_DIR` (the node
   store and tracker source are the same directory on a box running both).
4. Archive with `dereference=True` in both tar writers so model file contents
   ship instead of snapshot symlinks.

## Acceptance criteria

- [x] Fresh tracker (empty registry) + caller with enough memory for a
  recommended preset → `/v1/network/assign` returns 200 with that preset,
  `gap_found=true`, and `model_sources` populated when the tracker holds a
  local snapshot. (Verified live: 128 GB caller got qwen3.6-35b-a3b 0–39
  with tracker `model_sources`.)
- [x] Fresh tracker + caller too small for any recommended preset → still 503.
  (Verified live with a 4 GB caller.)
- [x] `meshnet-tracker start` in a directory with `.env` setting
  `MESHNET_DOWNLOAD_DIR` serves `/v1/model-files/download` from that dir with
  no extra flags. (Verified live; tar entries are regular files, not
  symlinks.)
- [x] Explicit `--models-dir` and `MESHNET_MODELS_DIR` still take precedence,
  in that order.
- [x] `python -m pytest` passes from repo root (two known env-dependent
  failures occur only while a live meshnet-node holds port 7000).
