Skip to content

feat(training): derived snapshots from replayed vitals and modelset-v1 manifests - #27

Merged
ng merged 6 commits into
mainfrom
feat/derived-snapshot
Nov 16, 2026
Merged

ng merged 6 commits into
mainfrom
feat/derived-snapshot

Conversation

@ng

@ng ng commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Plan C5 (training side, training-12) and the modelset-v1 writer from docs/plans/model-graph-plan.md. Based on main (the locked holdout, #26, is merged).

  • scripts/derive_snapshot.py
    • ingest REPLAY_DIR caches core's pnpm biometrics:local-fit replay --archive … readings by (night, engine, profile) as data/cache/vitals/<night>-<engine12>-<profile12>.json. The file is the readings verbatim, with a .source.json beside it. Nights core skipped get a .skipped.json with core's reason. The cache is write-once: replaying the same engine and profile with different bytes is refused.
    • derive SOURCE.db --out NEW.db copies the archive database (SQLite backup). For each replayed night and side, it replaces the vitals and vitals_quality rows inside the night's in-bed window, found with core's noon-to-noon nightOf. Other sides, other nights and all other tables are unchanged. Inserted rows point at a replay processing run when the schema has biometric_processing_runs.
    • A derived_snapshot table records per night: source database SHA-256, engine manifest hash, resolved profile hash, readings SHA-256, replay.json SHA-256, the window, and the counts of removed and inserted rows.
    • Refused: a reading computed with another profile, a night whose sleep records changed since the replay, deriving from a derived snapshot, and overwriting an output.
    • Core's readings format is parsed in one function (read_readings) and replay.json in another (read_replay). The code follows scripts/biometrics-local-fit/replay.ts on core branch feat/local-fit-archive-replay, which is still being written.
  • scripts/modelset.py
    • hash, check and write RUN for RUN/model/set.json, the shape in the plan.
    • Core's canonical JSON (finite-binary64-json-v1) is ported exactly: UTF-16 key order, exact binary64 decimal expansion, JSON.stringify escaping, node, depth, string and byte budgets.
    • nodes.stage.sha256 is computed as core's upload validator computes it (stage-model-set.ts stageModelSha256): dataHash (the 2M-node budget), applied after stageModelSchema.parse sets epochSeconds to 300. configHash is exported too.
    • problems() reproduces core's strict modelSetSchema and modelSetProblem checks, plus training.inputs ∈ {replayed, live}.
    • scripts/canonical-vectors.ts computes the vectors with core's own code. It was run with pnpm exec tsx in sleepypod-core-archive fc40624c and in the stage-model-set worktree 1fd2a784; both gave identical output, now pinned in test_modelset.py.
  • Training gate (core #928). Replayed readings replace a night's rows only when core's nights[].parity.trainingGate is pass, from replay --compare-stored. --allow-ungated also accepts nights core could not judge (not_gated_*, no_heart_rate_to_compare, no comparison at all), and records that per night; a fail is never used. Every other night keeps its stored rows. derived_snapshot records each night's verdict, core's check values and the reason. The thresholds are read from core's verdict, never recomputed here, and the README notes they rest on two nights. The gate is one function (training_gate) passed to derive, so a different gate is a one-place change.
  • Golden stage hash. test_modelset.py pins core #930's golden forest, 6fe42238…7906, next to the earlier vectors.
  • One canonical-JSON port. scripts/canonical_json.py is now the only Python implementation. modelset.py, movement_portable.py (feat(training): export the movement model as a portable JSON forest #24, movement body sha256: unbounded, as verify-movement.ts hashes it) and the trial's model_sha256 in stage-backtest.py (feat(training): weekly trial scoring of pod model id 3 (live) vs id 2 (preview) #29) all import it. Their pinned tests still pass: the movement.json sha256 checked by verify-movement.ts, and golden 6fe42238…7906 in both test_stage_backtest.py and test_modelset.py. Key order is now UTF-16 everywhere, where movement used code-point order; the two agree on the ASCII keys those documents use.
  • make-synthetic-inputs.py gains --nights N and --replay DIR, which writes a synthetic replay in core's layout. Synthetic databases also gain a vitals_quality table.

Test plan

  • uv run --locked python -m unittest discover -s scripts -p 'test_*.py' (261 tests):
    • pinned canonical vectors and limits
    • derive replaces only the side and window, including quality rows, provenance and the processing run
    • all the refusals listed above
    • a synthetic end-to-end run: make-synthetic-inputs → synthetic readings → derive → export-runtime-features.ts → stage-backtest.py
  • All of README "Validate without personal data", plus the new smoke-graph steps (also added to .github/workflows/validate.yml).
  • Once core's replay --archive lands and the archive is populated: derive the 24 raw nights and check the C5 parity gate in replay.json.

No real health data in git or CI; never contacts a pod.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fd4d91a5-af70-4a22-a6ea-7736df758559
Commits

Reviewing files that changed from the base of the PR and between 207ce8c and c7585c4.

Files selected for processing: 12

  • .github/workflows/validate.yml
  • README.md
  • scripts/canonical-fixtures.json
  • scripts/canonical-vectors.ts
  • scripts/canonical_json.py
  • scripts/derive_snapshot.py
  • scripts/make-synthetic-inputs.py
  • scripts/modelset.py
  • scripts/movement_portable.py
  • scripts/stage-backtest.py
  • scripts/test_derive_snapshot.py
  • scripts/test_modelset.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ng
ng force-pushed the feat/locked-holdout branch 3 times, most recently from 2aff58c to d9f18ac Compare November 16, 2026 00:07
@ng
ng changed the base branch from feat/locked-holdout to main November 16, 2026 00:10
@ng
ng force-pushed the feat/derived-snapshot branch from 6fee71f to 3f88bf5 Compare November 16, 2026 00:16
@ng
ng force-pushed the feat/derived-snapshot branch from 3f88bf5 to d9e4227 Compare November 16, 2026 00:22
ng and others added 5 commits November 15, 2026 16:34
…set-v1 so stage models train on one pinned engine and profile

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ut of derived snapshots so a bad replay never trains a model

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…has no contract for its features

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sses, and pin core's golden stage hash, so derived snapshots never train on replays that miss the stored rows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ent models and trial hashes can never disagree with core differently

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ng
ng force-pushed the feat/derived-snapshot branch from d9e4227 to 4acfc52 Compare November 16, 2026 00:37
@ng
ng merged commit 68243f0 into main Nov 16, 2026
3 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