Compare commits

...
3 Commits
Author SHA1 Message Date
AlexKucera 3193714a61 test(session): finish-audit closeout for #184
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
Three-reviewer fanout over PR #184's deferred nil-scope fix:

- pin the titled drain's APPLY half (unpinned suite-wide) over a new
  hangOnPromptLoad rig mode (prompt parks, load answers);
  flip-verified against a nil-only drain guard
- cut the dead Equatable on PendingScope (converged finding)
- name the same-turn pendingRestart ceiling on the drain: respawn's
  .starting window drops the consumed scope; consume-at-apply is the
  upgrade path (follow-up ticket)
- changelog + devlog for the PR; AGENTS.md rails refreshed

Suite 654 executed / 0 failed; swiftformat clean; swiftlint
unchanged (both warnings pre-exist on main).
2026-11-10 16:23:08 +01:00
AlexKucera 836da5833d fix(session): drain a deferred nil scope as an explicit clear
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
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).
2026-11-10 00:34:30 +01:00
AlexKucera 8531d798bc test(session): pin deferred nil scope lost at stream and replay drain
CI / ci (push) Canceled after 0s
Leaving the piece mid-stream (New Post over a streaming reply) or
mid-replay defers a nil scope request like any switch, but the drain
guards on the optional title — an explicit nil target (clear) is
indistinguishable from no pending request, so activeEntry survives on
the old piece under a nothing-open context.

Two RED pins over the scripted rig: hangOnPrompt (stream parks, cancel
ends it, drain at sendPrompt turn end) and loadReplayHold (replay parks,
releaseHeldLoad completes it, drain at resume). Both fail on this base:
executed 4 / passed 2 / failed 2 (the two new pins).
2026-11-10 00:09:14 +01:00
8 changed files with 245 additions and 17 deletions

No files matched your search

