Repository navigation
fix(genome): Fix-2 — honest metrics + RecordingFineTuningAdapter conservation test (task #237) - #1581
Conversation
…ervation test (task #237) Closes the 3 remaining math/VDD-honesty findings from the original review (M1, M2, M3). The metric layer + the conservation VDD test now match their marketing — pre-fix, both were "honest-looking but tautological." ## M1 closed — honest trained_tokens via gradient_tokens_consumed PRE-FIX (R1 BLOCK M1, job_actor.rs:305): `trained_tokens = steps × batch_size × sequence_length` In the stand-in path, train_step trains on ONE target per sample (the narrow(1, 0, 1) first column), not seq_len. With default schedule (batch=4, seq=32) this inflated the metric by 32×. The artifact's metrics.trained_tokens — which forge/alloy surfaces as training provenance — was lying about training scale. POST-FIX: - `TrainingMetrics` gains `gradient_tokens_consumed: u64` — accumulator for gradient-bearing target positions ACROSS train_step calls. - `train_step` returns `(loss, tokens_used)` instead of just loss. tokens_used counts samples whose attention_mask first-column is 1 (non-pad first target). For all-ones-mask common case this equals batch_size; for pad-first-target samples it's smaller. - `job_actor::run_actor` reads `metrics.gradient_tokens_consumed` straight into `JobMetrics::trained_tokens` — the honest count, no schedule-derived multiplication. Alloy provenance gets the real signal per [[forge-alloy-secures-commodity-zero-trust-plus-reputation]]. - `train_epoch` adapted to new return shape (tokens_used accumulates via train_step's internal metric update; train_epoch just averages loss). ## M2 closed — RecordingFineTuningAdapter as canonical system fixture PRE-FIX (R1 BLOCK M2, training_trigger.rs:982): the conservation VDD test asserted `trained_tokens > 0` and claimed it proved "every submitted example flowed through dispatch EXACTLY once." It proved nothing of the kind — `trained_tokens` is a function of schedule, not example count. A bug doubling or dropping examples would have passed the > 0 check. POST-FIX: - New module `genome::fine_tuning::recording_adapter` gated behind `#[cfg(any(test, feature = "test-fixtures"))]` per CLAUDE.md test discipline. Production binaries physically cannot link it. Canonical fixture per the "one fixture per concern" rule — `RecordingFineTuningAdapter` is the FineTuningAdapter equivalent of `HeuristicInferenceAdapter`. - `RecordingFineTuningAdapter` captures every TrainingJobRequest it receives in an `Arc<Mutex<Vec<...>>>` that tests can read. Advertises `supported_base_model_prefixes: ["recording-test"]` + `produces_local_artifact: true` so coordinator routing in tests is deterministic. Returns fake JobHandle immediately + reports Completed on poll. - VDD `submitted_examples_flow_through_dispatch_intact` rewritten: builds a runtime with the recording adapter registered (instead of LocalCandleFineTuner), submits, asserts EXACT example count AND per-position prompt match between submitted and dispatched datasets. Real conservation accounting. - New VDD test `multi_submit_accumulation_preserves_order_through_dispatch`: 4 submits × 3 examples → 12 accumulated → fires once at threshold; asserts the dispatched dataset's example order matches the global submission order. Catches a bug where accumulator's extend would prepend instead of append. Bonus: this fixture also unlocks Fix-3's deterministic Notify-based concurrency test (the C1/C2 race that the smoke-level stress test couldn't deterministically force). ## M3 closed (LGTM-with-notes) — pad-as-target counted honestly PRE-FIX (R1 LGTM M3, training_loop.rs:357): for short examples, `target_ids.narrow(1, 0, 1)` could pick the pad id (0) as target. Cross-entropy then trained "predict pad" — corrupted gradient signal. The standin couldn't easily mask pad targets out of cross_entropy itself (candle doesn't have an ignore_index), but it SHOULDN'T have lied about the count either. POST-FIX: `tokens_used` in train_step is computed from `attention_mask.narrow(1, 0, 1).sum_all()` — count of samples whose first target is NON-pad. Samples with pad-first-target contribute 0 to the metric. Cross-entropy still computes loss over the full batch (including pad targets), but the surfaced count is honest. Full pad-masking inside cross_entropy lands alongside the real-model-loading slice. Documented in train_step's doc comment. ## Tests - training_loop: 12 → 14 (added 2 VDD tests for honest counting) - training_trigger: 12 → 13 (added 1 multi-submit VDD) - fine_tuning total: 76 → 81 (above 2 plus 3 in recording_adapter) - All passing under default `cargo test`. Stress tests still pass under `--features stress-tests`. Co-Authored-By: Claude Opus 4.7 <[email protected]>
…nt skip (task #237) Closes the BLOCKs from the round-1 reviewer on PR #1581: ## BLOCK 1 closed — M1 semantic drift PRE-FIX: `train_step` computed `tokens_used` from `attention_mask.first_col.sum()`. But `target_ids = input_ids[1..]` (causal LM shift), so `target_ids.narrow(1, 0, 1)` selects target[0] = input[1], NOT input[0]. `attention_mask[0]` reflects INPUT[0]'s pad status — off by ONE POSITION from what was actually trained against. Concrete failing case the reviewer named: a 1-byte ByteTokenizer example. inputs=[X+1, 0, 0, ...], target_ids=[0, 0, 0, ...], attention_mask=[1, 0, 0, ...]. The first target IS pad (id 0) but mask[0]=1 → tokens_used counted as 1. The metric re-inflated in exactly the class M1 was filed to eliminate. POST-FIX: New `TokenizedBatch::target_mask` field aligned to TARGET positions. DataLoader computes it from `target_ids != pad_id` while building batches (one place, structural). `train_step` reads `target_mask.first_col.sum()` instead of `attention_mask.first_col.sum()`. The fields are doc'd as STRUCTURALLY distinct so a future refactor can't silently re-mix them. ## BLOCK 2 closed — pad-target VDD test now uses DataLoader PRE-FIX: `pad_first_target_contributes_zero_to_tokens_used` hand-crafted a TokenizedBatch with mask aligned to the implementation's BUG (first-INPUT pad status), so the test passed while the bug shipped. POST-FIX: Renamed to `pad_first_target_via_dataloader_contributes_zero_to_tokens_used`. Constructs the batch via `DataLoader::new(&[TrainingExample{prompt:"X",completion:""}], &ByteTokenizer::new(), 1, 4, ...)` — same path production uses. Asserts tokens_used == 0, gradient_tokens_consumed == 0, steps_completed == 1 (step ran but no backward). This test would have FAILED on the round-1 code, correctly surfacing the drift. Added sibling `mixed_pad_and_real_first_targets_count_only_real` to pin the per-sample counting math against a hand-built batch (both targets explicitly distinct). ## LGTM 4 closed — partial all-pad gradient skip The reviewer flagged: even with honest tokens_used, cross_entropy still trains on pad targets in mixed batches → garbage gradient signal flowing into LoRA. Per `[[no-fallbacks-ever]]` doctrine, "lands with full mask integration alongside real model loading" is itself a fallback shape. POST-FIX: `train_step` short-circuits at the all-pad case (tokens_used == 0): skip cross_entropy + skip optimizer.backward_step, return early. AdamW never steps on a loss derived ENTIRELY from pad-target predictions. steps_completed still advances (the call happened); gradient_tokens_consumed stays at 0 (correctly). The partial-pad case (some samples real, some pad) still trains cross_entropy across the whole batch — that's a real limitation of the standin that requires per-sample loss masking. Documented as such. Full mitigation lands with the real-model-loading slice's embedding-table swap. ## LGTM 3 closed — recording_adapter docstring concurrency note Added explicit note that under concurrent dispatches, push order reflects mutex-acquisition order, NOT caller spawn order. Serial tests can rely on order; concurrent tests should use set-membership or embed a sequence number. Links to the existing stress test as the set-membership pattern reference. ## Updated hand-built TokenizedBatch sites Five existing tests in training_loop.rs constructed TokenizedBatch inline with only the old 3 fields. Each now also builds target_mask matching its target_ids contents. The hand-built sites are appropriate for the local invariants they test (per-sample math, overfit-convergence, etc.); the DataLoader-driven test is the drift-class pin. ## Tests - training_loop: 14 → 15 (added DataLoader drift pin; renamed hand-built variant to `mixed_pad_and_real_first_targets_count_only_real`) - training_trigger: 13 (unchanged from Fix-2 round 1) - fine_tuning total: 81 → 82 - Stress test still passes under --features stress-tests All passing. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Round-2 fixes pushed ( BLOCK 1 (M1 semantic drift) — fixed. Added structurally distinct BLOCK 2 (VDD test sidestepped drift) — fixed. Renamed LGTM 4 (partial doctrine concern, all-pad batch) — addressed. LGTM 3 (recording_adapter docstring) — added explicit concurrency note: under concurrent LGTMs 5/6/7 — confirmed correct, no changes needed (sanity-check items the reviewer already cleared). Tests: training_loop 14 → 15 (DataLoader drift pin + per-sample math pin), fine_tuning total 81 → 82. All passing. Stress tests still green under |
…recious mirror; confinement reads only the mirror's objects (card 573cc58a, airc half d166e4f2) card_staging::stage_for_card made the card's checkout a worktree of repo_registry's clone, which for continuum is the DEPLOY checkout. Every resident's card was therefore registered in the deploy repo's .git (M5: .git/worktrees/cc2db61d). git under confinement failed there, and #5116 could only fix it by granting write on that .git. Joel: do it right. - card_staging: ensure_mirror(repo, registry clone), then ensure_card_clone from the mirror (airc-lib, airc #1581). The checkout is at the same worktree_path_for path; its .git is inside it, objects are borrowed through alternates, and origin is the real remote, so the carry pushes. - confinement: each ~/.airc/mirrors/*/*.git/objects is a READ-only root (canonicalised with every root). No write root is added anywhere, and nothing of a mirror but its objects is readable. - disk governor: TrackedDir airc-mirrors, with a decided deferred eviction: whole-mirror removal only when no live card clone names it in its alternates. Never prune in place; preciousObjects refuses it. Test (macOS, real sandbox-exec): on_macos_a_card_clone_reads_its_mirror_and_commits_but_cannot_write_the_mirror. Her git reads the borrowed base, her commit lands, and a write into the mirror's objects is refused by the OS. Not in this commit: the airc-lib pin bump (needs #1581 merged) and migration of existing linked worktrees (follow-up card). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
The previous pin 379a147 is refs/pull/1572/head; #1572 landed on canary as squash 582dba1 with the same BoardSnapshot.submission_reviews field, so the move from 379a147 to 27a12d7 (#1581) drops no airc behaviour. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…recious mirror; confinement reads only the mirror's objects (card 573cc58a, airc half d166e4f2) card_staging::stage_for_card made the card's checkout a worktree of repo_registry's clone, which for continuum is the DEPLOY checkout. Every resident's card was therefore registered in the deploy repo's .git (M5: .git/worktrees/cc2db61d). git under confinement failed there, and #5116 could only fix it by granting write on that .git. Joel: do it right. - card_staging: ensure_mirror(repo, registry clone), then ensure_card_clone from the mirror (airc-lib, airc #1581). The checkout is at the same worktree_path_for path; its .git is inside it, objects are borrowed through alternates, and origin is the real remote, so the carry pushes. - confinement: each ~/.airc/mirrors/*/*.git/objects is a READ-only root (canonicalised with every root). No write root is added anywhere, and nothing of a mirror but its objects is readable. - disk governor: TrackedDir airc-mirrors, with a decided deferred eviction: whole-mirror removal only when no live card clone names it in its alternates. Never prune in place; preciousObjects refuses it. Test (macOS, real sandbox-exec): on_macos_a_card_clone_reads_its_mirror_and_commits_but_cannot_write_the_mirror. Her git reads the borrowed base, her commit lands, and a write into the mirror's objects is refused by the OS. Not in this commit: the airc-lib pin bump (needs #1581 merged) and migration of existing linked worktrees (follow-up card). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
The previous pin 379a147 is refs/pull/1572/head; #1572 landed on canary as squash 582dba1 with the same BoardSnapshot.submission_reviews field, so the move from 379a147 to 27a12d7 (#1581) drops no airc behaviour. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…recious mirror (card 573cc58a) Rebased onto canary 769df97 as one commit: the net change of the four reviewed commits (e39d996..f0981c0), because #5080 moved disk_eviction's tests to their own file. - card_staging: a card's checkout is a standalone clone with alternates from ~/.airc/mirrors (airc #1581). A held linked worktree migrates when nothing can be lost (airc #1582), with a card.checkout.migrated probe. The airc pin moves to 51f7869 (old pin 27a12d7 is an ancestor). - confinement: each mirror's objects/ is a read-only root for a workspace-reach caller. - disk: airc-mirrors is a TrackedDir, and its eviction is deferred with a named owner. - The cache-class eviction decisions (OWNED, DEFERRED) move out of disk_eviction/tests.rs into disk_eviction/eviction_decisions.rs, which their test reads. tests.rs goes from 1,145 to 930 lines; file_size baseline 159,447 to 159,305. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…recious mirror (card 573cc58a) Rebased onto canary 769df97 as one commit: the net change of the four reviewed commits (e39d996..f0981c0), because #5080 moved disk_eviction's tests to their own file. - card_staging: a card's checkout is a standalone clone with alternates from ~/.airc/mirrors (airc #1581). A held linked worktree migrates when nothing can be lost (airc #1582), with a card.checkout.migrated probe. The airc pin moves to 51f7869 (old pin 27a12d7 is an ancestor). - confinement: each mirror's objects/ is a read-only root for a workspace-reach caller. - disk: airc-mirrors is a TrackedDir, and its eviction is deferred with a named owner. - The cache-class eviction decisions (OWNED, DEFERRED) move out of disk_eviction/tests.rs into disk_eviction/eviction_decisions.rs, which their test reads. tests.rs goes from 1,145 to 930 lines; file_size baseline 159,447 to 159,305. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…recious mirror (card 573cc58a) Rebased onto canary 769df97 as one commit: the net change of the four reviewed commits (e39d996..f0981c0), because #5080 moved disk_eviction's tests to their own file. - card_staging: a card's checkout is a standalone clone with alternates from ~/.airc/mirrors (airc #1581). A held linked worktree migrates when nothing can be lost (airc #1582), with a card.checkout.migrated probe. The airc pin moves to 51f7869 (old pin 27a12d7 is an ancestor). - confinement: each mirror's objects/ is a read-only root for a workspace-reach caller. - disk: airc-mirrors is a TrackedDir, and its eviction is deferred with a named owner. - The cache-class eviction decisions (OWNED, DEFERRED) move out of disk_eviction/tests.rs into disk_eviction/eviction_decisions.rs, which their test reads. tests.rs goes from 1,145 to 930 lines; file_size baseline 159,447 to 159,305. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…onfinement reads only the mirror's objects (card 573cc58a) (#5132) * feat(work,code): a resident's card checkout is its own clone from a precious mirror (card 573cc58a) Rebased onto canary 769df97 as one commit: the net change of the four reviewed commits (e39d996..f0981c0), because #5080 moved disk_eviction's tests to their own file. - card_staging: a card's checkout is a standalone clone with alternates from ~/.airc/mirrors (airc #1581). A held linked worktree migrates when nothing can be lost (airc #1582), with a card.checkout.migrated probe. The airc pin moves to 51f7869 (old pin 27a12d7 is an ancestor). - confinement: each mirror's objects/ is a read-only root for a workspace-reach caller. - disk: airc-mirrors is a TrackedDir, and its eviction is deferred with a named owner. - The cache-class eviction decisions (OWNED, DEFERRED) move out of disk_eviction/tests.rs into disk_eviction/eviction_decisions.rs, which their test reads. tests.rs goes from 1,145 to 930 lines; file_size baseline 159,447 to 159,305. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE * fix(work): a resident's HELD linked checkout migrates when her turn on it starts (card 573cc58a) Fable's live receipt from the M5 deploy of #5132 (build 91ea7dba9, 04:10-05:10Z): card.checkout.migrated fired 0 times in an hour. All three held checkouts (cc2db61d, 1b232595, e710ed0f) were linked, clean and pushed, so all were eligible. Two defects, both mine: 1. stage_for_card returned any existing checkout before reaching ensure_card_clone, so the migration was unreachable for exactly the checkouts it was written for. A linked worktree now falls through to the clone path, which migrates it. 2. Staging ran only on a new claim, and residents keep their claims. card_staging::restage_held_linked_checkout runs from bind_card, as her turn on a held card starts and before her hands are rooted, so nothing of hers is running in the tree that may move. A card clone is untouched. If migration cannot happen, the old tree stays hers. Also: - The airc pin moves to 44478afa6 (#1591): a migrated clone borrows its llama.cpp submodule (453 MB) from a node mirror, instead of downloading it inside her turn. 51f7869 is an ancestor. - persona_workspace.rs's 1,995-line test module moves, unchanged except a leading blank line, to cognition/persona_workspace/tests.rs (#![cfg(test)]). The higher-ring items it uses are imported once in the parent under #[cfg(test)], so upward imports stay at 256. BASELINE_LINES_OVER goes from 159,277 to 158,283. Not compiled here (IntelMac rule): every edited file parses and source-hygiene is 37/0. CI is the compile check, and Fable's next M5 deploy is the live check. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE * fix(work): a held linked tree that cannot migrate is not restaged on every turn (card 573cc58a) Fable on #5132 at 5d2f157: a held linked tree that can never migrate (dirty, detached, unpushed) was restaged at every turn start, each time an ensure_mirror GitHub fetch, a submodule pass and an arrival, until she committed. restage_held_linked_checkout now tries only when the local checks the migration itself needs already pass: clean (is_dirty), on a branch (current_branch) and nothing unpushed (has_unpushed_work). These use local git only, no network. It also tries at most once per carry interval (card_carry::CARRY_SWEEP, 300 s) per (resident, card). The carry is what pushes her commits, so that is when an unpushed tree can become migratable. is_dirty and CARRY_SWEEP become pub(crate) for this. Not compiled here (IntelMac rule): files parse; source-hygiene 37/0. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE * hygiene: file_size baseline 158,255, card 573cc58a's splits measured on canary 16a075c Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Fix-2 of the canary-quality cleanup (task #237)
Closes the 3 remaining math/VDD-honesty findings from the original 3-reviewer adversarial pass: M1 (trained_tokens inflation), M2 (conservation test was tautological), M3 (pad-as-target gradient corruption — LGTM-with-notes).
The metric layer + the conservation VDD test now match their marketing. Pre-fix, both were "honest-looking but tautological."
Findings closed
trained_tokens = steps × batch × seq_leninflated 32× in stand-in path; alloy provenance lied about training scalegradient_tokens_consumed: u64onTrainingMetrics, accumulated insidetrain_stepfrom actual non-pad first-target counttrained_tokens > 0and claimed to prove "every example flowed through exactly once" — bug doubling or dropping examples would have passedRecordingFineTuningAdaptercaptures dispatchedTrainingDataset; test asserts exact example count + per-position prompt match between submitted and dispatchednarrow(1, 0, 1)could pick pad id (0) as target → gradient flows for "predict pad"; count didn't reflect corruptiontokens_usedcomputed fromattention_mask.first_col.sum()— samples with pad-first-target contribute 0 to the metric. Full cross-entropy pad masking lands with real-model loading.RecordingFineTuningAdapter — new canonical system fixture
core/continuum-core/src/genome/fine_tuning/recording_adapter.rs— gated behind#[cfg(any(test, feature = "test-fixtures"))]per CLAUDE.md test discipline. Production binaries physically cannot link it.This is the FineTuningAdapter equivalent of
HeuristicInferenceAdapter— the canonical test fixture for capturing dispatchedTrainingJobRequests. Per the "one fixture per concern" rule, future tests that need to verify "did the trigger / coordinator dispatch the right examples?" import this fixture rather than rolling their own stub.Bonus: this fixture also unlocks Fix-3's deterministic Notify-based concurrency test (the C1/C2 race that the smoke-level stress test couldn't deterministically force).
Honest
train_stepshapetokens_used= count of samples whoseattention_mask.first_col[i] == 1(non-pad first target). Accumulates intometrics.gradient_tokens_consumedinside the function.train_epochadapted;job_actor::run_actorreadsmetrics.gradient_tokens_consumedstraight intoJobMetrics::trained_tokens.Tests
training_loopgradient_tokens_consumed_counts_non_pad_first_targets,pad_first_target_contributes_zero_to_tokens_used)training_triggermulti_submit_accumulation_preserves_order_through_dispatch)recording_adapter(new)job_actorhappy_pathstill assertstrained_tokens > 0and still passes — honest count is non-zero for any real run)Total fine_tuning: 76 → 81 passing. training_trigger: 12 → 13. All default
cargo testgreen.Adversarial review prompt for next round
Bring back the math/VDD-honesty lens specifically. Refute claims:
gradient_tokens_consumedactually equal the SUM of non-pad first-targets across all train_step calls in BOTH standin + a future real-wiring scenario? (i.e., is the field's semantic invariant intact, or did I just rename without fixing?)RecordingFineTuningAdapter::captures()ordering guaranteed? The internalMutex<Vec<_>>is push-only, so it must be insertion-ordered — but verify under the multi-job dispatch scenarios the new VDD tests exercise.examples[i].prompt == dispatched[i].promptper-position. Is the trigger'sentry.examples.extend(p.examples.into_iter())actually preserving insertion order, or is there a hidden reordering elsewhere in the drain path?Files changed
core/continuum-core/src/genome/fine_tuning/recording_adapter.rs(NEW)core/continuum-core/src/genome/fine_tuning/mod.rs(re-export)core/continuum-core/src/genome/fine_tuning/training_loop.rs(return tuple, accumulate metric, +2 VDD)core/continuum-core/src/genome/fine_tuning/job_actor.rs(read honest count)core/continuum-core/src/modules/training_trigger.rs(VDD test rewrites to use recorder)