# Spawn colour at a provably-live window — JIT plan (Request #41, adapter 0.41.2)

## Why
0.41.1 (#40) sends the spawn rename+colour from SessionStart(startup|resume). MEASURED 2026-09-21 from
session transcripts on HFENDULEAM: at session start the keystrokes mostly arrive BEFORE the window
reads input. perri resumes: 1 clean (09-19), 1 blended into a prompt (09-16), 1 swallowed (09-21, no
command record, no prompt). `lia` fresh startups at all three node bring-ups: nothing landed, 3 of 3.
Roughly 1 success in 6. The earlier "1 blended in 289 transcripts" scan could not see a SWALLOWED
send, so it covered half the population. Also measured: CC re-writes `agent-color` after a resume
with no /color run, i.e. CC restores a coloured session's colour itself on resume.

## Scope
Move the spawn colour send OFF SessionStart and ONTO the first provably-live idle moment of a session id:
1. `hook.rs`: new helper (once per sid; marker `state/session/<eid>.colored` = sid; needs
   $SPT_SESSION_NAME; sends `rename_payload(name, colour, true)` `--force-native`, label "spawn rename").
   Call sites: END of `handle_stop` (after the idle mark — the across-clear quiet-window branch returns
   earlier, so an armed recharge never races it) and `handle_notification` idle_prompt branch (covers
   launched-then-left sessions).
2. `handle_session_start`: REMOVE the startup|resume send (restore clear-only). The clear path writes the
   marker for the NEW sid so the first post-clear Stop does not re-send.
3. `translate.rs` emit-now branch: unchanged.
4. Tests: replace `spawn_sends_the_rename_with_the_profile_colour_at_once` with Stop/idle_prompt
   once-per-sid tests (sent once, not twice; not sent in the quiet window; not sent without a name;
   clear writes the marker); restore a "startup/resume/compact never send rename" test.
5. REQ-SESSION-COLOR amended again (why SessionStart timing is wrong — the measured numbers above);
   manifest 0.41.2 + note; CHANGELOG [0.41.2] (product terms); `[strings]` comment.

## Open questions
- compact rotates the sid, so the first Stop after a compact re-sends name+colour. Idempotent; accept.
- Is `self_id` at Stop always the spawn's endpoint id? Yes for spt-hosted; harness-hosted has no
  $SPT_SESSION_NAME, so the helper no-ops there.

## Gate
`sh ci/run-gates.sh` PASS + `traceable-reqs check` exit 0, then the release runbook spine (3 triples
fresh, pack, tag, piped release notes + verify, mirror), `spt adapter update claude-spt`, alchemy:
`state #41 wip` is set; after push: comment, `sweep`, `release v0.41.2`.
Field check after release: rerun the fresh-session transcript scan; expect a clean /rename + /color
local_command shortly after each session's FIRST turn ends.
