# Session 22 design — kido_sched_destroy on bare metal (PENDING #1 + gate proof)
2026-10-22, builder crew (micro-agent circle)

> OUTCOME (recorded post-hoc, after execution — not part of the
> deliberation): the toolchain was PRESENT at design time and ABSENT
> minutes later (binary gone; `apt-get install` → "E: Unable to locate
> package", main pocket unreachable — the 5th data point). The hosted
> battery had already passed 12/12. Per this design's own C6, the
> session degraded: PENDING #1 stays OPEN, the QEMU halves (delta-0
> re-proof, scratch destroy-gate image) could not run, and the session
> pivoted to the next unbuilt module — kido-mmu (deliberation
> `2026-10-22-kido-session22-mmu-design.md`, drafted + tested this
> session). The design below stands as the ready plan for the next
> tooled VM.

## The state

Session 20 (2026-10-21) drafted `kido_sched_destroy()` — teardown at
rest, the destroy API queued since session 6 — and left its
conformance at 16 MET / 0 PARTIAL / 0 DEFERRED / 2 PENDING
(environmental). Session 21 (2026-10-22) closed PENDING #2 (reloc
rerun on the settled tree, 19/19 + 28/28) but PENDING #1 stayed open:
the cross toolchain was absent (4th occurrence), so destroy's ARM64
`ctx`-zeroing `#if` branches were inspection-only and no bare-metal
execution of any destroy code existed. The hosted battery covers
destroy 110/110 (§§50–59: refusal gates, happy path, re-init round
trip, stats) — the logic is proven; the ARM64 encoding and any
bare-metal behavior are not.

This VM HAS the toolchain (`aarch64-linux-gnu-gcc` 13.x present,
`apt-get install` reports the package already newest — the install
session 20 left in flight evidently landed, or this VM was imaged
with it). So this session closes PENDING #1 for real and, while the
toolchain is warm, puts destroy's safety gates on bare metal for the
first time.

## The piece

A verification session in the lineage of sessions 6/8/11/14/18/19:
one solid piece — **destroy's safety gates, proven on bare metal** —
plus the PENDING #1 closure it rides on. Pristine sources throughout;
`/tmp` scratch only; zero Gate-file modifications; no bootable-kernel
claim; first boot is N8toriousAi's to witness.

The work, in order:

