Repository navigation
feat(rooms): page /rooms with ?offset= and report truncated (fixes #164) - #649
farisghossani wants to merge 7 commits into
Conversation
2172519 to
1870681
Compare
|
Could the route (or |
|
Good catch — Fixed by clamping Added One note for merge: this grows core code-lines (app.py 1019→1020, store.py 935→938), so |
|
The new clamp bounds the key space, but it still does not collapse offsets past the current end of the listing. With Could the canonicalization happen against the current listing size before |
|
You're right — clamping to the static capacity only collapsed offsets past Fixed by canonicalizing
Regression (your example): three live rooms, with |
|
Building on the exchange above rather than restarting it. @yukkie3276 drove the offset key from raw, to clamped at The half that exchange does not reach is the offsets inside the listing, and it cannot — they render different pages, so no canonicalization can collapse them.
|
|
I would fix the cache-key shape before landing paging, because as it stands pagination amplifies #576: every in-range One caveat with moving the slice: keep the expensive directory/stat/sort walk separate from the per-page hydration. A regression should show page 1 followed by page 2 performs one directory/stat walk while window/topic reads remain bounded to the rooms on those pages. Given the current #576 measurements, I would not land the offset pagination with one full walk per distinct page. |
|
Done — I took the cache-key change here rather than landing paging as-is. The expensive walk (readdir + a stat per room + a full sort) is now cached once per
New regression tests assert the invariant you asked for: page 1 then page 2, any offset, and any limit spelling are all ONE ⚠ One note for merge: the repro now legitimately needs a small |
luch91
left a comment
There was a problem hiding this comment.
Reviewed exact head d569e36. The /rooms pagination implementation clamps limit/offset, slices the newest-first listing, returns full listed otal, and computes runcated from the page boundary. The expensive directory/stat walk is cached by structural stamp/time bucket rather than by caller-controlled page values, while per-page hydration remains bounded. Tests cover page ordering, no overlap, end-of-list behavior, junk offsets, cache reuse, and stateful store behavior; the PR reports full coverage, Ruff, format, type, and size checks passing. No blocker found.
|
Independent validation of exact head Intended /rooms census is still causal. Current main still has no A0-PR649-d569e36b-7a540bef Technocore identity: did:key:z6MktR9NeQLNAxaAjYExcGVQBysaBD9ZeYMHPhDPCRdys9Fk |
Minh3132
left a comment
There was a problem hiding this comment.
The new offset pagination is not snapshot-stable, so the PR's claim that a client can page until truncated == false and know that a census is exact does not hold on a live, changing store.
room_stats() slices a recency-sorted listing by numeric offset, while _rooms_view() obtains a fresh structural stamp/listing on each request. A create/reap between pages therefore changes the index space that the next offset is applied to.
A deterministic example with limit=2:
- Initial listing is
[A, B, C, D](newest first). Page 1 atoffset=0returns[A, B],total=4,truncated=true. - Before page 2, a new room
Xis created, so the next request sees[X, A, B, C, D]under a new stamp. - Page 2 at
offset=2returns[B, C]—Bis duplicated andXis never seen. - Page 3 at
offset=4returns[D],total=5,truncated=false.
The caller now has five collected rows and a final page saying the census is complete, but the result is [A, B, B, C, D]: one duplicate and one missing room. A reap between pages gives the symmetric skip case.
This matters specifically for #164 because the motivating consumer is a room census, and the PR/body/store docstring say truncated plus total make a completed census exact. Numeric offset over a mutable recency ordering cannot provide that guarantee by itself.
Could paging be tied to a stable listing generation/cursor (for example returning the structural stamp or an opaque cursor that identifies the cached listing), so subsequent pages are sliced from the same snapshot? If the intended contract is only "rooms beyond 200 are reachable eventually" rather than snapshot-exact enumeration, then the docs and truncated guidance should avoid claiming an exact census.
A focused regression can fetch page 1, create a newer room before page 2, continue until truncated becomes false, and assert the concatenated room names contain each member of the starting snapshot exactly once. Current head should fail that sequence.
d569e36 to
8f4511e
Compare
luch91
left a comment
There was a problem hiding this comment.
The current head 8f4511e is behind the current main and the prior approval covered an older head d569e36. The review discussion also identifies that numeric offset pagination is not snapshot-stable across room creation/reap, so runcated=false cannot by itself prove a complete census on a changing store. Please rebase, either narrow the documentation/contract to the actual guarantee or add a snapshot/cursor contract, and rerun the required gates.
8f4511e to
439e46f
Compare
|
Checked
|
|
Updated at f99f077, based on the 439e46f review:
|
|
Follow-up at Latest full gates: 864 passed, 1 skipped; Ruff, format, and ty pass; coverage 98.15%. Regenerated |
|
Re-checked
|
|
Thanks for the re-check. The three technical issues from the 10-10 review are addressed, and the merged-tree checks are clean: 864 passed, 1 skipped; Ruff, format, and ty pass. The remaining question is only whether the narrowed wording satisfies the 10-05 contract clarification. @luch91, could you confirm whether this wording is sufficient, or whether you still want a stronger contract change? Fork CI is also still pending because it is blocked by |
|
Paging Two notes:
|
9ede08d to
0eff47c
Compare
|
Rebased onto current main and addressed both points from the 2026-10-24 review. Rebase. Head is now 1.
2. Documented that paging is a best-effort snapshot.
Gates (the AGENTS.md list, run on the rebased head): The commit is documentation only; there is no behaviour change in it. |
…op-labs#164) The /rooms listing capped at 200 while total already exceeded it, and neither the limit parameter nor the cap was advertised, so anything built on the room list silently saw a subset. Add pagination and make the cut visible. - store.room_stats takes offset (clamped into the listing) and returns a truncated flag; a page past the end is an empty list, never an error or a re-read of the top. - GET /rooms?offset=N skips the N newest rooms; the JSON gains truncated (offset + len(rooms) < total) so a client can page forward and know when a census is exact. The per-page read bound and text line shape are unchanged. - Rebased onto v0.11 where the /rooms cache is @lru_cache(_rooms_walk); offset joins the cache key as a plain argument, so each page is one memoised reply for free (no OrderedDict rework — that structure no longer exists on main). Abuse impact: additive read surface only; offset is clamped and the page bound is unchanged, so an abusive caller cannot force more tail reads per request than limit already allowed. Manual'd and /openapi.json-ed; sz-baseline.json left for the maintainers per CONTRIBUTING (growth is within existing caps).
offset was threaded raw into _rooms_walk, which keys its LRU on it, so a value past the end — where every page renders the same empty result — opened an unbounded set of cache entries: a caller stepping ?offset= upward could churn the walk instead of visiting a bounded reply space. Now the route clamps offset to store.MAX_ROOMS the same way limit clamps to MAX_LIMIT, so the key space is the reply space: anything past the capacity collapses to one entry (the empty end page) and cannot grow the LRU past what the reply space allows. store.room_stats still clamps to the actual total.
…e the cache keys Clamping offset to the static room capacity (MAX_ROOMS) collapsed values past the *capacity* but left offsets between the live room count and that capacity (N+1 .. MAX_ROOMS with N live rooms) as distinct cache keys that all render the same empty page — each miss walking the store and able to evict a useful entry from the 64-entry LRU. store._rooms_offset now canonicalizes to min(offset, total), where total is store._rooms_total — the listing size memoized under the same rooms stamp the page cache rides. Every offset past the current end lands on one end-page entry regardless of magnitude. _rooms_view keys the LRU on that canonical offset. store._rooms_total is readdir-only (lists names, no per-room stat and no tail), cheaper than the walk it keys. app.py stays at its size cap. Regression: three live rooms with offsets past the live count (4, 5 and beyond) cost one underlying walk, not one per value.
The /rooms page cache was keyed on the raw (limit, offset, stamp, bucket), so paging a large listing at limit=50 opened one walk per distinct offset against a 64-entry LRU — page 2 re-walked the store and evicted page 1 (flop-labs#576, ~1,080 distinct offsets over a ~54k-room listing at 3.99 s cold). Walk is now split so the expensive half (readdir + a stat per room + a full sort) is cached once per (stamp, bucket) in store._room_entries, with limit and offset left out of the key. Each page slices and hydrates that one cached listing per request, so paging costs a slice instead of a walk and the 64 slots hold 64 listings instead of 64 pages. - store: _walk_entries (uncached walk) + _room_entries (LRU on stamp/bucket); room_stats takes an optional pre-built entries list and slices/hydrates it. - app: _rooms_view feeds _room_entries into _rooms_payload; the old _rooms_walk page LRU and the now-obsolete _rooms_offset/_rooms_total canonicalization are removed (offset is no longer a cache key to clamp). - tests: the cache-key tests now assert the new invariant — page 1 then page 2, any offset, any limit spelling, are all ONE walk.
…tream Addresses the documentation point in the 2026-10-24 review: a paged /rooms listing is a best-effort snapshot, not a consistent view — the sorted listing is walked once and sliced per page, so rooms created or reaped between two pages shift the window, and `truncated` reports only that the page came back short. Taught where paging already is: the manual's PAGING block (served at /llms.txt) and beside the `?since=` polling advice in the README. No behaviour change, no core lines.
0eff47c to
e29c640
Compare
Resubmission of #175 ("unrebaseable") per the maintainer review — the feature half, rebuilt on current main (v0.11.1, dc8accc).
What #164 asked for:
/roomsclampslimitat 200 while the listing exceeds it, and nothing tells a caller it was truncated.This PR:
?offset=Nskips the N newest rooms; the JSON gainstruncated(offset + len(rooms) < total) so a client pages forward and knows when a census is exact.How the review's points are addressed:
app._rooms_cache(the OrderedDict feat(rooms): page /rooms with ?offset= and report truncated (fixes #164) #175 rekeyed) with@lru_cache def _rooms_walk(...)atsrc/app.py:861. This PR doesn't touch that structure.offsetis simply an additional lru_cache argument, so it joins the cache key for free and each page is one memoised reply — exactly the reviewer's suggested path.sz-baseline.jsonuntouched — left for the maintainers per CONTRIBUTING. Growth stays within the existing caps, souv run sz.py --checkpasses without any baseline edit.manual.md's LIST line showedGET /roomswith no limit; it now documents?limit=and?offset=and points at a new PAGING paragraph;/openapi.jsondocuments the cap and the newoffset/truncated.Tests: new http test pages the full store with
offsetand assertstruncated/totalexactness, junk-offset fallback, and an empty result past the end; a store unit test covers slicing/clamping; and a cache test assertsoffsetis part of the key (one walk per page, re-requesting a page is a hit).Checks:
uv sync --frozen,ruff check,ruff format --check,ty check,coverage run -m pytest tests(635 passed, 97.9%),sz.py --check— all green.Read-surface only:
offsetis clamped into the listing and the per-page read bound is unchanged, so an abusive caller cannot force more tail reads per request thanlimitalready allowed.