# WO-20: Exact session continuation across exit and restart

## Incident

On 2026-09-03, the `telegram_test` TUI displayed the latest pentest task during
startup, but the first restored model context combined a completed `breach.py`
handoff with an unrelated, older `page.tsx` todo tree. The user then entered
`continue`, and Omnius continued the stale tree instead of the task that was
active before `/quit`.

## Root causes

- `/quit`, `/exit`, readline close, and fallback exit abort an active runner.
  The explicit quit paths also delete `.omnius/history/pending-task.json`.
- Startup selects handoff, completion ledger, todo state, context chronology,
  and visual history independently. These projections need not identify the
  same session or run.
- Generic restore mutates the process-wide task session, even though the
  restored transcript is historical orientation only.
- The host interprets words such as `continue` with a regular expression and
  uses that classification to reuse a restored task identity.
- A resumed task is submitted as a generated wrapper. The wrapper can replace
  the original user goal in new completion, workboard, and handoff records.
- Pending-task consumption checks only phase and session. It does not prove the
  recovered run, epoch, and owner generation.
- Updating an existing session-context entry changes its timestamp in place,
  but does not move it into chronological order. Tail readers can therefore
  report an older task as latest.

## Required invariants

- [x] An active task receives a typed, atomic continuation checkpoint before a
  resumable exit.
- [x] `/quit`, `/exit`, readline close, and graceful process termination pause
  and preserve the active run. Explicit `/stop` and Ctrl+C remain terminal and
  delete the pending checkpoint. Escape now cancels inference and waits for
  explicit input; repeated Escape remains paused, as specified in
  `../WO-tui-escape-input-wait-20261014.md`.
- [x] A checkpoint identifies the project, original goal, session, run, task
  epoch, owner generation, lifecycle phase, exit reason, and capture time.
- [x] Manual startup automatically adopts a checkpoint explicitly marked for
  restart, without requiring an updater environment variable.
- [x] Exact continuation context is scoped to the checkpoint session and run.
  A global handoff, ledger, todo tree, or transcript cannot replace it.
- [x] Generic context restore is orientation only. It does not bind task/todo
  identity or mutate `OMNIUS_SESSION_ID`.
- [x] Continuation authority comes from typed lifecycle state or an explicit
  command. It never comes from semantic keyword or regular-expression
  classification of user prose.
- [x] The resumed runner receives the exact original user goal. Progress and
  historical orientation remain separate context.
- [x] A pending checkpoint is consumed only after the runner proves the same
  session, run, epoch, and owner generation in the running phase.
- [x] Session-context entries remain ordered by their effective save time after
  merge or replacement.
- [x] Corrupt, cross-project, incomplete, or identity-mismatched checkpoints
  fail closed and remain available for diagnosis unless explicitly stopped.

## Deterministic verification

- [x] Pending checkpoint round-trip and schema validation.
- [x] Exact four-field adoption match and one-field-at-a-time mismatch table.
- [x] Quit wiring has no abort/discard path for an active resumable run.
- [x] Restart continuation remains exact in the presence of a newer handoff,
  higher-scoring stale ledger, unrelated todos, and unrelated visual history.
- [x] Generic restore cannot bind a subsequent fresh task to historical todos.
- [x] A resumed run persists the original goal, not a synthetic continuation
  wrapper.
- [x] Session-context merge reorders the updated entry chronologically.
- [x] Focused CLI typecheck/build and affected tests pass.

## Delivery evidence

Implemented in the CLI session directory, TUI lifecycle coordinator, command
surface, and runner continuation gate. Verification on 2026-09-03:

- Focused CLI interruption, restore, session-diary, and command suites: 52
  passed.
- Focused orchestrator context and interruption suites: 67 passed.
- Complete orchestrator suite: 2,292 passed, 14 skipped.
- Complete CLI suite: 2,425 passed. Two unrelated tests timed out while the CLI
  and orchestrator suites ran concurrently; both passed alone, 35 of 35.
- CLI and orchestrator typechecks passed.
- CLI and orchestrator builds passed.
- A two-process, no-inference harness wrote the checkpoint in one process and
  recovered the exact `harness-session/harness-run/epoch-3` selection in a
  second process.

No live inference or service restart was required for this host-side
state-machine repair.
