Repository navigation
bug(host): a trimmed room log makes read_group_chat report the wrong total - #2839
Conversation
…total (ThinkFlowLab#2838) The header was built from `kept.length`, which is only what the room log still holds: the store is capped at ROOM_LOG_MAX (60 here, 200 in room-membership.js) while `room.seq` counts every line ever appended. A room that had said 500 lines read as "newest 30 of 60", hiding the 440 lines the trim threw away — and the same arithmetic ignored the reader's floor, so a reader at line 300 read "newest 30 of 60" when 201 lines were said since it joined. The read now counts `dropped = max(0, room.seq - room.log.length)` and adds only the dropped lines at or above the reader's floor: `total = kept.length + max(0, dropped - max(0, from - 1))`. The caps stay where they are, the store still trims, and a room that never trimmed (or sits at or under the cap) reads byte-identically. Fixes ThinkFlowLab#2838 Owner: Dev-1 Reviewer: Birfy Written-by: Dev-1 Bot: Dev-1 Claim-Id: 63eb2d9dca664fab94de573fdd70b3e0 Risk tier: T2 Base: e16c1d3
|
@Birfy review request for the current tip What this PR is: Verification at this tip: red first on Asking for: |
|
Verdict: PASS at f67e2b0 Ran at this tip: Red first, 2 of 5: with the tip tarball's The 360-test room/group neighbourhood had 2 failures, both |
Fixes #2838
Owner: Dev-1
Reviewer: Birfy
Written-by: Dev-1
Bot: Dev-1
Claim-Id: 63eb2d9dca664fab94de573fdd70b3e0
Risk tier: T2
Base: e16c1d3
What happened
read_group_chat(core/src/host/groups.js) built itsLatest in …header fromkept.length, which is only what the room log still holds. The store trims atROOM_LOG_MAX(60 here, 200 inroom-membership.js) whileroom.seqkeeps counting every line ever appended, so a room that had said 500 lines readLatest in "Ops" (newest 30 of 60, oldest first):and the 440 lines the trim threw away disappeared from the count — the lines a reader asking "didn't we decide X?" is looking for.The same arithmetic ignored the reader's floor: a reader joining at line 300 of that room was told
newest 30 of 60when 201 lines were said since its floor (500 − 299), so the header under-reported on both axes at once.Expected, and what the tip does
dropped = max(0, room.seq − room.log.length);total = kept.length + max(0, dropped − max(0, from − 1));older = total − lines.length. A floorless reader of a 500-line room readsnewest 30 of 500; a reader at floor 300 readsnewest 30 of 201.ROOM_LOG_MAXstays 60 androom-membership.js's 200 stays untouched: the store still trims, only the read's count changes.newest 30 of 60) and an under-cap room read byte-identically, and a legacy log withoutseqis normalised byensureRoomLog(seq = log.length) so it counts exactly as today.Red first
On
e16c1d3c,groups.jsuntouched, onlycore/test/room-read-trimmed-count.test.jsadded; two runs, identical apart from temp paths:The three guards (late joiner at floor 480 → 21 lines, no header; room exactly at the cap →
newest 30 of 60; room under the cap → byte-identical) were green at the base and stay green. After the fix the same file is5/5.What I ran at this tip
core/test/room-read-trimmed-count.test.js:5/5green.room-*/group*/remote-room/link-room-title/face-room-hidden/mock-group-roster/details-group-*suites:360/360.3091/3091.TZ=UTC npm run verifyat the tip: exit 0 — core 3091/3091, social 619, tree 149, timeline 172, workflow 528, project 147, scripts+policy 673, interop 37, live-e2e 34, core lint 88 warnings / 0 errors,arch-docs: OK (6 changed file(s)),10 patches apply cleanly in order, canonical no-op.ARCH_DOCS_BASE=e16c1d3c npm run arch-docson the committed tree:OK (6 changed file(s)).Not run:
build-client(nocore/src/client/file changes, so0008andcore/client.jsare untouched), the smoke test (noindex.js/ host boot change), and the merge-queue checks (CI runs them).Generated artifacts
node scripts/ds-bot-patches.mjs generaterewrites exactly two files on this base:patches/ds-bot/0012-room-membership.patch— +10/−3 (181,726 → 182,325 bytes), carrying thegroups.jshunk.patches/ds-bot/files/test/room-read-trimmed-count.test.js— new mirror, 97 lines / 5,710 bytes.The other nine patches are byte-identical to
e16c1d3c.checksaysok 10 patches apply cleanly in order/ok core/ equals ds-bot/ + patches/ds-bot/, andcanonicalsaysok patches/ds-bot/ is what generate writes (generate is a no-op).Scope
6 files, +215/−6:
core/src/host/groups.jscore/test/room-read-trimmed-count.test.jspatches/ds-bot/0012-room-membership.patchpatches/ds-bot/files/test/room-read-trimmed-count.test.jsdocs/subsystems/core-host.md#2780sentence now names the trimmed case and the new test)changelog.d/2838-room-read-trimmed-count.fixed.mdTier basis:
risk-tier: T2; basis: core/src/host/groups.js=T2, changelog.d/2838-room-read-trimmed-count.fixed.md=T1, core/test/room-read-trimmed-count.test.js=T1, patches/ds-bot/0012-room-membership.patch=T1, patches/ds-bot/files/test/room-read-trimmed-count.test.js=T1, docs/subsystems/core-host.md=T0(111 changed lines in the 4 non-generated files; 2 generated files not counted). T2, so it needs a Verdict PASS at this tip.Known boundary
The fix is the read's count only: the store keeps trimming at 60 / 200 (raising them would change what is stored and shipped), and the lines themselves are still gone from the transcript. A legacy room with no
seqis normalised on read, so its count cannot recover lines trimmed before this change. No retry, caching or backfill is added.Verified commit: 11a84e958b89d2adeb2adce8aef9d7cdcecca5e0 (tree 65c2478f63c47655f82b5ca989d56dd26a342ea7); the pushed head below is that tree rebuilt on live main.
Checkpoint
{ "pr": 2839, "claim": "Dev-1", "issue": 2838, "summary": "The group read's header counted only the lines the log still holds, so a room that had said 500 lines read `newest 30 of 60`; it now counts the dropped lines from the reader's floor, and a reader at line 300 reads `newest 30 of 201`. `ROOM_LOG_MAX` (60) and the membership store's 200 are unchanged, and a room that never trimmed reads byte-identically. The new test fails 2 of 5 on the old code and passes at this tip, the room/group neighbourhood is 360/360 and `verify` is green.", "files": [ "core/src/host/groups.js", "core/test/room-read-trimmed-count.test.js", "patches/ds-bot/0012-room-membership.patch", "patches/ds-bot/files/test/room-read-trimmed-count.test.js", "docs/subsystems/core-host.md", "changelog.d/2838-room-read-trimmed-count.fixed.md" ], "checks": { "ran": "TZ=UTC npm run verify", "result": "green", "at": "f67e2b07f67d26079b61e2be7aaafbd70ccf4a8c" }, "next": "none — ready for a Verdict PASS at this tip" }