+5 -6
View File
@@ -205,15 +205,14 @@ Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Fu
<!-- write-log: window-start -->
| Date | Log |
|------|-----|
| 2026-11-10 | [20261110-pr184-deferred-empty-piece-scope-lost-audit_log.md](docs/devlog/20261110-pr184-deferred-empty-piece-scope-lost-audit_log.md) |
| 2026-11-10 | [20261110-issue182-profilelayout-config-set-rail_log.md](docs/devlog/20261110-issue182-profilelayout-config-set-rail_log.md) |
| 2026-11-10 | [20261110-issue181-provider-descriptor-pass-readiness_log.md](docs/devlog/20261110-issue181-provider-descriptor-pass-readiness_log.md) |
| 2026-11-10 | [20261110-issue180-postfrontmatter-codec-one-readwrite-engine_log.md](docs/devlog/20261110-issue180-postfrontmatter-codec-one-readwrite-engine_log.md) |
| 2026-11-09 | [20261109-issue179-postsmodel-write-rail_log.md](docs/devlog/20261109-issue179-postsmodel-write-rail_log.md) |
| 2026-11-09 | [20261109-issue178-extract-engine-host-transport-seam_log.md](docs/devlog/20261109-issue178-extract-engine-host-transport-seam_log.md) |
| 2026-11-09 | [20261109-issue177-type-transcript-rail-shared-tool-payload-decoder_log.md](docs/devlog/20261109-issue177-type-transcript-rail-shared-tool-payload-decoder_log.md) |
| 2026-11-09 | [20261109-issue183-shrink-agentsmd_log.md](docs/devlog/20261109-issue183-shrink-agentsmd_log.md) |
| 2026-11-05 | [20261105-issue175-nous-portal-provider_log.md](docs/devlog/20261105-issue175-nous-portal-provider_log.md) |
| 2026-11-05 | [20261105-issue171-default-home-icloud-pin-once-legacy-guard_log.md](docs/devlog/20261105-issue171-default-home-icloud-pin-once-legacy-guard_log.md) |
| 2026-11-04 | [20261104-issue158-wayfinder-map-cold-turkey-closed_log.md](docs/devlog/20261104-issue158-wayfinder-map-cold-turkey-closed_log.md) |
| 2026-11-04 | [20261104-issue166-preset-chips-cold-turkey-arm-bar_log.md](docs/devlog/20261104-issue166-preset-chips-cold-turkey-arm-bar_log.md) |
| 2026-11-04 | [20261104-issue165-s5-1-tie-in-cold-turkey-block-first-draft-eligibility_log.md](docs/devlog/20261104-issue165-s5-1-tie-in-cold-turkey-block-first-draft-eligibility_log.md) |
| 2026-11-04 | [20261104-issue163-cold-turkey-calibration-gate-calm_log.md](docs/devlog/20261104-issue163-cold-turkey-calibration-gate-calm_log.md) |
| 2026-11-04 | [20261104-issue162-cold-turkey-writing-lock-integration_log.md](docs/devlog/20261104-issue162-cold-turkey-writing-lock-integration_log.md) |
| 2026-11-04 | [20261104-issue161-cold-turkey-goal-engine_log.md](docs/devlog/20261104-issue161-cold-turkey-goal-engine_log.md) |
<!-- write-log: window-end -->
+4
View File
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format
## [Unreleased]
### Fixed
- **session:** a deferred nil scope drains as an explicit clear (PR #184, finding class #176) — `pendingScopePieceTitle: String?` let "a scope request is pending" and "which piece it targets" ride the same optionality, so a nil-target request (the writer leaves the piece mid-stream or mid-replay: New Post, unsaved draft, external guest, nothing open) deferred correctly but at drain time read as "no pending request" and returned without touching `activeEntry` — the old piece's conversation stayed live under a nothing-open context, at all four drain sites. Pending-ness now rides `PendingScope` (`.none` | `.scope(String?)`): a nil target is an explicit clear everywhere it drains. Finish-audit fanout (3 reviewers): dead `Equatable` cut, the same-turn `pendingRestart` ceiling documented at the drain (the scope is lost in respawn's `.starting` window — consume-at-apply is the upgrade path), and the titled-apply half pinned for the first time over a new `hangOnPromptLoad` rig mode (prompt parks, load answers; flip-verified). Suite 654 (PR #184)
### Changed
- **home:** Fresh installs default to iCloud (#171, resolution of #170/map #167 — plain build slice for #145) — with no stored Home override, launch resolves once and PINS the winner so the Home never silently moves: a legacy `~/Documents/Museion` directory wins (existing Homes migrate manually, never silently; a stray plain file is not a Home and falls through), else `<CloudDocs>/Museion` when iCloud Drive is present (dynamically resolved unprefixed `Library/Mobile Documents/com~apple~CloudDocs` path, plain FileManager probing — no ubiquity entitlements per ADR-0009), else the silent Documents fallback. No dialog, no rail pill — Settings just shows the resolved path. Repoint-only stands (ADR-0004), zero mover code. The probe/defaults seam is injectable and default constructions under hosted tests neither probe nor pin — the runner app's real iCloud state and defaults are never touched. +9 tests incl. the flip-verified CloudDocs spelling pin and the non-destructive hosted no-write guard. Suite 628 (issue #171)
+20 -7
View File
@@ -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 {
case none
case scope(String?)
}
private var pendingScope: PendingScope = .none
/// #137: per-pass readiness (refreshPassReadiness, same-file #137
/// extension) + the injectable read seam (tests). Stored in the class
/// body — extensions carry no stored state.
@@ -585,7 +592,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
@@ -593,10 +600,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 {
@@ -1103,9 +1110,15 @@ 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. Ceiling: a
/// same-turn pendingRestart drains first and respawn's `.starting`
/// window makes the scope Task no-op AFTER consumption — the scope
/// is lost (pre-existing rail shape, titled and nil alike;
/// ponytail: consume-at-apply is the upgrade path).
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) }
}
+1 -1
View File
@@ -22,7 +22,7 @@ Conventions every suite follows. Per-suite pin inventories are NOT kept here —
- One runnable check per non-trivial fact: the smallest test that fails if the logic breaks. No fixtures or per-function suites unless asked.
- Never touch the real machine: throwaway Homes in temp dirs (`makeHome`, `storeHome`, `makeModelHome`, `makeSessionHome`, `importHome`); every `ProfileProvisioner.perform` call injects `masterRoot` (the default writes the REAL Application Support); keychain tests inject their OWN account slot (a live production token is never read, replaced, or deleted); roster/defaults under hosted tests redirect to temp or assert `.standard` byte-unchanged; `psScan` is stubbed (a dev machine may run the real engine).
- Shared helpers are `internal` in the founding file. When a suite crosses a file-length or type-body ceiling, split the new pins into their own file and keep the helpers where they are (PostStorePassTests, MicropubModelTests, MCPToolsPromoteTests, SettingsModelWritePathTests precedents).
- Engine tests run IN-PROCESS at the `EngineTransport` seam (#178): `ScriptedEngine.swift` holds the scripted adapter (mode strings mirroring the retired zsh fake: full/crashAfterHandshake/hangOnPrompt/cancelOnPrompt/refuseOnPrompt/noStopReason/strayResearchOnPrompt/loadReplay*/strictMcp), the shared payloads (`ScriptedPayloads`), and the rig roots — build rigs there, never duplicate. Spawn observables: the rig's spawned-profiles record (which engine ran), transport identity (`mentor.host.chat`/`oneShot`) where pid pins used to live, `isClosed` for reaped. Child processes appear in EXACTLY ONE suite — `EngineSmokeTests`, one real-process wire smoke per LLM Surface (chat/pass1/pass2, ADR-0014) over the zsh fake (`makeFakeACP`/`acpTempDir`, defined in ACPClientTests.swift, kept as the wire fixture). The fake-`hermes` CLI harness (ProfileProvisioner/Backup suites) still speaks real `Process` with base64 payloads, `<name>-spawn-log`, `<name>-prompt-log`, and `defer` teardown at rig creation.
- Engine tests run IN-PROCESS at the `EngineTransport` seam (#178): `ScriptedEngine.swift` holds the scripted adapter (mode strings mirroring the retired zsh fake: full/crashAfterHandshake/hangOnPrompt/hangOnPromptLoad/cancelOnPrompt/refuseOnPrompt/noStopReason/strayResearchOnPrompt/loadReplay*/strictMcp), the shared payloads (`ScriptedPayloads`), and the rig roots — build rigs there, never duplicate. Spawn observables: the rig's spawned-profiles record (which engine ran), transport identity (`mentor.host.chat`/`oneShot`) where pid pins used to live, `isClosed` for reaped. Child processes appear in EXACTLY ONE suite — `EngineSmokeTests`, one real-process wire smoke per LLM Surface (chat/pass1/pass2, ADR-0014) over the zsh fake (`makeFakeACP`/`acpTempDir`, defined in ACPClientTests.swift, kept as the wire fixture). The fake-`hermes` CLI harness (ProfileProvisioner/Backup suites) still speaks real `Process` with base64 payloads, `<name>-spawn-log`, `<name>-prompt-log`, and `defer` teardown at rig creation.
- Waiting: bounded poll loops, each arming its OWN deadline; poll for the watcher rescan after disk writes. Lock/goal machine tests pass `spawnsTicker: false` — the real 1 s ticker could complete a met goal before an injected tick (the #30/#147 flake family).
- Suite-name filters (`-only-testing:MuseionTests/<Suite>`) do not run free functions — pin things as suite members.
+3 -3
View File
@@ -202,7 +202,7 @@ final class ScriptedEngine: EngineTransport, @unchecked Sendable {
self.onStderrLine?("cancel received")
// #124: the cancel-acknowledging hold — the real engine answers
// its hanging prompt the moment session/cancel arrives.
guard self.mode == "hangOnPrompt", let id = self.heldPromptID,
guard self.mode.hasPrefix("hangOnPrompt"), let id = self.heldPromptID,
let continuation = self.parked.removeValue(forKey: id) else { return }
self.heldPromptID = nil
continuation.resume(returning: .object(["stopReason": .string("cancelled")]))
@@ -332,7 +332,7 @@ extension ScriptedEngine {
return
}
toolCall(sid, title: "submit_fix_cards", rawInput: ScriptedPayloads.fixCard)
if mode == "hangOnPrompt" {
if mode.hasPrefix("hangOnPrompt") {
park(id: id, continuation: continuation)
heldPromptID = id
return
@@ -345,7 +345,7 @@ extension ScriptedEngine {
params: JSONValue?,
continuation: CheckedContinuation<JSONValue?, any Error>,
) {
guard mode.hasPrefix("loadReplay") else {
guard mode.hasPrefix("loadReplay") || mode == "hangOnPromptLoad" else {
park(id: id, continuation: continuation) // the zsh never answers
return
}
+155
View File
@@ -7,6 +7,9 @@
// newest-first) pinned here: match, no-match, and title-with-no-roster.
// #178: the defer pin runs IN-PROCESS over a ScriptedEngines rig at the
// EngineTransport seam — no child process.
// deferred-empty-piece-scope-lost: the DEFERRED nil-target pins — leaving
// the piece mid-stream or mid-replay must CLEAR the hosting at drain
// time (nil is an explicit clear target, not "no pending request").
//
import Foundation
@@ -91,4 +94,156 @@ struct SessionScopeTests {
// swapped behind the replay.
#expect(model.activeEntry?.sessionId == activeBefore)
}
/// deferred-empty-piece-scope-lost (a): a nil scope request (the writer
/// left the piece — New Post, unsaved draft, external guest, nothing
/// open) arriving while a turn STREAMS defers like any switch, and the
/// drain at turn end must CLEAR the hosting — the old piece's
/// conversation may not survive under a nothing-open context. Pinned
/// over the scripted rig's `hangOnPrompt` mode parking the turn;
/// `stopStreaming` ends it (the sendPrompt drain fires).
@MainActor
@Test func `deferred nil scope during a stream clears hosting at turn end`() async throws {
let rosterDir = acpTempDir("scope-nil-stream")
let engines = ScriptedEngines(mode: "hangOnPrompt")
let model = engines.makeMentor(rosterDirectory: rosterDir)
defer { model.shutdown() }
await model.openSession() // empty roster — creates the default session, completes
guard case .ready = model.phase else {
Issue.record("expected ready, got \(model.phase)")
return
}
guard await model.newSession(name: "On A", pieceTitle: "Piece A") != nil else {
Issue.record("session creation refused")
return
}
// The turn parks mid-stream (hangOnPrompt) — isStreaming holds.
_ = Task { await model.sendPrompt("hold this") }
var streaming = false
for _ in 0 ..< 250 where !streaming {
streaming = model.isStreaming
if !streaming {
try await Task.sleep(nanoseconds: 20_000_000)
}
}
#expect(streaming)
// The writer leaves the piece mid-stream — the clear defers to turn
// end; the in-flight transcript stays up.
await model.scopeHostedSession(toOpenPieceTitle: nil)
#expect(model.activeEntry?.pieceTitle == "Piece A")
// Cancel ends the turn — the deferred clear must land now.
model.stopStreaming()
var cleared = false
for _ in 0 ..< 250 where !cleared {
cleared = !model.isStreaming && model.activeEntry == nil
if !cleared {
try await Task.sleep(nanoseconds: 20_000_000)
}
}
#expect(cleared)
}
/// The titled twin of (a), pinning the drain's APPLY half — no test
/// anywhere drove a deferred NON-nil switch to its applied state (the
/// replay-deferral pin never releases its hold; the nil pins activate
/// nothing). Same rig shape over the `hangOnPromptLoad` mode (prompt
/// parks, load answers): stopStreaming ends the turn, the drain must
/// activate the target piece's session.
@MainActor
@Test func `deferred titled scope during a stream applies at turn end`() async throws {
let rosterDir = acpTempDir("scope-titled-stream")
let engines = ScriptedEngines(mode: "hangOnPromptLoad")
let model = engines.makeMentor(rosterDirectory: rosterDir)
defer { model.shutdown() }
await model.openSession() // empty roster — creates the default session, completes
guard case .ready = model.phase else {
Issue.record("expected ready, got \(model.phase)")
return
}
// B first, then A — A is the active surface (newest), B the target.
guard await model.newSession(name: "On B", pieceTitle: "Piece B") != nil,
await model.newSession(name: "On A", pieceTitle: "Piece A") != nil
else {
Issue.record("session creation refused")
return
}
#expect(model.activeEntry?.pieceTitle == "Piece A")
// The turn parks mid-stream (hangOnPrompt) — isStreaming holds.
_ = Task { await model.sendPrompt("hold this") }
var streaming = false
for _ in 0 ..< 250 where !streaming {
streaming = model.isStreaming
if !streaming {
try await Task.sleep(nanoseconds: 20_000_000)
}
}
#expect(streaming)
// The writer switches to B mid-stream — the switch defers to
// turn end; A stays the pane's surface.
await model.scopeHostedSession(toOpenPieceTitle: "Piece B")
#expect(model.activeEntry?.pieceTitle == "Piece A")
// Cancel ends the turn — the deferred switch must apply now.
model.stopStreaming()
var applied = false
for _ in 0 ..< 250 where !applied {
applied = !model.isStreaming && model.activeEntry?.pieceTitle == "Piece B"
if !applied {
try await Task.sleep(nanoseconds: 20_000_000)
}
}
#expect(applied)
}
/// deferred-empty-piece-scope-lost (b): the same nil-scope loss when the
/// request arrives while a session/load REPLAYS — the replay's
/// completion drains the pending scope; the explicit nil target must
/// clear the hosting the replay just activated, or the old piece's
/// conversation survives under a nothing-open context. Pinned over the
/// scripted rig's `loadReplayHold` mode parking the replay;
/// `releaseHeldLoad()` completes it (the resume drain fires).
@MainActor
@Test func `deferred nil scope behind a replay clears hosting at replay end`() async throws {
let rosterDir = acpTempDir("scope-nil-replay")
let engines = ScriptedEngines(mode: "loadReplayHold")
let model = engines.makeMentor(rosterDirectory: rosterDir)
defer { model.shutdown() }
await model.openSession() // empty roster — creates the default session, completes
guard case .ready = model.phase else {
Issue.record("expected ready, got \(model.phase)")
return
}
// Two rostered pieces through the real flow; B's session is active.
guard await model.newSession(name: "On A", pieceTitle: "Piece A") != nil,
await model.newSession(name: "On B", pieceTitle: "Piece B") != nil
else {
Issue.record("session creation refused")
return
}
let entryA = try #require(model.roster.first { $0.pieceTitle == "Piece A" })
// Park A's replay behind the hold — the load sits in flight, the
// slot stays taken, and B remains the pane's surface.
_ = Task { await model.resumeSession(entryA) }
var held = false
for _ in 0 ..< 250 where !held {
held = model.stderrTail.contains { $0.contains("hold-load") }
if !held {
try await Task.sleep(nanoseconds: 20_000_000)
}
}
#expect(held)
// The writer leaves the piece while the replay streams into A's
// store — the clear defers behind the replay.
await model.scopeHostedSession(toOpenPieceTitle: nil)
// Release: the replay completes and activates A, then the deferred
// nil scope must clear the hosting.
engines.releaseHeldLoad()
var cleared = false
for _ in 0 ..< 250 where !cleared {
cleared = model.activeEntry == nil
if !cleared {
try await Task.sleep(nanoseconds: 20_000_000)
}
}
#expect(cleared)
}
}
@@ -0,0 +1,56 @@
# PR #184 finish-audit — deferred nil scope drains as an explicit clear
> **Date:** 2026-11-10
> **Type:** issue
> **Reference:** PR #184 `fix/deferred-empty-piece-scope-lost` (finding class #176)
## Goal
Run the finish-audit reviewer fanout (ponytail / security / general) over PR #184 — `fix(session): drain a deferred nil scope as an explicit clear`, 2 commits ahead of `origin/main` touching `Museion/MentorSessionModel.swift` and `MuseionTests/SessionScopeTests.swift` — then fix what the reviewers flagged.
## What Was Done
- Resolved the audit scope mechanically: branch `fix/deferred-empty-piece-scope-lost`, commits 836da58 (fix) + 8531d79 (pin), clean tree, no untracked files. Baseline gates before dispatch: `build-for-testing` green, full unit suite 653/653 (xcresult executed count), swiftformat clean, swiftlint warnings at `MentorSessionModel.swift:158/:192` verified pre-existing on main.
- Dispatched the three reviewers in one parallel batch with resolved facts + exclusion list (enum shape settled, pendingRestart sibling pattern, poll-loop conventions, pre-existing lint warnings).
- Applied audit fixes on the PR branch (working tree, uncommitted):
- Cut the dead `: Equatable` conformance from `PendingScope` (converged finding — ponytail + general independently; only `guard case let` reads, no `==` anywhere).
- Ceiling comment on `firePendingScopeIfRequested` naming the restart race and its consume-at-apply upgrade path (see Decisions).
- New pin `deferred titled scope during a stream applies at turn end` — the drain's APPLY half for a NON-nil target was unpinned suite-wide (the replay-deferral pin never releases its hold; the nil pins activate nothing).
- New rig mode `hangOnPromptLoad` in `ScriptedEngine` (prompt parks + `session/load` answers) — required by the pin: titled apply rides `resumeSession`, and no existing mode parked a prompt while answering a load.
- Flip-verified the new pin: weakened the drain guard to `title == nil` → exactly the titled pin failed (5.4 s poll timeout), both nil pins passed; restored, re-ran green.
- Final gate after all fixes: swiftformat clean, lint exit 0 (same two pre-existing warnings), full unit suite **654 executed / 0 failed**.
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Restart race DEFERRED with a ceiling comment, not fixed in-audit | General reviewer's MEDIUM verified real: a same-turn `pendingRestart` + `pendingScope` makes both turn-end defers spawn sibling Tasks; `respawn()` sets `phase = .starting` before its `await startChat()` suspension, the scope Task then no-ops on the `isReady` guard with the pending already consumed → scope lost, respawn's rail re-activates the old entry. But the reviewer's sketched remediation (re-fire at respawn completion) is provably a no-op — `pendingScope = .none` runs before the drop. A correct fix needs consume-at-apply semantics, which changes the documented "not-ready direct call is a no-op" contract (a not-ready call would arm a stale pending that fires at the next drain). Design change with its own hazard → follow-up ticket, not an audit patch. |
| Rig extension (`hangOnPromptLoad`) over test contortion | The alternative was a two-hold release dance in `loadReplayHold` (release, wait, release again) — brittle and unreadable. One mode string, three one-line branch widenings, existing modes byte-identical (`hasPrefix` keeps `hangOnPrompt` semantics unchanged). |
| Security INFO-1/INFO-2: no action | Both display-only, both pre-existing shapes (owner ruling 2026-11-07 semantics; replay-slot design #137/#178). The PR strictly improves both (the nil clear was lost permanently pre-fix). |
| Reviewer call-site count corrected | 4 drain call sites (:538, :573, :827, :978) + the definition — the dispatch's "five" phrasing miscounted; the general reviewer's grep is right. |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| New titled pin failed its first green run ("Expectation failed: applied", 5.4 s) | The rig's `load` parks `session/load` forever in every mode except `loadReplay*` ("the zsh never answers") — the drain's `resumeSession(B)` never returned within the poll. Diagnosed by pulling `failureText` from the xcresult, not re-running. | Added the `hangOnPromptLoad` rig mode. |
| Reviewer's proposed remediation didn't survive scrutiny | The re-fire sketch ignores that `pendingScope = .none` (:1117) precedes the Task creation (:1118) — consumption happens before the not-ready drop. | Timeline analysis in the parent; deferred the real fix rather than landing a plausible-looking no-op. |
## Files Changed
| File | Change Summary |
|------|---------------|
| `Museion/MentorSessionModel.swift` | Cut dead `Equatable` on `PendingScope`; ceiling comment on `firePendingScopeIfRequested` (restart race, consume-at-apply upgrade path) |
| `MuseionTests/ScriptedEngine.swift` | New `hangOnPromptLoad` mode — prompt parks (cancel releases), load answers with the replay shape |
| `MuseionTests/SessionScopeTests.swift` | New pin: deferred titled scope applies at turn end |
| `MuseionTests/AGENTS.md` | Mode-string list gains `hangOnPromptLoad` |
## Open Items & Next Steps
- [ ] Follow-up ticket: same-turn `pendingRestart` + `pendingScope` loses the scope at the restart window (titled and nil alike; consume-at-apply is the upgrade path). Ceiling comment already in code.
- [ ] Titled-defer APPLY behind the REPLAY drain (:538) is still unpinned (stream drain :827 now is).
- [ ] Working-tree fixes are uncommitted — PR #184 needs the audit diff committed and pushed (owner authorization required).
---
*Log written by write-log skill*
+1
View File
@@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa
<!-- write-log: full-index -->
| Date | Type | File | Summary |
|------|------|------|---------|
| 2026-11-10 | issue | [20261110-pr184-deferred-empty-piece-scope-lost-audit_log.md](20261110-pr184-deferred-empty-piece-scope-lost-audit_log.md) | PR #184 finish-audit: dead Equatable cut, restart-race ceiling named, titled-apply pin + hangOnPromptLoad rig mode |
| 2026-11-09 | issue | [20261109-issue178-extract-engine-host-transport-seam_log.md](20261109-issue178-extract-engine-host-transport-seam_log.md) | Engine lifecycle → EngineHost behind the EngineTransport seam; scripted in-process tests, one real smoke per surface |
| 2026-11-09 | issue | [20261109-issue177-type-transcript-rail-shared-tool-payload-decoder_log.md](20261109-issue177-type-transcript-rail-shared-tool-payload-decoder_log.md) | SessionRow text rows typed (speaker+notice), kick-off sniffed at append seam, one ToolPayloads decoder both rails read |
| 2026-11-09 | issue | [20261109-issue183-shrink-agentsmd_log.md](20261109-issue183-shrink-agentsmd_log.md) | AGENTS.md rails shrunk 206 KB → 36 KB — contracts and rulings kept, per-issue diaries cut; serif payload untouched (#183) |