Skip to content

feat(reporting): opt-in compaction of superseded snapshot revision content - #3200

Merged
bokelley merged 1 commit into
mainfrom
bokelley/reporting-snapshot-compaction
Oct 11, 2026
Merged

bokelley merged 1 commit into
mainfrom
bokelley/reporting-snapshot-compaction

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in compaction of superseded snapshot revision content, as permitted by adcontextprotocol/adcp#8100 (reporting-revision.json content_retention). Off by default; do not enable in production before the next eligible minor after November 20, 2026 (documented in the guides and the option's TSDoc).

  • PostgresReportingLedgerStore.compactSupersededSnapshots({ statusRetentionDays, automatedRecoveryWindowSeconds, limit?, maxFeedHoldDays?, account_id?, signal? }).
  • Options: maintenance: { compaction: { enabled: true; limit? } } on createReliableReportingService, and compaction: { enabled: true; limit? } on createPostgresReliableReportingProductionService. Both reuse the service's statusRetentionDays and automatedRecoveryWindowSeconds. New maintenance task: snapshot compaction.

What is compacted

A snapshot is compacted only when: a later revision supersedes it and it is not the revision the current revision supersedes (so current and official revisions are never touched); its grace of max(automatedRecoveryWindowSeconds, 3600) s since the successor's created_at has passed; no caller is owed it (any caller's receipt in any status, or current received / unreadable / content_mismatch statement, while the window of statusRetentionDays from the successor's created_at is open); it has rows; and there is no live obligation lease, pending materialization of it, or unread live feed consumer for its change row.

Only row content is dropped; headers, manifests and metadata listings stay. The row set becomes pruned, so exact reads give the existing ROWS_EXPIRED -> nondisclosing REFERENCE_NOT_FOUND. A revision that is owed but unreadable still answers SERVICE_UNAVAILABLE.

Safety

Same three resumable phases as retirement: eligibility re-check plus pruning mark in one statement under the account lock (so no new revision can share its chunks), fenced external object deletes via the existing path skipping any object a non-pruned row set still references, then chunk manifest / unreferenced PostgreSQL body removal and pruned. A crash after phase 1 resumes on the next pass.

Interpretations

  • The obligation is the logical slice; its revisions form one supersession chain.
  • (d) pins hold only while the revision's window (statusRetentionDays from its successor's created_at) is open; (b) always holds while the current revision names it (stricter than the minimum).
  • No change-feed row is recorded for compaction (metadata is unchanged; unread consumers hold compaction back instead).
  • Zero-row revisions are skipped (nothing to reclaim; an empty read stays correct).
  • listRevisions (which hydrates rows) now omits compacted revisions rather than failing; listRevisionMetadata lists all.

Testing

New PG suite test/lib/reporting-snapshot-compaction-pg.test.js (added to the CI PG list): five-snapshot chain, grace and recovery-window math, official/current never compacted, receipt and statement pins across callers and window lapse, shared chunks (object and PostgreSQL bindings), filesystem object deletes, crash/resume, provider failure, owed-but-lost content, lease/materialization/feed holds, default-off and maintenance wiring. Existing retention, core-maintenance, row-storage and ledger PG suites pass.

🤖 Generated with Claude Code

…ntent

Implements the compaction adcontextprotocol/adcp#8100 permits: drops row
content of superseded snapshots no caller is owed, keeping every revision's
metadata. Off by default; reuses retirement's resumable, fenced deletes.

Co-Authored-By: Claude Sonnet <[email protected]>
@bokelley
bokelley enabled auto-merge (squash) October 11, 2026 10:31

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Approve

Approve — opt-in snapshot compaction for the Postgres reporting ledger, no blocking findings.

Checked:

  • compactSupersededSnapshots mirrors retirement's resumable three-phase delete narrowed to one revision; eligibility CTE (postgres.ts L260-325) is fail-closed — only superseded snapshots past max(grace,3600)s, never the current revision's predecessor, excluded while owed by any caller's receipt/current statement, and respects the full lease/materialization/feed-consumer hold set.
  • Phase-2 shared-object guard (L417-423) keeps byte-identical shared chunks until the last referencing revision is compacted; resume arm excludes tombstoned obligations so it won't collide with retirement's own pruning marks (L1754); binding.rows.length === 0 handles the retirement-wins-the-race case.
  • Changeset present and correctly typed minor for the new src/lib/** surface (satisfies changeset-vs-wire-impact).
  • 592-line PG integration test covers grace boundary, official/current protection, per-caller owed holds, shared-chunk/PG-body survival, crash resume, failed-delete retry, owed-but-lost → SERVICE_UNAVAILABLE, and maintenance wiring.

Decision table: no critical/high/medium findings; gated_paths false; high_risk false; no team gate; no prior decision. Note review_decision is REVIEW_REQUIRED but gated_paths is false, so row 2 does not fire. Falls through to row 9 → approve.

@bokelley
bokelley merged commit 925a880 into main Oct 11, 2026
42 checks passed
@bokelley
bokelley deleted the bokelley/reporting-snapshot-compaction branch October 11, 2026 10:41
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