# 06 — Runbook: bringing a fresh box back The container root is an **overlay filesystem**. `/home/marimo` does **not** survive a relaunch; it has been wiped at least three times. Everything in `dragonlimited/dragon-state` does survive. This page is the operational procedure, corrected and with the two traps that actually bite. Workspace convention: **`/home/marimo/dragon_fsds`** is the workspace root. ## 0. Before anything: the token ```bash export HF_TOKEN_BOOT= # restore_state.py and sync_state.py require THIS name export HF_TOKEN= # some tooling reads this one ``` Put it in the **environment**, never in a notebook cell and never in a tracked file — the notebooks are published to public repositories. *Reading* needs no token: the model repos are public. ## 1. Get the ops scripts They live in `dragon-harness/ops/`. Flatten them into the workspace (`ops/*.py` → workspace root, `ops/*.json` → workspace root). ## 2. Restore the state ```bash python restore_state.py # pulls dragon-state:state/** -> /home/marimo/dragon_fsds python check_resume.py # 60/61 manifest items should read "yes" ``` Measured on 2026-11-21: **61 files, 0 failures, 7.2 GB, ~2 minutes.** > **Trap 1 — the mapping.** A restore pass that matches on a single `/` silently skips every flat > `state/` entry. The mapping that works: `state/**` → workspace, `ops/*.py` → workspace > flattened, `workplan/done/` → `workplan_done/`, `workplan/logs/.log` → `workplan_.log`. > > **Trap 2 — the manifest.** `sync_state.py` reads `state_manifest.json` **at import**, so the sync > service cannot start without it. It *is* published now; `ops/state_manifest.json.example` is the > reconstruction if it is ever missing again. ## 3. Verify the restore — do not trust it ```bash python run_harness.py # expect: 6,802 items | 6,791 hit | 99.8% | agreement 6,802 ``` If that number moves, **the data moved, not the harness**. This is the single best check that the restore is good, because it touches the facts database, the eval items and the whole scoring path. The harness also needs the eval data, which is **not** in `dragon-state` — pull it from the public eval repo into `data/`: ```bash for f in dragon-finance-eval.jsonl dragon-finance-eval-largecap.jsonl verification.json \ corpus_overlap_accessions.txt; do curl -sL -o data/$f \ "https://huggingface.co/datasets/dragonlimited/Dragon-Finance-Eval/raw/main/data/$f" done ``` ## 4. Recover the programs that only exist in a notebook payload Seven ops scripts (`checkpoint_sync.py`, `test_resume.py`, `publish_plan.py`, `build_provenance.py`, `sign_bundle.py`, `push_provenance.py`, `backup_notebook.py`) were never published as files. They are carried inside the live model notebook's payload. If the file at `state/notebook.py` does not carry them, recover the payload-bearing revision from git history: ```bash GIT_TERMINAL_PROMPT=0 git clone --filter=blob:none --no-checkout --single-branch \ https://huggingface.co/dragonlimited/dragon-state ds-git cd ds-git for b in $(git rev-list --objects --all -- state/notebook.py | awk '{print $1}'); do echo "$(git cat-file -s $b) $b"; done | sort -rn | head # find ~204,133 bytes git cat-file blob > ../notebook-payload.py ``` Then decode: the payload is a dict `name -> (sha256, base64(zlib(source)))`. **Verify every sha256** against `state/notebook_snapshot.json`'s `programs_carried` — on 2026-11-21 all 23 verified. ## 5. Restart the state sync ```bash python sync_state.py --watch --every 300 & ``` This is what makes the night survivable. Without it, nothing written after the restore leaves the box. ## 6. Continue training **The correct trainer is `train_sft_v4.py`.** (`RESTORE.md` says `train_fixed.py` — that is the older trainer, see `07-CORRECTIONS.md` §7.) The trainer resumes from **`{DRAGON_OUT}/resume.pt`** if it exists, restoring the LoRA weights, the optimizer state, the step counter and the patience state — that is the difference between continuing and restarting. ```bash export DRAGON_TRACES=/home/marimo/dragon_fsds/tool_traces_all.jsonl # sha256 ef90f212... export DRAGON_OUT=/home/marimo/dragon_fsds/dragon-lora-v8 # a NEW directory export DRAGON_LOG=/home/marimo/dragon_fsds/sft_v8_log.txt export DRAGON_MAX_STEPS=1500 DRAGON_EVAL_EVERY=150 DRAGON_PATIENCE=3 python train_sft_v4.py ``` Two things to do first, and both were learned the hard way: 1. **Never continue in a run directory that is already published.** `train_sft_v4.py` writes `adapter_best.pt` into `DRAGON_OUT`, so resuming inside `dragon-lora-v7/` would overwrite the adapter that `runs/verdict-v7/` and the model card both cite. Seed a new directory instead: ```bash mkdir -p dragon-lora-v8 && cd dragon-lora-v8 for f in resume.pt adapter_best.pt adapter_last.pt RUN_STATE.json; do hf download dragonlimited/dragon-state runs/dragon-lora-v7/$f --repo-type model --local-dir . done ``` 2. **Drop the scheduler state when you resume.** v7's cosine ran `T_max=900` and finished at `last_epoch=900`, so a restored scheduler sits at its minimum and the continuation would not learn: ```python import torch; ck = torch.load("resume.pt", map_location="cpu") ck.pop("sched", None) # keep weights, optimizer, step, patience torch.save(ck, "resume.pt") ``` Declare it wherever the resulting numbers are reported: the LR schedule is a new cycle, so a resumed run is not a strict continuation of the old one in every respect. ## 7. Do not start these * `run_workplan.py` — **no retry cap**: a job whose script is missing is re-admitted every tick. * `keeper.py` — its service list still includes `cpu_lane.py`, which does not exist. * More than one trainer at a time. Three GPU jobs were considered safe in the old plan because each is bandwidth-bound at low occupancy (~15 GB each, 98 GB card) — but only one **trainer**. * **Nothing on the corpus side.** Its notebook's standing rule says the model work is driven from elsewhere and the corpus must not be started on its behalf, and a corpus publish round must not be joined to a model run. ## 8. Publishing back `checkpoint_sync.py` pushes `resume.pt`, `adapter_best.pt`, `adapter_last.pt` and `RUN_STATE.json` to `dragon-state:runs//`, verifies by re-downloading, and skips unchanged files. ```bash python checkpoint_sync.py --push /home/marimo/dragon_fsds/dragon-lora-v8 python checkpoint_sync.py --status # local vs Hub, per run, with the step each records ``` **Cap the commits.** The account allows ~128 repository commits per hour and a full sync pass costs one per changed file. Pace writes; do not loop a full push every minute.