feat(mentor): blind read A/B judgment (#122)
CI / ci (push) Canceled after 0s

A purposeful writer action on the open post — the "Blind Read" button
beside Run Pass — triggers a whole-document advisory judgment: the
current document against the Pass-start snapshot (the newest
passes/pass-N.md on disk), decided by a FRESH session of the same
museion profile over the existing one-shot ACP rail. Both versions
travel inline in one prompt under neutral A/B position labels with
randomized order — the judge never learns which is the rewrite — and
the A/B-to-origin reveal appends only after the verdict, so the mapping
cannot leak; cancelled, refused, and spawn-failed turns reveal nothing.

Advisory-only per decision #120: no Pass State advance, no cards, no
Learnings, the roster never grows — the verdict is display-only and
dies with the transient transcript. The writer stays judge of record;
demonstrator picks and Fix Card status are untouched. Honest refusals
for the degenerate states: no snapshot yet, an unchanged document, or
a busy rail (passes and reads refuse each other; the pass bar's one
Cancel ends either).

The pass engine's spawn/session/teardown block became one shared
runOneShot rail (failure rows speak the run's own name), the pass-bar
button gates on a derived openPieceHasSnapshot flag, the fake ACP
gained a prompt-log observable, and the GLOSSARY "Blind Read" term
landed with the issue.

Finish-audit (three reviewers): a refusal still ends .ended, so the
reveal now gates on the stopReason (flip-verified pin), plus the
Cancel-rail and pass/blind-read exclusivity pins. Suite 500; swiftformat
clean; swiftlint adds no violations over the HEAD baseline.

Closes #122
This commit is contained in:
AlexKucera committed 2026-10-30 17:31:00 +01:00
1 parent 4724e00b73
commit 97e86cf62d
15 files changed
+627 -32

No files matched your search

+52 -10
View File
@@ -845,11 +845,56 @@ extension MentorSessionModel {
/// running untouched.
@discardableResult
func runPass(kind: PassKind, stub: String, pieceTitle: String) async -> TurnOutcome {
// #137 audit: no force-unwrap — the map is total over today's two
// kinds, but a future PassKind case must refuse, not trap.
guard let surface = ProfileSurface(passKind: kind) else { return .failed }
return await runOneShot(
profile: surface.profileName,
name: kind.rawValue,
prompt: stub,
pieceTitle: pieceTitle,
)
}
/// #122: run one Blind Read — a whole-document A/B judgment by a FRESH
/// session of the SAME museion profile (the chat surface: context-free
/// means no editing history, not a different judge — decision #120; the
/// Knife floor + no-flattery personas ride the profile). The verdict and
/// the app-side reveal stream into the shared transient transcript;
/// the reveal lands only on a completed turn. Never rostered, never
/// saved — advisory-only, records nothing.
@discardableResult
func runBlindRead(prompt: String, pieceTitle: String, reveal: String) async -> TurnOutcome {
let outcome = await runOneShot(
profile: ProfileSurface.chat.profileName,
name: "Blind Read",
prompt: prompt,
pieceTitle: pieceTitle,
)
// The mapping the writer reads — appended AFTER the turn so it can
// never leak to the judge. Cancelled/refused turns reveal nothing
// (a refusal still ends .ended — gate on the stopReason, runPass's
// advance posture; a 2×-document prompt makes context-length
// refusals a realistic path).
if case let .ended(stopReason) = outcome, stopReason != "refusal" {
appendRow(.text(reveal), to: Self.passTranscriptKey)
}
return outcome
}
/// The shared ONE-SHOT engine rail (#137 passes, #122 Blind Read): a
/// fresh engine on `profile`, a transient unrostered transcript, one
/// turn, teardown at its end. Same lifecycles for both riders — the
/// cancel rail (stopStreaming) and the read-only composer guard key on
/// the transient entry and need no per-rider branches. `name` ("Pass 1"
/// / "Blind Read") composes the entry label — callers can't pass a
/// title-inconsistent one.
private func runOneShot(profile: String, name: String, prompt: String, pieceTitle: String) async -> TurnOutcome {
guard phase.isReady, !isStreaming, passClient == nil, let binaryPath else { return .failed }
let label = "\(kind.rawValue) · \(pieceTitle)"
let label = "\(name) · \(pieceTitle)"
// The transient surface: a fresh transcript under the pass key and a
// pass entry that lives only for this run — never rostered, never
// saved (#129: passes are one-shot, the chat engine owns sessions).
// saved (#129: one-shot runs, the chat engine owns sessions).
transcripts[Self.passTranscriptKey] = SessionTranscript()
activeEntry = SessionEntry(
sessionId: Self.passTranscriptKey, name: label, pieceTitle: pieceTitle, createdAt: Date(),
@@ -860,10 +905,7 @@ extension MentorSessionModel {
teardownPassEngine()
firePendingRestartIfRequested()
}
// #137 audit: no force-unwrap — the map is total over today's two
// kinds, but a future PassKind case must refuse, not trap.
guard let surface = ProfileSurface(passKind: kind) else { return .failed }
let pass = ACPEngineClient(binaryPath: binaryPath, profile: surface.profileName)
let pass = ACPEngineClient(binaryPath: binaryPath, profile: profile)
passClient = pass
passClientRef = pass
// KNOWN EDGE (#137, accepted v1): a CHAT-engine crash mid-pass flips
@@ -895,21 +937,21 @@ extension MentorSessionModel {
"mcpServers": .array([]),
]))
guard let sid = result?.objectValue?["sessionId"]?.stringValue, !sid.isEmpty else {
appendRow(.text("Pass failed — the engine refused a session."), to: Self.passTranscriptKey)
appendRow(.text("\(label) failed — the engine refused a session."), to: Self.passTranscriptKey)
return .failed
}
passWireId = sid
} catch {
appendRow(.text("Pass failed — \(error.localizedDescription)"), to: Self.passTranscriptKey)
appendRow(.text("\(label) failed — \(error.localizedDescription)"), to: Self.passTranscriptKey)
return .failed
}
// Cancel clicked while the engine was spawning: stop before the
// prompt — the run ends cancelled, nothing streams.
if passCancelRequested {
appendRow(.text("\(kind.rawValue) cancelled."), to: Self.passTranscriptKey)
appendRow(.text("\(label) cancelled."), to: Self.passTranscriptKey)
return .cancelled
}
return await turnCore(client: pass, wireSid: passWireId ?? "", key: Self.passTranscriptKey, prompt: stub, label: label)
return await turnCore(client: pass, wireSid: passWireId ?? "", key: Self.passTranscriptKey, prompt: prompt, label: label)
}
/// Kill the pass engine and clear its rail — at the verdict (the defer