Files
museion/docs/devlog/20261022-issue28-session-lifecycle-ui_log.md
T
AlexKucera 9895614b7e
CI / ci (push) Canceled after 0s
feat(sessions): session lifecycle UI (S2.3) (#28)
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
2026-10-22 12:21:12 +02:00

70 lines
6.9 KiB
Markdown

# Sessions: Session lifecycle UI (S2.3)
> **Date:** 2026-10-22
> **Type:** issue
> **Reference:** [issue #28](https://git.babylondreams.de/AlexKucera/Museion/issues/28) (blocked-by #14, closed)
## Goal
Each Session is a conversation with the standard affordances, engine-owned — Museion only UIs them: new/cancel/fork/resume/compact from the Sessions pane, every pass auto-creating its session, freeform sessions free-floating or piece-associated by name/convention, cancel mid-pass, live streaming, transcripts staying behind on an engine swap (ADR-0007).
## What Was Done
- **`MentorSessionModel.swift`** rewritten single-session → multi-session: per-session transcripts keyed by wire sessionId, `rows`/`streamingText`/`streamingThought` same-named proxies over the ACTIVE session (all callers compile unchanged). `SessionEntry` + `SessionRoster` (names-only JSON at `~/Library/Application Support/Museion/sessions.json`, injectable dir, hosted-test temp redirect). New API: `newSession(name:pieceTitle:)`, `resumeSession(_)` (session/load, replay-before-response, user turns rendered), `forkActiveSession()`, `compactActiveSession()` (`/compress` over the sendPrompt rail), `beginPassSession(kind:pieceTitle:)`, `canStartSession`, `transcriptRows(of:)`. Phase `.ready` lost its sessionId payload.
- **Notification routing**: updates filed under the PARAMS' sessionId; notification→MainActor hops ride `DispatchQueue.main.async` (Task-hops starved under parallel tests; main queue = FIFO with the continuation resume → replay-before-response guaranteed).
- **`PostsModel.runPass`**: `beginPassSession` after snapshot, before sendPrompt (flag-after-await + ownership re-guard — see Gotchas).
- **`SessionsPaneView.swift`** (new): PaneHeader + New Session control (Menu with "on \<piece\>" variant when Posts has an open piece), roster list (LibraryPostRow strip language, row click = resumeSession), actions row (Fork · Compact, `canStartSession`-disabled), liveness + Stop, transcript via shared renderer.
- **`SessionTranscriptView.swift`** (new): transcript rendering extracted verbatim from MentorPaneView (#24 `defaultScrollAnchor(.bottom)` preserved); `isWritingRow` lives here, MentorPaneView delegates.
- **`WorkspaceView.swift`**: Sessions placeholder → real pane; `PlaceholderPane` deleted.
- **Fake ACP** (`ACPClientTests.swift`): unique ids per session/new, prompt-sid echo, `loadReplay`/`loadReplayHold` modes (replay-before-response; hold parks until `load-go` for interleaving pins), session/fork (F-\<n\> / "" refusal), mcpServers strictness on new/load/fork.
- **Tests**: `SessionLifecycleTests.swift` (12 pins — scenarios + finish-audit), `PassRunTests` roster pin, five finish-audit pins (concurrent resume, refusal attribution, mid-turn create refusal, roster 0600, restart-replays-from-engine via real SIGKILL).
- **DOX pass**: `Museion/AGENTS.md` (workspace shell, ACP bridge #28 block, MentorPaneView), `MuseionTests/AGENTS.md` (fake modes, SessionLifecycleTests entry, PassRunTests roster pin), persistence-exception line.
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Roster = Museion-side names+ids JSON (no `session/list`) | PRD "association stays by name/convention"; engine list would surface unrelated hermes CLI sessions; transcripts stay engine-owned (ADR-0007) — roster persists the four name fields ONLY |
| Compact = `/compress` slash prompt over sendPrompt | The engine's compact surface is a slash command; the label rail hides the raw command |
| Relaunch default-open RESUMES (`session/load` newest entry) | Fresh transcript over an engine that knows the session would prompt/fork/compact against unloaded state (spec-review catch) |
| Restart replaces kept rows with the engine replay | ADR-0007: the engine owns the words; a diverging local copy would lie. The deleted `rows.isEmpty` skip was dead code (activate() resets one line above) |
| `DispatchQueue.main.async` for notification hops | `Task { @MainActor }` starved behind parallel test work — replay landed seconds late; main queue is FIFO with the continuation resume, making wire order guaranteed |
| Flag-after-await + ownership re-guard in runPass | Flag-before-await breaks the #124 Cancel pin (Stop no-ops during session/new); the re-guard closes the double-click window the await opened |
| Two public session-creation names over one private rail | `newSession` (pane) / `beginPassSession` (pass naming) — the seam reads at the call site |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|-----------|-----|
| Replay updates landed seconds late or never in tests | `Task { @MainActor }` hops starve under parallel test load | `DispatchQueue.main.async` hops (FIFO with continuation resume) |
| #124 Cancel pin hung during pass start | `runningPass` set before the session/new await → Stop observed the flag with `isStreaming` false → cancel no-op | Flag goes live after the awaits + ownership re-guard |
| resumeSession wiped the just-replayed transcript | Shared `activate()` reset the store after replay filled it | Replay path activates without reset |
| Fast double-click interleaved replays, diverting chunks into live buffers | `replayingSessionId` is one slot; resume never set `isStreaming` | Refuse-while-replaying guard (converged finding, 3 reviewers) |
| Restart's kept transcript silently wiped | Dead `rows.isEmpty` skip (activate() resets above it) | Unconditional resume + honest docs (ADR-0007 posture) |
| finish-audit suite run hung 14 min | New pin awaited a held `hangOnPrompt` turn nothing cancelled | Free the held turn (`shutdown()`) before awaiting, matching the neighboring pin |
## Files Changed
| File | Change Summary |
|------|----------------|
| `Museion/MentorSessionModel.swift` | Multi-session model, roster, session lifecycle wire rails, replay handling |
| `Museion/PostsModel.swift` | runPass auto-creates its session + ownership re-guard |
| `Museion/SessionsPaneView.swift` | New — the Sessions pane |
| `Museion/SessionTranscriptView.swift` | New — shared transcript renderer |
| `Museion/MentorPaneView.swift` | Transcript extraction, `.ready` payload adaptation |
| `Museion/WorkspaceView.swift` | Real Sessions pane wiring, PlaceholderPane deleted |
| `MuseionTests/SessionLifecycleTests.swift` | New — 12 lifecycle + finish-audit pins |
| `MuseionTests/ACPClientTests.swift` | Fake session-lifecycle wire (new/load/fork, hold mode) |
| `MuseionTests/PassRunTests.swift` | Pass-roster pin |
| `Museion/AGENTS.md` / `MuseionTests/AGENTS.md` / `AGENTS.md` | DOX pass (#28 contracts, fake modes, index-stats churn) |
## Open Items & Next Steps
- [ ] Model picker, pane input field, `session/list`, session renaming — deliberate v1 cuts, none ticketed
- [ ] `session/load` timeout has no runtime pin (not wire-observable with an instant fake); the fix is `timeout: promptTimeout`
- [ ] Transcripts dict grows for the app's life (fine at single-writer load; prune-on-pane-entry if ever felt)
---
*Log written by write-log skill*