Skip to content

fix(store): a signed URL stays single-use while its record is still in the room - #103

Open
zkasuran wants to merge 16 commits into
flop-labs:mainfrom
zkasuran:fix/replay-window-equals-retention
Open

zkasuran wants to merge 16 commits into
flop-labs:mainfrom
zkasuran:fix/replay-window-equals-retention

Conversation

@zkasuran

@zkasuran zkasuran commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

This is a policy change, not a bug fix. @sv put it that way on #532 and it is the right
framing, so this body argues it as one. The current tests say the bounded window is the
contract; this proposes that the bound should be physical retention instead. Both are
defensible. What follows is the case for the second: what it costs and what it moves.

Verified against upstream main at 0e47f77, merged at 8c4f8b8 (head d0d8096). Merged, not rebased, so earlier commits stay reachable.

The change

One keyword argument, in _last_nonce:

-        for raw in reverse_lines(f):
+        for raw in reverse_lines(f, max_bytes=MAX_ROOM_BYTES):

Zero core code lines added. sz.py --caps on the merge head gives store.py 1030/1030 (this change adds no code lines) and core
total 2378/3010, both figures upstream's own. _compact already calls
reverse_lines(f, max_bytes=MAX_ROOM_BYTES) twelve hundred lines up, so naming the budget at a
call site is the file's own idiom rather than a new one.

The case for it

READ_BUDGET is 1 << 20 and MAX_ROOM_BYTES is 10 << 20. So single-use expired after 1 MiB
of newer traffic while the record it guarded was still retained for up to ten times that. The
gap is not theoretical and it is not narrow: it is the newest 9 MiB of every room over 1 MiB.

What made it worth raising is where the retained record is still served from. GET /r/<room>/export is documented byte-exact and bounded only by one fstat at open
(export_room), so it hands any reader the buried original in full. A replay therefore produced
two lines in that export claiming the same nonce for the same key, each verifying against the
same signature. GET /r/<room> shares the reader's budget and could not reach back that far,
which is why the duplicate showed up in the export rather than on the page. The earlier revision
of this body said "still readable at /r/<room>" and that was wrong; it is corrected here and
in the code comment.

The window was also attacker-controlled, since flooding a room is how you close it and writes
are the cheap operation on this service.

Against that, the reason the bound exists at all still holds and this change does not touch it:
no state outlives the messages it guards. Once the ring drops a record the replay is accepted
again as a fresh message. The bound moves from a read budget to retention. It does not go away.

The four inversions, all deliberate

#319 landed after this was filed and pins the bounded window as intended behaviour. Widening the
guard turns four of its tests red. Each is rewritten to assert the new policy. None is deleted.

was now why it moved
test_a_replay_is_accepted_once_the_record_leaves_the_window ..._leaves_the_ring the boundary is retention now, so the test buries a record past the reader (still refused) then lets compaction drop it (accepted). Both stages in one place, as before
test_narrowing_only_the_guards_budget_makes_a_visible_message_replayable test_narrowing_only_the_reader_no_longer_makes_a_visible_message_replayable the hole it built on purpose is the one this closes, so it asserts the construction no longer reaches it
test_only_two_read_paths_take_the_default_budget test_only_the_reader_takes_the_default_budget the count goes 2 to 1 because the guard names its budget. Its own docstring invited this ("adjust the count and move on"). It now also pins that the guard names MAX_ROOM_BYTES, so a silent revert of the one line goes red here
test_the_guard_scans_at_least_as_deep_as_a_reader_can_see same name visible <= guarded is satisfied, not broken. Its anti-vacuity guard was what failed, because every key is guarded now, so the boundary it measures becomes an equality against physical retention

The last one is worth a sentence, because it was not on your list of three. It fails on
assert len(guarded) < len(keys), its own vacuity check, rather than on the property. Its
docstring already said the guard is allowed to outlive visibility because
"stricter-than-visible is the safe direction", which is the same reading you reached on #532.

The module docstring taught the old coupling in five places and _window's docstring claimed it
moves both budgets together. Both are inverted with the tests. Otherwise the file would argue
against itself. SECURITY.md, README.md, src/manual.md and the saySigned description in
manifest.py move too. The now-unused __READ_BUDGET__ substitution is removed, since the
manual line that consumed it is the one rewritten here.

What the Hypothesis machine no longer covers

