Files
museion/docs/devlog/20261110-pr184-deferred-empty-piece-scope-lost-audit_log.md
AlexKucera a3ef007562
CI / ci (pull_request) Canceled after 0s
CI / ci (push) Canceled after 0s
test(session): finish-audit closeout for #184
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:25:58 +01:00

5.6 KiB

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