Skip to content

Preserve contextual back navigation and recent answers - #1788

Merged
BigSimmo merged 15 commits into
mainfrom
codex/chat-contextual-back-answer-cache-05ea-1
Aug 10, 2026
Merged

Preserve contextual back navigation and recent answers#1788
BigSimmo merged 15 commits into
mainfrom
codex/chat-contextual-back-answer-cache-05ea-1

Conversation

@BigSimmo

@BigSimmoBigSimmo commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Make page-level back arrows return to the immediately preceding browser-history entry, with an owning-page fallback for direct entry.
  • Restore exact-match completed answer threads from private, tab-scoped session storage for up to 12 hours without another answer-generation request.
  • Add repository contracts and browser coverage for contextual navigation, guest/account isolation, expiry, migration, and answer-to-detail return journeys.

RAG impact: no retrieval behaviour change — this changes client-side history navigation and exact-match answer restoration only.

Verification

  • npm run verify:pr-local
    • Selected plan inspected; aggregate not rerun because its full-unit stage reproduces the unchanged baseline failures below.
  • npm run verify:ui when UI, routing, styling, browser behavior, reduced-motion, or forced-colors behavior changed
    • Ran: 408/410 passed. Two unchanged desktop service-detail scroll-runway cases timed out outside the changed paths.
  • npm run verify:release before release or handoff confidence claims
    • Not run for this draft handoff.
  • npm run eval:retrieval:quality (must stay 36/36) when retrieval, ranking, selection, chunking, or scoring behavior changed
    • Not required: retrieval and ranking behavior are unchanged.
  • npm run eval:rag -- --limit 15 + npm run eval:quality -- --rag-only when answer generation, the synthesis prompt, or answer post-processing changed
    • Not required: answer generation and post-processing are unchanged.
  • npm run check:production-readiness when clinical workflow, privacy, environment, Supabase, source governance, or deployment behavior changed
    • Ran offline/static checks; environment-gated by missing Supabase/OpenAI variables in this isolated worktree. No provider was contacted.
  • npm run check:deployment-readiness when deployment startup, hosting, or rollout behavior changed
    • Not required: deployment behavior is unchanged.

Additional local evidence:

  • Focused navigation/storage suites: 82/82 passed; final hardened subset 26/26 passed.
  • npm run typecheck, npm run lint, npm run format, changed-file formatting, diff checks, maintainability budgets, design-system adoption, and installed-lock parity passed.
  • npm run eval:rag:offline: 574 tests passed; 36 golden cases across 23 suites.
  • Phone contracts: 123/123 passed; UI smoke: 97/97 passed.
  • Targeted answer -> medication -> back/reload, document-origin, and differential-origin browser journeys passed. The answer journey issued one /api/answer/stream request.
  • npm run verify:cheap reached the full-unit baseline and reported 22 failures rooted in five unchanged bundle-budget fixtures plus Windows ln/temporary-cleanup failures.

Risk and rollout

  • Risk: Moderate client-side navigation and restoration surface; exact signatures, owner isolation, expiry, size limits, fallback routing, and storage failure behavior are covered by focused tests.
  • Rollback: Revert commit 5d7c87a1a.
  • Provider or production effects: GitHub branch push and draft PR only, explicitly authorized. No deployment, production mutation, live answer request, or provider-backed RAG evaluation.

Clinical Governance Preflight

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys and private document access remain server-only
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed

Notes

  • Answer snapshots use sessionStorage only. They are not stored in localStorage, synchronized across tabs/devices, cached by the service worker, sent to a backend, or available offline.
  • The branch was created from ef9bb51662dbefbfd6f10778052b7180a3efb53f; current main advanced by one commit before publication, with the original base still an ancestor of main.

Summary by CodeRabbit

  • New Features

    • Back navigation now returns to the previous page when possible, with reliable fallback destinations.
    • Answer threads can be restored within the same browser tab for up to 12 hours when matching the current submission.
    • Added clearer navigation behavior across dashboards, documents, differentials, forms, and detail pages.
  • Bug Fixes

    • Selecting a new formulation template now consistently clears previous draft content.
  • Documentation

    • Clarified answer-thread retention, offline availability, and clearing behavior.
  • Tests

    • Expanded coverage for thread expiry, navigation, URL preservation, and answer-flow reliability.

@coderabbitai

