fix(knowledge): settle detach reservations when a knowledge base is purged - #8184
Conversation
…urged - Retention purge settles a detached connector's remaining detach_reserved_bytes (same lock order and settlement branches as the detach job) and zeroes it before the knowledge base delete cascades the connector away - Test drain helper picks the oldest pending outbox row - Unfilled-projection fixture writes its Tin row the way the projection trigger does - Knowledge ACL harness also runs the 0021 projection source/ACL postgres test
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
|
@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 9 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | 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.
All reported issues were addressed across 10 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…nts and the rest after
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
detach_reserved_bytes, the kept bytes charged to the workspace at removal. The pending detach job then found no knowledge base and settled nothing, so the charge stayed on the workspace and payer ledgerssettleDetachedConnectorReservationsafter the documents are hard-deleted and before the knowledge base rows are deleted. Per knowledge base, in one transaction, it locks the base then its detached connectors with a non-zero reservation (same order as the detach job), applies the detach job's own settlement (refund a positive remainder, admitted charge for an overdraft; now one shared helper), and zeroes the reservation so a retried purge or a detach run that still reaches the connector settles nothing twicescripts/test-knowledge-acls.tsalso runs the 0021 projection source/ACL postgres test, since its setup already applies 0021Type of Change
Testing
purged-detach-reservation.integration.ts(3 tests, real Postgres), wired into the CI knowledge integration step: detach reserves, one bounded run releases part of the source, purge runs; ledger ends at 0 and the late detach job leaves it there. Also covers the zeroing (settle twice, then drain) and the overdraft branchcleanup-soft-deletes.test.ts27/27 (new ordering test goes red without the call);lib/knowledge/connectorsunit tests pass; storage-accounting, search-source-progress, unfilled-projection-source integration pass (32/32 with the new file); 0016 + 0021 postgres tests 23/23bun run lint,bun run check:audits, apps/sim type-check passChecklist