Spaces:
Sleeping
fix(upload): show heuristic-floor card on LLM-fail path + extend poll to 150s (KI-331)
Browse filesUser caught live on Test Policy.pdf 8MB upload (2026-05-27): after Gemini
3/3 retries failed and the 120s poll timed out, the frontend pushed only
a prose "I couldn't pull a full analysis" message and never surfaced the
heuristic-baseline card β even though `record.json` already had
47.8% completeness / grade C / 6 sub-scores from the heuristic pass
that runs BEFORE the LLM ever fires.
Two changes:
1. KI-331 β fail/timeout branch now pushes the card-bearing assistant
message FIRST (same citations as the success path β inline
PolicyScorecardWidget renders with whatever record.json has), then
the soft caveat ("I couldn't pull a full analysis"), then the choice
prompt. setActiveUploadPid still fires so the brain's DIVE-IN block
activates for follow-up questions about the policy.
2. MAX_TRIES bumped 40 β 50 (120s β 150s polling budget). Live audit
showed Gemini retry #3 sometimes lands at ~130s on large/complex
PDFs; 15s extra buffer eliminates the borderline-miss case.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- frontend/src/app/page.tsx +37 -4
|
@@ -1518,7 +1518,11 @@ export default function Page() {
|
|
| 1518 |
// the Send button + voice paths are all gated by extractionInFlight,
|
| 1519 |
// and the chat only progresses once the card data is fully populated.
|
| 1520 |
const POLL_INTERVAL_MS = 3000;
|
| 1521 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1522 |
let landed = false;
|
| 1523 |
let finalCompleteness: number | null = null;
|
| 1524 |
let finalGrade: string | null = null;
|
|
@@ -1577,12 +1581,41 @@ export default function Page() {
|
|
| 1577 |
// race the previous flow exhibited.
|
| 1578 |
pushAssistant(t("upload.chat_choice"));
|
| 1579 |
} else {
|
| 1580 |
-
//
|
| 1581 |
-
//
|
| 1582 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1583 |
pushAssistant(
|
| 1584 |
t("upload.chat_extraction_failed", { name: r.policy_name }),
|
| 1585 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1586 |
pushAssistant(t("upload.chat_choice"));
|
| 1587 |
}
|
| 1588 |
} catch (e: unknown) {
|
|
|
|
| 1518 |
// the Send button + voice paths are all gated by extractionInFlight,
|
| 1519 |
// and the chat only progresses once the card data is fully populated.
|
| 1520 |
const POLL_INTERVAL_MS = 3000;
|
| 1521 |
+
// 2026-05-27 β bumped from 40 (120s) to 50 (150s) after a live
|
| 1522 |
+
// 8MB-PDF audit showed Gemini retry #3 sometimes lands at ~130s,
|
| 1523 |
+
// i.e. just past the prior cutoff. 15s extra buffer eliminates
|
| 1524 |
+
// the borderline-miss case.
|
| 1525 |
+
const MAX_TRIES = 50; // 50 Γ 3s = 150s
|
| 1526 |
let landed = false;
|
| 1527 |
let finalCompleteness: number | null = null;
|
| 1528 |
let finalGrade: string | null = null;
|
|
|
|
| 1581 |
// race the previous flow exhibited.
|
| 1582 |
pushAssistant(t("upload.chat_choice"));
|
| 1583 |
} else {
|
| 1584 |
+
// KI-331 (2026-05-27) β fail/timeout no longer hides the
|
| 1585 |
+
// heuristic-floor card. The heuristic baseline (~47.8% comp,
|
| 1586 |
+
// grade C) was written synchronously inside the upload HTTP
|
| 1587 |
+
// call BEFORE the LLM ever fired β so a /api/policies/{pid}/
|
| 1588 |
+
// scorecard request right now will return a real card with 6
|
| 1589 |
+
// sub-scores. Earlier behaviour pushed only a prose
|
| 1590 |
+
// "couldn't pull a full analysis" message and left the user
|
| 1591 |
+
// staring at no data. Now we push the SAME card-bearing
|
| 1592 |
+
// assistant message + a soft caveat below, so the user can
|
| 1593 |
+
// still see what we extracted and the choice prompt has
|
| 1594 |
+
// visible context.
|
| 1595 |
+
pushAssistant(
|
| 1596 |
+
t("upload.chat_card_ready", { name: r.policy_name }),
|
| 1597 |
+
{
|
| 1598 |
+
citations: [
|
| 1599 |
+
{
|
| 1600 |
+
policy_id: r.policy_id,
|
| 1601 |
+
policy_name: r.policy_name,
|
| 1602 |
+
insurer_slug: finalInsurerSlug || "user-upload",
|
| 1603 |
+
page_start: 1,
|
| 1604 |
+
page_end: r.pages_indexed,
|
| 1605 |
+
source_url: "",
|
| 1606 |
+
score: 1.0,
|
| 1607 |
+
},
|
| 1608 |
+
],
|
| 1609 |
+
},
|
| 1610 |
+
);
|
| 1611 |
+
// Soft caveat β honest about which path we landed on.
|
| 1612 |
pushAssistant(
|
| 1613 |
t("upload.chat_extraction_failed", { name: r.policy_name }),
|
| 1614 |
);
|
| 1615 |
+
// Same dive-in target flag as the success path so the brain's
|
| 1616 |
+
// ACTIVE POLICY DIVE-IN block fires on the next chat turn even
|
| 1617 |
+
// when the LLM extraction missed.
|
| 1618 |
+
setActiveUploadPid(r.policy_id);
|
| 1619 |
pushAssistant(t("upload.chat_choice"));
|
| 1620 |
}
|
| 1621 |
} catch (e: unknown) {
|