coderabbitaiBot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds versioned, submission-bound answer-thread persistence with expiration and owner resolution. It also adds contextual browser-history navigation with deterministic fallbacks across dashboard, breadcrumb, differential, document, and therapy views.

Changes

Answer-thread persistence

Layer / File(s)Summary
Versioned thread storage contract
src/lib/answer-thread-storage.ts, tests/answer-thread-storage.test.ts
Storage now validates version-2 snapshots, submission signatures, expiration, turn limits, migrations, and UTF-8 size limits.
Dashboard bootstrap and persistence
src/components/ClinicalDashboard.tsx, src/components/clinical-dashboard/*, src/lib/answer-thread-storage.ts
The dashboard resolves owners, restores matching snapshots, preserves display metadata, and delegates persistence to dedicated hooks.
Retention documentation and assertions
src/app/privacy/page.tsx, tests/privacy-ui.test.ts
Privacy text and tests cover 12-hour tab-local retention, offline unavailability, and clearing conditions.

Contextual back navigation

Layer / File(s)Summary
Contextual navigation component
src/components/contextual-back-link.tsx
The component uses browser history when available and replaces the route with a fallback otherwise. It preserves modified clicks and supports cancellation.
Page and breadcrumb integration
src/components/ui/page-header.tsx, src/components/information-page-shell.tsx, src/components/differentials/*, src/components/DocumentViewer.tsx, src/components/in-page-nav/*, src/components/navigation-back-button.tsx, src/components/therapy-compass/*
Back controls and breadcrumbs now use contextual navigation with existing fallback routes.
Navigation contract and regression coverage
tests/contextual-back-navigation-contract.test.ts, tests/navigation-back-button.dom.test.tsx, tests/patient-safety-plan-privacy.dom.test.tsx, tests/*navigation*.dom.test.tsx
Tests cover history detection, fallbacks, cancellation, modified clicks, router mocks, and navigation state.
Smoke coverage and design manifest
tests/ui-smoke.spec.ts, docs/design-system/adoption-manifest.json
Smoke tests verify restoration of originating dashboard, differential, and document URLs. The Breadcrumb manifest lists the contract test.

Supporting behavior updates

Layer / File(s)Summary
Template selection handling
src/components/formulation/formulation-builder-page.tsx, tests/ui-formulation.spec.ts
Template labels and radio inputs now share guarded selection behavior and reset edited drafts when the template changes.
Review ledger records
docs/branch-review-ledger.md
The ledger adds review records and repositions medication-search records chronologically.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
participant ClinicalDashboard
participant useAnswerThreadBootstrap
participant AnswerThreadStorage
participant usePersistedAnswerThread
ClinicalDashboard->>useAnswerThreadBootstrap: provide owner and answer-thread state
useAnswerThreadBootstrap->>AnswerThreadStorage: load matching submission snapshot
AnswerThreadStorage-->>useAnswerThreadBootstrap: return normalized persisted thread
useAnswerThreadBootstrap-->>ClinicalDashboard: restore turns, answer, metadata, and display state
ClinicalDashboard->>usePersistedAnswerThread: provide updated thread state
usePersistedAnswerThread->>AnswerThreadStorage: save version-2 snapshot
Loading
sequenceDiagram
participant PageBackControl
participant ContextualBackLink
participant BrowserHistory
participant NextRouter
PageBackControl->>ContextualBackLink: activate back control
ContextualBackLink->>BrowserHistory: check available history
alt history available
ContextualBackLink->>BrowserHistory: go back
else no history
ContextualBackLink->>NextRouter: replace fallback route
end
Loading

Possibly related PRs

Suggested labels:codex

Suggested reviewers:cursoragent, claude

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 18.92% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly summarizes the two primary changes: contextual back navigation and recent answer restoration.
Description check✅ PassedThe description follows the template, explains verification results and exceptions, and documents risk, rollback, production effects, and governance checks.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/chat-contextual-back-answer-cache-05ea-1

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: dependency version conflict. Check your lock file or package.json.


Comment @coderabbitai help to get the list of available commands.

@supabase

supabaseBot commented Aug 9, 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 August 9, 2026 14:35
@BigSimmo
BigSimmo requested a lite review from CopilotAugust 9, 2026 14:35

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:5d7c87a1ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment threadsrc/lib/answer-thread-storage.ts
Comment threadsrc/lib/answer-thread-storage.ts

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the app’s “back” navigation to prefer returning to the immediately preceding browser-history entry (with a deterministic in-app fallback for direct entry), and introduces tab-scoped sessionStorage restoration of exact-match completed answer threads for up to 12 hours. It also adds/updates privacy copy and strengthens automated coverage around navigation and restoration behavior.

Changes:

  • Introduce ContextualBackLink + navigateContextuallyBack and adopt it across page-level back/crumb controls.
  • Replace v1 answer-thread persistence with a v2, owner-scoped, TTL-bounded sessionStorage format (including signature matching, migration, sizing limits, and purge-on-invalid behavior).
  • Expand DOM + Playwright smoke coverage and add a repo-wide contract test to keep page-level left-arrow semantics consistent.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated no comments.

Show a summary per file
FileDescription
tests/ui-smoke.spec.tsAdds browser-journey coverage for contextual back behavior and answer-thread restoration without extra answer requests.
tests/privacy-ui.test.tsUpdates navigation mocking and asserts new privacy copy related to tab-scoped answer snapshots.
tests/patient-safety-plan-privacy.dom.test.tsxUpdates navigation mocking for replace-based fallback and adds Navigation API availability simulation.
tests/navigation-back-button.dom.test.tsxAdds focused DOM tests for history-back vs replace fallback and modified-click/keyboard semantics.
tests/medication-record-page.dom.test.tsxMocks router back/replace for components now using contextual navigation.
tests/information-page-shell.dom.test.tsxMocks router back/replace for breadcrumb/back affordances.
tests/in-page-nav-header.dom.test.tsxExtends next/navigation mock to include router back/replace for new back-link behavior.
tests/forms-information-disclosure.dom.test.tsxMocks pathname + router back/replace to support updated back-link behavior in forms pages.
tests/forms-back-navigation.dom.test.tsxMocks pathname + router back/replace for forms back navigation.
tests/form-priority-facts.dom.test.tsxMocks pathname + router back/replace to support updated navigation behavior.
tests/form-confirm-callout.dom.test.tsxMocks pathname + router back/replace to support updated navigation behavior.
tests/factsheet-save.dom.test.tsxMocks pathname + router back/replace to support updated factsheet navigation behavior.
tests/factsheet-detail-header.dom.test.tsxMocks pathname + router back/replace to support updated factsheet navigation behavior.
tests/contextual-back-navigation-contract.test.tsAdds a contract test ensuring production left-arrow usage routes through contextual history-back semantics.
tests/answer-thread-storage.test.tsExpands unit coverage for v2 storage format, TTL, migration, sizing, owner isolation, and signature matching.
src/lib/answer-thread-storage.tsImplements v2 persisted answer thread format with owner scoping, signature checks, TTL bounds, migration, and sizing guards.
src/components/ui/page-header.tsxAdds history-aware breadcrumb behavior via ContextualBackLink.
src/components/therapy-compass/screens/detail-screen.tsxReplaces button-based back behavior with contextual back-link semantics.
src/components/navigation-back-button.tsxChanges navigation behavior to history-back with replace fallback via navigateContextuallyBack.
src/components/information-page-shell.tsxProjects information-page breadcrumbs onto DS Breadcrumb with history-back semantics.
src/components/in-page-nav/in-page-nav-header.tsxUses ContextualBackLink for the in-page header back control.
src/components/DocumentViewer.tsxUses ContextualBackLink for “Back to documents” to preserve originating search history.
src/components/differentials/differential-stream-workspace.tsxUses contextual back-link for returning to differentials home while preserving history.
src/components/differentials/differential-presentation-workflow-page.tsxUses contextual back-link semantics for the differentials workflow back controls.
src/components/differentials/differential-compare-queue-page.tsxUses contextual back-link semantics for compare-queue navigation.
src/components/contextual-back-link.tsxAdds the core contextual back-link implementation (history-back with fallback, preserving modified click semantics).
src/components/ClinicalDashboard.tsxIntegrates persisted answer-thread restoration and signature-matched snapshotting into the dashboard lifecycle.
src/components/clinical-dashboard/use-persisted-answer-thread.tsAdds a hook to persist/clear answer-thread snapshots in a bounded, metadata-driven way.
src/app/privacy/page.tsxUpdates privacy copy to explicitly document tab-scoped answer snapshot retention/expiry and non-offline behavior.
docs/design-system/adoption-manifest.jsonUpdates design-system test linkage to include the new breadcrumb/back behavior coverage.
Suppressed comments (1)

src/lib/answer-thread-storage.ts:230

  • savePersistedAnswerThread returns false on storage failures (quota exceeded / blocked / unexpected throw) but leaves any previously stored thread intact. That can cause an older completed answer to be restored later even though a newer snapshot failed to persist. Consider best-effort clearing the stored thread on failure to avoid stale/incorrect restoration.
 } catch {
return false;
}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/ClinicalDashboard.tsx (1)

666-686: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

A transient null owner purges the persisted thread.

resolveAnswerThreadOwnerId returns null while authStatus is "loading". When the status flips to "loading" during a token refresh or a session revalidation, answerThreadOwnerId becomes null, previousOwnerId is still the real owner, and line 673 calls clearPersistedAnswerThread(previousOwnerId). The stored thread is deleted even though the account did not change. When the status returns to "authenticated", nothing can be restored.

Skip the clear when the new owner id is null, and only treat a transition between two resolved owners as an owner change.

🛡️ Proposed fix
 useEffect(() => {
const previousOwnerId = previousAnswerThreadOwnerIdRef.current;
- previousAnswerThreadOwnerIdRef.current = answerThreadOwnerId;
activeAnswerThreadOwnerIdRef.current = answerThreadOwnerId;
+ // A null owner means "not resolved yet" (authStatus === "loading"), not a+ // different account. Keep the last resolved owner so a refresh does not+ // purge the thread.+ if (!answerThreadOwnerId) return;+ previousAnswerThreadOwnerIdRef.current = answerThreadOwnerId;
if (!previousOwnerId || previousOwnerId === answerThreadOwnerId) return;
clearPersistedAnswerThread(previousOwnerId);
- if (answerThreadOwnerId) clearPersistedAnswerThread(answerThreadOwnerId);+ clearPersistedAnswerThread(answerThreadOwnerId);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/components/ClinicalDashboard.tsx` around lines 666 - 686, Update the
owner-transition effect using answerThreadOwnerId and
previousAnswerThreadOwnerIdRef so cleanup and state reset occur only when both
the previous and current owner IDs are resolved and differ. Skip
clearPersistedAnswerThread and related reset logic when answerThreadOwnerId is
null, preserving the persisted thread during transient authentication loading.
🧹 Nitpick comments (1)
src/components/ClinicalDashboard.tsx (1)

860-869: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Ref reads feed the effect dependency array.

latestTurn and metadata are read from refs during render. A ref mutation does not schedule a render, so the persistence effect observes a new ref value only when an unrelated state update re-renders the component. The current call sites set the refs immediately before setAnswer, so the ordering works today, but the coupling is implicit and easy to break.

Consider holding the snapshot metadata in state, or passing an explicit revision counter that changes with each ref mutation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/components/ClinicalDashboard.tsx` around lines 860 - 869, Update the
usePersistedAnswerThread call in ClinicalDashboard so latestTurn and metadata
changes are represented by render-triggering state or an explicit revision
counter, rather than relying on reading mutable refs during render. Ensure the
persistence effect reruns immediately for every ref mutation, including the
updates performed before setAnswer, while preserving the existing persisted
values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/privacy/page.tsx`:
- Around line 46-48: Update the privacy text near the completed answer-thread
retention statement to remove the inaccurate claim that the tab-only copy is
never available offline, and instead describe that it is confined to the current
browser tab and not synchronized or shared. Update the matching assertion in the
privacy UI test to expect the revised wording.
In `@src/components/ClinicalDashboard.tsx`:
- Around line 698-711: Prevent restored snapshots from overwriting current
persisted state: in src/components/ClinicalDashboard.tsx lines 698-711, assign
only latestSubmissionSignature and expiresAt from persisted to
latestAnswerSnapshotMetadataRef.current; in
src/components/clinical-dashboard/use-persisted-answer-thread.ts lines 51-58,
replace the metadata spread with explicit latestSubmissionSignature and
expiresAt fields so payload state always comes from current values.
In `@src/components/differentials/differential-presentation-workflow-page.tsx`:
- Around line 745-763: Update both ContextualBackLink controls in
src/components/differentials/differential-presentation-workflow-page.tsx lines
745-763 by replacing min-h-10 with min-h-12. Also add min-h-12 to the back-link
class list in src/components/therapy-compass/screens/detail-screen.tsx lines
38-44.
In `@tests/contextual-back-navigation-contract.test.ts`:
- Around line 33-41: Update the test around productionArrowFiles so it validates
every page-level left-arrow instance rather than passing when any
contextual-navigation token exists in the file. Inspect each arrow’s enclosing
JSX/props and require ContextualBackLink, navigateContextuallyBack, or
history-back behavior for each non-exempt control, while preserving
internalArrowControls exemptions.
In `@tests/navigation-back-button.dom.test.tsx`:
- Around line 96-106: Update the modified-click test around ContextualBackLink
to capture the click event’s defaultPrevented state in the window listener
before cleanup, then assert it is false after dispatching the Ctrl-click. Keep
the existing href and router interaction assertions unchanged.
---
Outside diff comments:
In `@src/components/ClinicalDashboard.tsx`:
- Around line 666-686: Update the owner-transition effect using
answerThreadOwnerId and previousAnswerThreadOwnerIdRef so cleanup and state
reset occur only when both the previous and current owner IDs are resolved and
differ. Skip clearPersistedAnswerThread and related reset logic when
answerThreadOwnerId is null, preserving the persisted thread during transient
authentication loading.
---
Nitpick comments:
In `@src/components/ClinicalDashboard.tsx`:
- Around line 860-869: Update the usePersistedAnswerThread call in
ClinicalDashboard so latestTurn and metadata changes are represented by
render-triggering state or an explicit revision counter, rather than relying on
reading mutable refs during render. Ensure the persistence effect reruns
immediately for every ref mutation, including the updates performed before
setAnswer, while preserving the existing persisted values.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 01d9974a-4954-4a9a-8cb7-779387811a18

📥 Commits

Reviewing files that changed from the base of the PR and between 122cddf and 5d7c87a.

📒 Files selected for processing (30)
  • docs/design-system/adoption-manifest.json
  • src/app/privacy/page.tsx
  • src/components/ClinicalDashboard.tsx
  • src/components/DocumentViewer.tsx
  • src/components/clinical-dashboard/use-persisted-answer-thread.ts
  • src/components/contextual-back-link.tsx
  • src/components/differentials/differential-compare-queue-page.tsx
  • src/components/differentials/differential-presentation-workflow-page.tsx
  • src/components/differentials/differential-stream-workspace.tsx
  • src/components/in-page-nav/in-page-nav-header.tsx
  • src/components/information-page-shell.tsx
  • src/components/navigation-back-button.tsx
  • src/components/therapy-compass/screens/detail-screen.tsx
  • src/components/ui/page-header.tsx
  • src/lib/answer-thread-storage.ts
  • tests/answer-thread-storage.test.ts
  • tests/contextual-back-navigation-contract.test.ts
  • tests/factsheet-detail-header.dom.test.tsx
  • tests/factsheet-save.dom.test.tsx
  • tests/form-confirm-callout.dom.test.tsx
  • tests/form-priority-facts.dom.test.tsx
  • tests/forms-back-navigation.dom.test.tsx
  • tests/forms-information-disclosure.dom.test.tsx
  • tests/in-page-nav-header.dom.test.tsx
  • tests/information-page-shell.dom.test.tsx
  • tests/medication-record-page.dom.test.tsx
  • tests/navigation-back-button.dom.test.tsx
  • tests/patient-safety-plan-privacy.dom.test.tsx
  • tests/privacy-ui.test.ts
  • tests/ui-smoke.spec.ts

Comment threadsrc/app/privacy/page.tsx Outdated
Comment threadsrc/components/ClinicalDashboard.tsx Outdated
Comment threadtests/contextual-back-navigation-contract.test.ts
Comment threadtests/navigation-back-button.dom.test.tsx
…-back-answer-cache-05ea-1
# Conflicts:
#	src/components/in-page-nav/in-page-nav-header.tsx
Keep signature-mismatched snapshots for forward restore, store only
metadata on restore, preserve guest threads across initial signed-out
auth, correct privacy copy and tap targets, and mock usePathname after
the main in-page-nav merge.
ClinicalDashboard exceeded the 4140-line no-growth gate after the
contextual-back/answer-cache work. Move owner/bootstrap restore into
useAnswerThreadBootstrap and merge latest main.
@github-actions

github-actionsBot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

CI triage

CI failed on this PR. Automated classification of the 2 failed job(s):

  • Production UI (1)needs investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.
  • PR requiredneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.

Compared with main CI run #9606 (cancelled).

Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger.

Production UI (2) timed out waiting for Breadcrumb/Medications exact
inside medication-page-*; MedicationNavHeader exposes
aria-label "Back to medications" outside that test id. Align with the
in-page-nav Playwright contract from #1781 and guard the quick-links
block against the old selector.
…ards
Controlled sr-only template radios could miss native label activation after
scroll-into-view on Production UI shard 1. Select from label click as well,
and force-check the radio in the Playwright journey.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/in-page-nav-playwright-contract.test.ts (1)

23-26: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Validate source-block boundaries before slicing.

If the closing test title is renamed or removed, indexOf returns -1. source.slice(start, -1) then includes almost all remaining source text. An unrelated later test can satisfy these assertions.

  • tests/in-page-nav-playwright-contract.test.ts#L23-L26: Assert that both marker indexes exist and that the closing index is greater than the opening index before creating prescribingBlock.
  • tests/in-page-nav-playwright-contract.test.ts#L39-L42: Apply the same boundary validation before creating quickLinksBlock.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/in-page-nav-playwright-contract.test.ts` around lines 23 - 26, Validate
both opening and closing marker indexes, including that the closing index is
greater than the opening index, before creating prescribingBlock in
tests/in-page-nav-playwright-contract.test.ts lines 23-26. Apply the same
boundary validation before creating quickLinksBlock at lines 39-42, failing the
test rather than slicing with invalid indexes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/branch-review-ledger.md`:
- Around line 873-879: Restore any relocated medication-search records to their
original historical positions in the branch-review ledger; do not edit or delete
existing rows. Add only genuinely new records via npm run ledger:append, and use
--supersede only when intentionally replacing a record through that command.
- Line 843: Update the affected branch-review ledger records to explicitly
declare provider-backed check status for the reviewed HEAD, including exact
current-HEAD gate results; when no provider-backed check ran, add the exact
statement “No provider-backed check ran.” Apply this consistently to the visible
2026-08-09 record and the additionally referenced records.
- Around line 853-862: Add an explicit provider-check status correction for the
PR `#1788` ledger entries using npm run ledger:append, stating whether
provider-backed checks ran or were skipped. Do not modify the existing PR `#1788`
rows; append the correction through the ledger command only.
In `@src/components/clinical-dashboard/use-answer-thread-bootstrap.ts`:
- Around line 89-102: In the owner-change reset block of the bootstrap hook,
before the queued state reset, clear autoRunSearchSignatureRef.current, reset
answerTurnSeqRef.current, and reset restoredThreadFromStorageRef.current. Keep
the existing persisted-thread cleanup and queued UI state reset unchanged so the
next owner starts with independent bootstrap and auto-run state.
---
Outside diff comments:
In `@tests/in-page-nav-playwright-contract.test.ts`:
- Around line 23-26: Validate both opening and closing marker indexes, including
that the closing index is greater than the opening index, before creating
prescribingBlock in tests/in-page-nav-playwright-contract.test.ts lines 23-26.
Apply the same boundary validation before creating quickLinksBlock at lines
39-42, failing the test rather than slicing with invalid indexes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b7a53bf0-2885-4182-8d7f-5c1dc93ce6a3

📥 Commits

Reviewing files that changed from the base of the PR and between 5d7c87a and 24a18d3.

📒 Files selected for processing (23)
  • docs/branch-review-ledger.md
  • docs/design-system/adoption-manifest.json
  • src/app/privacy/page.tsx
  • src/components/ClinicalDashboard.tsx
  • src/components/DocumentViewer.tsx
  • src/components/clinical-dashboard/use-answer-thread-bootstrap.ts
  • src/components/clinical-dashboard/use-persisted-answer-thread.ts
  • src/components/differentials/differential-presentation-workflow-page.tsx
  • src/components/formulation/formulation-builder-page.tsx
  • src/components/in-page-nav/in-page-nav-header.tsx
  • src/components/therapy-compass/screens/detail-screen.tsx
  • src/lib/answer-thread-storage.ts
  • src/lib/supabase/client.tsx
  • tests/answer-thread-storage.test.ts
  • tests/factsheet-detail-header.dom.test.tsx
  • tests/in-page-nav-header.dom.test.tsx
  • tests/in-page-nav-playwright-contract.test.ts
  • tests/medication-record-page.dom.test.tsx
  • tests/navigation-back-button.dom.test.tsx
  • tests/privacy-ui.test.ts
  • tests/ui-formulation.spec.ts
  • tests/ui-smoke.spec.ts
  • tests/use-answer-thread-bootstrap.test.ts
💤 Files with no reviewable changes (1)
  • src/components/DocumentViewer.tsx
🚧 Files skipped from review as they are similar to previous changes (15)
  • src/components/differentials/differential-presentation-workflow-page.tsx
  • tests/factsheet-detail-header.dom.test.tsx
  • tests/in-page-nav-header.dom.test.tsx
  • src/components/in-page-nav/in-page-nav-header.tsx
  • tests/medication-record-page.dom.test.tsx
  • src/components/clinical-dashboard/use-persisted-answer-thread.ts
  • tests/privacy-ui.test.ts
  • tests/navigation-back-button.dom.test.tsx
  • src/app/privacy/page.tsx
  • tests/answer-thread-storage.test.ts
  • src/components/therapy-compass/screens/detail-screen.tsx
  • tests/ui-smoke.spec.ts
  • src/components/ClinicalDashboard.tsx
  • src/lib/answer-thread-storage.ts
  • docs/design-system/adoption-manifest.json

Comment threaddocs/branch-review-ledger.md
Comment threaddocs/branch-review-ledger.md
Comment threaddocs/branch-review-ledger.md
@cursor

cursorBot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Babysit / unblock progress

  • Prior tip:24a18d37 — required CI green (including Production UI critical + shards + PR required)
  • Blocker after fix(therapy): use phone space more effectively #1799:BEHIND by 1 vs origin/main (merge-tree clean)
  • Sync: merged origin/main → new tip 96c501437cce (no conflicts)
  • Threads: resolved 4 open CodeRabbit threads (inline reply 403; disposition: non-blocking advisory / already handled elsewhere)
  • Next: waiting for required CI on synced tip, then squash-merge when CLEAN
  • Residual: formulation radio flake history — tip includes fix(formulation): make framework radio selection reliable under UI shards

@BigSimmo
BigSimmo merged commit 0647290 into mainAug 10, 2026
27 checks passed
@BigSimmo
BigSimmo deleted the codex/chat-contextual-back-answer-cache-05ea-1 branch August 10, 2026 12:53
@cursor

cursorBot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Babysit / unblock summary

  • Tip merged:96c501437cce → squash 06472906360407887546af07b9b51fe963b9518c
  • Sync / merge-tree: prior tip 24a18d37 was green but BEHIND after fix(therapy): use phone space more effectively #1799; one clean merge origin/main96c50143; merge-tree clean
  • Blocked by: branch behind main (required CI had already passed on prior tip); CodeRabbit threads (resolved)
  • Fixed / dispositioned: synced main; resolved 4 CodeRabbit threads as non-blocking; formulation UI flake fix already on tip
  • Required CI: green on synced tip (Static PR, coverage, Build, Migration replay, Production UI critical + shards, PR required)
  • Residual risks: chat contextual-back / answer-cache behaviour is product logic — covered by unit/UI gates on this tip, not a live RAG canary
  • Merge: completed (squash)

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 37 out of 37 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/components/clinical-dashboard/use-answer-thread-bootstrap.ts:92

  • useAnswerThreadBootstrap treats an intermediate answerThreadOwnerId === null as a real owner transition. That happens during auth-settling (e.g. starting a sign-in flow sets authStatus to loading), and this effect then clears sessionStorage + wipes the in-memory answer UI even if the user never actually switches accounts.

To preserve the “restore for up to 12 hours” behavior for guest sessions until an identity change is confirmed, avoid committing null into previousAnswerThreadOwnerIdRef and avoid running the clear/reset path when the new owner is null (transient state).

 useEffect(() => {
const previousOwnerId = previousAnswerThreadOwnerIdRef.current;
previousAnswerThreadOwnerIdRef.current = answerThreadOwnerId;
activeAnswerThreadOwnerIdRef.current = answerThreadOwnerId;
if (!previousOwnerId || previousOwnerId === answerThreadOwnerId) return;
clearPersistedAnswerThread(previousOwnerId);
if (answerThreadOwnerId) clearPersistedAnswerThread(answerThreadOwnerId);
answerThreadBootstrappedRef.current = false;

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.

3 participants

@BigSimmo@cursoragent