diff --git a/Museion/MentorSessionModel.swift b/Museion/MentorSessionModel.swift index e844b28..bddabea 100644 --- a/Museion/MentorSessionModel.swift +++ b/Museion/MentorSessionModel.swift @@ -280,8 +280,15 @@ final class MentorSessionModel { /// Owner ruling (2026-11-07): an open-piece switch that arrived while a /// turn or pass streamed — fires at turn end /// (firePendingScopeIfRequested); an in-flight transcript is never - /// torn down mid-stream. - private var pendingScopePieceTitle: String? + /// torn down mid-stream. Pending-ness rides the enum, NEVER the + /// target's optionality: a nil target is an explicit clear (nothing + /// open hosts nothing), not "no pending request". + private enum PendingScope: Equatable { + case none + case scope(String?) + } + + private var pendingScope: PendingScope = .none /// #137: per-pass readiness — refreshed at pane entry (re-entry /// re-fires the pane's .task — the key-added-in-Settings re-enable /// path). #181: computed in the PassReadiness module over the provider @@ -589,7 +596,7 @@ final class MentorSessionModel { func scopeHostedSession(toOpenPieceTitle pieceTitle: String?) async { guard phase.isReady else { return } guard !isStreaming else { - pendingScopePieceTitle = pieceTitle + pendingScope = .scope(pieceTitle) return } // Finish-audit: a replay in flight defers the switch too — the @@ -597,10 +604,10 @@ final class MentorSessionModel { // "Resume refused" row into the transcript (the replay's // completion re-fires the pending scope). guard replayingSessionId == nil else { - pendingScopePieceTitle = pieceTitle + pendingScope = .scope(pieceTitle) return } - pendingScopePieceTitle = nil + pendingScope = .none let target = SessionRoster.hostedSessionId(forOpenPieceTitle: pieceTitle, in: roster) guard activeEntry?.sessionId != target else { return } guard let entry = roster.first(where: { $0.sessionId == target }) else { @@ -1064,9 +1071,11 @@ extension MentorSessionModel { /// Owner ruling (2026-11-07): a deferred open-piece switch fires at turn /// end — from BOTH turn-end defers (chat sendPrompt and the pass run), /// after `isStreaming` cleared, so the scope rail re-evaluates for real. + /// A deferred nil target drains too — it is an explicit clear, so the + /// old piece's hosting must not survive the drain. private func firePendingScopeIfRequested() { - guard let title = pendingScopePieceTitle else { return } - pendingScopePieceTitle = nil + guard case let .scope(title) = pendingScope else { return } + pendingScope = .none Task { await scopeHostedSession(toOpenPieceTitle: title) } }