fix(knowledge): bound every connector-lease ACL transaction to one short page - #8195
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
…les, update ACL test callers
…e-transactions-bounded
…ction rows, and skip unchanged work
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 21 files
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Fix all with cubic | Re-trigger cubic
…e-transactions-bounded # Conflicts: # apps/sim/lib/knowledge/connectors/member-sync-engine.ts
… locked chunk counts, and check the sweep budget per page
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 21 files
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Fix all with cubic | Re-trigger cubic
… pending rewrites until they finish
…s on any provisioned database
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 21 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 21 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 21 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
Summary
document.aclis one short page: bounded by its documents' chunk rows (PROJECTION_ROW_BATCH_SIZE, the constant detachment already uses, moved tosync-limits; a document larger than the cap gets a page alone), underLEASE_PAGE_LOCK_TIMEOUT_MS(15 s) /LEASE_PAGE_STATEMENT_TIMEOUT_MS(30 s). The ACL trigger rewrites every filled search projection row of a document whose ACL is assigned, so a transaction spanning many batches held the connector row (and the table lock a migration queues behind) across unbounded fan-out, and a timeout rolled back every batch that had landedleaseTransaction,withMemberLease, the content pass's lease transaction and the stale-member sweep write first and take the connector row lock as their final statement (a lost lease still rolls the page back). No page waits on document rows — which a processing commit may hold for its whole write — while holding aknowledge_connectorlock. Only ACL pages carry the page bounds; other lease bodies keep the role's timeoutspersistDocumentAcls: the evidence refresh returns what it matched; only the rest is read and written as changes, in row-bounded pages. The unchanged-refresh vs changed-write split and the unresolved-evidence guard are unchangedrestoreWorkspaceDocumentAcls: out of the completion transaction, paged, mode-guarded, and run only whileaccessRewritePendingis set (the mode switch and ACL-resetting edits are the only sources of that drift; every other writer of a workspace-mode document writes the workspace ACL)chunk_count)rewriteConnectorAclsand the restore share one single-pass keyset walker ((external_id, id)windows of 500); evidence-only rows are cleared without assigningaclrematerializeDocumentAcls, row-bounded pages). Observation changes that must commit with their ACLs (unseen removal, membership rewrite, stale sweep) take at most 25 documents and one page of projection rows; the invariant they keep is per document. The content completion's connector-wide count runs before the lease transactiondisableMemberSync: suspends members (which revokes reads at once: a reader needs an active member's observation as well as ACL overlap), revokes ACLs in guarded row-bounded pages, and flips the connector todisabledonly after the last page, in one statement that also proves the lease. It was one unguardedSET acl = '{}'underFOR UPDATEthat could time out and retry forever. An interrupted or out-of-budget run resumes on the next run; a disable that fails part-way goes through the normal failure path (log failed, lease released) instead of leaving the connector runninggetTransientDatabaseFailureclassifier) defers that connector to the next tick and the others are still swept; the scheduler logs a failed sweep and still dispatchesRound trips per 100k unchanged documents
Type of Change
Testing
connector-lease-pages.integration.ts(real migrated PostgreSQL 17, wired into both PostgreSQL CI jobs), 18 tests: every ACL assignment is recorded with its transaction and timeouts; each transaction stays within one page under the bounds; a page and a member page waiting on a locked document row hold noknowledge_connectorlock (pg_locks); a document above the row cap still lands alone; a lease lost between pages stops further writes while committed pages stay; the pending restore runs before completion and a healthy workspace sync never walks; listing, change-feed and membership rematerialisation page by rows; an interrupted disable resumes to disabled with every ACL empty; a failing disable closes as an ordinary failure; a stale sweep defers a connector a member run holds and still sweeps the otherslib/knowledge+app/api/knowledgeunit suites, the knowledge*.postgres.test.tsfiles, 0021 migration test, related knowledge integration suites on a freshly migrated database, lint,check:audits, type-checkChecklist