From 8bded90094496b11dccecca306f77bf47bd35c82 Mon Sep 17 00:00:00 2001 From: robbond Date: Sun, 30 Aug 2026 08:28:29 +0100 Subject: [PATCH] fix(confidence-engine): preserve follow-up progression ownership --- components/reasoning-workspace.jsx | 56 +++- docs/current-handoff.md | 66 +++++ tests/open-questions-vs-assumptions.test.jsx | 293 +++++++++++++++++++ vitest.config.js | 2 +- 4 files changed, 408 insertions(+), 9 deletions(-) diff --git a/components/reasoning-workspace.jsx b/components/reasoning-workspace.jsx index fe42985..c227b70 100644 --- a/components/reasoning-workspace.jsx +++ b/components/reasoning-workspace.jsx @@ -149,6 +149,20 @@ function FocusedQuestionBody({ // Without this guard, selecting a follow-up question would erase "Previously answered" + "Your response". const hasCompletedContext = processingStep !== "active" && Boolean(focused?.result); + // ── Source of completed context: latest canonical Contribution when follow-up is active ── + // After setFollowUpQuestion() mutates focused.question/answer, derive from the + // latest completed Contribution so the narrative remains correct. + const hasActiveFollowUp = hasCompletedContext && !hasAnswer + && (focused.result?.possibleFollowUpQuestions || []).some((q) => q === focused?.question); + const latestCompletedContrib = [...(focusedContributions || [])].reverse().find((c) => c?.question && c?.answer); + + const displayedCompletedQuestion = hasActiveFollowUp + ? (latestCompletedContrib?.question ?? focused?.question) + : focused?.question; + const displayedCompletedAnswer = hasActiveFollowUp + ? (latestCompletedContrib?.answer ?? focused?.answer ?? "") + : focused?.answer; + // ── Local correction state (FQB-owned, not propagated upward) ─ const [editingFindingId, setEditingFindingId] = useState(null); const [draft, setDraft] = useState(""); @@ -180,15 +194,15 @@ function FocusedQuestionBody({
{(hasAnswer || hasCompletedContext) && focused?.question?.trim() ? (
- {/* Previously answered question */} + {/* Previously answered question — sourced from contribution when follow-up is active */}

Previously answered

-

{focused.question}

+

{displayedCompletedQuestion}

{/* User's verbatim response — distinct provenance from Engine-derived content */}

Your response

-

{focused.answer}

+

{displayedCompletedAnswer}

) : focused?.question?.trim() ? ( @@ -200,7 +214,7 @@ function FocusedQuestionBody({

{formulateMsg}

) : null} - {focused?.question?.trim() && processingStep !== "active" && focused.status === "formulated" && !hasAnswer && ( + {focused?.question?.trim() && processingStep !== "active" && focused.status === "formulated" && !hasAnswer && !hasActiveFollowUp && (