# Deliberation: kido-alloc × kido-sched integration (2026-10-14)

Gate context: N8toriousAi approved kido-alloc standalone, ratified the fence, accepted the QEMU
multitasking proof, then ordered this integration — properly sequenced, fence fulfilled.
One builder owns kido-sched.* for this task. kido-resonate was drafted against the fenced
tree and must keep compiling and passing.

## Positions

- **P1 — Wire alloc_init inside kido_sched_init, one place (CHOSEN).** The scheduler is the
  allocator's first client; sched_init initializes kido-alloc from kido-mem's region list
  (hosted: the static arena as a synthetic region) before any task can be created. The
  header documents the effective order: alloc init → sched init → task creation. This is
  exactly what the allocator's design deliberation converged on (P7/C4): "the scheduler —
  the first client — wires it in kido_sched_init, one place."
- **P2 — Caller (kido_main) inits the allocator explicitly (REJECTED).** Would touch the
  approved kido-boot.c, force every test caller (including kido-resonate's self-test) to
  remember the order, and scatter the one place into many. Explicitness is not worth the
  churn when the precondition can be established once, loudly, inside sched_init.

## Challenges

- **C1 — Re-init resets the allocator while TCB stacks are live.** kido_alloc_init
  documents reset semantics. Coherent here: sched_init also resets every TCB to EMPTY, so
  no dangling stack pointers survive the reset. The self-test's double-init path proves it.
- **C2 — First-fit allocates low-to-high; old tests asserted top-down carve order.**
  The direction was never load-bearing — order + non-overlap is the invariant. Tests are
  adapted to allocator semantics (increasing address order), not weakened.
- **C3 — DONE-slot recycle: keep the stack vs free+realloc.** Keep (as the fenced tree
  does). The QEMU-proof cycle already fixed the fresh-carve churn leak; free+realloc on
  recycle would reintroduplicate churn and fragment for zero benefit. The stack stays
  allocated in the allocator's accounting — reuse "goes through the allocator" as briefed.
- **C4 — kido_free has no steady-state caller in the scheduler.** Honest: there is no
  destroy API, and re-init resets the allocator. The free path is proven by the
  integration self-test directly (scratch alloc/free, stats return to baseline), and the
  header states free becomes live when a destroy API lands. No fake teardown invented.
- **C5 — Hosted needs a region list.** The static carve arena becomes a synthetic
  single region {&arena, sizeof(arena)}. 512 KiB / 16 KiB stacks = 32 slots of headroom
  over the 16-task table. Bare metal keeps the largest-region rule via kido-mem.

## Convergence

P1 with C1–C5 answered above. Scheduler keeps its public interface byte-for-byte
(signatures and semantics); only the backing changes from watermark carve to kido_alloc.
Exhaustion: kido_alloc's NO_MEMORY propagates from kido_sched_create with the slot left
EMPTY — never a half-created task. Reservation stays 0,0 (sched D2 still open, documented
in both headers). kido-resonate's self-test compiles and passes unchanged against the
integrated tree (it uses only the public interface).

## Preserved dissent

- **D1:** Free-on-recycle would exercise kido_free in production instead of only in tests;
  a destroy path that never runs in the steady state is a latent untested path.
  *Overruled:* the steady state genuinely has no teardown moment (tasks run to DONE and
  the queue halts; tests re-init). Forcing free+realloc on recycle manufactures churn the
  codebase already fixed once. When a destroy API is specified, it will free — and be
  tested then.
