Skip to content

chore: implement audit remediation fixes#1153

Merged
BigSimmo merged 40 commits into
mainfrom
audit-remediation
Jul 25, 2026
Merged

chore: implement audit remediation fixes#1153
BigSimmo merged 40 commits into
mainfrom
audit-remediation

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Audit remediation: IPv6/port client-IP normalization, defensive semantic-rerank score clamping, PWA BroadcastChannel update signaling, heavyweight test-run lock live-owner preservation, PDF extractor signal handling, and fixed skill-catalog count pins.

RAG impact: no retrieval behaviour change — clamps non-finite/out-of-range similarity into [0,1] for scoring only; in-range scores, comparator key order, and release ranking are unchanged.

Verification

  • Focused: node scripts/run-vitest.mjs run tests/test-runner-safety.test.ts (17/17)
  • Focused: node scripts/run-vitest.mjs run tests/database-skills.test.ts (4/4) and npm run check:skills
  • Verification not run: full npm run verify:pr-local not re-run after the latest merge; CI unit/static gates will re-validate on this head.
  • UI verification not run: PWA lifecycle BroadcastChannel update is covered by unit/route tests; full Chromium npm run verify:ui not run in this cloud agent session.

Risk and rollout

  • Risk: medium — touches public API rate-limit identity, semantic-rerank score sanitization, document extraction error handling, and PWA update UX; lock/skills fixes are tooling-only.
  • Rollback: after squash-merge, revert the single squash commit on main; no schema/migration dependency.
  • Provider or production effects: None

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

  • Review P1 live-lock reclaim and P2 skill-catalog tautology were fixed and resolved on-thread.
  • PR_POLICY_BODY.md exists so CI Sync PR policy body can write this description (agent token cannot edit the live PR body directly). Safe to delete after policy is green if you do not want the sync template retained.

BigSimmo added 2 commits July 24, 2026 15:12
- Fix IPv6 rate limit header parsing

- Add bounded similarity scores to semantic rerank

- Sync PWA updates across tabs via BroadcastChannel

- Add non-blocking backoff lock for test-run-lock

- Update vitest configuration and test suite assertions
@supabase

supabase Bot commented Jul 24, 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 ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR applies audit remediation across client-IP parsing, semantic reranking, PWA update signaling, PDF extraction errors, skill manifest synchronization, live-lock handling, proxy session refresh, and related policy and review records.

Changes

Audit remediation

Layer / File(s) Summary
Score and process safety
src/lib/public-api-access.ts, src/lib/semantic-rerank.ts, src/lib/extractors/document.ts
Forwarded IPs are normalized, reranking values are clamped to [0,1], and signal-terminated PDF extractor processes receive dedicated error classification.
PWA update signaling
src/components/pwa-lifecycle.tsx
Service-worker updates are announced across tabs with BroadcastChannel, with guarded setup, messaging, and cleanup.
Skill manifest synchronization
scripts/sync-skills.mjs, package.json, tests/database-skills.test.ts
Skill manifests are generated for registered skills and aliases, catalog omissions fail synchronization, and coverage/sync commands are added.
Regression validation
tests/pdf-extractor.test.ts, tests/proxy.test.ts, tests/test-runner-safety.test.ts
Tests cover killed PDF workers, preservation of proxy headers and cookies, and retention of active live-lock ownership.
Policy and review records
PR_POLICY_BODY.md, docs/branch-review-ledger.md
Policy verification, governance checks, rollout notes, remediation notes, and audit review entries are recorded.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ServiceWorker
  participant TabA
  participant TabB
  ServiceWorker->>TabA: controller change
  TabA->>TabA: activate update-ready state
  TabA->>TabB: BroadcastChannel sw-updated
  TabB->>TabB: activate update-ready state
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% 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 name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main audit remediation changes and stays concise.
Description check ✅ Passed The description follows the template and includes summary, verification, risk/rollout, governance preflight, and notes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch audit-remediation

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.

❤️ Share

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

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: 6f87e0ec88

ℹ️ 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 thread scripts/test-run-lock.mjs Outdated
Comment thread tests/database-skills.test.ts Outdated
@BigSimmo

Copy link
Copy Markdown
Owner Author