1. **Hosted regression gate** on the settled tree (tree byte-untouched
   since session 21's battery): the full battery per each module's
   TESTING line, `-Wall -Wextra -Werror`, zero warnings required,
   plus the audit fixture test.
2. **PENDING #1 — cross-compile**: all 10 C TUs
   (`aarch64-linux-gnu-gcc -ffreestanding -O0 -Wall -Wextra -Werror`,
   zero warnings) + both `.S` files assembled. This specifically
   compiles destroy's ARM64 `ctx`-zeroing branches — the exact
   inspection-only gap session 20 named.
3. **Delta-0 re-proof of the settled tree** (pristine recipe:
   harness linker copy at 0x40080000, entry objects first, raw binary,
   QEMU virt/cortex-a57/128MiB, `-d int`): breath →
   `ABCABCABCABC` → zero exceptions. Session 21's "no QEMU owed"
   rested on "nothing changed since session 19" — but session 20's
   destroy code IS linked into the boot image now (a file on the
   boot path changed), so re-proving the settled tree boots is
   honest regression, not theater. Claimed as exactly that.
4. **Scratch destroy-gate image** (`/tmp` only, never committed):
   a copy of the proven `kido-entry-arm64.S` with ONE harness line
   changed (`bl kido_entry_c_main` → `bl kido_destroy_proof_main`)
   + a scratch C TU that mirrors the proven chain's first three
   steps (reloc tripwire → bootinfo fill → HAL fill) and then
   exercises the gates:
   - Phase 1 (main context): `sched_init` → create A, B →
     `kido_sched_destroy()` must return `KIDO_ERR_EARLY_ENV`
     (READY-refusal) → print `READY-refusal OK`; then create C
     must succeed (proves the refusal left table+allocator usable).
   - Phase 2 (re-init, then task context): `sched_init` again →
     create Z (self-refusal task), A, B → `kido_sched_run()` →
     Z calls `kido_sched_destroy()` on itself → must return
     `KIDO_ERR_EARLY_ENV` → prints `SELF-REFUSAL OK` → returns
     (DONE); A, B print their 4-mark loops → DONE → queue empties
     → the designed loud halt.
   - Expected console: the three proof lines + `ABABABAB`, then
     silence (halt spin), zero exceptions, exit 124.

## Positions

- **P1 regression keeper.** Hosted battery first, full width — the
  fence-break precedent (session 5: a corrupted free list only a
  linked test caught) is why. Timestamps are a claim; the battery
  is the proof (session-21 D2, adopted).
- **P2 pending closer.** PENDING #1's exact content is the
  cross-compile of the touched TUs. The toolchain is present, so
  the item closes by action, not by another dated "absent" note.
  The 10-TU set is the whole settled tree; destroy's TU
  (`kido-sched.c`) is inside it. Zero warnings or the item stays
  open — no partial credit.
- **P3 gate prover.** The refusal law is destroy's safety-critical
  half: a refusal that misfires as acceptance frees a live stack
  (silent corruption); an acceptance that misfires as refusal is
  merely loud. The hosted test pins the logic; only bare metal
  proves the ARM64 branches execute and the gates hold under the
  real switch. The scratch image is the honest vehicle: `/tmp`
  only, pristine sources, the proven entry with a one-line
  redirect — every proven step (delta measure, EL drop, phase-3
  relocator, delta-aware SP, BSS-at-actual, report stash) runs
  unchanged before the redirect.
- **P4 honesty auditor.** Three precise non-claims, stated up front:
  (a) the happy path (destroy at rest freeing stacks that carried
  real switch traffic) is NOT exercised on bare metal — it cannot
  be: `kido_sched_run()` never returns by design, and the refusal
  law forbids teardown over any RUNNING task, so destroy-at-rest is
  unreachable after `run()` on this kernel. The happy path stays
  hosted-proven (110/110) + cross-compiled. Its bare-metal moment
  awaits a `kido_main` with a shutdown path — named future, not
  hidden gap. (b) The delta-0 re-proof proves the settled tree
  still boots with destroy linked in; it does not prove destroy —
  the scratch image does that, and the claims are kept separate.
  (c) The scratch image's entry is a harness copy; the one-line
  diff is stated in the ledger, not smuggled.
- **P5 scope keeper.** No new module, no source edits, no stamp
  generated (gate stays closed — delta-0 proceeds under the closed
  gate, as the tripwire's contract requires). D1
  (`KIDO_ERR_NO_TASKS`) stays N8toriousAi's call. Phase 4 and
  UEFI/RPi4/MMU stay future.

## Challenges

- **C1 — Is the scratch entry.S copy honest, or a second boot path?**
  Answered (P3): it is the proven `.S` byte-identical except the
  final call target — the diff is one line, and all eight proven
  steps execute before the redirect. The redirect itself is the
  documented harness line, the same way session 19's measurement
  build was `/tmp`-only. The pristine recipe's delta-0 re-proof
  runs separately, so the proven path is re-proven unmodified.
- **C2 — Why not exercise destroy through the existing kido_main?**
  `kido_main` lives in Gate-approved `kido-boot.c`; changing its
  behavior (even behind a `-D`) needs Gate ratification. The
  scratch image leaves every approved file pristine. The
  discipline is: sources untouched, harness in `/tmp`.
- **C3 — Phase 1 creates C after the refusal: is that a valid
  "table intact" proof?** The refusal gate is specified to leave
  table+allocator byte-identical (session-20 deliberation P2).
  A subsequent successful create proves the table is usable;
  the hosted test pins byte-identity. The bare-metal check is
  the usability half — stated as such, not as the full pin.
- **C4 — Should the destroy image also run relocated (+0x80000)?**
  No. Destroy is delta-agnostic portable C; the relocation proof
  is closed (session 18, both signs). Stacking the proofs would
  blur which mechanism owns a failure. Delta-0 only, stated.
- **C5 — The re-init between Phase 1 and Phase 2: does re-init
  after a refused destroy have defined semantics?** Yes —
  documented in `kido_sched_init`: re-init resets table and
  allocator; coherent because every TCB is EMPTY-or-untouched
  (the refusal touched nothing). The hosted test covers the
  re-init round trip; Phase 2 exercises it on bare metal as a
  bonus, claimed as bonus.
- **C6 — What if the toolchain vanishes mid-session?** Then
  PENDING #1 stays open with a 5th dated data point and the
  session degrades to the hosted battery only — recorded, not
  hidden. (It is present at design time; the design does not
  assume it survives.)

## Convergence

Run the battery; close PENDING #1 by compiling; re-prove the
settled tree delta-0; prove the refusal gates on bare metal via
the scratch image; record the three non-claims (P4) in the ledger
verbatim. One solid piece: destroy's safety gates, proven where
they must never misfire. The full build plan still queues for
N8toriousAi; first boot is his to witness.

## Preserved dissent

- **D1 (overruled):** skip the scratch image — cross-compile plus
  the delta-0 re-proof is enough for one session. Overruled:
  compiling proves encoding, not execution; the refusal gates are
  the safety-critical half of session 20's new code and have never
  executed anywhere but hosted. The scratch image is `/tmp`-only
  and its claims are fenced (P4).
- **D2 (overruled):** prove the happy path on bare metal too, via
  a hand-driven `kido_ctx_switch` from the scratch main.
  Overruled: that reimplements the run loop in a harness file —
  a second scheduler by another name. The refusal law makes
  destroy-at-rest unreachable after `run()` by design; the honest
  move is to name the future (a `kido_main` with a shutdown path),
  not to stage it.
