Skip to content

fix(session): report native compaction ref count correctly - #1514

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
quifox:2026-09-27_fix-compaction-ref-log
Sep 27, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
quifox:2026-09-27_fix-compaction-ref-log

Conversation

@quifox

@quifox quifox commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Count surviving native-compaction refs with Object.keys(prunedByRaw).length instead of reading .length from a plain object.
  • Extend the existing compaction-archive fixture to assert the diagnostic reports the surviving ref count.

Fixes #1513

Verification

  • node --import tsx --test tests/compaction-archive.test.ts — 5 passed.
  • Regression check: with the old prunedByRaw.length expression restored temporarily, the new assertion fails as expected; restoring the fix returns the suite to 5/5.
  • Full npm ci / npm run typecheck / npm run build were not rerun locally because the WSL environment currently cannot reach the npm registry and the Docker Desktop backend is unavailable. No dependency or build configuration changes are included in this PR.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR review — verified clean, ready to merge (merge stays human-only per repo rules).

① Original issue (#1513) — direction check

Confirmed the bug at the source before reviewing the fix: src/session.ts:648-650 builds prunedByRaw as a plain Record<string, string>, and the diagnostic logged prunedByRaw.length → "pruned ref maps to undefined live raw id(s)". Pruning itself always worked; only the reported count was wrong. Your proposed direction (Object.keys(prunedByRaw).length + assertion in the fixture) fixes the producer of the bad bytes (the log statement itself) — root cause, not a mask.

② Regression review — existing behaviors on touched paths

Touched behavior Verdict
applyCompactionArchive state mutations (archive write, byRaw/byRef prune, boundary consumption, markDirty) Unchanged — diff touches only the string argument of the info-level log
Diagnostic log output Intended change (this fix): undefined → actual surviving count (e.g. 5) — flagged here as the behavior delta, nothing else drifts
tests/compaction-archive.test.ts helpers runShortenedTurn gains an optional log param defaulting to noLog — all other call sites byte-identical; existing assertions untouched
Config surface / wire shape / persistence / kernel pin Untouched. This is a local diagnostic log — never touches the wire, both compression modes unaffected

③ Code review

One-line fix at the decision point, correct API for counting object keys. Test change is minimal and idiomatic (optional param with default preserves the existing signature).

④ Test validity — independently reproduced

I did NOT just trust the PR description; I ran the counterfactual myself: temporarily restored the old prunedByRaw.length expression → the new assertion fails with exactly 'log reports the surviving ref count' (4/5 pass); restored the fix → 5/5. The assertion has teeth and pins the precise count (tail.length = 5), which also implicitly verifies every tail message holds a byRaw entry and no stray live ids survive. Not a tautology.

⑤ Local verification (the part missing from your WSL environment)

On branch head c452707f (exactly current master a1a9dba0 + 1 commit, 0 behind — no rebase needed):

  • npm ci — clean (390 packages)
  • npm run typecheck — clean
  • node --import tsx --test tests/compaction-archive.test.ts — 5/5 pass
  • Full npm test — 2961 pass / 0 fail / 12 skipped (skips are the default-gated e2e suites)
  • npm run build — success

⑥ Diff cleanliness & auto-merge gate (§7.4)

2 files, +6/-4, every line serves the PR's purpose — no generated/lockfile churn, no whitespace noise. All eight auto-merge gates hold: single-module scoped fix:, regression test reproduces the original bug, green on the rebased head, no config/wire/persistence/cross-repo changes, clean diff, Fixes #1513, and no load-bearing infra touched (the ref-map mutation logic itself is unchanged — only its log line).

结论:修复了 native compaction 诊断日志读取普通对象 .length 导致输出 undefined 的问题(改为 Object.keys().length),并补了有牙齿的回归断言;本地全量验证通过(typecheck / 2961 测试 / build 全绿,且独立复现了旧表达式会失败新断言),可以合并。

@quifox — welcome! Nice first contribution: minimal diff, correct root-cause targeting, and an honest verification section. The maintainer can merge whenever.

@ranxianglei

Copy link
Copy Markdown
Owner

Verified on a Linux host (your WSL couldn't reach npm, so these were run for you): full tests/compaction-archive.test.ts 5/5 pass, tsc --noEmit clean, and the mutation check — restoring the old prunedByRaw.length expression reddens exactly your new assertion, reverting returns 5/5.

Two things worth calling out: the assertion pins the exact surviving count (${tail.length}), which is stronger than a \d+ regex; and threading the logger through the existing runShortenedTurn helper (default noLog, zero churn for other callers) is the cleaner shape — a duplicate standalone mirror was the alternative.

A parallel fix (#1515) was opened independently before this one landed; it's being closed in favor of this PR (external contributions take precedence for identical fixes, and yours is the tighter diff). ✅ Ready to merge — Fixes #1513.

@ranxianglei

Copy link
Copy Markdown
Owner

Update: this fix just landed via #1515, which was merged about a minute before this PR's disposition — the src/session.ts change there is byte-identical to yours, and #1513 is now closed by it. Merging this on top would be an empty merge on the src side plus a duplicate test, so closing here instead.

To be explicit about what your contribution was worth: your diagnosis was exactly right, your one-line fix was independently verified correct (5/5 + typecheck + mutation-red), and your test shape — threading the logger through the existing runShortenedTurn helper with an exact-count assertion — was judged the tighter of the two. The race was purely chronological, not qualitative. Hope to see more from you — first-reports of the "log line looks wrong" kind that come with a root-cause analysis and a verified fix are exactly what this repo runs on. 🙏

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Confirmed both threads line up on our end:

  • fix: report the surviving raw-id count in the native-compaction boundary log #1515 verified closed in favor of this PR — its closing comment records the same rationale (identical independent fix, external PR takes precedence, tighter diff via the threaded logger + exact-count assertion). No orphaned work there.
  • The mutation check result matches ours exactly: old prunedByRaw.length → only the new assertion reddens; fix restored → 5/5. Two independent runs, same verdict.

Nothing else pending from review. Merge is yours to execute per repo rules — after it lands, Fixes #1513 auto-closes the original bug report and CI publishes nothing new (plain fix PR, no release branch involved).

结论:#1515 已确认按“外部贡献优先”关闭、无遗留工作;本 PR 双路验证一致(mutation check 均只红新断言),审查完毕,等待人工合并即可。

@ranxianglei ranxianglei reopened this Sep 27, 2026
@ranxianglei
ranxianglei merged commit 8c41b0e into ranxianglei:master Sep 27, 2026
24 checks passed
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.

Native compaction log reports undefined live ref count

2 participants