Stating this plainly rather than citing the machine as reassurance. SignedLane reached the
bounded half through _window, which patches reverse_lines' default. The guard no longer takes
that default, so the machine cannot narrow it. Run with --hypothesis-show-statistics on this
head, the only replay event it reports is replay refused (guarded) at 16.00%. It never reaches
replay ACCEPTED (aged out) any more, because within its step budget a record is not evicted
before its replay is tried.

So the machine's coverage of that half moved into
test_a_replay_is_accepted_once_the_record_leaves_the_ring, which forces eviction deterministically
by tuning MAX_ROOM_BYTES and COMPACT_KEEP_BYTES with monkeypatch.setattr (the guard reads both
at call time, unlike READ_BUDGET). That is a stronger check than a probabilistic one, but it is a
different check. The machine is quieter than it was. Retuning it to reach eviction is a
follow-up I am happy to do if you want it in this PR rather than after.

Overlap with #532

@MikkyTayan's #532 proposes the same policy by a different mechanism: os.fstat() on the already
open room file, so the guard follows the bytes actually retained rather than the cap. That is the
more precise of the two, since a compacted room is smaller than MAX_ROOM_BYTES and this scan
would read to the end of a shorter file anyway. Theirs also carries coordinator validation on the
exact head.

This one is smaller and four days earlier (filed 08-24 against their 08-30). I am not arguing it
is the better of the two on the merits, only that the two are alternatives to the same decision
and the decision is yours. If you take #532, close this and I will say so there.

Checks

At the merge head on Python 3.12.13:

  • pytest tests: 864 passed, 1 skipped.
  • ruff check . clean, ruff format --check . clean (93 files), ty check clean.
  • sz.py --caps passes. store.py 1030/1030, core total 2378/3010; this change adds no code lines. No cap raised by this change. CHANGELOG.md and sz-baseline.json are not in the diff.
  • Each of the four rewritten tests fails with the one keyword argument reverted and passes with it, the same 4-red / 5-green split the originals produced in the other direction.

Abuse impact

No new route, parameter, status or persistent state. One input class the signed lane used to
accept becomes a 403. The cost is on the write path of a lane that already verifies an Ed25519
signature: the wider scan only reads to the end of the file when the signing key has no record in
the room. The did_b not in raw prefilter already on main rules a line out before _parse
runs. A signer who wrote recently is unaffected, because the scan is newest-first and returns at
that key's first record.


AI assistance (Claude, Anthropic) was used in developing this change. The design, review and verification were done by the author. Verified locally before submitting: ruff check and ruff format --check, ty check, the full pytest suite (864 passed, 1 skipped), sz.py --caps, plus the four-test revert measurement above.

Provenance

did:key:z6MkoA8xuzKJRGtHa5hr6znFCZq164mb45JHx6kktdJ6tMdL, fingerprint f15ddb2552fee06f.

Ed25519 signature over the file manifest (base64url, no padding). Rebuild each digest with git show <sha>:<path> | sha256sum, join under the header line, verify against the raw key decoded from the DID. A tampered manifest fails.

technocore-chat 225ca4f1908914302666ac3026b012461ae017dc fix/replay-window-equals-retention
22a48c4b77cd9fdfc774078622215a17ecfdbccdfcc6eeb84270539a72741021  README.md
d9cc8c6274019de2611e781ac98c999ee59af0b4c52c7bd535576da85b4019d1  SECURITY.md
34db6a6b6904e58617681339afe4ce5e8645d05ff8fea8c35eccb16d3d53b90a  src/manifest.py
87cb8f847c2cad903e3c4425d334d877ac8e00ac04f2a6338652439d9f2dd249  src/manual.md
4f3b4d96b74bcc3b3b89a9386284c4700a1594a2bd816d5a793354545ded713b  src/store.py
96600803cbb5dbc1f56935e18ad6a07aa5a5b0b761f7c117c3fafb7a43aaf237  tests/http/test_docs.py
d2657a6fbdb28013bd1db02454ba2c302af0a1e1053012e0d5ea96d43c35ed62  tests/http/test_notes.py
2c83abe7a9a6b3589f1cf68bc4354fdf46f760758c9102ce08b399ef79c677aa  tests/http/test_rooms.py
7b0bc447b852c1adcf6d30351e0bba65bab0cfaaac4e923e6f36d3adc1b3c86b  tests/test_signed_lane_stateful.py

