Skip to content

[PR] fix(storage): report actual session cleanup ownership - #6622

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-13_cleanup-accounting
Nov 14, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-13_cleanup-accounting

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #6620.

The session-maintenance CLI reports rows and bytes released by deletion, but its accounting currently confuses references with owners, includes pinned survivors, and counts Unicode characters as bytes. This can understate reclaimable content or claim that retained checkpoint bytes were freed.

Changes

  • Count each reference released by deleteSession() per content hash with UNION ALL. Several references owned by one session can release the same blob; a pinned checkpoint contributes zero releases and continues to keep its blob alive. Report each reclaimed blob once.
  • Count inline JSON as UTF-8 bytes and include orphans_json, alongside the existing session JSON, block payload and extension fields.
  • Include session, conversation-binding and reclaimed CAS rows in the CLI total. Treat pinnedCheckpoints as a subset of checkpoint rows and subtract the surviving rows exactly once.
  • Clarify the internal statistics fields and their ownership contract. The deletion transaction and CLI JSON field names remain unchanged.

Observable correction

These values come from real SQLite fixtures and actual deletion, not mocked query results:

Case Previous report Actual result / corrected report
Two unpinned checkpoints sharing one session-owned blob 0 reclaimable bytes 34 bytes
One pinned checkpoint 18 reclaimable bytes 0 bytes; checkpoint survives
Messages, repeated media, paired block views and CCR entries 278 reclaimable CAS bytes 370 bytes
Unicode inline JSON, extension and orphan content 207 inline bytes 298 bytes
Full CLI removal with pinned/unpinned checkpoints 15 released rows 21 rows

Logical payload-byte accounting is separate from physical database shrinkage. The existing indexDbBefore, indexDbAfter and vacuum result continue to report that separately; this does not promise immediate file-size reduction.

Validation

  • Eight new real SQLite/CLI cases: 5 fail and 3 pass on the original base; all 8 pass after the fix.
  • Compatibility controls cover another session retaining shared content, mixed pinned/unpinned references to the same hash, missing sessions and statistics remaining read-only.
  • The integrated CLI test compares reported rows and logical bytes with before/after database contents and confirms that the pinned checkpoint survives.
  • New cases plus maintenance, archive/GC, replica, media and archive-refcount suites: 32 passed.
  • Typecheck, complete build, unused-export guard, test-import-graph guard and git diff --check pass.
  • Independent review traced the query through the actual per-reference release and scoped collection paths, and checked pinned-row subtraction and UTF-8 accounting.

No configuration, schema/version, kernel or persistence-format changes. Current-head remote CI is a separate check after publication.

@ranxianglei ranxianglei changed the title fix(storage): report actual session cleanup ownership [PR] fix(storage): report actual session cleanup ownership Nov 13, 2026
@ranxianglei
ranxianglei merged commit b09116f into ranxianglei:master Nov 14, 2026
43 of 48 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner

Superseded by #6677 (merged as 3858b6956, 2026-11-14).

Landed into master via the real merge commit b09116f9393 (Merge Afloat16/2026-11-13_cleanup-accounting (PR #6622)), so your original commits are preserved verbatim in master history — only hashes of the batch wrapper changed, your authorship and commit messages are intact.

The fix for #6620 is now in master. Closing this PR as superseded — thanks for the careful, well-tested fix.

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.

Session cleanup reports incorrect released rows and CAS bytes

2 participants