# EXP-65: the outcome gate keyed on signals Cadence receives: the teacher's label and the brain's own forecast error

- Date: 2026-10-16 | Cadence version: 0.83.0 (`6499e56`, `~/_cadence_study`, upstream main; EXP-63's head, so EXP-63's rows pair directly) | Program iter: none (memory track; the open question on upstream #202)
- Script: `exp/EXP-65_inbrain_gate.py` (imports EXP-63, which imports EXP-56: same chambers, brain, signals, trace rule and readings) | Evidence: `exp/EXP-65-check.out`, `exp/EXP-65-pilot.*`, `exp/EXP-65-full.*`

## Summary
- Question: EXP-63's outcome gate (hold out of the temporal context only decisions the world answered as failures) kept EXP-57's gain and removed EXP-59's invisible-action break, but it read the chamber's success flag as an oracle; in that chamber nothing `step()` receives under reward alone tells a miss from the invisible correct WOOD. Can a gate keyed on signals Cadence does receive stand in for the oracle? Two candidates: (a) the corrective teacher's label, which `step(teacher=...)` receives right after a guided miss; (b) the brain's own signed forecast error for the decision (the learner's `dopamine`, computed inside the next `step()`).
- Setup: EXP-63 exactly (0.83 `Brain.compose(7, 5, modules=(48, 24), arousal=True, memory_choice=True)`, efference off, V5 rules, 10 decisions per attempt, 120 attempts, natural and corrective signals, readings on a saved copy). New arms, all gating during training only (no label and no feedback reach the brain while it is read, so every new arm reads with the plain context):
  - `lab5`: before the call that carries a teacher label, the last decision is taken back out of the context (the label marks it a miss; guided decisions only, 4 in every 12). Corrective signal only: under the natural signal no label exists and lab5 is ctx5 by construction (checked).
  - `td5`: the brain's `learn()` is wrapped; after it computes the forecast error of the last decision, if `dopamine < 0` (threshold fixed now, not tuned) the context is restored before the demonstration is recorded and before `act()`. Both signals.
  - `out5t`: EXP-63's oracle gate during training only, plain reads. A clean greedy pass contains no miss, so read-time holding cannot change it; out5t's greedy passes must equal out5's (checked), and out5t is the matched ceiling for the first-try and sampled readings.
  - Comparators: EXP-63's ctx5 / hold5 / out5 rows on the same seeds (invisible chain 63_000 + i, 48 per signal; hidden chain 63_000 + i, 24 per signal). MODE=check recomputes three stored EXP-63 rows through this script and requires them identical.
  - Diagnostic in every new arm: per training decision (non-terminal), the stage, the chamber's outcome and the brain's dopamine. AUC = P(a miss's forecast error < a success's), per life; `auc_s1` is stage 1 of the invisible chain, where the success is the invisible WOOD. This asks whether the brain can tell the two apart at all, independent of the threshold.
- Check (`MODE=check`, before the pilot): (a) three stored EXP-63 rows recompute identically through this script; (b) on seed 65_990: td5 with threshold -inf, lab5 under natural, and a logging-only ctx5 are identical to ctx5; (c) out5t's training and greedy pass equal out5's; (d) `learn()` never changes the stream's context (so restoring after `learn()` is the same context EXP-63 restores before the call); (e) dopamine is alive (nonzero, varies). A failed check stops the run.
- Pilot (invisible chain, seeds 63_500 + i, 6 per signal, pairs with EXP-63's pilot rows): prints every chain link per arm (holds on misses, holds on correct decisions, holds on the invisible WOOD, AUC). It cannot change arms, threshold, seeds or predictions. If dopamine is dead (check e fails), td5 is dropped from the full run and reported as unavailable, not refuted.
- RUN GATE: (1) predictions below, written before the check. (2) Window: EXP-63 measured the window at 120 attempts on these seeds (invisible corrective: out5 19 vs ctx5 5 of 48 clean passes). (3) Variance: arms paired by seed; exact McNemar on clean-pass discordant pairs, paired SEM on rates. (4) Metrics: clean greedy pass (four stages in four greedy decisions), first-try accuracy at stage 2 (right after the invisible WOOD), sampled success; no degenerate policy passes a clean greedy pass. (5) Chain: signal (label present / dopamine < 0) -> held decisions (on misses vs on correct moves, especially the invisible WOOD) -> records filed on first-try keys -> clean passes.
- Prediction (written before any run):
  - (P1, headline) Invisible chain, corrective (48 pairs): clean greedy passes lab5 > ctx5, more lab5-only than ctx5-only pairs, exact McNemar p < .05.
  - (P2, safe) Invisible chain, corrective: stage-2 first-try accuracy lab5 - ctx5 > -.05 (a label never follows a correct decision, so the invisible WOOD is never held).
  - (P3, exploratory, no verdict weight) lab5's clean passes reach at least half of the oracle's gain: lab5 >= (ctx5 + out5) / 2 on the invisible corrective arm.
  - (P4) td5 on the invisible chain: mean per-life `auc_s1` below .65 (the brain's forecast error cannot tell a stage-1 miss from the invisible WOOD: same observation, reward 0 for both under the natural signal).
  - (P5) Invisible chain, pooled (96 pairs): td5 shows no reliable clean-pass gain over ctx5 (td5-only <= ctx5-only, or exact McNemar p >= .05).
  - (P6, direction only) Hidden chain, corrective (24 pairs): lab5-only >= ctx5-only clean-pass pairs.
- Decision rule (written before any run): P1 and P2 hold -> for #202, under corrective teaching the label is an in-library failure signal: an outcome-keyed gene can key on "a teacher label followed this decision" with no new input, for taught decisions; under reward alone it still needs a failure input from the world. P2 holds, P1 fails -> the label gate is safe but too sparse at 120 attempts to carry the gain; the gene still needs a failure input. P2 fails -> unexpected (labels never follow correct moves): investigate before any claim. td5: P4 and P5 hold -> the brain's own forecast error cannot stand in for the oracle here, which confirms EXP-63's reading that reward alone needs a world failure signal. P4 fails, P5 holds -> the signal is in the error but threshold 0 does not use it; queue a calibrated gate. P5 fails (td5 gain p < .05) -> the brain's own forecast is a usable failure signal; decision-grade for #202, ping. Verdict: SUPPORTIVE if P1 and P2 hold; BOUNDARY if P2 holds and P1 fails; NULL if P2 fails (loop: CONFIRMED / INCONCLUSIVE / REFUTED). The forecast arm gets its own line: USABLE (P5 fails), SIGNAL-UNUSED (P4 fails, P5 holds), BLIND (P4 and P5 hold).
- Amendments (2026-10-16, after the check and pilot, before the full run; no arm, threshold, seed, metric or prediction changed):
  - Check (d) was scoped too wide. The first check run failed it: `learn()` changed the context 120 times, once per attempt, at the done call, where the library clears the stream's context (EXP-56 documents this; no gate ever acts on a boundary). (d) now counts non-boundary calls only and reports the done resets separately: 0 off a boundary, 120 at done. The rerun passed every check.
  - Pre-run code review (2 adversarial reviewers, no blocking finding). One verified the gate-fired path directly: td5's restore point gated on the chamber's flag reproduces out5 exactly (train stats, saved arrays, readings) on 8 lives; that test is now part of MODE=check. One replayed the summary code on EXP-63's rows and reproduced EXP-63's published numbers. Robustness fixes applied: check (e) gates PASS (dopamine alive and varying), the threshold is stored per row and locked to 0 outside the check, pairing asserts equal seed bases, a missing comparator file stops the run, stage differences print their pair count, the P3 bar is printed.
  - P4's scope, fixed now: the mean per-life `auc_s1` over all 96 td5 lives on the invisible chain (pooled, as P5); per-signal values reported beside it. The pilot's values (pooled .546, natural .551, corrective .541, 6 seeds each) lie below .65 at every scope, so the choice does not decide P4 on the pilot. An AUC below .5 means the error ranks the invisible WOOD below misses (inverted); it is reported as exploratory, with |auc - .5|, not counted toward P4.
  - The `dopamine` read is the learner's TD error clipped at 1, not centred (`dopamine_center` is 0 on the composed brain), per the review.
- Check (`exp/EXP-65-check.out`): PASS after the amendment above. Stored EXP-63 rows recompute identically; td5 at threshold -inf, lab5 under natural and the logging-only ctx5 equal ctx5; out5t trains and passes greedily exactly as out5; td5's restore point gated on the chamber's flag equals out5 (the gate-fired path); `learn()` leaves the context alone off a boundary; dopamine is alive.
- Pilot (6 seeds per signal, `exp/EXP-65-pilot.*`): every chain link moved. lab5 held 943 decisions, all misses (none correct); td5 held 3,762, 849 of them correct (451 the invisible WOOD), stage-1 AUC .546 pooled; out5t's clean passes equal out5's. Nothing changed after it.
- Result (seeds 63_000+, 120 attempts, 3 workers, 25 min; `exp/EXP-65-full.*`; comparators are EXP-63's rows on the same seeds):

  | invisible chain | pairs | clean greedy passes | x-only / y-only (exact McNemar p) | stage-1 first try, diff (SEM) | stage-2 first try, diff (SEM) | sampled, diff (SEM) |
  |---|---|---|---|---|---|---|
  | lab5 vs ctx5, corrective | 48 | **9 vs 5** | **8 / 4 (p .39)** | +.008 (.054) | **-.005 (.059)** | -.011 (.062) |
  | lab5 vs out5t, corrective | 48 | 9 vs 19 | 5 / 15 (p .041) | **-.186 (.043)** | +.033 (.043) | -.021 (.043) |
  | out5t vs ctx5, corrective | 48 | 19 vs 5 | 18 / 4 (p .004) | +.194 (.057) | -.038 (.058) | +.010 (.051) |
  | td5 vs ctx5, pooled | 96 | **2 vs 5** | **2 / 5 (p .45)** | -.018 (.028) | -.081 (.040) | -.108 (.035) |
  | td5 vs ctx5, corrective | 48 | 2 vs 5 | 2 / 5 (p .45) | -.029 (.054) | -.151 (.061) | -.187 (.065) |
  | out5t vs out5, pooled | 96 | 19 vs 19 | 0 / 0 | -.004 (.004) | -.047 (.006) | -.084 (.010) |

  What the gates held during training (invisible chain): lab5 7,749 decisions, every one a miss, 32% of the 23,966 misses (the guided share); never a correct move. td5 30,572 decisions: 23,865 misses (32% of 75,088) and 6,707 correct moves, 3,824 of them the invisible WOOD. The brain's own forecast error at stage 1, miss vs the invisible WOOD: AUC .525 (SEM .005, 96 lives; natural .512, corrective .538); over all stages .554.
  Hidden chain (24 pairs per signal): corrective clean passes lab5 3 vs ctx5 2 (2 / 1), out5t 13 (11 / 0 vs ctx5, p .001); td5 pooled 0 vs 4 (0 / 4, p .125). Exploratory, not claimed: on the hidden chain under the natural signal the stage-1 AUC is inverted, .421 (SEM .015): the brain's error ranks misses above the correct WOOD there.
  P1 FAILED (8 / 4, p .39). P2 HELD (-.005, and no correct decision was ever held). P3 FAILED (9 against a bar of 12; exploratory). P4 HELD (.525). P5 HELD (2 / 5; td5 is worse than the plain context on stage 2 and sampled success). P6 HELD (2 / 1).
- Verdict: BOUNDARY (loop: INCONCLUSIVE). The teacher's label is a safe failure signal (it never holds a correct move, so no invisible-action break) but at 120 attempts it does not carry the oracle gate's gain: 9 clean passes against 5 for the plain context and 19 for the oracle. The brain's own forecast error is BLIND: it cannot tell a stage-1 miss from the invisible WOOD (AUC .525), and as a gate it holds thousands of correct moves and does worse than no gate. So for #202, in this chamber an outcome-keyed gene has no in-library signal that stands in for the world's failure flag.

## Reflection
- What it means: the decomposition says where the oracle gate's gain lives and why the label cannot reach it. out5t (the oracle during training only) reproduces all of out5's clean passes, so the gain is made while the brain learns, not while it is read, and it shows up as stage-1 first-try accuracy (+.19 over the plain context): with misses held, the record of the eventual right move lands on the first-try key. Two thirds of the training decisions are autonomous, and that is where most misses happen; the teacher only labels guided misses, so lab5 holds 32% of the misses and loses exactly at stage 1 (-.19 against out5t). The label is the right kind of signal (precise, never wrong about a correct move) with the wrong coverage. The brain's own forecast error is the opposite failure: it is available at every decision but carries no information about the one distinction that matters here, because a miss and the invisible WOOD both leave the same observation and both pay 0. Read-time holding matters for sampled success (out5 beats out5t by .08) but not for clean passes, as the design predicted.
- Process: pre-registered and pushed (93d5645) before any run. The first check failed one item that was scoped too wide (the library's context reset at done); it was rescoped and reported as an amendment before the pilot, together with the fixes from two adversarial pre-run reviewers (no blocking finding; one verified the gate-fired path directly, which is now part of the check), committed at 75dfc6a before the full run. Comparators are EXP-63's rows on the same seeds, which the check recomputed identically, so the new arms pair with already-published lives rather than fresh ones; the new arms themselves are new. Limits: one chamber family, one composed brain, 120 attempts, a threshold of 0 for the forecast gate (the AUC says no threshold would rescue it at stage 1), an instrument-level rule, and a label gate that only exists under corrective teaching.
- Lesson: before keying a gate on an available signal, measure the signal's coverage of the decisions the oracle gate acted on, not only its precision. A perfectly precise signal that sees a third of the events recovers far less than a third of the effect when the effect lives in the unseen part (here, the autonomous misses at stage 1). And a metric that cannot be touched by one phase (a clean greedy pass contains no misses, so read-time holding cannot change it) is a free decomposition of where an effect is made.
- Next: the #202 comment can now say that two in-library candidates were measured and neither stands in for the world's failure flag, so the gene needs a per-decision failure input. Queued EXP-66: the smallest such input through the channel Cadence already has, a small negative reward on a failed action, with the gate keyed on it; measure whether the penalty itself changes learning (penalty without gate vs penalty with gate vs the plain context).