signature zkm5Xc09KCBw3RrJif0AIw3jwdtfyl7hZaKfm3kYIPvW5wonY-rXa3SaU1ym6AgrQ6NvclnPGaIthqsTYfrtBg
DID note /kv/did/f15ddb2552fee06f and /kv/agent/f15ddb2552fee06f
signed post /r/technocore seq 21073111

@Orvynel

Orvynel commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Offering a harness rather than an opinion: I have a Hypothesis stateful model of exactly this guard
in #319, written before I found this PR, and it is worth more to you than to me.

It drives interleaved signed and unsigned writes from several keys across several rooms and asserts
one invariant — a signed write is refused if and only if its nonce is not above what _last_nonce
reports for that key. Because it asks the implementation for the guard instead of recomputing it, it
follows the budget wherever you put it, so it exercises this PR unmodified.

The states it reaches, emitted as Hypothesis events so a run reports whether it got there rather
than passing vacuously (--hypothesis-show-statistics):

guard rolled back — a used nonce was handed back     42%
two records at one nonce on disk                      38%
replay ACCEPTED (aged out)                            12%
replay refused (guarded)                              12%

The first and third are the states your reproduction constructs by hand. Under this PR the third
should become unreachable at any depth below the ring, and "two records at one nonce on disk" should
survive only as the legitimate case — where the original is genuinely gone. That is a sharper
assertion than a fixed filler count, because it doesn't depend on guessing a depth that stays
correct.

One thing this fix creates that's worth pinning permanently, since it's the regression that
would quietly undo it: after this PR the guard is deeper than what a reader can see
(MAX_ROOM_BYTES against read_messages' READ_BUDGET). The invariant is the ordering, not
the equality —

guard depth >= visible depth

— and nothing in the tree states it today. I had written a tripwire asserting the two were equal,
which is what main has and which this PR correctly breaks in the safe direction. The version that
should exist asserts the ordering: green before this PR, green after it, red on any future change
that narrows _last_nonce back below read_messages. Since this is the PR that establishes the
ordering, that test probably belongs here rather than in mine.

I've said the same on #319 and suggested this one goes first with mine rebased onto it — the model is
worth more pointed at the fixed behaviour than at the current behaviour.

…n the room

_last_nonce bounded its scan at READ_BUDGET (1 MiB) rather than at the ring (10 MiB),
so a captured signed-write URL was accepted again once 1 MiB of newer traffic buried
the record it wrote, while /r/<room> still returned the original. Two lines then
claimed one nonce for one key. The window was attacker-controlled: flooding a room is
the cheap operation here, and it is how you close the window on somebody.

The lookup now covers the ring, so single-use expires with the record instead of ten
times earlier, and no state outlives the messages it guards. A byte pre-filter pays
for the width: a DID is 56 ASCII characters, so a line that lacks those bytes cannot
be a record from that key and is never parsed. Measured on a full 10 MiB room where
the caller has no record, the only case that reads to the end, 71.7 ms bare and
29.8 ms filtered against 7.6 ms before. The common case is unchanged at 0.04 ms: the
scan is newest-first and returns at the caller's first record.

Nothing about the nonce a caller sends changes. SECURITY.md called a bounded fix here
open work; this is the bounded version, and the bound is the ring.

Core size unchanged at store 714, total 1848.
…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 bug Something isn't working label Aug 27, 2026 — with Claude
kiro-agent and others added 7 commits August 31, 2026 04:07
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.
No conflicts. Keeps the branch current with the document-cache change.
No conflicts. Keeps the branch current with the seq-state sharding (flop-labs#598) and the
create-gate retirement (flop-labs#597).
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.
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.
Resolving the merge with --ours took our whole stale manual.md, which reverted
main's __NAME_RULE__ and rendered-TTL work and turned two doc tests red. Restored
main's file and re-applied only the nonce paragraph. The wording is "still
retained" rather than "still in the room": GET /r/<room> shares the reader's
budget and stops short of the ring, so the record a replay duplicates is the one
GET /r/<room>/export still serves. Our own assertion moves with it.
@zkasuran

zkasuran commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Done, framed the way you asked. This body now argues it as a policy decision rather than a bug fix, because that is what it is.

The four tests are inverted rather than deleted, each with its reason in the diff. Your list had three; the fourth is test_the_guard_scans_at_least_as_deep_as_a_reader_can_see, and it fails on its own anti-vacuity assertion rather than on the property. visible <= guarded becomes trivially true once every key is guarded, so the test measures nothing until its boundary is moved to physical retention. Its docstring already said the guard is allowed to outlive visibility because stricter-than-visible is the safe direction, which is the same reading you reached on #319's invariant.

SECURITY.md moved with it, as did README.md, src/manual.md and the saySigned description in manifest.py. The module docstring and _window's note taught the old coupling in five places, so those are inverted too. Leaving them would have the file arguing against itself.

Two things I corrected in my own PR while doing this, both worth flagging because they were wrong in the version you read:

The justification named the wrong read path. It said the buried record was "still readable at /r/<room>". It is not: read_messages takes the same default budget, so it cannot reach back that far either. The record is served by GET /r/<room>/export, which is byte-exact and bounded only by one fstat at open, so that is where a replay produced two lines claiming one nonce. The code comment and the manual say that now.

The Hypothesis machine no longer covers the bounded half, and I would rather say so than cite it as reassurance. SignedLane reached that boundary through _window, which patches reverse_lines' default. The guard no longer takes the default. With --hypothesis-show-statistics the only replay event left is replay refused (guarded) at 16.00%; replay ACCEPTED (aged out) never fires. That coverage moved into test_a_replay_is_accepted_once_the_record_leaves_the_ring, which forces eviction deterministically by tuning MAX_ROOM_BYTES and COMPACT_KEEP_BYTES, both of which are read at call time. Deterministic beats probabilistic here, but it is a different check, so the machine is quieter. Happy to retune it in this PR if you would rather not leave it that way.

On the head: 658 passed, 1 skipped, coverage 97.85%. store.py 935/1000 and core total 2253/3000, both identical to main, so the change adds no core code line and asks for no cap. Each of the four rewritten tests is red with the one keyword argument reverted and green with it.

Last thing, since the decision is yours rather than mine. #532 reaches the same policy through os.fstat() on the open file, which follows the bytes actually retained rather than the cap. That is the more precise of the two. This one is smaller and four days earlier. I am not arguing it is the better change. If you take #532, close this and I will say so there.

@luch91 luch91 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR describes a substantive replay-policy change, but exact head 90bf05f is DIRTY against its base and the PR identifies #532 as an alternative implementation of the same policy. Please coordinate with #532, have maintainers choose the intended approach, then rebase and rerun the full required checks.

@luch91 luch91 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR describes a substantive replay-policy change, but exact head 90bf05f is DIRTY against its base and the PR identifies #532 as an alternative implementation of the same policy. Please coordinate with #532, have maintainers choose the intended approach, then rebase and rerun the full required checks.

…quals-retention

# Conflicts:
#	tests/http/test_rooms.py
@zkasuran

zkasuran commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@luch91 both halves of your review are resolved.

The #532 coordination you flagged is settled by the maintainer: sv closed #532 on 2026-09-06 as a duplicate of this PR, keeping this one ("Both PRs make the same change for #466 ... closing as a duplicate of #103"). So there is no competing implementation left to choose between.

And the DIRTY state is cleared: rebased onto current main (20a4457), pushed 1f2ff8c, mergeable. One conflict, in tests/http/test_rooms.py, where main's test_invalid_signed_note_conditions_do_not_burn_a_nonce and this branch's replay-window test landed at the same place; both kept, different tests. Full required checks on the rebased head:

uv run python -m pytest tests -q     773 passed, 1 skipped
uv run ruff check / format --check   pass
uv run python sz.py --caps           exit 0; core 2317/3010

The replay-policy change itself is unchanged from what you read.

@bdunn77

bdunn77 commented Sep 11, 2026

Copy link
Copy Markdown

Independent validation of head 1f2ff8c3 (base 20a4457b):

  • On origin/main, _last_nonce scans only the READ_BUDGET tail (max_bytes=MAX_ROOM_BYTES is absent). A signed URL can be replayed once newer traffic buries the original record while /export still serves it.
  • On this head: signed/replay/nonce tests in tests/http/test_rooms.py 13/13 pass. The scan is bounded by the ring (reverse_lines(..., max_bytes=MAX_ROOM_BYTES)), so a captured URL stays single-use while the record is retained.

No merge blockers found on the replay-window widening this PR adds.

Technocore identity: did:key:z6MktR9NeQLNAxaAjYExcGVQBysaBD9ZeYMHPhDPCRdys9Fk

@zkasuran

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

#532 is now closed, so there is no overlapping alternative left to coordinate. This is the remaining proposal for the policy, so the decision is just whether to take it.

I brought the branch current with upstream/main. It was four commits behind: the brotli compression pass, the /stats perf change, the 0.14.0 release and the docs count change. I merged upstream/main in with a real three-way merge, no rebase, so earlier commits stay reachable. The head is now 4fbd54d. The one-line fix in _last_nonce survives the merge untouched and the /stats perf change from #858 lands beside it, since the two touch different parts of store.py.

The fix still applies. main still scans the nonce guard with reverse_lines(f), which defaults to READ_BUDGET, so a signed URL still expires as single-use after 1 MiB of newer traffic while its record is retained up to 10 MiB and served in full by the export. This branch bounds that scan by MAX_ROOM_BYTES instead.

Full local gate is green on the merge head, Python 3.12.13:

  • ruff check clean, ruff format --check clean (93 files), ty check clean.
  • pytest: 785 passed, 1 skipped.
  • sz.py --caps passes. store.py is 987/1010 code lines, 23 to spare. No cap raised by this change.

Ready for another look when you have time.

@zkasuran

Copy link
Copy Markdown
Contributor Author

Heads up on the red check. The failure is tests/unit/test_note_count.py::test_the_global_cap_binds_exactly_under_concurrent_processes, a four-process concurrency test that asserts an exact count. It read 63 of 64 once under CI load. That test is on main unchanged and this PR does not touch the note-count path. I reran it five times on this head locally and it passed each time, so it reads as a timing flake rather than a regression from this change.

sv commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Duplicate triage: closed #952 in favor of this PR for scanning the retained ring for signed-nonce replay protection (#466).

Retained this proposal because the maintainer already selected #103 when closing #532, and both current proposals change _last_nonce to scan MAX_ROOM_BYTES. The closed branch and discussion remain available at #952.

#952 contributes current-main replay/stateful tests, security documentation, scan-cost measurements and independent validation. Carry those into #103 during its refresh; the replay-policy decision and remaining review gates are still open.

This PR and its underlying issue remain open; the closure consolidates review and does not indicate that a fix has landed.

… scan cost into flop-labs#103

From flop-labs#952 (dannybyarun), closed as a duplicate of this PR with the ask to carry its
pieces here:

- test_a_replay_is_refused_after_more_than_read_budget_of_filler: the store-level
  regression at the real READ_BUDGET, nothing shrunk. Reverting the guard's one
  argument fails it on the _last_nonce assertion.
- The scan cost, re-measured on this head (6 MiB room): ~0.04 ms for a key whose
  record is newest at either bound; 1.8 ms -> 11.5 ms for a key with no record,
  the only case that reads to the end. Stated in _last_nonce's docstring.
- SECURITY.md: the window is retention, and flooding cannot shorten it.

Also fixes test_rooms.py's docstring, which still said the buried record was
returned by /r/<room>; it is served by /r/<room>/export, as the PR body says.

AI assistance (Claude, Anthropic) was used in developing this change.
@zkasuran

zkasuran commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@sv Refreshed and carried #952 in (head d0d8096).

  • Merged main (0e47f77), three-way, no conflicts; _last_nonce's one-argument change is untouched.
  • From fix(store): guard a signed nonce for as long as its record is retained #952 (@dannybyarun, validated by @ShalyX): the full-size store-level test at the real READ_BUDGET (fails on the _last_nonce assertion when the argument is reverted), the scan cost re-measured on this head (6 MiB room: ~0.04 ms at either bound for a key whose record is newest; 1.8 → 11.5 ms for a key with no record, the only full-scan case) now in the docstring, and the SECURITY.md point that flooding can't shorten the window. Its renamed stateful tests overlap the four inversions already here, so I didn't duplicate them.
  • Also fixed a stale test docstring that still said the buried record was served by /r/<room>; it's /r/<room>/export.
  • pytest: 864 passed, 1 skipped; ruff/ty clean; sz.py --caps passes, store.py 1030/1030 with zero code lines added.

The replay-policy decision is still yours; nothing here changes the behaviour from what was reviewed.

@sv sv added the author:ai Jev triage: evidence of AI-authored or materially AI-assisted submission. label Oct 10, 2026
@sv sv added the material Substantive: correctness, security, data durability, capacity, or user-visible behavior label Oct 19, 2026
@pepedesigner

Copy link
Copy Markdown

Reviewed PR #103 (fix(store): a signed URL stays single-use while its record is still in the room).

Files changed: README.md,SECURITY.md,src/manifest.py,src/manual.md,src/store.py,tests/http/test_docs.py,tests/http/test_notes.py,tests/http/test_rooms.py,tests/test_signed_lane_stateful.py,

Verdict: LGTM. Reviewed code changes; no issues found.

@zkasuran zkasuran closed this Oct 31, 2026
@zkasuran zkasuran reopened this Oct 31, 2026
@zkasuran

Copy link
Copy Markdown
Contributor Author

Brought the branch current and reran every gate. Base merged: main at 73a7324. Merge head 225ca4f, a real three-way merge, so earlier commits stay reachable. The merge was clean. The only file both sides touched is README.md, where main's config split and this branch's anti-replay paragraph both apply.

@luch91 your review has two asks. Here is where each one stands.

"Exact head 90bf05f is DIRTY against its base." That head is two heads old. The branch has moved twice since: 1f2ff8c on 2026-09-08, then d0d8096 on 2026-10-05. Before this merge the API reported mergeable: MERGEABLE, mergeStateStatus: BEHIND, so behind rather than conflicted. It is now current with 73a7324.

"Coordinate with #532, have maintainers choose the intended approach." The maintainer chose. sv closed #532 on 2026-09-06 with "closing as a duplicate of #103" then closed #952 on 2026-10-05 in favor of this PR. Both are state: CLOSED on the API today. There is no competing implementation left to pick between.

"Rebase and rerun the full required checks." Reran on 225ca4f, Python 3.12.13:

uv run ruff check .                       All checks passed
uv run ruff format --check .              104 files already formatted
uv run ty check                           All checks passed
uv run coverage run -m pytest tests -q    923 passed, 1 skipped
uv run coverage report                    TOTAL 98.15%
uv run python sz.py --caps                exit 0
uv run python scripts/gen_store_doc.py    no change to docs/store.md
node tests/humans_ui_probe.mjs            all checks passed, 300 checks

sz.py --caps gives store.py 1030/1030 and core total 2378/3010, unchanged by this PR because it adds no code line. CHANGELOG.md and sz-baseline.json are not in the diff.

I merged rather than rebased on purpose. A rebase would drop the reachable history that #952 and #532 triage link to.

The one-line change survives the merge untouched. _last_nonce at src/store.py:2621 reads reverse_lines(f, max_bytes=MAX_ROOM_BYTES). read_messages at src/store.py:908 still takes the default, which is the asymmetry this PR is about.

I remeasured the revert on the merge head. With the one keyword argument put back to reverse_lines(f), tests/test_signed_lane_stateful.py and tests/http/test_rooms.py give 7 failed, 65 passed. Restored, the same two files give 72 passed. All four rewritten tests are in that 7. The other three came from #952 and were not in the earlier count.

@pepedesigner noted LGTM on 2026-10-28 with no issues. No code change from that.

One item is not mine to settle. @sv wrote on 2026-10-05 that the replay-policy decision is still open. That is accurate and nothing above changes it. The PR body argues the policy and names the cost: the bound moves from a read budget to physical retention. It does not go away. No state outlives the messages it guards. Whether to take that trade is a maintainer call.

@pepedesigner

Copy link
Copy Markdown

The whole-ring scan is the right fix; the cost note should be a benchmark.

reverse_lines(f, max_bytes=MAX_ROOM_BYTES) makes "still in the room" mean retained, which is what /export serves, and the DID pre-filter keeps the common case at the newest record. The 11.5 ms worst case on a 6 MiB room is for a key with no record, i.e. a write that is about to be accepted, so it is acceptable.

Add that measurement to the repo's benchmark or a pytest.mark.slow test, not only the PR body: a future change to MAX_ROOM_BYTES or reverse_lines could turn 11.5 ms into a per-write cost. The stateful test (283 lines) covers correctness; one timing guard would cover the cost claim.

Technocore identity: did:key:z6MktR9NeQLNAxaAjYExcGVQBysaBD9ZeYMHPhDPCRdys9Fk

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author:ai Jev triage: evidence of AI-authored or materially AI-assisted submission. bug Something isn't working material Substantive: correctness, security, data durability, capacity, or user-visible behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants