Fix answer search: port PR #315 Supabase-key fallback to /api/answer/stream + memoize classifier verdicts - #326
Merged
Conversation
…oute The UI's answer search calls POST /api/answer/stream, but PR #315's Supabase API-key configuration fallback only landed on /api/answer and /api/search — so document search recovered while answer search kept failing with a generic stream error. Port the non-production demo fallback to the stream route (extracting its inline demo payload builder for reuse) and tag key-configuration errors with a stable `supabase_api_key_configuration` code in the production SSE error payload so operators can diagnose it from the client. Also apply the documented finding #11 interim hardening: memoize the generative query classifier's definitive verdicts per normalized query (10 min TTL) so bare low-confidence queries like "bipolar disorder" stop nondeterministically short-circuiting to "unsupported" between runs. Transient classifier failures are not cached, mirroring the rag_aliases lesson. No retrieval selection/scoring behavior changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0179yo6uA4zAxx2hMKS88MXG
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
Confirmed live: the project's legacy anon/service_role JWTs were disabled on 2026-07-05, and PostgREST rejects them with "Legacy API keys are disabled" — which the existing unregistered/invalid matcher missed, so neither the non-production demo fallback nor the tagged stream error code fired for the exact failure breaking answer search. Match that message (and "Secret API key required") in isSupabaseApiKeyConfigurationError, with unit coverage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0179yo6uA4zAxx2hMKS88MXG
BigSimmo
marked this pull request as ready for review
July 6, 2026 13:45
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
BigSimmo
enabled auto-merge
July 6, 2026 13:45
…ier memo Main landed a parallel fix for the same answer-stream gap (PR #329-era buildDemoStreamAnswer + classifier verdict memoization). Resolution keeps main's implementations wholesale (its memo adds in-flight coalescing and an analyzer-versioned cache key) and drops this branch's duplicates, while preserving this branch's additions main lacked: the stable supabase_api_key_configuration code on production stream errors and the expanded key-error detection ("Legacy API keys are disabled" — confirmed live) with its unit tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0179yo6uA4zAxx2hMKS88MXG
BigSimmo
added a commit
that referenced
this pull request
Aug 17, 2026
This was referenced Aug 18, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /api/answer/stream, but PR Fix public answer search when anonymous limiter is unavailable #315 ("fix public answer search") added the Supabase API-key configuration fallback only to/api/answerand/api/search. So after Fix public answer search when anonymous limiter is unavailable #315, document search recovered from a misconfigured/rotated Supabase key while answer search kept failing with a generic "Answer generation failed" stream error — exactly the reported "answer search is not working".fallbackMode: "non_production_demo") instead of an SSE error. The route's inline demo payload builder was extracted intobuildDemoAnswerPayload()and reused for both the demo branch and the fallback.details.code = "supabase_api_key_configuration"so operators can diagnose a bad deploy key from the browser network tab.docs/process-hardening.md): memoize the generative query classifier's definitive verdicts per normalized query (10 min TTL, 500-entry cap) insrc/lib/rag.ts, so bare low-confidence queries ("bipolar disorder") stop nondeterministically flipping between answered andunsupported_short_circuit. Transient failures (timeout/parse error) are NOT cached, mirroring therag_aliaseslesson. The soft-tail short-circuit thresholds are untouched per the 2026-07-03 decision.tests/private-access-routes.test.ts(fallback outside production; tagged error, no fallback in production — the fallback test fails against the unfixed route) and newtests/rag-classifier-memo.test.ts(decline memoized; transient failure retried).Operator note (production): if the deployed site still fails, the live environment's Supabase keys are the remaining suspect — verify
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY(sb_publishable_…) andSUPABASE_SERVICE_ROLE_KEY(sb_secret_…) target projectsjrfecxgysukkwxsowpyand runnpm run check:supabase-project. Answer-search SSE errors with codesupabase_api_key_configurationconfirm this case.Verification
npm run verify:cheap— green (lint 0 errors, typecheck, 1101 vitest tests, runtime + sitemap checks)npm run verify:ui— green (103 Chromium tests, including all 9 answer-flow smoke tests)npm run verify:release— not run (release gate; needs live Supabase/OpenAI keys unavailable in this environment)npm run format:checknpm run eval:retrieval:quality— not triggered: no retrieval selection/scoring behavior changed (classifier memoization only makes the existing verdict deterministic per query; thresholds and ranking untouched). Needs live keys, cannot run in this environment — flagging per the template rule.npm run eval:rag/eval:quality --rag-only— not triggered: synthesis prompt and answer post-processing unchangednpm run check:production-readiness— only the expected missing-secret failures of this demo-mode environment (no new findings)npm run check:deployment-readiness— not applicable: no deployment/startup behavior changedAlso verified end-to-end in demo mode:
POST /api/answer/streamreturns progress + final demo answer with citations, and the new fallback test fails against the pre-fix route (red) and passes with the fix (green).Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy) — no env/project changesdemoMode: true+fallbackMode: "non_production_demo", and production never serves themNotes
npm run ensurecannot work in IPv6-less containers (scripts/dev-free-port.mjsrequires binding::1/::, so it exhausts all ports). Worked around locally by launching Next directly on the stable managed port; possibly worth a follow-up to make the IPv6 probe conditional.🤖 Generated with Claude Code
https://claude.ai/code/session_0179yo6uA4zAxx2hMKS88MXG
Generated by Claude Code