feat(sessions): session lifecycle UI (S2.3) (#28)
CI / ci (push) Canceled after 0s

Each Session is a conversation Museion UIs, never owns. The mentor
bridge hosts multiple engine-owned sessions: per-session transcripts
keyed by wire sessionId behind same-named proxies (every existing
caller compiles unchanged), a names-only roster at Application
Support/sessions.json (0600; id/name/pieceTitle/date — the words
stay engine-owned per ADR-0007), and the standard affordances over
the wire: session/new, session/load, session/fork, compact as the
/compress slash prompt, session/cancel as the Stop rail.

The Sessions pane replaces its placeholder: roster list (piece-
associated by name when Posts has an open piece), row-click resume
with the engine's full-history replay (user turns included), Fork ·
Compact, live streaming with Stop; every pass auto-creates its
rostered session and streams into it; the transcript renderer is
shared with the mentor pane. Notification hops ride the main queue
(FIFO with the continuation resume) so the adapter's replay-before-
response contract is guaranteed, not probabilistic.

Resume refusals are honest and entry-attributed (an engine-unknown
session never fabricates history); concurrent replays refuse instead
of interleaving; restart replays from the engine rather than trusting
a diverging local copy. Finish-audit (three reviewers) surfaced the
concurrent-resume race, the dead restart branch, the runPass guard
window, the 15 s session/load default, and the missing createSession
backstop — all fixed and pinned (12 lifecycle pins; 359 tests green).

Closes #28
This commit is contained in:
AlexKucera committed 2026-10-22 12:21:12 +02:00
1 parent 78c8844184
commit 9895614b7e
15 files changed
+1523 -245

No files matched your search

+23
View File
@@ -821,6 +821,29 @@ extension PostsModel {
lastError = error.localizedDescription
return
}
// #28 (S2.3): every pass auto-creates its own session — rostered
// 'Pass N · <title>' and activated, so the pass streams into ITS
// transcript. The existing ready-guard above stays the refusal pin.
let passSession = await mentor.beginPassSession(kind: kind, pieceTitle: title(of: id))
guard passSession != nil else {
lastError = "The mentor engine refused a session for the pass."
return
}
// Finish-audit: the beginPassSession await above is these guards'
// first suspension — a second Run Pass landing inside it re-passed
// every guard (both flags still unset) and minted a second pass
// session. Re-check ownership here, before the flag goes live; the
// sub-ms window where BOTH awaits are still in flight self-contains
// via sendPrompt's isStreaming refusal (one orphan roster entry,
// never a double stream — ponytail ceiling).
guard runningPass == nil else {
lastError = "A pass is already running."
return
}
// runningPass goes live only AFTER the session awaits are done: from
// here to sendPrompt's isStreaming there is no suspension, so anything
// observing runningPass (the pass bar, the #124 Cancel pin) can rely
// on Stop being able to cancel the live turn.
runningPass = kind
defer { runningPass = nil }
let stub = PassContext.stub(kind: kind, pieceURL: session.passPieceURL, hasResearch: session.hasResearch)