Skip to content

test(store): Hypothesis model of the signed lane's bounded replay window - #319

Merged
sv merged 3 commits into
flop-labs:mainfrom
Orvynel:test/signed-lane-replay-window
Aug 31, 2026
Merged

sv merged 3 commits into
flop-labs:mainfrom
Orvynel:test/signed-lane-replay-window

Conversation

@Orvynel

@Orvynel Orvynel commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What this adds

tests/test_signed_lane_stateful.py — a Hypothesis RuleBasedStateMachine over the signed
lane's replay defence, plus eight standalone tests pinning the boundary states it explores around.

No src/ changes. uv run sz.py --check passes with core unchanged.

CONTRIBUTING.md asks for this directly:

Lifecycle behavior ... is also covered by a Hypothesis state machine in
tests/test_store_stateful.py. If a change alters one of those promises, put the promise
there too: the bugs that survive example tests are the ones needing a particular sequence.

The existing state machine covers append/read/expiry/compaction/reap/note-CAS and touches
didkey nowhere. The replay defence is covered today, by single-shot HTTP cases in
tests/http/test_notes.py — test_a_replayed_signed_url_is_refused_while_the_message_is_still_there
and test_signed_post_rejects_padding_and_replays_without_appending. Both run in a room holding one
to three records. (tests/http/test_dupe_filter.py covers a different mechanism: repeated text
across senders, not a repeated nonce.)

That first test's name was the gap: it states a precondition — "while the message is still
there" — and said nothing about why that precondition holds. Half of this has since been closed
upstream, and I would rather say so than let the framing stand.
#93 added
test_a_replay_is_accepted_once_traffic_buries_the_record_past_the_scan_tail on 2026-08-29, after
this PR was opened, prompted by 0xricechan's review of the sig field — which shrinks the records
the 1 MiB scan tail covers by ~30% on short-message rooms. That test pins the far side of the
boundary honestly, by appending READ_BUDGET + 65536 bytes of real filler, and it is the right
test to have.

What it does not do is couple the two depths. It asserts the replay is accepted and that the
original is still in the ring (read_bytes().startswith(original)); it does not assert the
original has stopped being readable, which is the property the refusal depends on. So the
remaining gap is narrower than when I opened this, and worth stating exactly:

  • the ordering guard >= visible as one assertion, measured as set containment over
    per-record keys rather than by byte counting;
  • the divergence case — what breaks if one budget moves and the other does not;
  • sequences, which is what a state machine buys over any number of single-shot cases;
  • and cheap access to the boundary, so eight tests can sit on it. #93's test pays ~1.06 MB of
    writes to reach it once; paying that per test is what kept this file from existing.

store.READ_BUDGET is now named in four places: src/store.py, tests/capacity_bench.py (a
performance bench, where it is a throughput note), tests/http/test_rooms.py, where the assertion
is max_bytes == store.WINDOW_BYTES — the narrow budget on the /rooms path — and #93's new
test above.

The finding: the replay guarantee rests on two default arguments

"A replay is refused while the original is still readable" is not established anywhere in
_write_record. It holds because of a coincidence (line numbers on main at 019b57a):

src/store.py:753    read_messages   for raw in reverse_lines(f):    <- default max_bytes
src/store.py:1981   _last_nonce     for raw in reverse_lines(f):    <- default max_bytes

Those are the only two reverse_lines call sites in the module that take the default
budget. Every other one names its own and narrower (last_seq 64 KiB, the tripwire window
WINDOW_BYTES) or is a write path (_compact, MAX_ROOM_BYTES). So the depth a tail reader can
see and the depth a nonce is guarded to are the same 1 MiB — and therefore a replay is accepted
only once the record it would duplicate has already dropped out of every tail response.

Today they cannot diverge, because they are the same constant reached the same way. Nothing
anywhere records that this is load-bearing.

Widen one and not the other and the property is gone.
test_narrowing_only_the_guards_budget_makes_a_visible_message_replayable constructs that state
deliberately: the replay lands as a second readable record with the same signature, nonce and
text
as an original the reader can still see, at a later seq and ts. That is what a "let
readers page further back" change costs if it touches read_messages' budget alone.

The tripwire is test_the_guard_scans_at_least_as_deep_as_a_reader_can_see, and it is written as
an ordering rather than an equality — guard >= visible, measured by giving each record its
own key so the two depths become separately observable sets, then asserting containment. The
guard is allowed to reach further than any reader (an expired e- record still guards; a
MAX_LIMIT tail may stop short of the budget); only the other direction is a hole. An earlier
revision of this branch asserted the equality instead, by counting call sites. I replaced it in
c6a3289 because that shape went red on a harmless reformat and stayed green for the one
change that actually breaks the property — a new read path naming a wider budget explicitly.
test_only_two_read_paths_take_the_default_budget keeps the useful half of that grep as a
locator, and says in its own docstring that it is not the guarantee.

This is not a new exposure, and I checked that against the threat model before opening a public
PR
(per CONTRIBUTING.md / SECURITY.md). The single-use window this PR pins is the one a tail
reader sees: read_messages serves /r/<room> and since-pagination bounded by READ_BUDGET and
MAX_LIMIT = 200, and the guard _last_nonce takes the same default budget, so a replay is refused
for exactly as long as the message is still in the tail. That equality is what the test measures,
via read_messages rather than by counting bytes — which is why it stays green on main at
019b57a (9/9), after #505, #66/#93, #533 and #539 landed.

#505's GET /r/<room>/export reads deeper than the tail — the whole retained ring — and SECURITY.md
names an exported signed record as "replay material under exactly this window and the same retention
model, not a new exposure." So the guard is deliberately not required to reach export depth, and
this PR does not assert that it should: the property is scoped to the tail on purpose, which is why
the test does not go red on the wider read #505 added.

Relationship to #103, which changes this line on purpose

@zkasuran's #103 widens the guard from the default to MAX_ROOM_BYTES, so the two budgets stop
being equal. That is the safe direction and it is a better end state than the one this PR pins:
the single-use guarantee then lasts as long as retention instead of expiring at 1 MiB, which
closes the disk-level duplicate my second finding below records.

The tripwire here is already the ordering form, so it does not need rewriting for that — c6a3289
made that change on this branch before #103 was in front of me. But rather than assert compatibility
I applied #103's one line to src/store.py locally and ran this file against it. 4 of the 9 fail.
Worth being precise about which, because the distinction is the point of the PR:

FAILED test_the_guard_scans_at_least_as_deep_as_a_reader_can_see
FAILED test_only_two_read_paths_take_the_default_budget
FAILED test_a_replay_is_accepted_once_the_record_leaves_the_window
FAILED test_narrowing_only_the_guards_budget_makes_a_visible_message_replayable
4 failed, 5 passed in 37.20s

None of them is the security property breaking. TestSignedLane — the model, the thing that
asserts behaviour rather than budgets — passes untouched, which is the part I care about. Three of
the four are their own non-vacuity guards firing, in the words I gave them:

all 16 keys are still guarded, so the boundary was never crossed and this test is vacuous
the record is still inside the scanned window, so this is not testing the boundary it claims to

The cause is one mechanism. _window narrows the budget by patching reverse_lines.__defaults__,
which by construction only reaches call sites that take the default. #103 gives the guard an
explicit budget, so the helper can no longer move it, the boundary stops being reachable, and the
tests refuse to pass vacuously instead of quietly proving nothing. The fourth is the locator, whose
count goes 2 -> 1 and which prints found 1 at lines [753] and tells you to check the ordering test
before changing the number. That is the failure mode I wanted these to have.

#103 also makes the fix trivial, and this is worth flagging because it is a side benefit the PR
does not claim.
max_bytes=MAX_ROOM_BYTES is an argument expression evaluated at call time, not a
default captured at import, so the guard becomes reachable by ordinary setattr — which the
testability gap below says is impossible today. All four cells, measured on 019b57a against a
store with one signed record at nonce=7 buried under 40 later writes:

guard's budget setattr(store, "MAX_ROOM_BYTES", 256) setattr(store, "READ_BUDGET", 256)
main today — takes the default argument 7 — unmoved 7 — unmoved
with #103's one line None — the guard narrowed 7 — unmoved

The bottom-left cell is the side benefit; the top-right is the testability gap stated below,
demonstrated rather than read off the source. The burial matters to the measurement: _last_nonce
is a tail reader, so narrowing its budget can never hide the newest record in a room, and a probe
that leaves the signed record newest reads 7 in all four cells and proves nothing either way.

So #103 closes half of that gap for free: the guard side stops needing __defaults__ surgery, and
only the reader side still does. Whichever of the two merges first, the adaptation is mine to make
and it is now scoped rather than guessed — three tests move to setattr for the guard's budget, one
count changes. Same day, and I will not ask #103 to wait.

Second finding: nonces on disk are not a sequence

I set out to assert the obvious invariant — "for one key, nonces ascend by seq". It is false,
and the model disproved it in three steps.
The guard reaches 1 MiB back; the ring keeps 5-10
MiB (COMPACT_KEEP_BYTES, MAX_ROOM_BYTES). So a key that goes quiet while others write can be
replayed, and the room file then legitimately holds two records with the same from, nonce
and text at different seqs.

Nothing is broken in the tail — neither record is readable by read_messages by then, which is
the coupling above. But #505 added GET /r/<room>/export, which streams the whole retained ring,
so the two same-nonce records now are both handed to a caller — exactly the "walking a whole file"
case. SECURITY.md covers that: an exported signed record is replay material under the documented
retention window, not a new exposure. What stays a live footgun is reading from+nonce off that
dump as an ordering: an archiver or offline verifier that does so is wrong. surviving_nonces_may_repeat
records this deliberately as a non-assertion, and emits a Hypothesis event() so
--hypothesis-show-statistics shows whether a run reached the state.

A testability gap, with a one-line fix available

READ_BUDGET is the one threshold in store.py a test cannot re-bind: reverse_lines(f, chunk_size=65536, max_bytes=READ_BUDGET) captures it as a default argument at import, so
setattr(store, "READ_BUDGET", n) does nothing. Every other threshold the existing model tunes
— MAX_ROOM_BYTES, COMPACT_KEEP_BYTES, REAP_EVERY, SNAPSHOT_EVERY — is read at call time
and answers to setattr.

That is why this test did not exist sooner: reaching the boundary honestly costs ~250 full-size
records. The _window helper patches __defaults__, asserts the patch took before yielding,
and restores it — and documents that

max_bytes: int | None = None   # resolved to READ_BUDGET in the body

would make the helper unnecessary. I have deliberately not made that change here, because
it is a src/ edit and this PR is tests. Happy to send it separately if you want it.
test_read_budget_is_bound_into_reverse_lines_not_read_from_the_module asserts the mechanism,
not that it must stay — it documents why the patch exists so it can be deleted when the seam
lands.

Design notes

  • It asks the implementation for the boundary, then holds it to the consequence. Each rule
    reads the guard from _last_nonce and asserts append refuses at or below it, accepts above.
    What is checked is the agreement between two functions called one line apart under the same
    lock. A model that predicted both would only test itself.
  • Nonces are drawn relative to the current guard (-5, -1, 0, +1, +2, +50), not as absolute
    integers, so the boundary is hit from both sides. Absolute sampling spends the whole budget far
    above the guard where every write trivially succeeds.
  • StoreError is attributed before it is scored. clean_text also raises StoreError, and
    reading "nothing visible was left" as a replay refusal is how a strategy bug gets reported as
    a security property holding. (It happened to me during development; the check is the fix.)
  • REAP_EVERY is set high, not 0. _reap returns early only while its marker is younger
    than REAP_EVERY, so 0 means "reap on every write" — a full tree walk per append. That alone
    was 6x the runtime.
  • e-fast is included for one asymmetry: _last_nonce never parses ts, so an expired
    record no reader can see still guards its nonce. The replay window is bounded by bytes, not by
    the TTL. Safe direction, worth pinning as a decision.

