Skip to content

fix: remediate full-deep audit findings and retain release holds (rebuild of #3640) - #3653

Merged
gitar-bot[bot] merged 6 commits into
mainfrom
claude/rebuild-3640-20261018
Oct 18, 2026
Merged

gitar-bot[bot] merged 6 commits into
mainfrom
claude/rebuild-3640-20261018

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Requested by Josh · project thread

Clean rebuild of #3640. This PR carries the identical final code of #3640 at 83a49c5fa, merged with current main, as one commit. #3640 could not pass PR policy: qodo-code-review[bot] commits in its history touch Supabase or clinical paths, and history rewrites are banned. The owner chose a rebuild (thread decision, 18 Oct 2026). The bot's changes are included only as they stood at 83a49c5fa, so review them here. Earlier review discussion stays on #3640. Draft until the owner has reviewed it.

#3650 (RAG cache evidence revision) was merged into the old #3640 branch by the owner after this rebuild was cut. Its changes, including migration 20261018095804 and its seal entry (approved by the owner by name), are now carried here too, so this tree equals the old branch merged with main. Merge this after #3652, because #3652's migrations are dated earlier. Its own description and evidence are on #3650.

Summary

  • Prevent stale account requests and rollback from updating a different user's favourites, roster, sharing and calendar state; correct pay-history loading and selected-timezone conversions.
  • Make CME cleanup and ingestion recovery durable and transactional; minimize upload/worker diagnostics, harden RAG cache revocation/freshness and request coalescing, and preserve calculator/staff release holds.
  • Invalidate the RAG cache scope revision when table facts or images change (Invalidate RAG cache scope revision on table-fact and image edits (stacked on #3640) #3650).
  • Add an explicit isolated rootless catalog replay backend while retaining Docker as the default, preserve all existing migration seals, and document the audit findings, implementation and outstanding acceptance conditions.

Areas touched: App experience; Personal practice; Data platform and access; Answer engine; Source intake and indexing; Delivery and assurance; Knowledge and records.

RAG impact: behaviour change — cache governance/freshness, revocation, fallback, request coalescing and evidence-revision invalidation. Provider-backed before/after canary evidence is not available; it remains an owner-authorized acceptance condition.

Verification

Risk and rollout

  • Risk: High. This crosses account isolation, recovery state, private-document cleanup, clinical holds and RAG cache boundaries. Qualified clinical/privacy/provider approvals and candidate-matched hosted verification remain unmet. Deploying Invalidate RAG cache scope revision on table-fact and image edits (stacked on #3640) #3650's change invalidates every cached answer and search once.
  • Rollback: Revert application changes in a reviewed commit while retaining clinical/privacy holds. SQL and durable queue/state changes need a separately reviewed compatibility and data-recovery plan; reverting TypeScript alone does not undo database effects.
  • Provider or production effects: Creating/updating this PR may trigger configured GitHub CI and the existing Supabase preview-branch integration. No paid RAG evaluation, Railway deployment, production SQL application or merge is authorized by this publication.

Merge only inside the owner's specifically approved production database window. This PR contains supabase/migrations/20261018082910_audit_durable_recovery_pairing_and_cache_fences.sql and supabase/migrations/20261018095804_rag_cache_scope_evidence_revision.sql; merging to main automatically applies migrations to the live clinical database within seconds. This work did not alter owner-controlled auto-merge state.

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 PsychSift Production (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

Physiological calculators and staff activation remain held. No qualified clinical, legal, privacy or provider sign-off was fabricated. The cache revision is now a clinical-evidence hazard control that the owner should review; no hazard control is sealed here.


🤖 Generated with Claude Code

https://claude.ai/code/session_018UBtJDgQZJ3eBsxLWte9r4


Summary by Gitar

  • Roster alerts:
    • Added a durable offer alert outbox with per-device receipts and at-least-once push delivery in roster_offer_alert_outbox
    • Keyless open-shift posts now get a server-generated post key so their offer alerts enqueue
  • PDF extraction:
    • Table edge recovery now requires ruled cell boundaries, retaining ambiguous edge text for review via edge_recovery_needs_review
  • Release holds:
    • Sick-call projection now shares the real-staff release hold, and bedside calculator outputs stay held pending clinical review
  • Work role access:
    • Moving a hospital team revokes its whole-team supervisor grants in the same transaction via work_revoke_supervisors_on_team_move

This will update automatically on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented account-specific data and pending actions from carrying over when switching accounts.
    • Improved roster warnings and retries when calendar sources fail, corrected pay-period history coverage, and improved work-time handling across time zones.
    • Updated retrieval-cache freshness checks so governance and evidence changes are reflected; improved recovery handling for queued documents.
    • Added a release hold for clinical calculators pending review and gated hospital sick-call access behind a release setting.
  • Documentation

    • Expanded operational guidance, audit findings, remediation plans, and release-readiness records. Local acceptance and release readiness remain blocked by outstanding approvals and verification.

Clean rebuild of PR #3640 (head 83a49c5) as one commit on main 1837b0b, with identical
final code (the tree equals merging main into that head). Rebuilt because
qodo-code-review[bot] commits in #3640's history (577dc4f, a62fc95) touch protected
paths and fail the bot-authored-sensitive-commits PR policy, and history
rewrites are banned. Those bot changes appear here only as they stood at
83a49c5 and need owner review in this PR.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018UBtJDgQZJ3eBsxLWte9r4
@supabase

supabase Bot commented Oct 18, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy due to reaching the limit of concurrent preview branches.
Go to Project Integrations Settings ↗︎ if you wish to update this limit.


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

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: BigSimmo/PsychSift/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: b5060c40-86b4-40f9-bbf9-64faf5d1fe2a
📥 Commits

Reviewing files that changed from the base of the PR and between 8a7177d and 98cff21.

📒 Files selected for processing: 116
  • data/repo-awareness-snapshot.json
  • docs/README.md
  • docs/agents/codex-cloud-legacy-bootstrap.md
  • docs/audit/2026-10-17-full-deep-remediation-results.md
  • docs/audit/2026-10-17-full-deep-remediation-spec.md
  • docs/codebase-index.md
  • docs/database-drift-detection.md
  • docs/error-tracking.md
  • docs/governance/clinical-release-remediation-handoff-2026-10-17.md
  • docs/governance/physiological-calculator-hold-2026-10-17.md
  • docs/observability-slos.md
  • docs/organisation/systems/data-platform.json
  • docs/organisation/systems/personal-practice.json
  • docs/rag-behaviour/README.md
  • docs/rag-behaviour/cache-freshness.md
  • docs/rag-injection-threat-model.md
  • docs/reindex-runbook.md
  • docs/scripts-index.md
  • docs/superpowers/plans/2026-10-17-full-deep-remediation.md
  • railway.worker.json
  • scripts/check-worker-python-lock.mjs
  • scripts/generate-drift-manifest.ts
  • scripts/generate-worker-python-lock.mjs
  • scripts/lib/drift-rootless.ts
  • scripts/recover-ingestion-queue.ts
  • scripts/reindex.ts
  • scripts/test-run-lock.mjs
  • scripts/worker-python-lock-config.mjs
  • src/app/api/documents/[id]/reviews/route.ts
  • src/app/api/upload/route.ts
  • src/app/api/work/hospital/sick/route.ts
  • src/components/account-data-provider.tsx
  • src/components/admin/admin-new-job-page.tsx
  • src/components/admin/junior/use-roster-leave.ts
  • src/components/admin/new-job/admin-new-job-sharing.tsx
  • src/components/calculators/clinical-math-panel.tsx
  • src/components/roster/manage/roster-cover-tab.tsx
  • src/components/roster/roster-month-page.tsx
  • src/components/roster/roster-settings-page.tsx
  • src/components/roster/use-roster-links.ts
  • src/components/roster/use-roster-settings.ts
  • src/components/roster/use-roster-shifts.ts
  • src/components/roster/use-roster-team.ts
  • src/components/teaching/organise-model.ts
  • src/components/use-account-request-scope.ts
  • src/components/work-calendar/use-work-calendar-entries.ts
  • src/components/work-screens/admin/pay-page.tsx
  • src/instrumentation.ts
  • src/lib/calculators/clinical-math/governance.json
  • src/lib/cme/evidence-repository.ts
  • src/lib/ingestion-recovery.ts
  • src/lib/logger.ts
  • src/lib/observability/agent-monitoring.ts
  • src/lib/open-shifts/mine.ts
  • src/lib/open-shifts/posted.ts
  • src/lib/privacy.ts
  • src/lib/rag/rag-answer-coalescing.ts
  • src/lib/rag/rag-cache.ts
  • src/lib/rag/rag.ts
  • src/lib/site-content/adapters/index.ts
  • src/lib/supabase/database.types.ts
  • src/lib/trusted-document-admission.ts
  • src/lib/work-roles/people.ts
  • supabase/applied-migration-hashes.json
  • supabase/drift-manifest.json
  • supabase/migrations/20261018082910_audit_durable_recovery_pairing_and_cache_fences.sql
  • supabase/migrations/20261018095804_rag_cache_scope_evidence_revision.sql
  • supabase/schema.sql
  • tests/account-request-scope.dom.test.tsx
  • tests/admin-auth-transition.dom.test.tsx
  • tests/admin-new-job-page.dom.test.tsx
  • tests/admin-pay-history.dom.test.tsx
  • tests/agent-monitoring.test.ts
  • tests/clinical-math-bounds.test.ts
  • tests/clinical-math-governance.dom.test.tsx
  • tests/clinical-math-governance.test.ts
  • tests/clinical-math-panel-breakpoint.dom.test.tsx
  • tests/cme-evidence-api.test.ts
  • tests/diagnostic-minimisation.test.ts
  • tests/drift-rootless.test.ts
  • tests/factsheets-summary-context.test.ts
  • tests/favourites-session-race.dom.test.tsx
  • tests/fixtures/site-content/static-manifest-baseline.json
  • tests/hosted-migration-role-guard.test.ts
  • tests/ingestion-recovery.test.ts
  • tests/instrumentation.test.ts
  • tests/open-shifts-zone.test.ts
  • tests/operational-alerts.test.ts
  • tests/rag-answer-fallback.test.ts
  • tests/rag-cache-governance-revocation.test.ts
  • tests/rag-cache-indexing-stamp.test.ts
  • tests/rag-cache-invalidation.test.ts
  • tests/rag-cache-lru.test.ts
  • tests/rag-cache-test-revision.ts
  • tests/rag-shared-cache.test.ts
  • tests/rag-site-content-freshness.test.ts
  • tests/rag-tail-latency.test.ts
  • tests/railway-config.test.ts
  • tests/retrieval-access-scope.test.ts
  • tests/roster-auth-transition.dom.test.tsx
  • tests/roster-cover-tab.dom.test.tsx
  • tests/roster-month-page.dom.test.tsx
  • tests/sql/rag-cache-scope-evidence-revision.sql
  • tests/test-runner-safety.test.ts
  • tests/trusted-document-admission.test.ts
  • tests/ui-tools-search-mode-mockup.spec.ts
  • tests/ui-tools.spec.ts
  • tests/upload-diagnostic-minimisation.test.ts
  • tests/work-calendar-entries-enabled.dom.test.tsx
  • tests/work-roles-hospital-sick-release.test.ts
  • tests/work-roles-hospital-sick.test.ts
  • tests/work-roles-people-changes.test.ts
  • tests/worker-python-lock.test.ts
  • worker/main.ts
  • worker/python/requirements-cloud.in
  • worker/python/requirements-cloud.txt
+--------------------------------------------------------+
| Code review is a dish best served cold. Like a carrot. |
+--------------------------------------------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment thread src/lib/rag/rag-cache.ts Resolved
#3650 merged into the old #3640 branch after this rebuild was cut. This
applies exactly that branch's new changes, so the tree now equals the old
branch merged with main. Includes migration 20261018095804 and its seal
entry, which the owner approved by name.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018UBtJDgQZJ3eBsxLWte9r4

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

BigSimmo has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T13:57:53.685382Z 98cff21 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@BigSimmo
BigSimmo marked this pull request as draft October 18, 2026 12:54
Resolves the four overlaps: seal file keeps all four new entries in date
order, schema.sql appends this PR's projections after #3652's, the drift
manifest is a three-way merge of both generated manifests (no object changed
on both sides) with schema_sha256 matching schema.sql, and the site-content
baseline is regenerated from the merged sources.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018UBtJDgQZJ3eBsxLWte9r4
@BigSimmo
BigSimmo marked this pull request as ready for review October 18, 2026 13:05

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

BigSimmo has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@BigSimmo
BigSimmo marked this pull request as draft October 18, 2026 13:05

Copy link
Copy Markdown
Owner Author

PR required is red on 3471b1f6c in runs 39129744505 and 39129993250, but no job actually failed. The aggregate went red because its upstream jobs were cancelled when this PR went back to draft: static checks, build, unit coverage, migration replay, containers and UI. Safety, SAST and change scope all passed.

This PR stays in draft on purpose until #3652 merges, because #3652's migrations are dated earlier. After that, main gets merged into this branch, which also brings in #3652's later review fixes. That push re-runs the full CI, so no re-run is needed on this head.


Generated by Claude Code

@BigSimmo
BigSimmo marked this pull request as ready for review October 18, 2026 13:12

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

BigSimmo has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@gitar-bot
gitar-bot Bot enabled auto-merge October 18, 2026 13:16
gitar-bot[bot]
gitar-bot Bot previously approved these changes Oct 18, 2026

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

Gitar has auto-approved this PR (configure)

Brings in the review fixes (expired offer drain, booked-slot withdrawal,
NICE authority form) and the owner-approved cue exposure therapy wording.
The site-content baseline is regenerated from the merged sources.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018UBtJDgQZJ3eBsxLWte9r4

@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: 3471b1f6c1

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

gitar-bot[bot]
gitar-bot Bot previously approved these changes Oct 18, 2026

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

Gitar has auto-approved this PR (configure)

@BigSimmo
BigSimmo disabled auto-merge October 18, 2026 13:21
@BigSimmo
BigSimmo marked this pull request as draft October 18, 2026 13:24
gitar-bot[bot]
gitar-bot Bot previously approved these changes Oct 18, 2026

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

Gitar has auto-approved this PR (configure)

@BigSimmo
BigSimmo marked this pull request as ready for review October 18, 2026 13:51
@BigSimmo
BigSimmo dismissed gitar-bot[bot]’s stale review October 18, 2026 13:51

The merge-base changed after approval.

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

BigSimmo has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@gitar-bot
gitar-bot Bot enabled auto-merge October 18, 2026 13:52

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

Gitar has auto-approved this PR (configure)

@gitar-bot

gitar-bot Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor
Code Review ✅ Approved 1 closed / 1 findings

🔴 High risk · Production SQL changes to private-evidence cleanup, team authorization, and clinical RAG cache freshness could mishandle records or leave stale guidance available.

Remediation of the full-deep audit findings across account isolation, roster alerts, PDF extraction, CI, and RAG cache governance, with release holds retained. No open findings remain; the uncached full-scope revision RPC performance item was closed without a fix in this PR.

✅ 1 closed
Closed: Performance: Uncached full-scope revision RPC now runs many times per RAG request

📄 src/lib/rag/rag-cache.ts:1173-1187 📄 src/lib/rag/rag-cache.ts:403-409 📄 src/lib/rag/rag-cache.ts:674-676 📄 src/lib/rag/rag-cache.ts:989-990 📄 src/lib/rag/rag-cache.ts:1215-1216 📄 src/lib/rag/rag-cache.ts:1239-1240 📄 supabase/migrations/20261018082910_audit_durable_recovery_pairing_and_cache_fences.sql
cacheIndexingVersion no longer has its 5 s memo or its limit(1) latest-row query. Each call now runs rag_cache_scope_revision_v1, which reads every owner and public document in scope and md5-hashes each row's full metadata jsonb, with no status filter. Every call site also passes forceRefresh: true and the in-flight key calls it again, so one answer request makes this round trip roughly 6–10 times: request start, local answer, shared answer before and after the read, in-flight key before and after waiting, search caches, and the write paths. The cost of these round trips on the answer hot path grows with corpus size. Because the hash also covers queued and processing rows, any ingestion activity in the public scope also invalidates every user's cache. Suggested fix: compute the revision once per request and reuse it, and only re-read it for the after-read fence checks. Also limit the hash to the columns and statuses that matter for retrieval visibility, or keep a per-scope revision counter that is bumped by trigger.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Approved

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Important

Your trial ends in 3 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

@gitar-bot
gitar-bot Bot merged commit b907b5c into main Oct 18, 2026
41 of 42 checks passed
@gitar-bot
gitar-bot Bot deleted the claude/rebuild-3640-20261018 branch October 18, 2026 14:10
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