Skip to content

fix(knowledge): prevent KB deletion deadlocks - #7626

Merged
icecrasher321 merged 1 commit into
stagingfrom
codex/kb-deletion-deadlock
Sep 8, 2026
Merged

fix(knowledge): prevent KB deletion deadlocks#7626
icecrasher321 merged 1 commit into
stagingfrom
codex/kb-deletion-deadlock

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

  • Use FOR NO KEY UPDATE in the shared knowledge base soft-delete transaction. This lets an in-flight embedding insert complete its foreign-key check and release its document lock before deletion archives the document, while still serializing competing KB writes.
  • Add PostgreSQL regression coverage for concurrent publication and deletion, competing deletes, workspace scope, and search-index deletion guards.

Type of Change

  • Bug fix

Testing

  • Reproduced PostgreSQL 40P01 with the original lock; the regression passes with the fix.
  • 8 PostgreSQL integration tests and 83 focused unit tests passed.
  • App/auth type checks, repository lint, all 46 audits (including strict API boundary validation), block registry, docs manifest, and git diff --check passed.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 8, 2026 11:46pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the narrower lock preserves required write serialization while resolving the documented lock cycle.

Summary

  • Changes the deletion lock from FOR UPDATE to FOR NO KEY UPDATE.
  • Allows in-flight embedding publication to complete before child documents are archived.
  • Adds PostgreSQL integration coverage for publication/deletion concurrency, competing deletes, workspace scoping, and search-index guards.

Diagram

sequenceDiagram
    participant P as Embedding publication
    participant D as Document row
    participant K as Knowledge-base row
    participant X as KB deletion

    P->>D: FOR UPDATE
    X->>K: FOR NO KEY UPDATE
    X->>D: Archive document (waits)
    P->>K: FK check (KEY SHARE, compatible)
    P->>P: Insert embedding
    P-->>D: Commit and release lock
    X->>D: Archive document
    X->>K: Soft-delete knowledge base
    X-->>X: Commit
Loading

@icecrasher321
icecrasher321 merged commit dd8b159 into staging Sep 8, 2026
32 checks passed
@waleedlatif1
waleedlatif1 deleted the codex/kb-deletion-deadlock branch September 9, 2026 05:11
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.

1 participant