fix(l1): answer buttons must match the question — yes_label/no_label end-to-end

Live walk defect: the builder generated alternatives questions ("Is Jane's
account a Microsoft account or a local account?") while the UI could only
offer Yes/No. Root cause: SYSTEM_PROMPT mandated a label-less
'<yes/no question>' shape with no way to express the two answers.

- SYSTEM_PROMPT: question nodes must carry yes_label/no_label — the literal
  button texts; alternatives questions must use the alternatives as labels.
- validate_node: labels hard-floor-scanned, must be distinct non-empty strings.
- _ensure_labels: server defaults missing labels to Yes/No.
- advance_ai_build: records answer_label (and both labels) in walked_path,
  derived from the server-held pending_node — never client-supplied.
- _build_context: LLM context shows the chosen label, not a bare yes/no
  (a raw "-> yes" on an alternatives question degrades the next generation).
- normalize_walked_path: captured flywheel trees keep question labels.
- Frontend: buttons render yes_label/no_label; walk transcript and
  L1EscalationsSection render answer_label.

Phase 2A backend set: 137 passed / 0 failed / 8 deselected. tsc, eslint,
vite build clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 15:03:15 -04:00
parent db446e1fd6
commit 9c34d1e82d
7 changed files with 182 additions and 9 deletions

View File

@@ -183,6 +183,24 @@ async def advance_ai_build(
"answer": answer,
"l1_note": note,
}
# answer_label: the button text the tech actually clicked. Derived from
# the server-held pending_node (never client-supplied) so an
# alternatives question ("Microsoft account or local account?") records
# "Microsoft account", not a bare "yes", in the transcript, the LLM
# context, and the captured flywheel tree.
pending = session.pending_node
if (
answer in ("yes", "no")
and isinstance(pending, dict)
and pending.get("id") == node_id
):
label = pending.get(f"{answer}_label")
if label:
entry["answer_label"] = label
if pending.get("yes_label"):
entry["yes_label"] = pending["yes_label"]
if pending.get("no_label"):
entry["no_label"] = pending["no_label"]
# JSONB requires assigning a new list — in-place mutation isn't tracked
session.walked_path = [*session.walked_path, entry]
session.pending_node = None # the served node has now been answered