@codex resolve actionable Codex review findings for this pull request and current head using the repository instructions. This is the pull request's single automatic repair pass: do not perform a fresh review, create new standalone findings, or request another review. Work only the existing unresolved Codex threads on the current head. Always fix P0 and P1 findings. For P2 and lower findings, fix only clear, scoped, low-risk issues; otherwise disposition them with a concise reason. After fixing or dispositioning a thread, reply in that thread with as the first line, followed by a concise summary; that marker authorizes the workflow to close that exact thread. If human input or new authorization is required, do not use the marker and leave the thread open with the blocker. Finish only after every actionable thread is fixed or dispositioned and closed, or explicitly left open for a human decision. Do not update the branch from main, address unrelated reviews, broaden scope, or create more than one scoped fix commit. Do not use external APIs, paid services, credentials, dependency changes, or broad refactors unless explicitly authorized. Add targeted tests where behavior changes and run the narrowest relevant validation.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Unknown error
ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: 6f87e0ec88

ℹ️ 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 thread scripts/test-run-lock.mjs Outdated
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

CI triage

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

  • Safety and config checksneeds 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 #5377 (success).

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

@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.

1 similar comment
@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
Owner Author

@cursoragent fix the branch merge conflict please

@cursor

cursor Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Merge conflict is fixed.

