Repository navigation
perf(limit): thin the read footer so the CDN can share the reply - #730
Merged
Merged
Conversation
The budget footer makes a reply one caller's, so a read carrying one is no-store and the CDN bypasses it. That is fine for a warning nobody sees twice, and it was not: a client polling at its ceiling sits permanently inside the last quarter of its budget, so every reply it got carried a footer and none could be cached. Measured at the edge over 30 minutes: 47.7% of room reads `bypass` against a 7.2% hit rate, and 97% of the 429s came from three IPs — the cache switched itself off for exactly the callers generating the most load. Lowering the threshold does not help. A client pinned at its ceiling is permanently inside whatever band is chosen; 25% or 10% makes no difference to it. What breaks sharing is the footer's *presence*, not its precision, so the fix is to emit on a stride of the remaining budget: about six warnings across the band instead of one per reply. At 600/min that is 4.0% of in-band replies warning where 100% did. The stride is per_min // 24 rather than a constant, so a deployment with no requests to spare gets 1 and keeps the every-reply behaviour. `(left + 1) % stride` rather than `left % stride` so the multiple is never zero-left: a caller pinned at its ceiling is granted a token the moment one refills and would otherwise sit on the one value that always warns, which is the case this exists to remove. Note reads were never marked cacheable at all — /kv went to the origin every time even though the CDN's rule covers it. They now go through `_shareable`, the same decision the two room reads were already making inline. A note's bytes are identical for every caller that can name it, and an unlisted p- key is a capability URL, so a copy keyed on that URL reaches exactly the callers who could already read it. It cannot race a claim: `?if_absent=1` is settled on the write path under the note's own lock, never from a read. Written to fit the caps rather than move them: `_shareable` replaces four copies of the same conditional, which pays for the two note reads joining it. app.py stays at 1019/1020 and limit.py at 183/183 — no code lines added to either. Gates: ruff check, ruff format --check, ty check, sz --caps clean; 730 passed, 1 skipped.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1add0535c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Two review findings, both right. The stride was applied in a helper reads and writes share, so it thinned write footers too. A write reply is no-store whatever it carries — it mutates — so that bought no cacheability and cost a writer its pacing. At the production write budget of 300/min the stride is 12 and write warnings fell from every in-band reply to 7.9% of them; the test default of 30/min has a stride of 1, so nothing failed and the PR body claimed "no behaviour change for writes", which was wrong. It is `kind == "read"` now, and test_only_reads_are_thinned_because_only_reads_can_be_shared checks all three budgets rather than the one the defaults happen to use. Making note reads shareable also widened what CHAT_EDGE_CACHE_SECONDS governs, and both descriptions of the knob still said /rooms and plain room reads — so an operator could not find the new staleness from the configuration contract. The README row and the served /config text now name note reads, state that a note read can be that many seconds stale plus the stale-while-revalidate window, and record that it cannot race a claim because ?if_absent=1 is settled on the write path. Gates: ruff check, ruff format --check, ty check, sz --caps clean — app.py 1019/1020, limit.py 183/183 unchanged; 731 passed, 1 skipped.
…ult one
The write regression earlier in this PR got in because of how this suite picks
budgets, not because of a missing assertion. Every rate-knob test sets a tiny
one so it can exhaust it in a few requests — RATE_READ=1, =8, RATE_WRITE=2, =4,
=8 — which is right for testing exhaustion and blind to anything that scales
with the budget. The read stride is per_min // 24, so at every budget any test
had used it was 1, the thinning never engaged, and applying it to writes too
passed all 730 tests. It appeared only at the production 300/min.
A concrete test at three budgets would have caught this one and not the next.
So the claims are now asserted across the range with Hypothesis, in the same
derandomized style as tests/unit/test_parse_properties.py:
- a write footer is never thinned, at any budget — its presence is exactly the
threshold, because a write reply is no-store and has no sharing to buy;
- neither kind warns outside the threshold band;
- a read is never silent through the whole band, however the stride divides it.
Verified the gate rather than assuming it: with the regression reintroduced the
pre-existing budget tests still pass and this one fails.
Replaces test_only_reads_are_thinned_because_only_reads_can_be_shared, which
made the same claim at three hand-picked budgets and is strictly weaker.
Gates: ruff check, ruff format --check, ty check, sz --caps clean — app.py
1019/1020, limit.py 183/183 unchanged; 731 passed, 1 skipped.
WIZARDspace
added a commit
to WIZARDspace/technocore-chat
that referenced
this pull request
Sep 6, 2026
Two conflicts, both from flop-labs#730 landing on this file first: - src/app.py: flop-labs#730 wrapped the note read in _shareable() while this branch had rewritten the same return. Both kept — note_list now uses the view/body/note idiom flop-labs#730 introduced at app.py:985. - tests/http/test_notes.py: both sides appended tests at the end of the file, no overlap, all of both kept. The text-lane footer Saku0509 asked for on 2026-08-31 lands with it. It was dropped at the time as the whole of an additional core/app.py overage on a file with no headroom; flop-labs#730 freed those lines, and the rendering now sits in store.note_ns_footer beside the fact it states, following limit.budget_note. Net cost to core/app.py is zero: 1019, unchanged from main, against a cap of 1020. Without it ?keys=0 returned an empty body on the text lane, so the parameter added to make occupancy cheap to ask for answered nothing there. docs/store.md regenerated for the new public function, and manual.md now names both spellings rather than only the JSON lane's "true".
3 tasks done
sv
added a commit
that referenced
this pull request
Sep 7, 2026
## What Cuts **0.13.0**: folds `[Unreleased]` into a dated section, bumps the version the service, the MCP wrapper and the worker share (the same eight files as #723), and re-ratchets `sz-baseline.json`. Nothing a caller sees changes until the tag. ## Why Eleven commits since v0.12.1: fixes on the signed note lane, `/stats`, `/humans` passkeys, the MCP wrapper and `_b58decode`; the POST upload deadline and the slower sweep from #731; the shareable read footer from #730; and the Technocore branding. **MINOR rather than PATCH** because #713 gave the wrapper's `list_notes` a `limit` parameter and changed what a namespace over 50 keys returns — additive surface under the changelog's own rule. A reviewer could call that a patch; the version files are one substitution away. **The baseline refresh rides along.** `main` has failed `sz.py --check` since #753 put `app.py` at 1020 code lines against a recorded 1019. Only the measured `files` block moves; every cap is untouched. The alternative was a separate chore PR as for 0.12.1; folding it in means the tagged commit is green. After merge, by hand and in this order: tag `v0.13.0` and `mcp-v0.13.0` (lightweight, pushed to github.com directly), which builds the image and publishes the wrapper; pull the image on the box; then `edge/deploy.sh`, after the origin is up, so the snapshot carries the new `/humans` along with the favicon. ## Checks - [x] `uv run coverage run -m pytest tests -q && uv run coverage report` — 764 passed, 1 skipped - [x] `uv run ruff check . && uv run ruff format --check .` and `uv run ty check` - [x] `uv lock --check`, `uv run sz.py --check`, and both gates `release.yml` runs before building - [x] Docs that would now be wrong are updated: `CHANGELOG.md` is the change; the manual and `/skill.md` need nothing - [x] New surface on a world-writable service: nothing new
crazywriter1
added a commit
to crazywriter1/technocore-chat
that referenced
this pull request
Sep 9, 2026
…p-labs#719 flop-labs#725 flop-labs#730 CHAT_IDLE_SECONDS is not an env knob; /humans CSP is sha256- not a per-response nonce; README humans covers live room/signing/passkeys; budget footers thin reads on a stride while writes stay every in-band reply.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two changes to what a read reply may be shared with:
/kv/…) are marked cacheable, which they never were.No behaviour change for writes, and no code lines added to either capped file.
Why
The footer is one caller's pacing, so a reply carrying one is
no-storeand the CDN bypasses it. That's the right rule — but a client polling at its ceiling sits permanently inside the last quarter of its budget, so every reply it gets carries a footer and none of them can be cached.Measured at the edge over 30 minutes:
The cache switches itself off for exactly the callers generating the most load.
Lowering the threshold does not fix this. A client pinned at its ceiling is permanently inside whatever band you pick — 25% or 10% is the same to it. What breaks sharing is the footer's presence, not its precision. Hence the stride: at 600/min, 4.0% of in-band replies warn where 100% did, and the other 96% become the CDN's to hand out.
per_min // 24rather than a constant, so a deployment with no requests to spare gets a stride of 1 and keeps the every-reply behaviour.(left + 1) % striderather thanleft % strideso the multiple is never zero left — a caller pinned at its ceiling is granted a token the moment one refills, and would otherwise sit on the one value that always warns, which is the case this exists to remove./kvwas a separate miss: the CDN's cache rule already covers the path, but the handlers never marked the reply shareable, so every note read went to the origin. A note's bytes are identical for every caller that can name it, and an unlistedp-key is a capability URL — a copy keyed on that URL reaches exactly the callers who could already read it. It cannot race a claim either:?if_absent=1is settled on the write path under the note's own lock, never from a read.On the caps
limit.pywas at 183/183 andapp.pyat 1019/1020, so this was written to fit rather than to move them._shareablereplaces four copies of the same conditional, and that pays for the two note reads joining it. Both files are unchanged in code lines; the reasoning lives in docstrings, which aren't counted.What this does not do
It doesn't reduce the 429s — three clients on one provider's NAT are still being throttled as a group, and whether that's right is a separate question about per-IP bucketing behind shared egress.
Checks
uv run coverage run -m pytest tests -q— 730 passed, 1 skippeduv run ruff check . && uv run ruff format --check .anduv run ty checkuv run sz.py --caps— app.py 1019/1020, limit.py 183/183, core total 2316/3000test_a_note_read_carrying_a_budget_footer_is_not_sharedgates.