fix: harden Codex auto-resolve review guard#445
Conversation
… claude/llm-pipeline-review
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Defer embedding until after text/document fast paths and coverage gate - Rehydrate cached document metadata in attachDocumentRankingMetadata - Load env-dependent script imports after loadEnvConfig in seed/reindex scripts - Harden registry corpus: shared identity, medication tags, rollback, detail hrefs - Route registry citations to detail pages; handle registry rows in signed-url API - Prioritize safety warnings over registry info; preserve stale registry labels - Guard OCR repair against dropping isolated single-letter clinical tokens - Update skill docs, changelog dedup, CI Supabase setup-cli@v3 Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
- Backfill NULL document_images.index_generation_id during re-stamp - Count globally forced embedding eval cases in retrieval summaries Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Treat NULL document_images.index_generation_id as stale even when JSON metadata already matches the committed generation, and propagate global --force-embedding into eval reporting/validation so index-unit-vector runs count forced cases correctly. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
… codex/pr433-fix # Conflicts: # .cursor/skills/supabase-postgres-best-practices/CHANGELOG.md # .cursor/skills/supabase-postgres-best-practices/references/security-rls-performance.md # scripts/reindex-image-generation-metadata.ts # src/lib/differential-seed.ts # src/lib/document-index-units.ts # src/lib/medication-seed.ts # src/lib/rag.ts # src/lib/registry-corpus.ts # src/lib/registry-seed.ts # src/lib/source-governance.ts # src/lib/source-metadata.ts # supabase/migrations/20260708160000_retrieval_owner_matches_fail_closed.sql # supabase/migrations/20260708160001_retrieval_owner_matches_fail_closed.sql # supabase/migrations/20260708161000_retrieval_owner_matches_fail_closed.sql # tests/document-index-units.test.ts # tests/registry-corpus.test.ts # tests/source-governance.test.ts
PR #433 preview branch recorded 20260708160000 before the file was removed, causing remote migration versions not found in local migrations directory. Keep a no-op stub for history sync; transactional index DDL stays on 170000. Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(rag): finish registry re-embed and quality routing * fix: resolve merge conflicts with claude/llm-pipeline-review --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
… claude/llm-pipeline-review # Conflicts: # tests/rag-routing.test.ts
📝 WalkthroughWalkthroughAdds try/catch error handling for 403 responses when listing PR comments in a Codex autofix workflow, introduces a validation script and CI step guarding that workflow's structure, and updates AGENTS.md/docs to scope auto-resolve requests to actionable findings and restrict branch-review-ledger updates during pure reviews. ChangesCodex autofix workflow hardening and guard
Estimated code review effort: 2 (Simple) | ~12 minutes Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error, 1 warning)
✅ Passed checks (9 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
|
Updates to Preview Branch (codex/autoresolve-listcomments-403) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
|
@copilot resolve the merge conflicts in this pull request |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (6)
src/lib/rag-retrieval-variants.ts (1)
169-172: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNew admission/community branch overlaps with the existing comparison branch (Lines 184-187).
Both blocks add "admission community patients"-style variants for overlapping query shapes (single-branch admission+community vs. comparison admission+discharge). The
seenset dedupes, so this is not a correctness bug, but the near-duplicate logic adds maintenance surface.🤖 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/lib/rag-retrieval-variants.ts` around lines 169 - 172, The admission/community variant block in rag-retrieval-variants overlaps with the existing admission/discharge comparison branch and duplicates similar addVariant logic. Consolidate the shared “admission community patients”-style variant generation into one helper or shared conditional path used by both branches, and keep the unique query-shape checks in the surrounding logic so the variants are added from a single source of truth..github/workflows/live-drift.yml (1)
46-50: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider bumping
setup-nodeto the latest major.
actions/setup-node@v5works, butv6.xis current (node24-based). Not urgent for a weekly/manual workflow.🤖 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 @.github/workflows/live-drift.yml around lines 46 - 50, The workflow is still pinned to an older major of actions/setup-node; update the setup-node usage in the live-drift workflow to the current major release. Locate the existing actions/setup-node reference and bump it to the latest supported major while keeping the current node-version-file, cache, and cache-dependency-path settings unchanged.src/lib/registry-corpus.ts (2)
431-447: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low value
bestEffortReembedRegistryRecordAfterEditreports zero counts even after partial writes.When
reembedRegistryRecordAfterEditthrows mid-batch (see the batching loop above), earlier batches may have already written documents/chunks, but the caught "failed" result here always reportsdocumentCount: 0, chunkCount: 0, masking that partial writes occurred. Combined with the batching rollback gap, this makes it hard for downstream callers to detect and reconcile partial index state.🤖 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/lib/registry-corpus.ts` around lines 431 - 447, bestEffortReembedRegistryRecordAfterEdit currently returns a failed result with zero counts even when reembedRegistryRecordAfterEdit may have already written some documents/chunks before throwing. Update the error path in bestEffortReembedRegistryRecordAfterEdit to preserve/report the actual partial documentCount and chunkCount from the attempted re-embed instead of hardcoding zeros, using the existing reembedRegistryRecordAfterEdit flow and RegistryCorpusEmbedResult shape so downstream callers can detect partial writes.
360-406: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNear-identical slug lookup logic duplicated three times.
reembedClinicalRegistryRecordBySlug,reembedMedicationRecordBySlug, andreembedDifferentialRecordBySlugrepeat the same disabled-check → query-by-owner/slug(/kind) →maybeSingle()→ not-found/error pattern. Consider extracting a shared helper (table name + optional kind filter + row caster) to reduce triplication and ease adding future corpus kinds.🤖 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/lib/registry-corpus.ts` around lines 360 - 406, The slug-based re-embed flow is duplicated across reembedClinicalRegistryRecordBySlug, reembedMedicationRecordBySlug, and reembedDifferentialRecordBySlug. Extract the shared disabled-check, owner/slug lookup, optional kind filter, maybeSingle handling, and not_found/error logic into a common helper, then have each function pass its table name and row-specific embed/cast behavior to that helper. Keep the existing public function names but remove the repeated query boilerplate.src/lib/rag.ts (2)
2622-2624: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNo direct test coverage found for the new admission/community gate.
Neither
tests/rag-answer-fallback.test.tsnortests/rag-routing.test.ts(the test files included in this cohort) exerciseadmission_community_requires_title_rescueormissing_admission_community_title_support. If coverage exists elsewhere (e.g. an existingrag.test.ts) this can be disregarded; otherwise consider adding a regression test for a query matching admission+community intent with/without matching title support.Also applies to: 2666-2685, 2954-2963
🤖 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/lib/rag.ts` around lines 2622 - 2624, Add regression coverage for the new admission/community routing gate in rag.ts, especially the branch in the fast-path decision that returns admission_community_requires_title_rescue and the missing_admission_community_title_support path. Update an existing relevant test suite such as rag-answer-fallback.test.ts, rag-routing.test.ts, or rag.test.ts to exercise a query that matches admission+community intent both with and without title support, and assert the routing reason and fast-path behavior in the affected helpers like hasAdmissionCommunityLookupIntent and hasAdmissionCommunityTitleSupport.
2666-2685: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winFallback title-match branch is narrower than the titleHit branch.
When
match_explanation.titleHit/labelHitis set, support is granted via a general\badmission\b+\bcommunity\bcheck on the title (order-independent). When it isn't set, the fallback only matches three hardcoded literal phrases ("admission of community patient","admission community pt","admission to discharge for community"). A genuinely on-topic title with different word order or phrasing (e.g. "Community Patient Admission Pathway") would fail the fallback and incorrectly report missing title support, even though the same general regex check (used in the titleHit branch) would have matched it. This only degrades to the slower/structured path rather than causing a wrong answer, but the asymmetry looks unintentional.♻️ Suggested simplification
function hasAdmissionCommunityTitleSupport(results: SearchResult[]) { return results.slice(0, 5).some((result) => { - if (result.match_explanation?.titleHit || result.match_explanation?.labelHit) { - const title = normalizeDocumentAliasText(`${result.title} ${result.file_name}`); - return /\badmission\b/.test(title) && /\bcommunity\b/.test(title); - } - const title = normalizeDocumentAliasText(`${result.title} ${result.file_name}`); - return ( - title.includes("admission of community patient") || - title.includes("admission community pt") || - title.includes("admission to discharge for community") - ); + const title = normalizeDocumentAliasText(`${result.title} ${result.file_name}`); + return /\badmission\b/.test(title) && /\bcommunity\b/.test(title); }); }🤖 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/lib/rag.ts` around lines 2666 - 2685, The fallback branch in hasAdmissionCommunityTitleSupport is too narrow compared with the titleHit/labelHit branch, so align both paths by using the same general normalizeDocumentAliasText plus /\badmission\b/ and /\bcommunity\b/ title check for all results instead of only matching a few hardcoded phrases. Keep the existing result slicing and title/file_name concatenation, but remove the asymmetric literal-only fallback so Community Patient Admission Pathway-style titles are recognized consistently.
🤖 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 21-23: Mark the sample row in the branch review ledger as clearly
placeholder data, since the current example in the table uses a short Reviewed
HEAD value that conflicts with the real lookup flow used by git rev-parse.
Update the example entry in the table to either use a full commit SHA format or
move the sample outside the table, and keep the intent obvious by tying it to
the branch-review example row rather than a real reviewed HEAD value.
In `@docs/codex-review-protocol.md`:
- Around line 21-26: The protocol text is self-contradictory because the
pure-review rules in the mutation section forbid file edits while the ledger
requirement in the same section mandates updating docs/branch-review-ledger.md
after a review. Update the Mutation Rules in docs/codex-review-protocol.md so
that pure-review mode clearly excludes ledger writes, and move the ledger update
requirement into a separate post-review step or explicitly scope it to
non-pure-review workflows; keep the wording aligned with the surrounding
review-mode policy and the docs/branch-review-ledger.md reference.
In `@scripts/embed-registry-records.ts`:
- Around line 123-161: `listEligibleOwnerCounts` is loading full tables from
`clinical_registry_records`, `medication_records`, and `differential_records`
with plain `.select()`, which can hit Supabase/PostgREST’s 1000-row limit and
undercount owners. Update the logic to paginate each query with `.range()` in a
loop or replace the row scans with a server-side aggregate/RPC, and keep the
counting/sorting behavior in `listEligibleOwnerCounts` and `ensureOwnerCount`
unchanged.
---
Nitpick comments:
In @.github/workflows/live-drift.yml:
- Around line 46-50: The workflow is still pinned to an older major of
actions/setup-node; update the setup-node usage in the live-drift workflow to
the current major release. Locate the existing actions/setup-node reference and
bump it to the latest supported major while keeping the current
node-version-file, cache, and cache-dependency-path settings unchanged.
In `@src/lib/rag-retrieval-variants.ts`:
- Around line 169-172: The admission/community variant block in
rag-retrieval-variants overlaps with the existing admission/discharge comparison
branch and duplicates similar addVariant logic. Consolidate the shared
“admission community patients”-style variant generation into one helper or
shared conditional path used by both branches, and keep the unique query-shape
checks in the surrounding logic so the variants are added from a single source
of truth.
In `@src/lib/rag.ts`:
- Around line 2622-2624: Add regression coverage for the new admission/community
routing gate in rag.ts, especially the branch in the fast-path decision that
returns admission_community_requires_title_rescue and the
missing_admission_community_title_support path. Update an existing relevant test
suite such as rag-answer-fallback.test.ts, rag-routing.test.ts, or rag.test.ts
to exercise a query that matches admission+community intent both with and
without title support, and assert the routing reason and fast-path behavior in
the affected helpers like hasAdmissionCommunityLookupIntent and
hasAdmissionCommunityTitleSupport.
- Around line 2666-2685: The fallback branch in
hasAdmissionCommunityTitleSupport is too narrow compared with the
titleHit/labelHit branch, so align both paths by using the same general
normalizeDocumentAliasText plus /\badmission\b/ and /\bcommunity\b/ title check
for all results instead of only matching a few hardcoded phrases. Keep the
existing result slicing and title/file_name concatenation, but remove the
asymmetric literal-only fallback so Community Patient Admission Pathway-style
titles are recognized consistently.
In `@src/lib/registry-corpus.ts`:
- Around line 431-447: bestEffortReembedRegistryRecordAfterEdit currently
returns a failed result with zero counts even when
reembedRegistryRecordAfterEdit may have already written some documents/chunks
before throwing. Update the error path in
bestEffortReembedRegistryRecordAfterEdit to preserve/report the actual partial
documentCount and chunkCount from the attempted re-embed instead of hardcoding
zeros, using the existing reembedRegistryRecordAfterEdit flow and
RegistryCorpusEmbedResult shape so downstream callers can detect partial writes.
- Around line 360-406: The slug-based re-embed flow is duplicated across
reembedClinicalRegistryRecordBySlug, reembedMedicationRecordBySlug, and
reembedDifferentialRecordBySlug. Extract the shared disabled-check, owner/slug
lookup, optional kind filter, maybeSingle handling, and not_found/error logic
into a common helper, then have each function pass its table name and
row-specific embed/cast behavior to that helper. Keep the existing public
function names but remove the repeated query boilerplate.
🪄 Autofix (Beta)
✅ Autofix completed
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3edbc2c9-98d7-4d89-955e-84fa0b5134e0
📒 Files selected for processing (20)
.github/workflows/codex-autofix-review-comments.yml.github/workflows/live-drift.ymldocs/branch-review-ledger.mddocs/codex-prompt-playbook.mddocs/codex-review-protocol.mddocs/rag-hybrid-findings-and-todo.mdscripts/embed-registry-records.tssrc/lib/clinical-search.tssrc/lib/rag-extractive-answer.tssrc/lib/rag-retrieval-variants.tssrc/lib/rag-routing.tssrc/lib/rag.tssrc/lib/registry-corpus.tssupabase/drift-manifest.jsonsupabase/schema.sqltests/clinical-search.test.tstests/rag-answer-fallback.test.tstests/rag-routing.test.tstests/registry-corpus.test.tstests/retrieval-query-variants.test.ts
Head branch was pushed to by a user without write access
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 3 file(s) based on 3 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 3 file(s) based on 3 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
Head branch was pushed to by a user without write access
|
@copilot resolve the merge conflicts in this pull request |
Resolved. Merge commit:
Typecheck and Prettier checks pass. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ecd4fd4a0a
ℹ️ 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".
Summary
Verification
Notes