Merged origin/main into audit-remediation. The only conflict was in docs/branch-review-ledger.md; I kept both sides (main’s #1143 / search-chrome entries and this branch’s #1153 review row).

  • Commit: 935b0cbd
  • PR status: MERGEABLE against main
Open in Web Open in Cursor 

Add a regression test that an acquire against a live owner with
startedAt older than five minutes still throws and retains the lock,
so long-running builds/tests cannot be stolen by a later worktree.
Pin the catalog contract to 32 canonical skills, 8 aliases, and 40
discovered definitions so accidental catalog drift fails the suite.
Keep both ledger appends: main's PR #1143 / search-chrome review
records and this branch's PR #1153 audit remediation review row.
@cursor

cursor Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Merged origin/main into audit-remediation and resolved the sole conflict in docs/branch-review-ledger.md by keeping both appends (main’s PR #1143 / search-chrome review records + this branch’s PR #1153 review row). Branch is now mergeable against main (935b0cbd).

cursoragent and others added 5 commits July 24, 2026 07:55
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@BigSimmo
BigSimmo enabled auto-merge July 24, 2026 11:19
@BigSimmo

Copy link
Copy Markdown
Owner Author

@cursoragent resolve the failing CI policy check please

@cursor

cursor Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

PR policy is green.

I couldn't edit the PR description directly, so I added PR_POLICY_BODY.md and let CI sync it. That filled in:

  • RAG impact: no retrieval behaviour change — …
  • checked Clinical Governance Preflight
  • Summary / Verification / Risk and rollout

Latest check on 818f9efd: PR policy → success.

Open in Web Open in Cursor 

Add PR_POLICY_BODY.md so CI can write the required Clinical Governance
Preflight and RAG impact declaration that unblock the PR policy check.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: 32a3780693

ℹ️ 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 thread vitest.config.mts Outdated
Comment thread scripts/sync-skills.mjs Outdated
Nudge CI so PR policy re-evaluates the already synced description after
the sync/policy race on the prior tip.
@cursor

cursor Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

PR policy is green again.

Synced the required description via PR_POLICY_BODY.md (agent token cannot edit the live PR body directly):

  • RAG impact: no retrieval behaviour change — …
  • checked ## Clinical Governance Preflight
  • Summary / Verification / Risk and rollout filled

Latest PR policy run on 818f9efd: success.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: 60387f5145

ℹ️ 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 thread package.json
@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.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@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.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@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.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai coderabbitai Bot 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: 6

🤖 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 732: Move all four PR `#1153` entries in the branch-review ledger to the
end of the file, preserving their existing chronological append order and
content. Do not alter earlier historical entries or the ledger’s append-only
structure.

In `@PR_POLICY_BODY.md`:
- Line 17: Update the Rollback guidance in PR_POLICY_BODY.md to avoid assuming
merge commits or a specific merge strategy. Instruct maintainers to revert the
exact commit(s) introduced by the PR, or explicitly document the repository’s
enforced merge strategy if that is guaranteed.

In `@scripts/sync-skills.mjs`:
- Around line 24-30: Update the YAML generation in the sync-skills script to
serialize skill.name, shortDesc, and defaultPrompt as safely escaped
double-quoted scalars, using JSON.stringify or an equivalent YAML serializer.
Preserve the existing field names and allow_implicit_invocation value while
ensuring quotes, backslashes, and newlines cannot produce invalid YAML.
- Around line 13-18: Update the shortDesc normalization logic in
scripts/sync-skills.mjs to guarantee a minimum length of 25 characters,
including when the original description is empty or only a few characters long.
Replace or extend the current suffix strategy so the final value always remains
within the documented 25–64 character range while preserving the existing
truncation behavior for descriptions over 64 characters.

In `@tests/pdf-extractor.test.ts`:
- Around line 207-219: Update the test around the temporary directory setup
using a try/finally block, and ensure the finally clause calls rm on root with
recursive and force options. Keep the PDF/script creation and extractPdf
assertion in the try block so root is cleaned up regardless of test success or
failure.

In `@tests/test-runner-safety.test.ts`:
- Line 155: Remove the duplicate block-scoped retained declaration in the test
setup, keeping a single JSON.parse result for ownerPath that preserves the
existing token and pid typing and usage.
🪄 Autofix (Beta)

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: 30ce9b73-aa56-4171-9d8f-98219b838f24

📥 Commits

Reviewing files that changed from the base of the PR and between 4138c0d and 5105a6f.

📒 Files selected for processing (12)
  • PR_POLICY_BODY.md
  • docs/branch-review-ledger.md
  • package.json
  • scripts/sync-skills.mjs
  • src/components/pwa-lifecycle.tsx
  • src/lib/extractors/document.ts
  • src/lib/public-api-access.ts
  • src/lib/semantic-rerank.ts
  • tests/database-skills.test.ts
  • tests/pdf-extractor.test.ts
  • tests/proxy.test.ts
  • tests/test-runner-safety.test.ts

Comment thread docs/branch-review-ledger.md
Comment thread PR_POLICY_BODY.md Outdated
Comment thread scripts/sync-skills.mjs Outdated
Comment thread scripts/sync-skills.mjs
Comment thread tests/pdf-extractor.test.ts Outdated
Comment thread tests/test-runner-safety.test.ts
Co-authored-by: Cursor <cursoragent@cursor.com>
@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.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

github-actions Bot and others added 2 commits July 25, 2026 07:56
Same unblock as #1178: blocking npm audit keys off package-lock/.npmrc only.

Co-authored-by: Cursor <cursoragent@cursor.com>
@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.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Pad skill shortDesc to 25 chars and escape YAML double-quoted values;
clean up PDF extractor temp dirs; clarify squash-merge rollback wording.

Co-authored-by: Cursor <cursoragent@cursor.com>
@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.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@BigSimmo
BigSimmo merged commit 191b17d into main Jul 25, 2026
116 of 131 checks passed
@BigSimmo
BigSimmo deleted the audit-remediation branch July 25, 2026 09:11
BigSimmo added a commit that referenced this pull request Jul 25, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
BigSimmo added a commit that referenced this pull request Jul 25, 2026
* docs: ledger row for merged PR #1153 babysit

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs: ledger rows for merged PRs #1153 and #1178

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
cursor Bot pushed a commit that referenced this pull request Jul 25, 2026
#1175 deleted the #1134 leftover, then #1153 reintroduced a sync
template. Leaving it on main lets Sync PR policy body overwrite
unrelated PR descriptions. Remove it again after descriptions are set.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
cursor Bot pushed a commit that referenced this pull request Jul 25, 2026
…mplate cleanup (#1204)

* fix(#30): match expected files by distinct document identity

The merged #30 fix assigned each expectation to a distinct source
position. Positions are not documents: answer.citations carries one
entry per cited chunk, so a single combo-titled document arrives
several times and could still fill both comparison slots. First-come
assignment was also order-dependent -- a document matching two
expectations could consume the only source a narrower expectation
needed, so the same inputs produced different allHit results depending
on expectedFiles order.

Dedupe the window by document text and assign sources by maximum
bipartite matching, so coverage is both distinct-by-document and
order-independent.

RAG impact: no retrieval behaviour change -- eval matching only.

Also append label rows in place when building labelsByDocument; paging
past the 1,000-row cap (#75) means that loop now sees the full label
set, where per-row array rebuilds were quadratic.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>

* chore: remove leftover PR_POLICY_BODY.md after #1153

The sync-pr-policy-body CI job overwrites a pull request description
with this file whenever it exists on the head commit. The copy on main
holds the audit-remediation body from #1153, so every branch cut from
main silently inherits that description -- which is how #1177 lost its
own body. Remove it, as #953 did after #939; the job skips cleanly when
no template is present.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>

* docs(issues): record the #30 follow-up and open #80

Drop the stale queue row for #30/#75, which stayed in the recommended
queue after both were archived, note the distinct-identity hardening on
the #30 archive row, and open #80 to re-test the removed
admission-to-discharge widening under approved eval evidence.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>

* docs(ledger): append #1177 SHA correction and this review record

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>
Sign up for free to 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.

2 participants