perf(bundle): precompute cross-mode differentials index to slim the lazy chunk (#012) - #1287
Conversation
…azy chunk (#12) The cross-mode "Also in your library" strip dynamically imports cross-mode-differentials.ts, which statically pulled the full ~1.2 MB differentials snapshot (via @/lib/differentials) just to build a tiny {slug,title,clinicalHinge} + presentations + aliases catalog. That path is the only reason the snapshot landed in the lazy cross-mode chunk. Precompute the trimmed catalog at build time and import that instead: - scripts/build-cross-mode-differentials-index.mjs projects data/differentials-snapshot.json into src/data/cross-mode-differentials- index.json (~53 KB vs ~1.2 MB), mirroring the therapies-index generator. `--check` fails when the committed index is stale (parsed-value compare, so Prettier formatting never trips it). - cross-mode-differentials.ts now returns the precomputed JSON and no longer imports @/lib/differentials, so the lazy chunk drops the snapshot. - check:cross-mode-index is wired into verify:cheap next to check:therapy-data-index. - tests/cross-mode-differentials-index.test.ts asserts the index equals the live projection over the full snapshot, guarding against both snapshot-content and projection/alias-filter drift. No behaviour change: crossModeDifferentialCatalog() returns the same catalog, proven equal to the live projection. Resolves ledger #12. RAG impact: no retrieval behaviour change — this is a client bundle slim of a display-only cross-mode links catalog; no retrieval/ranking/ selection/eval or answer-generation code is touched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UbhUVWVJRwDibC2YtJ6aRX
This pull request has been ignored for the connected project Preview Branches by Supabase. |
Warning Review limit reached
Next review available in:18 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR adds a generated cross-mode differentials index, switches runtime loading to that artifact, adds drift and content validation, wires the check into CI, and updates related documentation and issue ledgers. ChangesCross-mode index
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Snapshot as differentials-snapshot
participant Builder as build-cross-mode-differentials-index.mjs
participant Index as cross-mode-differentials-index.json
participant Dashboard as cross-mode-links.tsx
participant Catalog as cross-mode-differentials.ts
Snapshot->>Builder: provide source differential data
Builder->>Index: generate trimmed catalog
Dashboard->>Catalog: dynamically import catalog
Catalog->>Index: load precomputed index
Index-->>Dashboard: return cross-mode data
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The gate-manifest guard requires every verify:cheap gate to also run explicitly in CI. Add the "Cross-mode differentials index drift" step next to the therapy-data-index one so check:cross-mode-index is enforced on PRs, matching the verify:cheap wiring. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UbhUVWVJRwDibC2YtJ6aRX
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
BigSimmo
commented
Jul 27, 2026
@cursoragent run bugbot on this please |
Bugbot on PR #1287 ( Findings
Cleared
No hosted |
Append-only review record for the cross-mode differentials index perf PR at 97ab067 — no P0/P1; residual P2 is missing import-graph lock. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
…ugbot #1287) Address the three non-blocking Bugbot findings on #1287: - P2: add an import-graph guard so a future re-add of a static `import … from "@/lib/differentials"` (or the raw snapshot) to cross-mode-differentials.ts fails the test — the value-equality check alone stays green regardless of how the catalog is produced, so it could not catch the ~1.2 MB snapshot silently returning to the lazy chunk. - P3: update the stale cross-mode-links.tsx comment (it now loads the ~53 KB precomputed index, not the full snapshot). - P3: list build-cross-mode-differentials-index.mjs in docs/scripts-index.md next to build-therapies-index.mjs. Test-only + docs/comment; no runtime behaviour change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UbhUVWVJRwDibC2YtJ6aRX
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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`:
- Line 1148: Update the ledger entry for PR `#1287` to reflect the final stack:
remove or mark as historical the “no import-graph lock” residual, stale
cross-mode-links.tsx comment, and missing scripts-index entry, and record the
corresponding completed safeguards and final verification results using the
existing check names.
In `@tests/cross-mode-differentials-index.test.ts`:
- Around line 37-50: Update the test “does not statically import the heavy
differentials module” to inspect the resolved module graph or build output
rather than only regexing cross-mode-differentials.ts. Recursively follow
resolved imports, including non-from forms and transitive helpers, and assert
that the lazy cross-mode graph contains cross-mode-differentials-index.json but
neither `@/lib/differentials` nor differentials-snapshot.
🪄 Autofix (Beta)
❌ Autofix failed (check again to retry)
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 Plus
Run ID: 06c1e2bb-428d-418d-b230-6425bb76a4c6
📒 Files selected for processing (10)
.github/workflows/ci.ymldocs/branch-review-ledger.mddocs/outstanding-issues.mddocs/scripts-index.mdpackage.jsonscripts/build-cross-mode-differentials-index.mjssrc/components/clinical-dashboard/cross-mode-links.tsxsrc/data/cross-mode-differentials-index.jsonsrc/lib/cross-mode-differentials.tstests/cross-mode-differentials-index.test.ts
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…Rabbit #1287) Address CodeRabbit's two Minor findings on the follow-up head: - Import-graph guard was a shallow regex on one file's `from` imports; a transitive helper import or a dynamic import()/require form could reintroduce @/lib/differentials while staying green. Replace it with an allowlist: cross-mode-differentials.ts may import ONLY the precomputed index + the (type-only) catalog type — every collected specifier (from / import() / require / side-effect) must be in the allowlist, so any reintroduction surfaces as a disallowed specifier. (Comment mentions aren't specifiers, so the explanatory "@/lib/differentials" reference is correctly ignored.) - The branch-review-ledger is append-only, so instead of editing the Bugbot row, append a superseding record noting the three residuals (import-graph lock, stale comment, scripts-index entry) are addressed, with the final verification. Test-only + append-only ledger record; no runtime change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UbhUVWVJRwDibC2YtJ6aRX
CI triageCI failed on this PR. Automated classification of the 2 failed job(s):
Compared with main CI run #5981 (success). Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger. |
Prevent a silent bundle regression: re-importing @/lib/differentials into the lazy cross-mode catalog would restore the ~1.2 MB snapshot while the data-equality gates stay green. Assert the trimmed JSON index import and the dynamic load site in cross-mode-links, and refresh the stale comment. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Append-only follow-up for the cross-mode differentials import-graph lock. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Remote landed an allowlist guard in the index test; keep local consumer dynamic-import lock and reconcile the comment conflict. # Conflicts: # src/components/clinical-dashboard/cross-mode-links.tsx Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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`:
- Line 1149: Correct the ledger entry’s test attribution: state that
tests/client-performance-boundaries.test.ts guards the dynamic import in
cross-mode-links.tsx, and identify tests/cross-mode-differentials-index.test.ts
as enforcing the cross-mode-differentials.ts allowlist. Preserve the remaining
test result and audit details.
🪄 Autofix (Beta)
❌ Autofix failed (check again to retry)
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 Plus
Run ID: 07dbae48-adee-4bc5-917a-65ac063d096a
📒 Files selected for processing (3)
docs/branch-review-ledger.mdtests/client-performance-boundaries.test.tstests/cross-mode-differentials-index.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/cross-mode-differentials-index.test.ts
Uh oh!
There was an error while loading. Please reload this page.
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. The branch was updated while autofix was in progress. Please try again. |
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. The branch was updated while autofix was in progress. Please try again. |
Production UI failed on a hydration overlap: getByTestId('differentials-home')
resolved to two nodes after the mode=differentials redirect. Wait for a single
settled owner (same helper as the mode-home loop) so transient duplicates do
not trip Playwright strict mode while permanent doubles still fail.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
BigSimmo
commented
Jul 27, 2026
@cursoragent please review this and fix the merge conflicts and find out the cause and ensure no regression and fix any other open comments also and failing CI testing |
PR #1287 is mergeable again at Merge conflict causeBoth tips only appended Open comments
CI / regression
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. ❌ Cannot run autofix: This PR has merge conflicts. Please resolve the conflicts with the base branch and try again. Alternatively, use |
GitHub marked the PR CONFLICTING/DIRTY while merge-tree was clean: both tips only appended docs/branch-review-ledger.md (union merge). Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. ❌ Cannot run autofix: This PR has merge conflicts. Please resolve the conflicts with the base branch and try again. Alternatively, use |
Strengthen the CodeRabbit follow-up: recursively resolve runtime imports from cross-mode-differentials.ts so a helper (or value-import of an allowlisted type module) cannot reintroduce @/lib/differentials or the snapshot while a surface regex stays green. Keep the entry allowlist as a fast fail. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Record main sync (ledger-only stale DIRTY), resolved-graph guard, and correct attribution for the consumer vs catalog import locks. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
BigSimmo
commented
Jul 27, 2026
@cursoragent please review all the issues in this PR. Please resolve failing CI and any merge conflicts or also any comments outstanding or issues you see. Please fix this now. |
Fixed and pushed (
Required checks are re-running on the new head ( |
Static PR Format check failed solely on this file after the resolved-graph guard landed; no logic change. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Closeout status ( |
BigSimmo
commented
Jul 28, 2026
@cursoragent please resolve all CI failing tests after understanding the issue. Please also fix any comments and resolve them and also ensure that you fix with smallest required fix with best coding practice and u derstabding the fix rather than simple patch. Please fix any merge conflicts and ensure any issues are found. Please resolve any issues you find. Please also run bugbot. Please mark comments resolved also once you resolve them. |
PR #1287 is mergeable again at What was wrong
Fixes landed
Required checks are re-running on this tip ( |
Append-only closeout for the outstanding-issues merge resolution and re-verification after syncing current origin/main. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Status at |
BigSimmo
commented
Jul 28, 2026
@cursoragent fix the merge conflicts and find the cause of them and resolve and also fix the failing CI |
Fixed and pushed (
Required checks are re-running on the new tip. |
GitHub CONFLICTING/DIRTY was staleness: merge-tree clean; only overlapping path is append-only branch-review-ledger.md (union) plus main's RAG claim support hardening. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Static PR Format check failed solely on docs/outstanding-issues.md after the recommended-queue rewrite; no content change beyond formatting. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Fixed at |
BigSimmo
commented
Jul 28, 2026
@cursoragent fix failing semgrep test |
Nothing to fix — Semgrep is already green, and #1287 is merged.
If the UI still shows a red Semgrep check, it’s a stale result from an older SHA. |
Uh oh!
There was an error while loading. Please reload this page.
Semgrep statusNo failing Semgrep to fix on this PR.
If GitHub still shows an older red Semgrep check, it’s stale UI from a prior SHA; the merge commit and final tip are green. |


Summary
Realizes ledger item #12. The cross-mode "Also in your library" strip dynamically imports
cross-mode-differentials.ts, which statically pulled the full ~1.2 MB differentials snapshot (via@/lib/differentials) just to build a tiny{slug,title,clinicalHinge}+ presentations + aliases catalog. That dynamic import is the only path by which the snapshot reached the lazy cross-mode chunk (verified — neithercross-mode-links.tsxnorcross-mode-links.tsimports differentials statically).Precompute the trimmed catalog at build time and import that instead:
scripts/build-cross-mode-differentials-index.mjsprojectsdata/differentials-snapshot.json→src/data/cross-mode-differentials-index.json(~53 KB vs ~1.2 MB, ~22× smaller), mirroring the existingbuild-therapies-index.mjsgenerator.--checkfails when the committed index is stale, comparing parsed values so Prettier's formatting never trips the gate.cross-mode-differentials.tsnow returns the precomputed JSON and no longer imports@/lib/differentials, so the lazy chunk drops the snapshot.check:cross-mode-indexis wired intoverify:cheapnext tocheck:therapy-data-index.tests/cross-mode-differentials-index.test.tsasserts the index equals the live projection over the full snapshot — guarding against both snapshot-content drift and any divergence in the projection / alias-filter logic.No behaviour change:
crossModeDifferentialCatalog()returns the same catalog, proven equal (deep-equal test) to the live projection.RAG impact: no retrieval behaviour change — this is a client-bundle slim of a display-only cross-mode links catalog; no retrieval/ranking/selection/eval or answer-generation code is touched (
cross-mode-differentials.tsis not a protected RAG surface).Verification
npm run check:cross-mode-index— drift gate passes (still passes after Prettier reformat, confirming the parsed-value compare)npm run test— full suite green: 3557 passed / 5 skipped / 0 failed, incl. the new drift test and the existingcross-mode-links.test.tsnpm run typecheck— cleannpm run lint— cleannpm run check:knip— clean (new script referenced viapackage.json, JSON imported by the lib, no unused/unresolved)npm run docs:check-scripts+npm run docs:check-index— cleandata/differentials-snapshot.jsonis 1,195,263 B; the trimmed index is 53,104 B, and the snapshot is no longer statically reachable from the cross-mode dynamic import.npm run build:analyze— not run in-session (heavy); the import-graph removal is deterministic and CI runs the production build.Risk and rollout
check:cross-mode-index(inverify:cheap/CI) and the drift test both fail closed with a clear "re-run the generator" message.Clinical Governance Preflight
N/A — no ingestion, answer generation, search/ranking, source rendering, document access, privacy, production env, or clinical output surface is touched. This is a client-bundle optimization of a cross-mode UI links catalog.
Notes
*-mockups.tsxfrom the prod artifact).#012moved to Resolved indocs/outstanding-issues.md.Generated by Claude Code
Summary by CodeRabbit
Performance
Reliability
Documentation