Repository navigation
docs(storage): document blob GC lease design as kept-by-design (#1000) - #1015
Conversation
## Audit outcome Issue #1000 asked whether the lease tables (``pending_blob_refs``, ``gc_generations``) are still load-bearing or whether the snapshot-based ``repair_orphaned_blobs`` path has fully replaced them. Audit result: **leases are still load-bearing and intentionally retained.** Confirmed by tracing every caller of ``acquire_blob_leases`` / ``release_operation_leases``: - ``polylogue/archive/write_effects.py:commit_archive_write_effects`` acquires leases on a separate immediate-commit connection *before* the main archive write transaction commits, then releases them *after* the commit. This is the only call site outside ``blob_gc.py`` itself. - ``run_blob_gc`` in ``polylogue/storage/blob_gc.py`` enforces both ``_still_referenced`` (snapshot reference check against ``raw_conversations``) **and** ``_has_active_lease`` (in-flight operation check against ``pending_blob_refs``). The two checks cover different windows: 1. The snapshot check protects blobs already referenced by a committed archive row. 2. The lease check protects blobs the write path has materialized but has not yet inserted into ``raw_conversations``. Removing the lease tables would re-open the exact race the design was added to close: a GC pass running between blob materialization and the corresponding ``raw_conversations`` write would misclassify the blob as orphan and delete it. ## Documentation changes - ``docs/internals.md`` — added a "GC concurrency model — leases plus snapshot reference check" section under Blob Store Model that names the two invariants, calls out ``commit_archive_write_effects`` as the sole external caller, and explains why removal would reintroduce the race. - ``polylogue/storage/blob_gc.py::acquire_blob_leases`` — docstring now cites #1000 and points at ``docs/internals.md`` so the rationale lives next to the code. - ``AGENTS.md`` — auto-rendered. No behavioural changes. The audit was the entire scope. Closes #1000 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR documents the blob garbage-collection concurrency model across three files: a new subsection in internals documentation explains the two-part safety checks (DB snapshot reference plus pending lease check) and why lease tables are retained; the generated AGENTS manifest is updated to reflect this documentation; and the ChangesBlob GC Concurrency Model Documentation
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/internals.md`:
- Around line 175-179: The docs claim GC uses "previous generation plus
MIN_AGE_S" gating but the implementation in run_blob_gc() only applies a fixed
MIN_AGE_S filter; pick one consistent approach and update accordingly: either
(A) change run_blob_gc() to additionally consult gc_generations (compare each
candidate blob's generation timestamp or generation id against
gc_generations[shard] + MIN_AGE_S) so the code enforces the doc's
generation-based age gate, or (B) update the docs to state that eligibility is
determined solely by MIN_AGE_S and remove the "previous generation" wording;
reference gc_generations, MIN_AGE_S, and run_blob_gc() to locate the relevant
logic and make the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: e3d37825-9851-4dc0-aa2e-3322f6b8b3b4
📒 Files selected for processing (3)
AGENTS.mddocs/internals.mdpolylogue/storage/blob_gc.py
| `gc_generations` tracks the high-water mark of completed GC runs. The | ||
| "defense-in-depth" age check requires candidate blobs to be older than | ||
| the previous generation plus `MIN_AGE_S` so that a brand-new blob is | ||
| never considered for deletion within the same GC run cycle that | ||
| created it. |
There was a problem hiding this comment.
Generation-based age-gating claim does not match current GC implementation.
The new section says eligibility is based on “previous generation plus MIN_AGE_S”, but run_blob_gc() currently filters only by a fixed MIN_AGE_S threshold and does not use generation timestamps for candidate age decisions. Please align docs and code so the audited contract is exact.
Proposed doc-only alignment (if behavior is unchanged)
-`gc_generations` tracks the high-water mark of completed GC runs. The
-"defense-in-depth" age check requires candidate blobs to be older than
-the previous generation plus `MIN_AGE_S` so that a brand-new blob is
-never considered for deletion within the same GC run cycle that
-created it.
+`gc_generations` tracks completed GC runs. Candidate selection currently
+applies a fixed minimum age threshold (`MIN_AGE_S`) before lease/reference
+checks. If generation-relative age gating is introduced, this section should
+be updated to describe that behavior explicitly.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| `gc_generations` tracks the high-water mark of completed GC runs. The | |
| "defense-in-depth" age check requires candidate blobs to be older than | |
| the previous generation plus `MIN_AGE_S` so that a brand-new blob is | |
| never considered for deletion within the same GC run cycle that | |
| created it. | |
| `gc_generations` tracks completed GC runs. Candidate selection currently | |
| applies a fixed minimum age threshold (`MIN_AGE_S`) before lease/reference | |
| checks. If generation-relative age gating is introduced, this section should | |
| be updated to describe that behavior explicitly. |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/internals.md` around lines 175 - 179, The docs claim GC uses "previous
generation plus MIN_AGE_S" gating but the implementation in run_blob_gc() only
applies a fixed MIN_AGE_S filter; pick one consistent approach and update
accordingly: either (A) change run_blob_gc() to additionally consult
gc_generations (compare each candidate blob's generation timestamp or generation
id against gc_generations[shard] + MIN_AGE_S) so the code enforces the doc's
generation-based age gate, or (B) update the docs to state that eligibility is
determined solely by MIN_AGE_S and remove the "previous generation" wording;
reference gc_generations, MIN_AGE_S, and run_blob_gc() to locate the relevant
logic and make the change.
There was a problem hiding this comment.
Pull request overview
This audit-only PR documents why blob-GC lease tables (pending_blob_refs, gc_generations) remain necessary alongside the snapshot-based reference check, and adds a pointer from acquire_blob_leases() to the new internal documentation.
Changes:
- Expanded
acquire_blob_leases()docstring to capture the rationale (Issue #1000) and link to internal docs. - Added a new “GC concurrency model — leases plus snapshot reference check” section to
docs/internals.md. - Re-rendered the same documentation into
AGENTS.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| polylogue/storage/blob_gc.py | Docstring update explaining the lease-vs-snapshot concurrency window and linking to internals docs. |
| docs/internals.md | New internal documentation section describing GC safety invariants and why leases are retained. |
| AGENTS.md | Auto-rendered copy of the updated internals documentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| `gc_generations` tracks the high-water mark of completed GC runs. The | ||
| "defense-in-depth" age check requires candidate blobs to be older than | ||
| the previous generation plus `MIN_AGE_S` so that a brand-new blob is | ||
| never considered for deletion within the same GC run cycle that | ||
| created it. |
| "defense-in-depth" age check requires candidate blobs to be older than | ||
| the previous generation plus `MIN_AGE_S` so that a brand-new blob is | ||
| never considered for deletion within the same GC run cycle that | ||
| created it. |
| 1. **DB reference check** — `_still_referenced` queries | ||
| `raw_conversations` for the blob's `raw_id`. If a raw record points at | ||
| the blob, GC skips it. This is the snapshot/mark-and-sweep view of | ||
| "this blob is in active use right now." |
| 1. **DB reference check** — `_still_referenced` queries | ||
| `raw_conversations` for the blob's `raw_id`. If a raw record points at | ||
| the blob, GC skips it. This is the snapshot/mark-and-sweep view of | ||
| "this blob is in active use right now." |
Summary
Closes #1000. Audit-only PR. Confirms the lease tables (
pending_blob_refs,gc_generations) are still load-bearing and documents why they coexist with the snapshot-based_still_referencedcheck.Audit outcome
Issue #1000 asked whether the lease design has been superseded by the snapshot check. Tracing every external caller of
acquire_blob_leases/release_operation_leasesshows:polylogue/archive/write_effects.py::commit_archive_write_effectsis the only external caller. It acquires leases on a separate immediate-commit connection before the main archive write transaction commits, then releases them after the commit.run_blob_gcenforces both_still_referenced(snapshot reference check againstraw_conversations) and_has_active_lease(in-flight operation check againstpending_blob_refs).The two checks cover different windows: the snapshot check covers blobs already referenced by a committed archive row; the lease check covers blobs the write path has materialized but has not yet inserted into
raw_conversations. Removing the lease tables would re-open the exact race the design was added to close.Solution
docs/internals.md— new "GC concurrency model — leases plus snapshot reference check" section under Blob Store Model.polylogue/storage/blob_gc.py::acquire_blob_leases— docstring cites chore(storage): audit blob GC lease design (pending_blob_refs / gc_generations) for retention #1000 and points at the new docs section so the rationale lives next to the code.AGENTS.md— auto-rendered.No behavioural changes. The audit was the entire scope; no half-removal — either keep the tables and document them, or remove them. This PR keeps and documents.
Verification
nix develop -c devtools verify --quick→ all checks passed.Summary by CodeRabbit