Skip to content

fix: audit P0 RAG cache, synopsis parity, and safety hardening - #278

Closed
BigSimmo wants to merge 7 commits into
cursor/content-access-review-a385from
cursor/fix-audit-p0-b54f
Closed

fix: audit P0 RAG cache, synopsis parity, and safety hardening#278
BigSimmo wants to merge 7 commits into
cursor/content-access-review-a385from
cursor/fix-audit-p0-b54f

Conversation

@BigSimmo

@BigSimmoBigSimmo commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses the highest-priority audit findings without changing eval-validated retrieval boost compounding.

RAG cache (P0)

  • Fix owner-scoped in-memory cache invalidation for versioned keys (rag-cache-v12|ownerId|...) via ragCacheKeyMatchesOwner
  • Stamp and validate indexingVersion on in-memory search/answer cache entries (parity with shared rag_response_cache)
  • Use scoreValue(result) (hybrid-aware) in deriveConfidence instead of raw similarity

Clinical evidence parity (P0)

  • Centralize evidence haystack construction in clinical-evidence-haystack.ts (synopsis, accessible table markdown, table facts, memory cards)
  • Wire synopsis into dose detectors, answer ranking, and evidence relevance scoring

Safety hardening (P0/P1)

  • Deep-memory rebuild: fail loudly if document_index_units delete fails (no silent swallow)
  • DELETE route: late active-job re-check before document delete (reindex TOCTOU)
  • runDocumentSearchShortcut: stale-response guard using searchRequestSeqRef (M10 parity)
  • Upload: document_upload rate-limit bucket (12/min)
  • Production readiness: require RAG_QUERY_HASH_SECRET in production-like envs
  • Worker: invalidate owner + anonymous shared RAG caches after ingestion job commit

Verification follow-up (this commit)

  • Removed merge conflict markers blocking lint
  • Fixed image signed-url duplicate fetch regression
  • Updated upload/route tests for managed local port guard (409) and anonymous rate-limit fixtures

Verification

  • Targeted audit regression tests (50/50): cache invalidation, synopsis ranking, dose detectors
  • npm run verify:cheap — lint + typecheck pass; 1069/1072 tests pass full suite (3 time out under parallel load, pass in isolation)
  • npm run eval:retrieval:quality — blocked in this environment (missing NEXT_PUBLIC_SUPABASE_URL / SUPABASE_SERVICE_ROLE_KEY); run locally before merge

Clinical Governance Preflight

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow introduced
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys remain server-only
  • Changes are conservative parity fixes (synopsis/markdown in existing detectors), not new ranking compounding

Follow-up (not in this PR)

P2–P3 audit items: CI eval gates, RLS integration tests, monolith splits, lint/format debt, docs cleanup — tracked separately from the July 2026 audit backlog.

Open in WebOpen in Cursor

- Hide footer Evidence/Sources chips on phone hero composers; scope stays in + menu
- Suppress bottom-dock composer flash until hero portal slot is ready
- Increase composer action/send touch targets to 44px on phones
- Update Playwright tests for scope menu, Answer home geometry, and stress fallback
@supabase

supabaseBot commented Jul 5, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@BigSimmo
BigSimmo marked this pull request as ready for review July 5, 2026 17:40
@cursor

cursorBot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@BigSimmo

Copy link
Copy Markdown
OwnerAuthor

Closing as superseded by merged work on \main:

Production is live with these fixes. Any remaining unique commits should be cherry-picked onto a fresh branch from current \main.

