Repository navigation
fix(rooms): report occupancy over the population the cap refuses on - #309
mehmetacill112-cell wants to merge 1 commit into
Conversation
d4bd3ed to
053b1c5
Compare
Benchmarked the "adds no I/O" claim, since I had asserted it rather than measured it
Method. One store built at the caps (
Difference +0.49 ms (+2.1%). Welch t = 1.19 (df ≈ 11.5) — not significant at this n, What I am claiming, and what I am not. I am not claiming zero. I am claiming the cost is I have corrected the code comment accordingly — it previously said "Free: the walk is For reference, |
luch91
left a comment
There was a problem hiding this comment.
Request changes: the PR explicitly reports sz.py --caps failing with core/store.py two lines over its cap, while leaving the baseline unchanged. The submitted branch therefore fails a repository-required check. Please reduce the change or provide maintainer-approved cap/baseline handling and rerun the exact check.
`room_stats` drops unlisted rooms before it totals, because the listing beside that total names what it counts and a `p-` name is a bearer credential. `_check_room_capacity` does not: it scans every `*.jsonl` in the directory. Printed against each other the pair claims headroom on a store that is already refusing — technocore.chat serves # 50 of 8627 rooms (cap 10240, 125.7M of 5.0G stored), newest first while a new room gets `400 room limit reached (10240 is the cap)`. The `near capacity` badge on /humans never fires for the same reason, so the first sign of a full service is a stranger's write failing, which is the outcome that gauge exists to prevent. `service_stats` already states the rule this applies: "the room totals here count every room including unlisted ones: they are what bounds the disk and the room cap". /rooms is the surface that had not caught up. room_stats now counts every `*.jsonl` before the listability filter — inside the walk that already runs, so it costs nothing — and returns it as `occupied`. The byte half reuses `room_bytes_used`, the total the reaper writes across every room, falling back to the listed sum before a pass has run. `total` and `bytes` keep their present meaning: they describe the listing below, and changing that would break every reader. The head, the /humans stats line and its `near capacity` badge move to the new fields, and manifest.py gains them so /openapi.json stays true. An aggregate over unlisted rooms is not an enumeration: no `p-` name is exposed, and the note line under the same listing already publishes a global total over namespaces it does not name.
053b1c5 to
07714c1
Compare
Rebased onto
|
| check | result on 019b57a |
|---|---|
ruff check . / ruff format --check . |
pass (71 files) |
ty check |
pass |
pytest tests |
571 passed |
coverage report |
97.54% |
schemathesis (CI's exact --checks list, --phases examples,coverage,fuzzing) |
854 generated, 854 passed |
sz.py --caps |
fails: core_total 2250 > cap 2247 |
The regression still earns its place on the new base: with git checkout main -- src/,
test_room_occupancy_is_counted_over_the_population_the_cap_refuses_on and two
tests/http/test_rooms.py cases fail; with the fix, 119 pass.
Why I have not simply reduced it
Your review offers two remedies — reduce the change, or maintainer-approved baseline
handling. I do not think the first one exists here, and I would rather show the numbers
than assert that.
main's core budget currently has exactly zero headroom:
core/app.py 1020 + config.py 62 + didkey.py 57 + limit.py 183 + store.py 925 = 2247
core_total cap = 2247
That is not specific to this PR. As of 019b57a, any change that adds one core code
line fails --caps. It is also recent — the headroom was there two days ago and the last
two merges consumed it:
2026-08-31 core_sum=2247 cap=2247 headroom +0 (019b57a)
2026-08-30 core_sum=2244 cap=2244 headroom +0
2026-08-30 core_sum=2231 cap=2240 headroom +9
2026-08-30 core_sum=2229 cap=2240 headroom +11
2026-08-27 core_sum=2069 cap=2072 headroom +3
Per-file, core/store.py is fine: 928 against a cap of 933, five to spare. It is the
total that refuses.
So the three routes a contributor has are all closed:
- Raise the cap myself —
queue-guard.ymlfails any PR touchingsz-baseline.json,
correctly, since it is maintainer-regenerated. - Golf the three lines down — CONTRIBUTING: "No code golf. A low core line count is
a constraint, not a score — unreadability is a reject even when the line count goes
down." I can makeoccupied += 1disappear into anenumerateand fold two list
initialisers onto one line, and I think that trade is exactly what that rule forbids. - Scope the change down — dropping
bytes_occupiedleaves 2249, still over a cap
with zero headroom, and it removes the half that reuses the reaper's existing byte
total instead of paying for a second stat pass.
The change is three core code lines: the pre-filter increment, "occupied", and
"bytes_occupied". CONTRIBUTING's own guidance is "three lines over a useful primitive
is an easy yes; three hundred lines means either a new primitive is missing or the change
belongs in extra, not core."
That leaves the second remedy in your review, which is a maintainer call rather than
something I can push a commit for. @sv — the branch is green on 019b57a on every other
check and needs three lines of core budget.
If you would rather I open a separate dead-code-removal PR against core first — CONTRIBUTING
says removing dead code from core is a win on its own — I am happy to go looking for the
three lines somewhere they are not load-bearing, and let this one land on top of it. Say
which you prefer and I will do that instead of guessing.
|
I rechecked current head 07714c1. The reported regression and occupancy assertions remain, but the author confirms the exact required sz.py --caps gate still fails (core_total 2250 > cap 2247) on the rebased main. Until a maintainer resolves baseline/headroom policy or the implementation fits the cap without code-golf, I cannot approve this branch. The functional evidence is useful; the merge gate is still unresolved. |
What
/roomsprints a head that compares a listed figure against an all-rooms cap, so itreports headroom on a store that is already refusing new rooms. Live, right now:
16% apparent headroom, and the next room fails. The refusal body then points the caller at
GET /rooms, which is the listing that under-reports.Both halves have the same shape:
room_stats()runsif not _listable(name): continuebefore appending toentries, thenreturns
"total": len(entries)beside"capacity": MAX_ROOMS._check_room_capacity()takes its count from_scan(path.parent, ".jsonl", sized=True),which applies no
_listablefilter.So the head under-reports by exactly the unlisted (
p-) rooms. The byte half matches:"bytes": sum(e[1] for e in entries)is the listed sum, printed againstMAX_TOTAL_ROOM_BYTES, which the create path checks against_scan(...)[1].The
near capacitybadge on/humansnever fires for the same reason —Math.max(roomsView.total / roomsView.capacity, ...)— so the first sign of a full service isa stranger's write failing, which is the outcome that gauge exists to prevent:
This is an existing rule, applied to the surface that missed it
service_statsalready documents exactly the distinction this fixes:/statstherefore already publishestotal/listed/unlistedover every room./roomsis the surface that had not caught up — and it is the one an agent actually reads before
deciding whether to create a room.
The change
room_stats()counts every*.jsonlentry before the listability filter — the same populationthe cap check counts, inside the walk that already runs, so it adds no I/O — and returns it as
occupied. The byte half reusesroom_bytes_used(), the total the reaper already writes acrossevery room; it drifts by at most one reap interval, which is the trade
note_statsdocumentsmaking for a display gauge, and falls back to the listed sum when no pass has run yet.
totalandbyteskeep their present meaning — they describe the listing below, and changingthat would break every reader. The head, the
/humansstats line and itsnear capacitybadgemove to
occupied/bytes_occupied.manifest.pygains the two fields so/openapi.jsonstays true.
Compatibility
The
/roomstext head is reshaped, which is public API under the rule that "reordering orreshaping a line can break an agent even when all the same fields remain":
From a local instance carrying three
p-rooms among its fixtures — the gap between the twocounts is exactly those rooms, which is the whole point:
# 14 of 14 listed rooms (17 of 5120 slots used, 12.1K of 5.0G stored), newest firstTwo numbers now differ where one stood, so both need names;
listed roomsandslots usedare the shortest honest pair I found. If you would rather not move the line at all, the
minimal alternative is to keep the existing wording and swap only the values — but then the
head's own count disagrees with the listing printed underneath it, which is why I did not.
Happy to take it either way.
JSON is additive:
total,bytes,capacity,bytes_capacityare unchanged, and two keysare added.
Proposed release note:
Abuse impact
No new route, parameter, or persistent state — two counters on an existing response, both
already computed inside an existing walk. An aggregate over unlisted rooms is not an
enumeration: no
p-name is exposed, and no signal about them that the note line under thesame listing does not already expose about namespaces it declines to name.
service_statsdraws this line explicitly ("Counts of those same things are safe and are what an operator
actually watches") and this stays on the safe side of it.
Tests and checks
Rebased onto
7c4810d(#298, the rooms/notes sharding), and every check below was re-runagainst that base rather than carried over — the conflict was in
room_stats's walk, so thecounter now sits at the top of the
_walkloop the shard change introduced.Ran the CI set on Python 3.12.3 / uv 0.11.16:
uv run coverage run -m pytest tests -quv run ruff check .uv run ruff format --check .uv run ty checkuv run coverage reportsrc/store.py96.36%,src/app.py99.00%uv run sz.py --capsRegression tests, verified failing without the fix and passing with it:
tests/unit/test_store.py::test_room_occupancy_is_counted_over_the_population_the_cap_refuses_on— asserts
occupiedagainst the refusal itself rather than a fixed number: whatever countmakes the next room fail is the count the gauge has to print.
tests/http/test_rooms.py::test_rooms_overview_hides_private_rooms_and_survives_an_empty_store— a
p-room stays out of the listing and shows up in the gauge.tests/http/test_rooms.py::test_rooms_overview_carries_stats_newest_first— the head line.With
src/stashed, all three fail (KeyError: 'occupied'and the cap assertion); restored,the suite is green.
The one failing check:
sz.py --capscore_totallands exactly on its cap;core/store.pyis two over. The change costs threecode lines there — one counter increment and the two dict keys — against the single line of
headroom
maincurrently has (840 of 841). I got the cost down as far as I could withoutgolf, which
CONTRIBUTING.mdrejects outright:app.pyis unchanged at 981;entries = []line(
entries, occupied = [], 0), which saved one.Dropping the byte half would save one more and still breach by one, while leaving the same
bug in the other gauge — so I kept both halves rather than buy a line with a worse fix.
I deliberately did not touch
sz-baseline.json.sz.pydocuments the caps as a ratchetthat may only move down, and describes raising them as exactly the decision the mechanism
exists to force — that is yours to make, not a contributor's to absorb.
CONTRIBUTING.md's ownline-tradeoff rule reads to me like it covers this case ("three lines over a useful primitive
is an easy yes"), but I would rather show you the number than quietly widen the ceiling. If
you would prefer this land without moving a cap, say so and I will find three code lines to
retire in
store.pyin a separate change first.Not covered
The empty-listing branch still prints
(no rooms yet — ...)whentotalis 0, which readswrong on a store holding only unlisted rooms. Left alone deliberately: different sentence,
different job, and I did not want to guess at the wording you would want. The added HTTP test
pins the current behaviour so a later fix has to change it on purpose.
Closing the byte half exactly, rather than via the reaper's total, would mean statting unlisted
rooms in this walk — a stat per room back on the most polled read, against a gauge that
tolerates one reap interval of drift. The test documents that trade at the point it shows
(
bytes_occupied == 0on a store with only unlisted rooms and no reap pass yet).Related: #312 — the empty-listing sentence this PR deliberately leaves alone, filed as a
report rather than a patch because it is a wording call. No dependencies on other open
pull requests.