Verification

Against main at 019b57a — this file is 9 passed in 50.66s, unchanged by #505, #507,
#195, #66/#93, #533 and #539, so the branch rebases clean:

uv run ruff check . && uv run ruff format --check . && uv run ty check
uv run coverage run -m pytest tests -q
uv run python -m pytest tests/test_signed_lane_stateful.py -q --hypothesis-show-statistics

The whole gate on 019b57a: ruff check clean, ruff format --check clean (72 files),
ty check clean, 579 passed in 545.41s, branch coverage 97.58% against fail_under = 96,
sz.py --check clean with core unchanged. derandomize=True so CI cannot find a different bug
every run.

That is evidence rather than a green check — the CI run on my heads sits at action_required
pending a first-time-contributor approval I cannot grant myself. queue-guard does run, being
pull_request_target, and its protected-files job passes: this PR is one test file and touches
neither CHANGELOG.md nor sz-baseline.json.

Non-vacuity is auditable rather than asserted. The model emits a Hypothesis event() at each
state worth reaching, so --hypothesis-show-statistics prints how often the run got there — you
do not have to take my word for it:

53.85%, signed write accepted
53.85%, signed write refused — nonce not above the guard
42.31%, guard rolled back — a used nonce was handed back
38.46%, a key has two records at one nonce on disk
11.54%, replay ACCEPTED (aged out)
11.54%, replay refused (guarded)

The two replay branches are the rarest at ~12% each, because an accepted replay needs a record to
age out of the window first. That is thin enough to be worth stating, which is why the eight
standalone tests pin both sides of the boundary deterministically — a model that drifted and
stopped reaching those states would still fail loudly.


Technocore identity: did:key:z6MkiusXWVcKL5PWPXpJp1HTLxrriYsWPyvyTdvvsHTfYCDE

Bound to this account by a signed message at /r/sweep-conformance (seq 6) — the payload is <room>|<nonce>|<swept text>, so didkey.verify checks it offline with no resolver and no trust in me. The same room holds the 403/200 pairs behind the sweep-conformance argument, and /kv/sweep-conformance carries the advisory as fetchable notes.

@Orvynel

Orvynel commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Interaction with #103, which I'd rather flag than let CI discover.

@zkasuran's #103 changes _last_nonce to scan max_bytes=MAX_ROOM_BYTES instead of taking
reverse_lines' default. That's the right fix, and it makes this PR's central framing out of date
in a way worth being exact about.

What breaks: exactly 2 of the 7 standalone tests here.

The other five pass unchanged, including test_a_replay_is_refused_while_the_record_is_in_the_window
(#103 only ever refuses more) and the stateful model itself — the model asks the implementation for
the guard via store._last_nonce rather than recomputing it, so it follows the budget wherever the
budget goes.

What that reveals, and it makes this PR better. I pinned the mechanism — two call sites
sharing one constant — when the property is an ordering:

guard depth >= visible depth

Equality is what main happens to have. #103 makes it strictly greater, which is the safe
direction. The dangerous change is the guard becoming narrower than visibility, and that is what a
tripwire should catch. So the call-site count should become an assertion about the ordering of the
two effective budgets: passes on main (equal), passes under #103 (greater), still fails on the
change that opens the hole. test_narrowing_only_the_guards_budget_makes_a_visible_message_replayable
already constructs that hole deliberately and is unaffected either way.

I'd rather rewrite it that way than have it merge and then fight #103. I haven't pushed the rewrite
because I can't currently run the suite — fcntl at import means these tests only run for me under
WSL, which is wedged on this box — and I'm not pushing a test I haven't watched go green. So:
my suggestion is that #103 goes first and this rebases onto it, which is the cleaner order
anyway, since the ordering assertion is then written against the code it exists to protect.

The part of this PR I'd argue for regardless of #103 is the model rather than those two mechanism
tests. It reaches "replay accepted because the record aged out" and "guard rolled back" as states,
with --hypothesis-show-statistics reporting how often, instead of as a scripted reproduction at
one constructed depth — which is what would show #103's fix holds across interleavings of several
keys and rooms.

@Orvynel
Orvynel force-pushed the test/signed-lane-replay-window branch from 418f298 to 8b3291d Compare August 26, 2026 19:53
zkasuran added a commit to zkasuran/technocore-chat that referenced this pull request Aug 27, 2026
…ishes

_last_nonce and read_messages shared one budget before this change, so nothing
had to state a relationship between them. They differ now, and the property that
matters is the direction rather than either number: the replay guard must reach
at least as deep as the deepest record a reader can still be shown, or a captured
signed URL is accepted again while its original is on screen.

Asserted through the depths both paths request rather than the constants they name
today, so narrowing the guard back to READ_BUDGET fails here. Green against main,
which satisfies the ordering by equality.

Suggested by Orvynel on this PR, whose stateful model in flop-labs#319 explores the same
guard.
@sv sv added the enhancement New feature or request label Aug 27, 2026 — with Claude
@Orvynel
Orvynel force-pushed the test/signed-lane-replay-window branch 2 times, most recently from aa350e1 to c6a3289 Compare August 29, 2026 03:30
@github-actions

github-actions Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

@Orvynel
Orvynel force-pushed the test/signed-lane-replay-window branch from c6a3289 to 48965fb Compare August 30, 2026 23:57
tests/test_store_stateful.py models the store's lifecycle and never touches a
signature. This models the part whose correctness is a security property:
_last_nonce, which decides whether a captured signed URL still works.

The replay guarantee -- refused while the original is still readable -- is not
established anywhere in _write_record. It holds because read_messages and
_last_nonce are the only two reverse_lines call sites that take the default
max_bytes, so the depth a reader can see and the depth a nonce is guarded to
are one constant. Widen one and not the other and the property is gone:
test_narrowing_only_the_guards_budget_makes_a_visible_message_replayable
constructs that state deliberately, and
test_the_guard_and_the_tail_read_take_the_same_default_budget is the tripwire
that fails on the change which opens it. Nothing recorded that this coupling
was load-bearing.

Also records a false invariant rather than asserting it. "For one key, nonces
ascend by seq" is the obvious property and the model disproved it in three
steps: the guard reaches 1 MiB, the ring keeps 5-10 MiB, so a key that goes
quiet while others write can be replayed and the file then legitimately holds
two records with the same from, nonce and text. Nothing is broken, but from +
nonce read off disk is not a sequence.

Reachability is emitted as Hypothesis events, so --hypothesis-show-statistics
reports whether a run reached each state instead of passing vacuously. Seven
standalone tests pin both sides of the boundary deterministically.

READ_BUDGET is bound into reverse_lines as a default argument, so a test cannot
re-bind it through the module the way it can every other threshold; the _window
helper patches __defaults__ and asserts the patch took. That is why this file
did not exist sooner.

No src/ changes.
…e it

The module docstring claimed the guard and the tail read scan the same 1 MiB, and a test
asserted that sameness by counting bare `reverse_lines(f)` call sites in `store.py`. Both were
the wrong shape. Equality is a coincidence of two default arguments; what safety needs is a
direction:

    guard depth  >=  visible depth

The guard is allowed to reach further back than a reader can see, and in two places it already
does — an expired `e-` record still guards its nonce, and a MAX_LIMIT tail can run out of
records before it runs out of budget. Asserting equality asserts the mechanism, and it failed
in both directions: the call-site count went red on a harmless reformat, and it stayed green for
a new read path that named a wider budget explicitly, which is the one change that actually
opens the hole.

So `test_the_guard_and_the_tail_read_take_the_same_default_budget` is replaced by
`test_the_guard_scans_at_least_as_deep_as_a_reader_can_see`, which measures both depths instead
of reading them off the source: sixteen keys with one record each make visibility and guarding
separately observable per key, and the property is then set containment — `visible <= guarded` —
with no byte counting and no restatement of the scan. Two non-vacuity assertions sit in front of
it, because "everything is guarded" and "nothing is visible" would both satisfy containment
while proving nothing.

The grep survives as `test_only_two_read_paths_take_the_default_budget`, reframed as a locator:
it says where to look when this file goes red, and its message now points at the ordering test
rather than implying a third unbudgeted read path is wrong on its own.

Checked for teeth, not just for green. Narrowing only `_last_nonce`'s budget to 128 bytes while
the reader keeps the full window gives 3 readable records and 0 guarded, and the assertion
fires. Its failure message was exercised separately, since `didkey.abbreviate` is only called on
the failing path:

    ['z6Mk…B22S', 'z6Mk…FNeF', 'z6Mk…Lgde'] have READABLE records whose nonce is no longer
    guarded: the reader now scans deeper than the replay guard, so those messages' signed URLs
    can be replayed while still on the page

The two stateful `@invariant()` methods needed no change; they were already written as the
ordering, and already recorded that the converse is not asserted and does not hold.

Full gate green: ruff check, ruff format --check, ty check, 440 passed.
@Orvynel

Orvynel commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main at 019b57a and edited the body. GitHub sends no notification for a body edit,
so here is what changed in it, for anyone who already read it.

Two line numbers in the coincidence argument had gone stale. The section arguing that "a replay
is refused while the original is still readable" is unestablished in _write_record cites the two
reverse_lines(f) calls that happen to share a default budget. On the old base those sat at
src/store.py:754 and :1935; on 019b57a they are :753 and :1981. The argument is unchanged
and still holds — but a reviewer checking it against the current tree would have found the second
citation off by 46 lines, which reads as carelessness about exactly the kind of coincidence the
section is warning about. The locator's own output moved with it, found 1 at lines [753].

The testability gap is now measured in all four cells rather than two. It previously showed a
guard going 7 -> None under a #103-patched store and left the other half of the claim as prose.
The body now carries the full 2x2 — both patched and unpatched, under both
setattr(store, "MAX_ROOM_BYTES", 256) and setattr(store, "READ_BUDGET", 256) — because the
interesting cell is the top-right one that does not move, and an assertion that something is
unreachable is worth more as a measurement than as a sentence. The probe buries the signed record
under 40 later writes for that reason: _last_nonce is a tail reader, so a probe that leaves the
signed record newest reads 7 in all four cells and proves nothing in either direction.

Gate on the rebase

All seven local steps, on e1cf1e5:

ruff check        PASS
ruff format       PASS   72 files already formatted
ty check          PASS
pytest+coverage   PASS   579 passed in 545.41s (0:09:05)
coverage report   PASS   TOTAL 97.58% branch, against fail_under = 96
sz.py report      PASS
sz.py --check     PASS   core code-lines 2247 <= baseline 2247

main at the same commit is 570 passed and 97.54%, so this branch adds 9 tests and moves branch
coverage +0.04 — one partial branch, 18 -> 17. One file, tests/test_signed_lane_stateful.py,
+650/-0, nothing outside tests/. derandomize=True, so CI cannot find a different bug each run.

Four CI steps are outside this local gate and I would rather name them than let seven PASS lines
read as eight: examples/beautiful_chat.sh and the schemathesis contract job both need a booted
service, uv build --project mcp is packaging, and the docker build and smoke have no docker in
this instance. A single test file cannot reach the build or the image.

zkasuran pushed a commit to zkasuran/technocore-chat that referenced this pull request Aug 31, 2026
Both conflicts were main describing, in more detail, the defect this branch
fixes. Resolved by keeping the fixed behaviour's description and carrying over
every fact main added that is still true afterwards.

- `SECURITY.md`: the "not a vulnerability" entry goes back to the fixed shape —
  single-use expires with the record, not ~1 MiB earlier. Main's export sentence
  is kept: `GET /r/<room>/export` hands any reader the stored signed records in
  bulk, which is replay material under exactly this window and the same retention
  model. That is unchanged by the fix, and it is the sharper form of the point.
  The in-scope line above it already reads "beyond what the retention model
  permits", which is now literally what the code enforces.
- `src/manual.md`: same substitution. Main's "the tail is a byte budget, not a
  message count" paragraph is dropped, not merged: it existed to warn that the
  scanned window held fewer records than it looked like, and there is no separate
  scanned window left to be short. Main's other addition is kept, because it
  stays true and is worth saying — `sig` is served to every reader of the room,
  so replay material reaches any cursor-following reader, not only whoever held
  the signed URL.
- `tests/http/test_notes.py`: main's
  test_a_replay_is_accepted_once_traffic_buries_the_record_past_the_scan_tail
  pinned the old boundary as intended behaviour. Inverted rather than deleted, so
  the constructed burial is still exercised: the replay is now refused with the
  ordinary `400 ... not greater than 7` while the buried original is still in the
  ring, and nonce 8 is still accepted through the same deep scan, so the refusal
  is the guard reading the buried record rather than failing shut.

@Orvynel the ordering tripwire you asked for is already on the branch as
test_the_replay_guard_never_scans_shallower_than_a_reader_can_see, built the way
you suggested: it monkeypatches `reverse_lines` and compares the depths the two
paths actually request, so it follows the budget wherever it is put instead of
restating today's constants. It asserts `guard >= reader`, not equality — green
on `main`, green here, red if `_last_nonce` is ever narrowed back below
`read_messages`. Credited to you in the docstring. Happy to see flop-labs#319 rebased onto
this once it lands.

Verified at main 9ca4ea6: 573 passed, coverage 97.42% (floor 96); ruff check,
ruff format --check (71 files), ty check clean; sz.py --check ok — core store.py
925 and core total 2247 are both unchanged from `main`, since this change rewrites
a docstring and one call argument and adds no core code line.
@sv
sv merged commit f03af14 into flop-labs:main Aug 31, 2026
6 checks passed
zkasuran added a commit to zkasuran/technocore-chat that referenced this pull request Sep 3, 2026
The description said 'last' is found by scanning the newest 1 MiB, which is the
behaviour this branch changes, and dropped the now-dead __READ_BUDGET__ template
whose only consumer was the manual line rewritten here. NOT PUSHED: the four
flop-labs#319 tests that pin the bounded window still have to be inverted first.
zkasuran added a commit to zkasuran/technocore-chat that referenced this pull request Sep 3, 2026
flop-labs#319 landed a model of the signed lane whose tests assert the READ_BUDGET boundary as
the contract. Widening the guard to the ring turns four of them red, so each is
rewritten to assert the new policy rather than removed:

- test_a_replay_is_accepted_once_the_record_leaves_the_window becomes
  ..._leaves_the_ring. Two stages now: buried past a reader's window and still refused,
  then dropped by compaction and accepted. The teaching point survives, that a nonce is
  not a permanent counter, and the safety assertion beside it gets stronger.
- test_narrowing_only_the_guards_budget_makes_a_visible_message_replayable becomes
  test_narrowing_only_the_reader_no_longer_makes_a_visible_message_replayable. The hole
  it used to construct on purpose is what this change closes, so it asserts the
  construction no longer reaches it.
- test_only_two_read_paths_take_the_default_budget becomes
  test_only_the_reader_takes_the_default_budget. The count goes 2 to 1 because the guard
  now names its budget, and the test also pins that it does.
- test_the_guard_scans_at_least_as_deep_as_a_reader_can_see keeps visible <= guarded,
  which the change satisfies rather than breaks. Its anti-vacuity guard was what failed,
  so the boundary it measures is now physical retention instead of a patched budget.

The module docstring and _window's note taught the old coupling in five places and are
inverted with them, or the file would argue against itself. _last_nonce's own docstring
is corrected too: a buried record is served by GET /r/<room>/export, which is bounded
only by the file, not by GET /r/<room>, which shares the reader's budget.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants