# Plan: Measure Mode Repair

## Overview

Restore `make run-measure` proof emission. The build is broken on `main`
because the `thread-lifecycle` measure-mode child exits before its park-path
proof line:

```
[thread-lifecycle] park path avg cycles:
```

`REVIEW_FINDINGS.md` and `WORKPLAN.md` both flag this as a blocker for
relying on measure-mode closeout evidence. This is a small targeted track
that should not block the Device Driver Foundation milestone but should be
landed before the next selected scheduler milestone.

The repair is scoped to whatever change is actually needed in the
`thread-lifecycle` measure-mode binary plus minimal kernel `measure.rs`
adjustments. Do not expand the scope into a broader scheduler refactor;
those follow-ups stay in `docs/backlog/scheduler-evolution.md`.

## Conflict Surface

Owned by this plan:

- `demos/thread-lifecycle/` (the measure-mode child)
- `kernel/src/measure.rs` (only narrow adjustments needed for the proof
  line; do not introduce new counters)
- `Makefile` `run-measure` recipe
- `system-measure.cue` if and only if the manifest must change to keep the
  child alive past the park path

Do not touch from this plan:

- Other `demos/*` crates
- Kernel scheduler core (`kernel/src/sched.rs`,
  `kernel/src/cap/endpoint.rs`)
- `tools/remote-session-client/`, kernel device code, or CUE defaults

## Validation Commands

- `make fmt-check`
- `cargo build --features qemu,measure`
- `cargo test-lib`
- `cargo build-demos-capos`
- `make run-measure`

## Success Criteria

`make run-measure` exits cleanly with the
`[thread-lifecycle] park path avg cycles:` proof line emitted, the
benchmark counters from `kernel/src/measure.rs` are unchanged or strictly
expanded, and `REVIEW_FINDINGS.md` plus `WORKPLAN.md` are updated to record
the closure.

### Task 1: Reproduce the broken proof emission

- [ ] Run `make run-measure` on the current branch base, capture the
      QEMU console log, and confirm the missing
      `[thread-lifecycle] park path avg cycles:` line.
- [ ] Identify whether the child exits before reaching the park path,
      whether the park path runs but the proof line is suppressed, or
      whether the kernel measure counter is consumed before the line is
      printed.
- [ ] Record the failure mode in the task branch handoff so the fix is
      narrowly scoped.

### Task 2: Implement the narrow fix

- [ ] Apply the minimum change in `demos/thread-lifecycle/` (or
      `kernel/src/measure.rs` if the failure mode requires it) so the
      proof line emits before the child exits.
- [ ] Keep counter shapes stable. If a counter must change, update the
      `make run-measure` parser and any host test that consumes it in
      the same task branch.
- [ ] Avoid introducing new measure-mode entry points; this is a
      regression repair.

### Task 3: Refresh closeout evidence and unblock dependents

- [ ] Verify `make run-measure` is green and capture the proof line in
      the task branch handoff.
- [ ] Remove the broken-on-main caveat from `WORKPLAN.md` and the
      paired note in `REVIEW_FINDINGS.md`.
- [ ] Add a `docs/changelog.md` entry referencing the repair commit and
      note the measure-mode closeout availability for the next selected
      scheduler milestone.
