Skip to content

fix(worker): re-check document and allowlist scope after claim_ingestion_jobs row lock - #3633

Merged
gitar-bot[bot] merged 2 commits into
mainfrom
fix/claim-ingestion-recheck-after-lock-1333
Oct 18, 2026
Merged

gitar-bot[bot] merged 2 commits into
mainfrom
fix/claim-ingestion-recheck-after-lock-1333

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

User description

Summary

  • Follow-up to fix(rag,worker): telemetry, document attribution, comparator parity, and atomic claim scope #3628. claim_ingestion_jobs(text, integer, integer, uuid[], text[]) picks candidates from a snapshot, takes the document authority lock, then locks the job row with FOR UPDATE SKIP LOCKED, but it never checked that the locked row still belonged to the picked document. A job re-pointed at another document in that window was leased under the picked document's authority, file-type recheck and sibling-lease check, and could sit outside the worker's document allowlist.
  • New migration supabase/migrations/20261018053558_recheck_ingestion_claim_scope_after_job_lock.sql replaces the five-argument function in place. After the job row lock it skips the job unless v_job.document_id still equals the picked document and is still inside p_allowed_document_ids. A skipped job stays pending with no lease and no consumed attempt, the same as every other skip in the loop. Signature, grants, return shape and every other branch are unchanged. The three-argument legacy function is not touched.
  • New tests/sql/ingestion-claim-recheck-after-lock.sql (run by the Migration replay job with every tests/sql/*.sql). It wraps lock_ingestion_document_authority inside its rolled-back transaction so the job is re-pointed between the pick and the job row lock, which makes the interleaving deterministic. It covers a document-allowlist worker, a file-type-allowlist worker and an unscoped worker (new document in scope but never authority-locked), plus a control and a follow-up claim that leases the job under its new document.
  • Companion files: supabase/schema.sql mirrors the migration (same pattern as fix(rag,worker): telemetry, document attribution, comparator parity, and atomic claim scope #3628), supabase/applied-migration-hashes.json via npm run migrations:seal (append-only, no existing entry changed). supabase/drift-manifest.json is taken byte-for-byte from this PR's Migration replay artifact (npm run drift:manifest needs Docker, which isn't available locally). database.types.ts is unchanged because the signature is unchanged.

Areas touched: Data platform and access

Verification

  • Checks run:
    • Offline harness (PGlite with a minimal stub of the touched tables and authority lock): against the fix(rag,worker): telemetry, document attribution, comparator parity, and atomic claim scope #3628 function the new test fails on all three re-point cases (a job re-pointed outside the document allowlist after the pick must not be claimed, ...disallowed file type..., ...must not be leased under the old document's authority) and the control passes. With the new migration applied, the whole file passes.
    • node scripts/check-migration-immutability.mjs: Migration immutability guard passed: 320 shipped migrations unchanged.
    • check:migration-role: Hosted migration-role guard passed. check:function-grants: OK — all 130 SECURITY DEFINER public function(s) are revoked from PUBLIC.
    • Vitest supabase-schema, migration-sql, migration-immutability, migration-history-guards, hosted-migration-role-guard, worker-row-contract, drift-detection: 300/301 passed. The one failure was the expected stale drift manifest before the CI artifact landed.
    • Hosted proof: the Migration replay job runs the full chain and the new SQL test against the real lock_ingestion_document_authority.

Risk and rollout

  • Risk: Low. One extra predicate on the locked row inside an existing SECURITY DEFINER function. It can only make the claim skip a job that it previously leased by mistake.
  • Rollback: a later migration restoring the fix(rag,worker): telemetry, document attribution, comparator parity, and atomic claim scope #3628 body. Any live database change needs its own owner approval.
  • Merge gate: this PR adds a migration under supabase/migrations/**. Merging to main applies it to the live clinical database within seconds and deploys. Merge only inside the owner's specifically approved database-change window. Auto-merge must stay off for this PR.
  • Provider or production effects: None. No live database, provider or deployment action was taken.

Notes

  • The legacy three-argument claim_ingestion_jobs(text, integer, integer) has the same document-identity gap (no allowlist, but it can still lease a re-pointed job under the old document's authority). It is out of scope here and could get a matching follow-up if wanted.

Summary by cubic

Fixes a race in claim_ingestion_jobs where a job re-pointed at a different document between the candidate pick and the job row lock could be leased under the wrong document's authority, bypassing file-type and document-allowlist checks.

  • Adds a migration that, after locking the job row, skips the claim unless the row still belongs to the picked document and remains inside the document allowlist. Skipped jobs stay pending with no lease and no consumed attempt.
  • Adds tests/sql/ingestion-claim-recheck-after-lock.sql that deterministically re-points a job mid-claim and covers document-allowlist, file-type-allowlist, and unscoped workers, plus a follow-up claim under the new document.
  • Mirrors the migration in supabase/schema.sql, seals the new migration hash, and regenerates the drift manifest from the Migration replay artifact. The legacy three-argument function is untouched.

Migration

  • Merging applies the new migration to the live clinical database; merge only inside the owner's approved database-change window.

Written for commit 63467e0. Summary will update on new commits.

View guided diff Turn on auto-fix


CodeAnt-AI Description

Prevent ingestion jobs from being claimed under a stale document

What Changed

  • Workers now skip a job if its document changes after the job is selected, or if the new document is outside the worker’s allowlist.
  • Skipped jobs remain pending without a lease or a consumed attempt, so a later claim can process them under the correct document.

Impact

✅ Jobs stay within document allowlists
✅ No leases under stale document authority
✅ Skipped jobs remain available for later claims

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • Bug Fixes
    • Ingestion jobs are now rechecked against their current document and file type before being claimed. Jobs that no longer match remain pending without a lease or consumed attempt; eligible jobs can be claimed under their current document.
  • Tests
    • Added regression coverage for jobs whose document changes during claim processing, along with a control case for unchanged jobs.

…ion_jobs row lock

Follow-up to #3628. The scoped claim picked candidates from a snapshot and
then locked the job row, but never checked that the locked row still
belonged to the picked document. A job re-pointed at another document in
that window was leased under the picked document's authority, file-type
check and sibling-lease check, and could sit outside the worker's document
allowlist.

New migration 20261018053558 replaces the five-argument
claim_ingestion_jobs in place (same signature, grants and behaviour) and,
after the job row lock, skips the job unless it still belongs to the picked
document and is still inside p_allowed_document_ids. A skipped job stays
pending with no lease and no consumed attempt.

tests/sql/ingestion-claim-recheck-after-lock.sql wraps the authority lock to
re-point the job between pick and lock. It fails against the #3628 function
(all three re-point cases are leased) and passes with this one.

schema.sql mirrors the migration; the hash is sealed with
npm run migrations:seal (append-only). The drift manifest follows from the
Migration replay artifact.

@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-18T05:42:36.279192Z 0c9b7c3 PR opened
ℹ️ 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.

@codeant-ai

codeant-ai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 0c9b7c3 Oct 18, 2026 · 05:40 05:43

@codeant-ai

codeant-ai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: BigSimmo/PsychSift/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 92fb0746-65b2-44e8-9813-7cb7d3cdb4fd
📥 Commits

Reviewing files that changed from the base of the PR and between 62558e5 and 63467e0.

📒 Files selected for processing: 5
  • supabase/applied-migration-hashes.json
  • supabase/drift-manifest.json
  • supabase/migrations/20261018053558_recheck_ingestion_claim_scope_after_job_lock.sql
  • supabase/schema.sql
  • tests/sql/ingestion-claim-recheck-after-lock.sql

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

📝 Walkthrough

The claim_ingestion_jobs function now rechecks document and file-type scope after locking the candidate job. A SQL regression test covers jobs whose document changes between candidate selection and authority locking.

Changes: Ingestion claim scope

Layer / File(s) Summary
Recheck scope before leasing
supabase/migrations/20261018053558_recheck_ingestion_claim_scope_after_job_lock.sql, supabase/schema.sql, supabase/applied-migration-hashes.json, supabase/drift-manifest.json
The claim function checks the locked document’s file type and verifies that the locked job still points to the picked document and matches the document allowlist. Eligible jobs receive a lease and are returned with the locked document. The schema and manifests record the updated definition.
Test document changes during claim
tests/sql/ingestion-claim-recheck-after-lock.sql
The test changes a job’s document before the authority lock. It checks that out-of-scope jobs remain pending without a lease or consumed attempt, and that an unmoved job and a later in-scope claim are leased.

Priority: ➖ Normal

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Claim as claim_ingestion_jobs
  participant Authority as lock_ingestion_document_authority
  participant Jobs as ingestion_jobs
  Claim->>Authority: Lock candidate document authority
  Authority-->>Claim: Return locked document
  Claim->>Jobs: Lock candidate job
  Jobs-->>Claim: Return current job row
  Claim->>Claim: Check document scope and set lease
Loading

Suggested reviewers: claude

Merge Risk: ⚪ Minimal · up to 63467

No actionable issue remains; the migration and schema agree. Merge during the approved database-change window after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: rechecking document and allowlist scope after the claim job row lock.
Description check Passed The description follows the required template. It includes the summary, areas touched, verification evidence, risk, rollback, provider effects, migration rollout restrictions, and notes. It also ident…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
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.
Full details: Description check

Explanation

The description follows the required template. It includes the summary, areas touched, verification evidence, risk, rollback, provider effects, migration rollout restrictions, and notes. It also identifies the reported stale drift-manifest test result and the required database-change window.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (5 skipped: 5 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ast-grep (0.45.3)
supabase/schema.sql

ast-grep skipped this file: it is too large to scan (17910207 bytes)

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

@supabase

supabase Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Updates to Preview Branch (fix/claim-ingestion-recheck-after-lock-1333) ↗︎

Deployments Status Updated
Database ✅ Sun, 18 Oct 2026 05:55:02 UTC
Services ✅ Sun, 18 Oct 2026 05:55:02 UTC
APIs ✅ Sun, 18 Oct 2026 05:55:02 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations ✅ Sun, 18 Oct 2026 05:55:04 UTC
Migrations ✅ Sun, 18 Oct 2026 05:55:05 UTC
Seeding ✅ Sun, 18 Oct 2026 05:55:07 UTC
Edge Functions ✅ Sun, 18 Oct 2026 05:55:09 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

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

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Oct 18, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Recheck ingestion job scope after locking its row

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Prevent re-pointed jobs from being leased under another document’s authority or outside worker
 scope.
• Leave skipped jobs pending without consuming an attempt; preserve the existing claim interface.
• Add deterministic regression coverage for scoped and unscoped claims, plus a successful follow-up
 claim.
Diagram

graph TD
  Pick["Pick candidate"] --> Authority["Lock document authority"] --> Validate["Check document and siblings"] --> Job["Lock job row"] --> Scope{"Scope valid?"}
  Scope -- "No" --> Skip["Leave pending"]
  Scope -- "Yes" --> Lease["Mint lease"]
Loading
High-Level Assessment

Rechecking the locked row is the appropriate fix: it validates the document tied to the acquired authority without changing the claim interface. Restarting the claim under a newly observed document would add lock and retry complexity; skipping lets a later claim acquire the correct authority.

Files changed (4) +235 / -2

Bug fix (2) +131 / -0
20261018053558_recheck_ingestion_claim_scope_after_job_lock.sqlValidate locked job scope before leasing +65/-0

Validate locked job scope before leasing

• Replaces the five-argument claim function so a job moved away from the picked document, or outside the document allowlist, is skipped after its row lock. Its signature, permissions and other claim behavior remain unchanged.

supabase/migrations/20261018053558_recheck_ingestion_claim_scope_after_job_lock.sql

schema.sqlMirror the claim-function migration +66/-0

Mirror the claim-function migration

• Appends the replacement function and its ownership and grants to the schema snapshot.

supabase/schema.sql

Tests (1) +101 / -0
ingestion-claim-recheck-after-lock.sqlCover job re-pointing between candidate pick and row lock +101/-0

Cover job re-pointing between candidate pick and row lock

• Uses a transaction-scoped authority-lock wrapper to move a job deterministically during a claim. Tests document and file-type allowlists, an unscoped worker, the unchanged-job control, and a later claim under the new document.

tests/sql/ingestion-claim-recheck-after-lock.sql

Other (1) +3 / -2
applied-migration-hashes.jsonSeal the new migration +3/-2

Seal the new migration

• Appends the new migration’s hash and refreshes the seal timestamp without changing existing hashes.

supabase/applied-migration-hashes.json

@gitar-bot
gitar-bot Bot enabled auto-merge (squash) October 18, 2026 05:40
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)

@codeant-ai

codeant-ai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

🏁 CodeAnt Quality Gate Results

Commit: 63467e03
Scan Time: 2026-10-18 06:06:55 UTC

✅ Overall Status: PASSED

Quality Gate Details

Quality Gate Status Details
Secrets ✅ PASSED 0 secrets found
Duplicate Code ✅ PASSED 0.0% duplicated
SAST ✅ PASSED No security issues
Bugs ✅ PASSED Rating S: No bugs
IAC ✅ PASSED No IAC issues

View Full Results

@qodo-code-review

qodo-code-review Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

No findings for this group


Remediation recommended

No findings for this group


Informational

No findings for this group

Grey Divider


Resolved findings

1. Drift checks fail on the stale manifest ✓ Resolved
Description
The new claim_ingestion_jobs definition changes supabase/schema.sql, but
supabase/drift-manifest.json still contains the previous schema hash and function snapshot. The
migration-replay job regenerates the manifest and compares it with the committed copy, while
check:drift rejects the hash mismatch before checking the live database.
Code

supabase/schema.sql[R34813-34814]

+create or replace function public.claim_ingestion_jobs(p_worker_id text, p_claim_limit integer, p_stale_after_minutes integer, p_allowed_document_ids uuid[], p_allowed_file_types text[])
+returns setof jsonb language plpgsql security definer set search_path = '' as $$
Relevance

●●● Strong

Recent reviews accept findings requiring regenerated drift manifests when schema.sql changes would
fail replay or hash checks.

PR-#3005
PR-#3332
PR-#3566

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The committed manifest has an older generation timestamp and schema hash. The drift checker compares
that hash with the current schema, and the migration-replay workflow compares a regenerated manifest
against the committed one.

supabase/drift-manifest.json[1-5]
scripts/check-drift.ts[526-533]
.github/workflows/ci.yml[1551-1557]
scripts/generate-drift-manifest.ts[6-15]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The schema mirror changed without updating the committed drift manifest, causing freshness and drift checks to fail.

## Fix Focus Areas
- supabase/schema.sql[34813-34814]
- supabase/drift-manifest.json[1-5]

## Recommended Fix
Run `npm run drift:manifest` against the updated schema and commit the resulting `supabase/drift-manifest.json`. Verify it with `npm run check:drift-manifest-freshness`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
❌ Tickets: failed to load — Ticket collection could not establish complete evidence
✅ Compliance rules (platform): 9 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: ⚖️ Balanced: Concurrency-sensitive claim logic and migration affect data access behavior.
✅ Fix-loop round: fix loop

Grey Divider

Tip of the day
💡 Did you know, you can move or hide resolved findings to focus on what still needs action

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit 63467e0 ⚖️ Balanced

Results up to commit 0c9b7c3 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required

No findings for this group


Remediation recommended

No findings for this group


Informational

No findings for this group


Resolved findings

1. Drift checks fail on the stale manifest ✓ Resolved
Description
The new claim_ingestion_jobs definition changes supabase/schema.sql, but
supabase/drift-manifest.json still contains the previous schema hash and function snapshot. The
migration-replay job regenerates the manifest and compares it with the committed copy, while
check:drift rejects the hash mismatch before checking the live database.
Code

supabase/schema.sql[R34813-34814]

+create or replace function public.claim_ingestion_jobs(p_worker_id text, p_claim_limit integer, p_stale_after_minutes integer, p_allowed_document_ids uuid[], p_allowed_file_types text[])
+returns setof jsonb language plpgsql security definer set search_path = '' as $$
Relevance

●●● Strong

Recent reviews accept findings requiring regenerated drift manifests when schema.sql changes would
fail replay or hash checks.

PR-#3005
PR-#3332
PR-#3566

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The committed manifest has an older generation timestamp and schema hash. The drift checker compares
that hash with the current schema, and the migration-replay workflow compares a regenerated manifest
against the committed one.

supabase/drift-manifest.json[1-5]
scripts/check-drift.ts[526-533]
.github/workflows/ci.yml[1551-1557]
scripts/generate-drift-manifest.ts[6-15]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The schema mirror changed without updating the committed drift manifest, causing freshness and drift checks to fail.

## Fix Focus Areas
- supabase/schema.sql[34813-34814]
- supabase/drift-manifest.json[1-5]

## Recommended Fix
Run `npm run drift:manifest` against the updated schema and commit the resulting `supabase/drift-manifest.json`. Verify it with `npm run check:drift-manifest-freshness`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread supabase/schema.sql Resolved

@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: 0c9b7c374e

ℹ️ 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 supabase/schema.sql Resolved
@codeant-ai

codeant-ai Bot commented Oct 18, 2026

Copy link
Copy Markdown

CodeAnt PR Risk: Low Risk

  • The PR appears safe to merge; the change narrowly closes a race in ingestion job claiming.
  • The claim function rechecks the locked job's document against the picked document and worker allowlist before issuing a lease.
  • The SQL regression test covers re-pointing during a claim, including out-of-scope documents and the subsequent valid claim.

Assessed commit: 0c9b7c374ead

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo Fixer

✅ Merged (0) · ☑ Fixed (0)

Process

  • ⏭ Skipped (1)

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Auto-fix isn't included in your plan ↗

Upgrade to Team

Byte-identical to the drift-manifest-39101323185 artifact that
scripts/generate-drift-manifest.ts (npm run drift:manifest) produced in the
Migration replay job of run 39101323185 for 0c9b7c3. Only
claim_ingestion_jobs(text,integer,integer,uuid[],text[]) def_hash and the
schema sha change; no hand edits.

@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

🔴 High risk · The migration changes ingestion-job document-scope authorization; a faulty recheck could let workers lease jobs outside their allowlist or under stale authority.

Adds a post-lock re-check to the claim_ingestion_jobs five-argument function so a job re-pointed to another document between pick and row lock is skipped rather than leased under the wrong document's authority, enforcing the document and file-type allowlists. No issues found.

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

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit 63467e0

@gitar-bot
gitar-bot Bot merged commit b12f3d4 into main Oct 18, 2026
46 checks passed
@gitar-bot
gitar-bot Bot deleted the fix/claim-ingestion-recheck-after-lock-1333 branch October 18, 2026 06:06
gitar-bot Bot pushed a commit that referenced this pull request Oct 18, 2026
…row lock (#3636)

* fix(worker): re-check document after the legacy claim_ingestion_jobs row lock

Follow-up to #3633 for the three-argument claim_ingestion_jobs(text, integer,
integer). It picked candidates from a snapshot, locked the picked document's
authority and sibling leases, then locked the job row without checking that
the row still belonged to the picked document, so a job re-pointed in that
window was leased under the old document's authority.

New migration 20261018062736 replaces the three-argument function in place
(same signature, defaults, grants and behaviour) and, after the job row lock,
skips the job unless it still belongs to the picked document. A skipped job
stays pending with no lease and no consumed attempt.

tests/sql/ingestion-legacy-claim-recheck-after-lock.sql wraps the authority
lock to re-point the job between pick and lock. It fails against the
20261013075944 function and passes with this one.

schema.sql mirrors the migration; the hash is sealed with
npm run migrations:seal (append-only). The drift manifest follows from the
Migration replay artifact.

* chore(db): regenerate drift manifest for legacy claim_ingestion_jobs recheck

Byte-identical to the drift-manifest-39104250354 artifact that scripts/generate-drift-manifest.ts (npm run drift:manifest) produced in the Migration replay job of run 39104250354 for be0b278. Only claim_ingestion_jobs(text,integer,integer) def_hash and the schema sha change; no hand edits.

---------

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

🟠 Medium blast radius size:L This PR changes 100-499 lines, ignoring generated files 🕐 20-40 Minutes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant