fix(ingestion): phase-3 continued — R11 janitor, R1 heartbeat+fences, R7/R9/R23 RPC hardening#369
Merged
Merged
Conversation
… storage Defense-in-depth complement to the DELETE-route path-clearing already landed in PR #346. scripts/cleanup-storage.ts now skips any storage_cleanup_jobs row whose document_id still resolves to a live document: the ledger FK is ON DELETE SET NULL, so a genuinely-deleted document has its ledger document_id nulled — a non-null id that still resolves means the delete aborted and the paths still belong to a live document. Protects pre-#346 poisoned rows and any abort path that still leaves populated paths. Pure partition logic extracted to src/lib/storage-cleanup-safety.ts with tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The worker never refreshed ingestion_jobs.locked_at during a job, so any build longer than WORKER_STALE_AFTER_MINUTES (45m) was reclaimed by claim_ingestion_jobs while the original worker was still alive — two workers on one document, the enabler (R1) for the R2-R8 write-clobber class. updateJobProgress now doubles as a lease heartbeat: shouldPersistJobProgress adds a heartbeat ceiling (1/3 of the stale window) forcing a write during long silent phases, and the write refreshes locked_at scoped to locked_by=workerId so a worker that already lost its lease no-ops instead of stealing it back. Additive and lease-scoped; the residual loser-write race is closed by the RPC locked_by fences (separate migration). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continues phase-3 concurrency fixes from #346, following the docs in #339 (
docs/ingestion-state-machine.md§6 violations, §8 backlog). The db-reliability hold (#342) has merged.Shipped and verified
App-code (no schema.sql):
scripts/cleanup-storage.tsskipsstorage_cleanup_jobsrows whosedocument_idstill resolves to a live document (FK isON DELETE SET NULL; non-null + resolves = aborted delete). Defense-in-depth for fix(ingestion): phase-3 concurrency fixes — R11, R15/R16, R22, R24d #346's DELETE-side path-clearing.locked_atduring long jobs (scoped tolocked_by = workerId), so a healthy worker past the 45-minute stale window is no longer false-reclaimed. Removes the R2–R8 enabler in the common case.Migration
20260708120000(NOT applied to live — operator apply perdocs/supabase-migration-reconciliation.md; schema.sql reconciled, drift manifest regenerated, replays clean in 13s):complete_ingestion_job+fail_or_retry_ingestion_jobtake an optionalp_worker_id; a reclaimed worker matches 0 rows →ok:false lease_lostinstead of clobbering the reclaimer's newer state. Backward compatible (default null); worker passesworkerId, treatslease_lostas a stop, keeps theisMissingSchemaErrorfallback.failedinstead of a permanently-unclaimablependingthat pins the batch.refresh_import_batch_statuslocks the batch row before counting (fixes the lost-update that stuck batches asprocessingforever).cleanup_abandonedre-asserts the open-job guard immediately before the deletes.Gates (parent-checkout binaries; worktree has no node_modules): eslint ✅ prettier ✅ tsc ✅ · vitest drift-detection + supabase-schema replay guards + ingestion + storage-cleanup-safety ✅ (69 + tests) ·
drift:manifestregenerated via Docker ✅.check:indexing/reindex:health/check:drift(live) and the migration apply are operator steps.Held — with live evidence (do NOT merge these here)
ingestion_jobsindex reshape). Route through that workstream. Live is clean (0 docs with multiple open jobs), so it's safe whenever it's done.ingestion_job_stages.job_idFK) — drift backlog item Bump gitleaks/gitleaks-action from 2 to 3 #8 plans to add this FK, but live has 253 orphan stage rows that would failVALIDATEand 0 agent-job-id rows. The evidence says remove the FK from schema.sql (match live) — the opposite of the backlog plan. Needs the backlog owner's decision; flagged, not flipped.document_sectionshasunique (document_id, section_index); scoping the delete to preserve agent sections and then re-inserting overlapping indexes is a unique violation. fix(ingestion): phase-3 concurrency fixes — R11, R15/R16, R22, R24d #346's route-side agent gate already closes the main concurrent vector. Needs a coordinated section-ownership design, not a small patch.Refs #339 #346 #342
🤖 Generated with Claude Code