@BigSimmoBigSimmo closed this Jul 5, 2026
@BigSimmo
BigSimmo deleted the cursor/fix-audit-p0-b54f branch July 9, 2026 13:01
cursorBot pushed a commit that referenced this pull request Aug 8, 2026
Resolve docs/outstanding-issues.md by keeping main's #278 visual-baseline
row and renumbering this PR's follow-ups to #279#284 (next-id=285).
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
cursorBot pushed a commit that referenced this pull request Aug 8, 2026
…seline, and add a baseline adopt helper (#1743)
* feat(design-system): mask the pinned chrome in the document-viewer baseline, and add a baseline adopt helper
Two changes that make refreshing a golden after a deliberate design change cheap
and readable, which is what the pixel gate needs in order to be read at all.
Mask the viewport-pinned chrome (#278). The document-viewer target clips a ~2900px
region against a 900px viewport, and it contains a `sm:sticky sm:top-0` header and
a `sm:fixed` composer. Playwright stitches an oversized element capture, so both
land partway DOWN the image, overlap whatever content sits behind them at that
offset, and move whenever content above them changes height -- so an unrelated edit
anywhere on the page redrew two bands of the golden and inflated every diff. Masked
rather than clipped away, because both are real chrome that belongs in the frame
and narrowing the selector would drop the rail panels this target exists to watch.
Their own geometry is covered by the phone-chrome contracts in
docs/search-chrome-behaviour.md, not by this pixel gate.
Fail loudly when a mask matches nothing. A mask selector that matches no element
masks nothing, silently -- the golden keeps comparing the region the mask was meant
to exclude while the declaration reads as protection that is not there. Renaming a
class is enough to cause it. Every declared mask must now resolve to at least one
element before the comparison is trusted. That guard is what makes the mask above
safe to rely on rather than merely present.
Add scripts/adopt-visual-baselines.mjs (npm run design-system:baselines:adopt).
Adopting previously meant hand-copying six PNGs and hand-assembling provenance.json
with a SHA-256 and pixel dimensions per candidate, the capture commit, the run id
and the reviewer attestation. Doing that by hand on every design change is the
friction that makes people skip the refresh and leave a red advisory standing.
It resolves candidates from both shapes the artifact can take -- visual-candidates/
when a target was awaiting a baseline, and <id>-actual.png when it compared and
differed. It refuses a missing or non-numeric run id, a short or unknown capture
commit, and a missing --reviewed-by, because that field records a HUMAN review of
the images. It never captures screenshots: baselines are platform-scoped and a
developer-machine shot lands where ubuntu CI never reads it. Dry run by default.
The document-viewer golden is NOT refreshed here -- masking changes its pixels, so
it must be re-shot from a CI run that already contains this mask. That is the
refresh loop the helper exists for, and it needs this to land first.
Verified: tsc 0 errors; lint exit 0; check:design-system-adoption exit 0;
docs:check-inventory current at 232 npm scripts; docs:check-links exit 0;
format:check clean. Helper exercised against two real artifacts -- it resolves all
six candidates from run 31251091603 and correctly refuses run 31254917796, which
was all-green and so contains no candidate images -- and all three input guards
were confirmed to reject. Dry run wrote nothing.
Refs #278, #118
* fix(design-system): support partial visual baseline refresh adoption
When CI changes only some surfaces, passing targets emit no *-actual.png
and unchanged images live under tests/__screenshots__/ in the artifact.
The adopt helper now resolves candidates from diff output, artifact
baselines, or committed goldens, records refresh provenance (including
replacedCandidateIds), and validates capture-head AWAITING_BASELINE
binding before writing. Also fix git cat-file reachability checks and
run mask-selector validation before candidate capture.
* chore(design-system): refresh document-viewer baseline after chrome masks
Adopt the masked document-viewer capture from visual-baseline-31267928439
(tip ac1d0dd) via the partial-refresh helper. Clears the expected advisory
diff introduced when the sticky header and fixed composer were masked.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
* fix(design-system): gate retained baselines on junit and uniquify the mask
Copilot: retaining screenshots from the artifact without visual-junit proof
could bless a stale golden for a target that failed before emitting an actual.
Require a passing junit case for every retained id, refuse all-green refreshes,
and only treat *-actual.png as a fresh diff. Also mask
[data-document-sticky-header] instead of .edge-glass-header so the fail-loud
guard cannot pass against the universal search header after a DocumentViewer rename.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
* chore(design-system): refresh masked document-viewer baseline after main sync
Re-adopt from visual-baseline-31268982766 on the post-#1741 merge tip so the
golden includes the unique data-document-sticky-header mask and the viewer
rework from main.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
BigSimmo pushed a commit that referenced this pull request Aug 20, 2026
…emand
The document-viewer baseline target masked `.document-viewer-composer`
because the composer was always rendered and, being viewport-pinned inside a
~2900px stitched capture, redrew a band of the golden on any unrelated edit
(#278). With search now closed by default the composer is not in the DOM at
all in the state this target captures, and `assertMaskSelectors` fails a mask
that matches nothing — deliberately, so a rename cannot silently stop masking.
`classify-visual-baseline-outcome.mjs` scores that as a non-drift failure, so
the advisory Visual baselines job would have gone hard red on every main push
for a reason unrelated to pixels. The mask is now the sticky header alone;
nothing is lost, since a masked region was never compared, and the closed
composer's resting layout is now inside the golden.
The committed Linux golden drifts with this change (the overview action is
"Search document" and the desktop composer clearance is released while
closed). That is ordinary pixel drift: advisory, and adopted post-land from
the job artifact with `npm run design-system:baselines:adopt`.
Also lands the PR #2199 review-ledger record.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoyoNN7nCUVDLaE84k6e6c
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@BigSimmo