fix: harden ingestion worker leases and address review follow-ups#937
Conversation
- Pass workerId through complete/fail ingestion RPCs and skip counters when the lease was reclaimed by another worker. - Generate embedding payloads before delete/insert and swap fields inside a single transaction to avoid partial enrichment gaps. - Check private access before document readiness in DocumentViewer.summarize so signed-out users see the sign-in message. - Return skill descriptions separately from validateSkillCatalog instead of mutating canonical catalog entries during validation. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
|
Updates to Preview Branch (cursor/ingestion-and-review-followups-0a3e) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
|
Warning Review limit reached
Next review available in: 10 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 (2)
📝 WalkthroughWalkthroughThe PR adds workflow policy validation, updates ingestion lease and embedding transaction handling, separates skill descriptions, restricts document management to administrators, refines summarization guards, and selects platform-appropriate Python executables. ChangesPR policy hardening
Ingestion processing
Skill catalog rendering
Document management access
Document summarization controls
Python executable selection
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Request as HTTP Request
participant Worker as IngestionWorker
participant Store as EmbeddingStore
participant RPC as SupabaseRPC
Request->>Worker: process claimed job
Worker->>Store: generate embeddings and hashes
Worker->>Store: replace fields in transaction
Worker->>RPC: complete or fail/retry job
RPC-->>Worker: return completion or lease-lost result
Worker-->>Request: report processed, failed, and lease_lost counts
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
- Use python3 by default on non-Windows when PYTHON_BIN is unset so PDF budget tests invoke the Python extractor instead of falling through to JS - Extract completeIngestionJob/failOrRetryIngestionJob helpers and track lease_lost explicitly in the worker response instead of failed -= 1 - Align pdf-extractor test python bin resolution with production code Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
- Gate DocumentManagementActions on isAdministratorUser for defense in depth - Add check-pr-policy-workflow guard for pull_request_target hardening invariants - Document trusted workflow_sha checkout in process-hardening notes - Extend account-access model test to lock administrator client gate Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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 `@scripts/check-pr-policy-workflow.mjs`:
- Around line 11-92: Replace the raw workflow-wide string checks in the
validation logic with YAML-aware inspection of the specific PR policy and
sync-pr-policy-body jobs, permissions, checkout steps, and script imports.
Validate executable checkout refs and credential settings rather than comments
or unrelated jobs; require workflow_sha, persist-credentials false, read-only
permissions, and trusted-base script imports. Expand forbidden checkout
validation to reject pull-request head ref variants, and ensure missing or
weakened settings fail the check.
In `@src/components/DocumentManagementActions.tsx`:
- Line 59: Revalidate authorization in both submit handlers in
DocumentManagementActions using the current canManage value before processing
submission. If permission is no longer available, prevent submission and close
or otherwise clear the active dialog mode so an already-open form cannot be
submitted after authentication or administrator status changes.
In `@src/lib/extractors/document.ts`:
- Around line 21-25: Update resolvePythonBin to consume the canonical parsed
PYTHON_BIN value from the existing environment configuration instead of
independently selecting python3 on non-Windows platforms. Ensure extraction and
worker/prerequisite checks use the same executable configuration; if the
environment schema is changed instead, update the corresponding prerequisites,
deployment documentation, and tests consistently.
In `@supabase/functions/ingestion-worker/index.ts`:
- Around line 218-260: Update processJob to conservatively handle completion
outcomes: treat null results and any ok === false reason other than lease_lost
as failures rather than returning "completed" or silently incrementing
processed, while preserving the lease_lost result. Add an early lease-ownership
validation before upsertDocumentSummary, upsertEmbeddingFields, and
markEnrichmentMetadata, or revalidate immediately before those writes, so a
worker that no longer owns the lease exits without performing redundant work.
🪄 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: b2662162-3d7c-4699-a553-2a037a99deb3
📒 Files selected for processing (11)
docs/process-hardening.mdpackage.jsonscripts/check-pr-policy-workflow.mjsscripts/list-database-skills.mjssrc/components/DocumentManagementActions.tsxsrc/components/DocumentViewer.tsxsrc/lib/extractors/document.tssupabase/functions/ingestion-worker/index.tstests/account-access-model.test.tstests/ingestion-edge-function-auth.test.tstests/pdf-extractor.test.ts
- Revalidate administrator access in DocumentManagementActions submit handlers - Centralize resolvePythonBin for extraction, env defaults, and worker prerequisites - Fail ingestion worker conservatively when complete_ingestion_job is ambiguous - Parse PR policy workflow YAML by job/step instead of whole-file string matching 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 `@src/lib/python-bin.ts`:
- Around line 2-4: The resolved executable from resolvePythonBin must be trimmed
before return; use the trimmed nonblank explicit value while preserving the
existing platform defaults. In src/lib/python-bin.ts lines 2-4, update
resolvePythonBin accordingly; src/lib/env.ts line 211 requires no direct change
because it is corrected by this root-cause fix.
🪄 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: e5dbd731-0207-41d2-8680-ea4888418894
📒 Files selected for processing (9)
scripts/check-pr-policy-workflow.mjssrc/components/DocumentManagementActions.tsxsrc/lib/env.tssrc/lib/extractors/document.tssrc/lib/python-bin.tssupabase/functions/ingestion-worker/index.tstests/account-access-model.test.tstests/ingestion-edge-function-auth.test.tstests/pdf-extractor.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- tests/account-access-model.test.ts
- src/components/DocumentManagementActions.tsx
- scripts/check-pr-policy-workflow.mjs
- supabase/functions/ingestion-worker/index.ts
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>
Keep the header-edge-pad fix current with origin/main after #937. Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Summary
Verification
npm run verify:cheap— local run on PR head: lint, typecheck, and 2892/2895 unit tests passed; 3 known failures remain intests/pdf-extraction-budget.test.ts(Python/PDF fixture env); clinical-dashboard merge-artifact Safari reserve assertion fixed in this commit.npm run check:production-readiness— passed locally for auth/privacy/admin-route changes.npm run verify:ui— hosted Production UI gate on this PR head (UI-scoped paths includeglobal-search-shell, detail pages, andDocumentViewer).Risk and rollout
Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes