Skip to content

Commit 6bd98a7

Browse files
authored
read_group_chat: keep the room-wide discount when a room's booking list is shorter than its count (#3047)
Fixes #3046 Written-by: FlyBot Dev-1 Claim-Id: 19c62a2ad22441e8a041b2d48f5bc158 Owner: Dev-1 Reviewer: Birfy Base: ab3604d Pushed head: 8497122 Tree: 3120734 Verified commit: ca1d3ba0405f1384b1e3042960f0aebd51601fa0 (local, not on the remote — the verifiable anchor is `Tree:`) Tier: T2 ## What changed `read_group_chat`'s `newest N of TOTAL` discounted only the bookings `room.reservedSeqs` names. A room that kept only its booking count (the shape #3037 already fell back on) and recorded one number afterwards carries a list shorter than `room.reserved`, so the read trusted a list that cannot place the room: the recorded numbers below the reader's floor were added back, the unrecorded bookings were counted as lines, and a window holding 196 lines read `newest 30 of 206`. A list shorter than the count now reads as unknown (`below = 0`) and keeps the room-wide discount — the same fallback an older room with no list at all already had. A room whose list covers its count keeps the per-booking arithmetic #3039 introduced, and a room with no floor booking is unchanged. Six files, +51/−4: - `core/src/host/groups.js` (+8/−1) - `core/test/read-group-total-below-floor.test.js` (+17, one RED case, alongside the #3039 cases) - `docs/subsystems/core-host.md` (one sentence, plus `core/test/read-group-total-below-floor.test.js` in the section's "Covered by" list) - `patches/ds-bot/0012-room-membership.patch` (regenerated) - `patches/ds-bot/files/test/read-group-total-below-floor.test.js` (mirror) - `changelog.d/3046-room-short-booking-list.fixed.md` ### 0012 was regenerated on the new live main `node scripts/ds-bot-patches.mjs generate` ran **on the new live main `ab3604de`, not on `c5d96d38`**: this branch's base already contains #3039, so regenerating on the old base would have carried that merge into `0012` a second time. `patches/ds-bot/0012-room-membership.patch` went 2713 → 2719 lines and `patches/ds-bot/files/test/read-group-total-below-floor.test.js` 107 → 124 lines; the regenerated `0012` carries only this change. `git status` after `generate` lists only the files above, `patch check` and `canonical` are both green. ## Red first, twice, unchanged source `core/test/read-group-total-below-floor.test.js` at base `ab3604de` with only the new test case added (the source fix not applied), run twice; after normalising `duration_ms` and the random `/tmp/ds-bot-below-floor-*` path the two logs are byte-identical (`diff` empty): ``` not ok 4 - P-800: a booking list shorter than its count keeps the room-wide discount location: '.../core/test/read-group-total-below-floor.test.js:114:1' failureType: 'testCodeFailure' error: 'the list names ten bookings and the room counted fifteen, so its placements are unknown and the room-wide discount stays: Latest in "Ops" (newest 30 of 206, oldest first):' # tests 4 # pass 3 # fail 1 ``` The shape: `seq: 510`, `reserved: 15`, `reservedSeqs` = ten numbers at 31..40 (all below the reader's floor of 300), log keeps 50 lines at 451..500. The window 300..510 holds 196 lines; base answers 206. ## Ran ``` git rev-list --count ab3604d..HEAD # 1 TZ=UTC npm test (core suite) # 3230/3230 node --import ./test/harness-resolve.mjs --test \ test/read-group-total-below-floor.test.js # 4/4 # the eight room/group suites 108/108 node scripts/ds-bot-patches.mjs generate / check / canonical # green, no-op ARCH_DOCS_BASE=ab3604de938db1c4519a05b197a1349010dc38a8 npm run arch-docs # OK (6 changed file(s)) TZ=UTC npm run verify # exit 0 ``` One environment note, so the machine is not a mystery: this box has a real `pnpm` in `/usr/bin`, and `core/test/bench-preflight.test.js` drops every `PATH` directory that holds one — which on this box drops `/usr/bin` and with it `mkdir`. That test fails identically on the unmodified base `ab3604de` (6 pass / 1 fail, same `mkdir: not found`), so the `verify` above ran with a `PATH` that is the same box minus `pnpm`; there core is 3230/3230 and both plugin suites are green. CI has no `pnpm` there and is the machine that decides. ## Not run - `core/dev/bench.sh smoke … && node dev/smoke.mjs` — not run for this change. ## Checkpoint <!-- flybot:checkpoint --> { "pr": 3047, "claim": "Dev-1", "issue": 3046, "summary": "read_group_chat's newest N of TOTAL discounted only the bookings room.reservedSeqs names, so a room whose booking list is shorter than its reserved count trusted a list that cannot place it: a window holding 196 lines read newest 30 of 206. A list shorter than the count now reads as unknown and keeps the room-wide discount, the fallback an older room with no list already had. A room whose list covers its count keeps the per-booking arithmetic #3039 added, and a room with no floor booking is unchanged.", "files": [ "core/src/host/groups.js", "core/test/read-group-total-below-floor.test.js", "docs/subsystems/core-host.md", "patches/ds-bot/0012-room-membership.patch", "patches/ds-bot/files/test/read-group-total-below-floor.test.js", "changelog.d/3046-room-short-booking-list.fixed.md" ], "checks": { "ran": "TZ=UTC npm run verify", "result": "green", "at": "ca1d3ba0405f1384b1e3042960f0aebd51601fa0" }, "next": "none \u2014 ready for review" } <!-- /flybot:checkpoint -->
1 parent 4fae033 commit 6bd98a7

6 files changed

Lines changed: 51 additions & 4 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`read_group_chat`'s `newest N of M` no longer trusts a booking list shorter than the room's own count: a room that kept only its booking count and recorded one number afterwards reported fewer lines than its window holds (`newest 30 of 206` where 196 are there), because the unrecorded bookings were counted as if every one sat inside the window. Such a room's placements are unknown, so it keeps the room-wide discount. ([#3046](https://github.com/ThinkFlowLab/FlyBot/issues/3046))

‎core/src/host/groups.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,13 @@ export function install(rt) {
10621062
// carries only `room.reserved`, and keeps the room-wide discount it had.
10631063
const reserved = Math.max(0, Number(room.reserved) || 0)
10641064
const booked = Array.isArray(room.reservedSeqs) ? room.reservedSeqs : []
1065-
const below = Math.min(reserved, Math.max(0, from - 1), booked.filter(seq => Number(seq) < from).length)
1065+
// A list shorter than the count cannot place the room's bookings: a room that kept only its
1066+
// count and recorded one number afterwards names that one while `reserved` still counts them
1067+
// all, so the unrecorded ones must not be counted as if every one sat inside the window.
1068+
// Unknown keeps the room-wide discount (#3046).
1069+
const below = reserved > booked.length
1070+
? 0
1071+
: Math.min(reserved, Math.max(0, from - 1), booked.filter(seq => Number(seq) < from).length)
10661072
const dropped = Math.max(0, (room.seq ?? 0) - (room.log ?? []).length - reserved)
10671073
const total = kept.length + Math.max(0, dropped - Math.max(0, from - 1) + below)
10681074
const older = total - lines.length

‎core/test/read-group-total-below-floor.test.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,20 @@ test('P-707 guard: a room with no recorded booking numbers reads as it did befor
105105
assert.equal(shownLines(out).length, 30, 'the read shows the newest 30 lines of the window')
106106
assert.match(out, /^Latest in "Ops" \(newest 30 of 201, oldest first\):$/m, `no recorded numbers means the old room-wide discount: ${out.split('\n')[0]}`)
107107
})
108+
109+
// RED today (#3046): a room that took its bookings before the numbers were recorded keeps only the
110+
// count, and one booking recorded afterwards makes the list look authoritative while `reserved`
111+
// still counts them all. The ten recorded numbers sit below b's floor, so they are added back, and
112+
// only the five unrecorded bookings are discounted: 206 where the window holds 196 lines. A list
113+
// shorter than the count cannot place the room's bookings, so the room-wide discount stays instead.
114+
test('P-800: a booking list shorter than its count keeps the room-wide discount', async (t) => {
115+
const host = await start(t, lines(50, 451), {
116+
seq: 510,
117+
reserved: 15,
118+
reservedSeqs: [31, 32, 33, 34, 35, 36, 37, 38, 39, 40],
119+
participants: [seat('a', 0), seat('b', 300)],
120+
})
121+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
122+
assert.equal(shownLines(out).length, 30, 'the read shows the newest 30 lines of the window')
123+
assert.match(out, /^Latest in "Ops" \(newest 30 of 196, oldest first\):$/m, `the list names ten bookings and the room counted fifteen, so its placements are unknown and the room-wide discount stays: ${out.split('\n')[0]}`)
124+
})

‎docs/subsystems/core-host.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ has lines (#2790, `core/test/room-read-floor-clamp.test.js`).
434434

435435
### Group reads say what a cap left out (#2780)
436436

437-
- `read_group_chat` shows at most `ROOM_READ_MAX` (30) of the room lines visible to the caller, the newest ones, and the cut used to be silent: `Latest in "<room>" (oldest first):` printed as if those 30 were the whole log, so a Bot asked "didn't we decide X?" read a truncated log as the whole log — the same failure #1906 fixed for the own-chat read. The header now names the cut, `Latest in "<room>" (newest 30 of 45, oldest first):`, and a read that fits the cap stays byte-identical; lines before the member's `joinedSeq` are not counted as left out, and a room whose log was trimmed counts the lines it dropped (the store keeps only the newest `ROOM_LOG_MAX` lines, 60 here and 200 in `room-membership.js`, while `room.seq` keeps counting every line, so 500 lines said and 60 kept read `newest 30 of 500`). A share-seq reservation for a co-seat mention writes no line, so it does not move what the read calls the total: the reservation takes its number from `room.seq` — the receiver keys its one-bubble rule on that number, so a second counter would stamp the next line with the number the mention just went out with (#2863) — and `room.reserved` counts the numbers issued that never became a line here, which the read subtracts before it names a cut. Counting those numbers as lines read as a cap that had dropped them and grew the header by one per mention (#2855). A booking also does not count for a reader whose floor sits above it: `room.reserved` is room-wide, so subtracting every booking shrank a window that starts above them — a room at 510 with ten bookings below a floor of 300 kept 60 lines and read `newest 30 of 201`, where 300..510 are 211 lines. `takeLineSeq` keeps each booking's number in `room.reservedSeqs`, and the read discounts only the bookings at or above the caller's floor; a room saved before that list existed carries only the count and keeps the room-wide discount (#3037). Covered by `core/test/room-read-honest-count.test.js`, `core/test/room-read-trimmed-count.test.js` and `core/test/group-work.test.js`.
437+
- `read_group_chat` shows at most `ROOM_READ_MAX` (30) of the room lines visible to the caller, the newest ones, and the cut used to be silent: `Latest in "<room>" (oldest first):` printed as if those 30 were the whole log, so a Bot asked "didn't we decide X?" read a truncated log as the whole log — the same failure #1906 fixed for the own-chat read. The header now names the cut, `Latest in "<room>" (newest 30 of 45, oldest first):`, and a read that fits the cap stays byte-identical; lines before the member's `joinedSeq` are not counted as left out, and a room whose log was trimmed counts the lines it dropped (the store keeps only the newest `ROOM_LOG_MAX` lines, 60 here and 200 in `room-membership.js`, while `room.seq` keeps counting every line, so 500 lines said and 60 kept read `newest 30 of 500`). A share-seq reservation for a co-seat mention writes no line, so it does not move what the read calls the total: the reservation takes its number from `room.seq` — the receiver keys its one-bubble rule on that number, so a second counter would stamp the next line with the number the mention just went out with (#2863) — and `room.reserved` counts the numbers issued that never became a line here, which the read subtracts before it names a cut. Counting those numbers as lines read as a cap that had dropped them and grew the header by one per mention (#2855). A booking also does not count for a reader whose floor sits above it: `room.reserved` is room-wide, so subtracting every booking shrank a window that starts above them — a room at 510 with ten bookings below a floor of 300 kept 60 lines and read `newest 30 of 201`, where 300..510 are 211 lines. `takeLineSeq` keeps each booking's number in `room.reservedSeqs`, and the read discounts only the bookings at or above the caller's floor; a room saved before that list existed carries only the count and keeps the room-wide discount (#3037). The same fallback covers a room whose list is shorter than its count — `reserved > booked.length` — because only bookings taken after the list existed carry a number, so the room's placements are unknown and the read keeps the room-wide discount instead of trusting the partial list (#3046). Covered by `core/test/room-read-honest-count.test.js`, `core/test/room-read-trimmed-count.test.js`, `core/test/read-group-total-below-floor.test.js` and `core/test/group-work.test.js`.
438438

439439
### Chat anchors name their part (#2710)
440440

‎patches/ds-bot/0012-room-membership.patch‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,7 @@ diff --git a/src/host/groups.js b/src/host/groups.js
21182118
},
21192119
}))
21202120

2121-
@@ -539,8 +539,32 @@ export function install(rt) {
2121+
@@ -539,8 +539,38 @@ export function install(rt) {
21222122
const { room, error } = rt.pickRoom(args.group, self)
21232123
if (error) return error
21242124
ensureRoomLog(room)
@@ -2145,7 +2145,13 @@ diff --git a/src/host/groups.js b/src/host/groups.js
21452145
+ // carries only `room.reserved`, and keeps the room-wide discount it had.
21462146
+ const reserved = Math.max(0, Number(room.reserved) || 0)
21472147
+ const booked = Array.isArray(room.reservedSeqs) ? room.reservedSeqs : []
2148-
+ const below = Math.min(reserved, Math.max(0, from - 1), booked.filter(seq => Number(seq) < from).length)
2148+
+ // A list shorter than the count cannot place the room's bookings: a room that kept only its
2149+
+ // count and recorded one number afterwards names that one while `reserved` still counts them
2150+
+ // all, so the unrecorded ones must not be counted as if every one sat inside the window.
2151+
+ // Unknown keeps the room-wide discount (#3046).
2152+
+ const below = reserved > booked.length
2153+
+ ? 0
2154+
+ : Math.min(reserved, Math.max(0, from - 1), booked.filter(seq => Number(seq) < from).length)
21492155
+ const dropped = Math.max(0, (room.seq ?? 0) - (room.log ?? []).length - reserved)
21502156
+ const total = kept.length + Math.max(0, dropped - Math.max(0, from - 1) + below)
21512157
+ const older = total - lines.length

‎patches/ds-bot/files/test/read-group-total-below-floor.test.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,20 @@ test('P-707 guard: a room with no recorded booking numbers reads as it did befor
105105
assert.equal(shownLines(out).length, 30, 'the read shows the newest 30 lines of the window')
106106
assert.match(out, /^Latest in "Ops" \(newest 30 of 201, oldest first\):$/m, `no recorded numbers means the old room-wide discount: ${out.split('\n')[0]}`)
107107
})
108+
109+
// RED today (#3046): a room that took its bookings before the numbers were recorded keeps only the
110+
// count, and one booking recorded afterwards makes the list look authoritative while `reserved`
111+
// still counts them all. The ten recorded numbers sit below b's floor, so they are added back, and
112+
// only the five unrecorded bookings are discounted: 206 where the window holds 196 lines. A list
113+
// shorter than the count cannot place the room's bookings, so the room-wide discount stays instead.
114+
test('P-800: a booking list shorter than its count keeps the room-wide discount', async (t) => {
115+
const host = await start(t, lines(50, 451), {
116+
seq: 510,
117+
reserved: 15,
118+
reservedSeqs: [31, 32, 33, 34, 35, 36, 37, 38, 39, 40],
119+
participants: [seat('a', 0), seat('b', 300)],
120+
})
121+
const out = await host.tool('read_group_chat', { group: 'Ops' }, 'gb')
122+
assert.equal(shownLines(out).length, 30, 'the read shows the newest 30 lines of the window')
123+
assert.match(out, /^Latest in "Ops" \(newest 30 of 196, oldest first\):$/m, `the list names ten bookings and the room counted fifteen, so its placements are unknown and the room-wide discount stays: ${out.split('\n')[0]}`)
124+
})

0 commit comments

Comments
 (0)