fix(session): drain a deferred nil scope as an explicit clear [museion/deferred-empty-piece-scope-lost] #184
@@ -280,8 +280,15 @@ final class MentorSessionModel {
|
|||||||
/// Owner ruling (2026-11-07): an open-piece switch that arrived while a
|
/// Owner ruling (2026-11-07): an open-piece switch that arrived while a
|
||||||
/// turn or pass streamed — fires at turn end
|
/// turn or pass streamed — fires at turn end
|
||||||
/// (firePendingScopeIfRequested); an in-flight transcript is never
|
/// (firePendingScopeIfRequested); an in-flight transcript is never
|
||||||
/// torn down mid-stream.
|
/// torn down mid-stream. Pending-ness rides the enum, NEVER the
|
||||||
private var pendingScopePieceTitle: String?
|
/// 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
|
/// #137: per-pass readiness — refreshed at pane entry (re-entry
|
||||||
/// re-fires the pane's .task — the key-added-in-Settings re-enable
|
/// re-fires the pane's .task — the key-added-in-Settings re-enable
|
||||||
/// path). #181: computed in the PassReadiness module over the provider
|
/// path). #181: computed in the PassReadiness module over the provider
|
||||||
@@ -589,7 +596,7 @@ final class MentorSessionModel {
|
|||||||
func scopeHostedSession(toOpenPieceTitle pieceTitle: String?) async {
|
func scopeHostedSession(toOpenPieceTitle pieceTitle: String?) async {
|
||||||
guard phase.isReady else { return }
|
guard phase.isReady else { return }
|
||||||
guard !isStreaming else {
|
guard !isStreaming else {
|
||||||
pendingScopePieceTitle = pieceTitle
|
pendingScope = .scope(pieceTitle)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Finish-audit: a replay in flight defers the switch too — the
|
// 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
|
// "Resume refused" row into the transcript (the replay's
|
||||||
// completion re-fires the pending scope).
|
// completion re-fires the pending scope).
|
||||||
guard replayingSessionId == nil else {
|
guard replayingSessionId == nil else {
|
||||||
pendingScopePieceTitle = pieceTitle
|
pendingScope = .scope(pieceTitle)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pendingScopePieceTitle = nil
|
pendingScope = .none
|
||||||
let target = SessionRoster.hostedSessionId(forOpenPieceTitle: pieceTitle, in: roster)
|
let target = SessionRoster.hostedSessionId(forOpenPieceTitle: pieceTitle, in: roster)
|
||||||
guard activeEntry?.sessionId != target else { return }
|
guard activeEntry?.sessionId != target else { return }
|
||||||
guard let entry = roster.first(where: { $0.sessionId == target }) else {
|
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
|
/// 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),
|
/// end — from BOTH turn-end defers (chat sendPrompt and the pass run),
|
||||||
/// after `isStreaming` cleared, so the scope rail re-evaluates for real.
|
/// 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() {
|
private func firePendingScopeIfRequested() {
|
||||||
guard let title = pendingScopePieceTitle else { return }
|
guard case let .scope(title) = pendingScope else { return }
|
||||||
pendingScopePieceTitle = nil
|
pendingScope = .none
|
||||||
Task { await scopeHostedSession(toOpenPieceTitle: title) }
|
Task { await scopeHostedSession(toOpenPieceTitle: title) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user