fix: multi-select Other coexistence + the malformed-assessment probe-done crash

Two live bugs from the modal-realism stress runs:

1. Multi-select ask: picking the custom 'Other…' row cleared every
   already-picked option, and picking any option cleared a typed custom
   answer — single-select displacement logic applied to both modes. The
   dock's selection is now a pure state machine in question-core
   (toggleOption/toggleOther over DockSelection, unit-tested): single
   displaces (unchanged), multi coexists — neither channel clears the
   other; the typed text always survives.

2. ProbeDoneCard crashed on a REJECTED probe_done call: the model
   stringified 'assessment' (the same double-encoding habit as the
   options bug), zod rejected the call, the model retried — but the
   card's input-preview fallback trusted the errored part's unvalidated
   input shape and died on assessment.strands.map. The preview now reads
   input only while the call is pending or streaming (guarded with
   Array.isArray); an output-error part renders a quiet
   malformed-and-retried note instead of the garbage.

Pinned: question-core.test.ts (3 dock-selection machine cases),
render-cards.test.tsx (4 probe-done card cases incl. the exact live
stringified shape, plus the multi-select ask markup pin).

Gates: tsc, lint, build, 315/315.
This commit is contained in:
amosblomqvist
2026-09-12 04:45:58 +03:00
parent 4baf8385be
commit e821c3277d
5 changed files with 215 additions and 46 deletions
+23 -5
View File
@@ -12,13 +12,27 @@ import type { ProbeDoneResult, ProbeDoneInput } from "@/src/core";
* the prober retried on (rendered quiet and small — it is model-facing
* bookkeeping, kept only for transcript honesty).
*
* The input preview is only trustworthy while the call is pending — an
* input-available input cleared schema validation at the boundary, and a
* mid-stream partial is guarded below. An output-error part's input was
* REJECTED by validation and can be any shape (live crash: the model
* stringified `assessment`); never render it.
*
* Deliberately plain v1: the proper assessment viewer design is deferred to
* the UI wave; this card just guarantees the data is never invisible.
*/
export function ProbeDoneCard({ part }: { part: { input?: unknown; output?: unknown } }) {
export function ProbeDoneCard({ part }: { part: { input?: unknown; output?: unknown; state?: unknown } }) {
const input = part.input as ProbeDoneInput | undefined;
const output = part.output as ProbeDoneResult | undefined;
const assessment = output?.ok ? output.assessment : (input?.assessment ?? null);
const state = typeof part.state === "string" ? part.state : "";
const assessment =
output?.ok
? output.assessment
: state === "output-error"
? null // the rejected call — its input is unvalidated garbage
: (input?.assessment ?? null);
const strands = assessment && Array.isArray(assessment.strands) ? assessment.strands : null;
return (
<div data-testid="probe-done-card" className="my-3 rounded-xl border bg-card/60 p-3">
@@ -28,15 +42,19 @@ export function ProbeDoneCard({ part }: { part: { input?: unknown; output?: unkn
</div>
{output && !output.ok ? (
<p className="text-sm text-muted-foreground">The prober retried: {output.error}</p>
) : assessment ? (
) : state === "output-error" ? (
<p className="text-sm text-muted-foreground">
The assessment was malformed — the prober retried with a corrected one.
</p>
) : strands ? (
<div className="space-y-2">
{assessment.strands.map((s, i) => (
{strands.map((s, i) => (
<div key={i} className="rounded-lg bg-background/60 px-3 py-2">
<div className="text-sm font-medium">{s.strand}</div>
<div className="mt-0.5 text-sm text-muted-foreground">{s.assessment}</div>
</div>
))}
{assessment.summary && (
{assessment?.summary && (
<p className="px-1 text-sm text-muted-foreground">{assessment.summary}</p>
)}
</div>