-
Notifications
You must be signed in to change notification settings - Fork 2
fix(maintenance): type unowned attachments and share the ANALYZE set #4697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,7 @@ | |
| _TERM_BLOCK_ORPHAN = "block_orphan" | ||
| _TERM_ATTACHMENT_REF_ORPHAN = "attachment_ref_orphan" | ||
| _TERM_ATTACHMENT_UNREFERENCED = "attachment_unreferenced" | ||
| _TERM_ATTACHMENT_UNOWNED = "attachment_unowned" | ||
|
|
||
| _RULES: dict[str, str] = { | ||
| _TERM_SOURCE_MISSING: ("acquired source file no longer exists on disk; the archive retains its raw payload bytes"), | ||
|
|
@@ -98,7 +99,14 @@ | |
| _TERM_MESSAGE_ORPHAN: "message names no session", | ||
| _TERM_BLOCK_ORPHAN: "block names no message", | ||
| _TERM_ATTACHMENT_REF_ORPHAN: "attachment ref names no message", | ||
| _TERM_ATTACHMENT_UNREFERENCED: "attachment has no ref and therefore no source lineage", | ||
| _TERM_ATTACHMENT_UNREFERENCED: ( | ||
| "attachment has no ref yet still carries a non-zero ref_count; its refs went away " | ||
| "without the ref-count sweep, so the row is unreachable from every read path" | ||
| ), | ||
| _TERM_ATTACHMENT_UNOWNED: ( | ||
| "attachment was written unreferenced because its owning message is ambiguous " | ||
| "(ref_count 0, never swept); identity and bytes are retained as evidence" | ||
| ), | ||
| } | ||
|
|
||
| _BLOCKING: frozenset[str] = frozenset( | ||
|
|
@@ -510,6 +518,8 @@ def audit_source_conservation( | |
| attachment_ref_orphans: list[tuple[Any, ...]] = [] | ||
| attachment_unreferenced_count = 0 | ||
| attachment_unreferenced: list[tuple[Any, ...]] = [] | ||
| attachment_unowned_count = 0 | ||
| attachment_unowned: list[tuple[Any, ...]] = [] | ||
| if table_exists(conn, "attachment_refs", schema="idx_tier"): | ||
| attachment_ref_orphan_count = int( | ||
| conn.execute( | ||
|
|
@@ -527,18 +537,43 @@ def audit_source_conservation( | |
| """, | ||
| (sample_limit,), | ||
| ).fetchall() | ||
| # A ref-less attachment splits on ``ref_count``. The writer inserts an | ||
| # owner-ambiguous row with ref_count 0 and keeps it out of the sweep, | ||
| # so ref_count 0 means "never had a ref" -- explained, non-blocking. | ||
| # Any ref-less row whose ref_count is non-zero was refreshed while refs | ||
| # existed and then lost them without the sweep running: it is | ||
| # unreachable from every read path and blocks. | ||
| unreferenced_predicate = """ | ||
| NOT EXISTS (SELECT 1 FROM idx_tier.attachment_refs ar WHERE ar.attachment_id = a.attachment_id) | ||
| """ | ||
| attachment_unreferenced_count = int( | ||
| conn.execute( | ||
| """ | ||
| f""" | ||
| SELECT COUNT(*) FROM idx_tier.attachments a | ||
| WHERE NOT EXISTS (SELECT 1 FROM idx_tier.attachment_refs ar WHERE ar.attachment_id = a.attachment_id) | ||
| WHERE {unreferenced_predicate} AND a.ref_count != 0 | ||
| """ | ||
| ).fetchone()[0] | ||
| ) | ||
| attachment_unreferenced = conn.execute( | ||
| """ | ||
| f""" | ||
| SELECT a.attachment_id FROM idx_tier.attachments a | ||
| WHERE NOT EXISTS (SELECT 1 FROM idx_tier.attachment_refs ar WHERE ar.attachment_id = a.attachment_id) | ||
| WHERE {unreferenced_predicate} AND a.ref_count != 0 | ||
| LIMIT ? | ||
| """, | ||
| (sample_limit,), | ||
| ).fetchall() | ||
| attachment_unowned_count = int( | ||
| conn.execute( | ||
| f""" | ||
| SELECT COUNT(*) FROM idx_tier.attachments a | ||
| WHERE {unreferenced_predicate} AND a.ref_count = 0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a parsed attachment names a message that does not exist—such as the Useful? React with 👍 / 👎. |
||
| """ | ||
| ).fetchone()[0] | ||
| ) | ||
| attachment_unowned = conn.execute( | ||
| f""" | ||
| SELECT a.attachment_id FROM idx_tier.attachments a | ||
| WHERE {unreferenced_predicate} AND a.ref_count = 0 | ||
| LIMIT ? | ||
| """, | ||
| (sample_limit,), | ||
|
|
@@ -603,6 +638,11 @@ def _term( | |
| attachment_unreferenced_count, | ||
| _sample(attachment_unreferenced, sample_limit), | ||
| ), | ||
| _term( | ||
| _TERM_ATTACHMENT_UNOWNED, | ||
| attachment_unowned_count, | ||
| _sample(attachment_unowned, sample_limit), | ||
| ), | ||
| ) | ||
| ) | ||
| return SourceConservationReport( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a genuinely ambiguous attachment carrying
inline_bytesor a precomputed blob, the ingest route preacquires the bytes asacquired, and the writer intentionally stores the attachment with no ref andref_count = 0. Although this new rule declares that state explained and says its bytes are retained as evidence, the same live/candidate verification registry still runsattachment-coverageandblob-reference-closure, both of which unconditionally return errors for every acquired attachment without a ref. Such valid input therefore still blocks archive verification or candidate promotion; those checks need to recognize explicit typed-unowned provenance, or this state needs a distinct acquisition status.Useful? React with 👍 / 👎.