Skip to content

[PR] fix(gc): retain sessions when companion metadata is unreadable - #7298

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-19_gc-companion-metadata-errors
Nov 21, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-19_gc-companion-metadata-errors

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #7297

What and why

A failed stat() on a session's content-store companion is currently treated as absence. GC can therefore omit that companion from the token-size gate, delete its session, and then delete the now-orphaned originals when the transient metadata error clears. Existing-but-unsupported companion types also incorrectly pass as absent.

Only ENOENT now permits the no-companion path. Other errors and non-file results retain the owner before any resident-session removal or unlink, so the orphan sweep still sees its reference. The sweep continues to process independent eligible sessions and logs why this session was kept.

Validation

  • Three regressions inject only the first companion metadata failure (EIO, EACCES, ELOOP) while using real temporary session/companion files. All fail on the base: two sessions are removed instead of only the independent eligible one, and the original content is orphan-collected.
  • With the fix, both retained files remain byte-identical; bytesFreed includes only the independent eligible session and companionsRemoved stays zero.
  • A fourth regression uses a real directory at the companion path; the base deletes its session, while the fix preserves it and the directory's contents.
  • Complete tests/session-gc.test.ts: 30 passed, 0 failed, 0 skipped, including existing absent-companion, normal co-deletion, token-size, surviving-twin, encrypted-file, resident/pending-save and request-path cases.
  • Typecheck, production build and dist guards, unused-export check, architecture check, and git diff --check pass.
  • Independent review checked both the deletion and orphan passes, including the restored stat call after a transient failure.

Validated on Linux / Node.js 24.22.3 against 6453feeeb842bd1e471d875bf00287e5036a96c7 (0.1.216) with both standard test-isolation preloads. The full repository regression verdict remains the remote CI on this PR's head.

Scope

This restores the existing retain-unreadable-data policy. The opt-in, age and token thresholds are unchanged. There is no kernel, persisted-format, wire or model-facing-text change. The earlier #6143 fixes malformed parsed records, while this change handles metadata failure before a companion can be read.

@ranxianglei ranxianglei changed the title fix(gc): retain sessions when companion metadata is unreadable [PR] fix(gc): retain sessions when companion metadata is unreadable Nov 19, 2026
@ranxianglei
ranxianglei merged commit 037a8d9 into ranxianglei:master Nov 21, 2026
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Session GC treats failed companion stat as absence and can delete originals

2 participants