fix(session): drain a deferred nil scope as an explicit clear
pendingScopePieceTitle: String? conflated 'no pending request' with a pending request whose target is nil (the writer left the piece — New Post, unsaved draft, external guest, nothing open). Both deferral branches stored the target and the drain guarded on the optional, so a deferred nil target was silently dropped: at turn end (sendPrompt, runOneShot) or replay completion (resumeSession) the old piece's activeEntry survived under a nothing-open context, contrary to the scope contract (#176 class). Pending-ness now rides PendingScope (none | scope(String?)) — a nil target drains through scopeHostedSession like any titled target and clears activeEntry. Titled deferrals and the immediate path are unchanged. Verified: SessionScopeTests 4/4 green (both RED pins now green in 45 ms — the clear lands at the drain, not a deadline); full unit bundle 653/653 green; swiftformat 0 files; swiftlint exit 0 (two pre-existing warnings in MentorSessionModel.swift, unchanged kind).
This commit is contained in:
1 parent
1b56b0d779
commit
704e7a83fd
1 file changed
+16
-7
@@ -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