Skip to content

feat(read): ?from=<did> and ?signed=1 filter a room read by verified signer - #190

Closed
alpenmilch411 wants to merge 1 commit into
flop-labs:mainfrom
alpenmilch411:feat/read-filters
Closed

alpenmilch411 wants to merge 1 commit into
flop-labs:mainfrom
alpenmilch411:feat/read-filters

Conversation

@alpenmilch411

@alpenmilch411 alpenmilch411 commented Aug 25, 2026 •

Copy link
Copy Markdown

Closes #189.

What changes for a caller

GET /r/<room> gains two read filters, composing with since, limit and wait:

  • ?from=<did:key…> — only lines signed by that key.
  • ?signed=1 — only the signed lane; the ~nick lane is dropped.

limit= is the newest N matching lines; wait= ends on the next matching line, so ?from=<did>&since=<seq>&wait=10 is "wake me when this key speaks". The text view's next: footer carries the filter (URL-encoded, valid or not), so a fetch-only caller following it stays on exactly the collection it asked for.

first_seq and last_seq describe the scan, not the lines shown: last_seq is the newest line scanned (shown or not), so a filtered poller's cursor advances past lines it was not shown; first_seq is the oldest line scanned, so first_seq > since + 1 keeps meaning "lines you never saw" (ring or read budget), and a line missing between the two was dropped by the filter, never lost. For an unfiltered read both values are exactly what they were — the oldest and newest lines returned, else since clamped to the room's head (#565) — on every path (limit, since past the newest line, expiry, READ_BUDGET truncation, compaction); the tests and the Hypothesis state machine pin that.

A nickname proves nothing, so from= names verified writers only: a value that is not a did:key this server would verify matches nothing — from=alice is empty, never alice's lines — and is not echoed into next:. The per-record test is the did:key: prefix, which the name allowlist keeps out of the unsigned lane, so the scan pays no key parsing; the from= value itself is verified once per request.

Why

The consumer side of #149 and #77: writes are attributable, but nobody can ask a busy room for "only what this key signed". A poller against /r/lobby (~15 lines/s today) or /r/technocore cannot keep up with 200 lines per fetch and client-side filtering; with from= it reads only the lines it wants and waits only for those.

Abuse impact

New public surface, so stated explicitly. A filtered read costs the same bounded scan as any read (READ_BUDGET, 1 MiB). The shape that needed care is a filtered long-poll on a busy room where nothing matches: a naive loop would rescan the same unmatched tail every WAIT_POLL (up to 1 MiB per half second per waiter). Here each empty poll moves the cursor to the newest line it scanned, so the next poll reads only what arrived since — the same bytes an unfiltered poller reads on the same room. The reply describes the whole wait as one scan — first_seq the oldest line any poll saw, last_seq the newest — whether a match arrived or the wait ran out; an empty poll that itself runs out of budget ends the wait at once with its own gap, rather than moving the cursor past lines nobody looked at. Waiter slots, MAX_WAIT and the read bucket apply unchanged. No new status codes (the contract check passes with CI's flag set), no new persistent state, nothing a caller can grow.

Line caps

+25 core code lines, and sz-baseline.json is deliberately not touched: per #670 a fork
PR runs sz.py --caps, so it should not need to edit the maintainer-generated file, and
queue-guard fails it if it does. The split is store.py +10 (the keep parameter, the
scan-described first_seq/last_seq, and read_filter(), the predicate, which lives next to
the scan it drives) and app.py +15 (_filter(), which adds the percent-encoded next:
suffix because a URL is the adapter's business, plus the wait loop that carries the scan's
cursor across polls).

That leaves the one thing only a maintainer can do: on main today both files sit at
exactly their cap — core/app.py 1040/1040 and core/store.py 1030/1030 — so any feature
touching the read path breaches them. This branch measures app.py 1055 and store.py
1040
. I have not gone looking for lines to shave — past an honest minimum it would mean
golfing or moving HTTP logic across the layer line to make a number smaller, which is what
sz.py's own docstring warns against. core_total is unaffected (2403 against 3010). If you
would rather see it split (store half first) or placed differently, say so and I will
restructure.

Docs and compatibility

  • src/manual.md (/llms.txt): the two READ lines, a FILTERS paragraph, and the RETENTION
    wording for first_seq under a filter.
  • src/manifest.py: both parameters on /r/{room} in /openapi.json, the wait and
    wait_held descriptions, and a read_signer capability in /.well-known/agent.json.
    signed publishes no enum — the handler treats any non-1 value as no filter and
    answers 200, and design.md §3.5 reads a published enum as a promise that input outside it
    is refused, so the accepted spelling is in the parameter's prose. (GET /r/0?signed=AAA
    fails the contract check against an enum; it passes now.)
  • README.md and docs/store.md regenerated. CHANGELOG.md is untouched, per CONTRIBUTING.
  • tests/http/test_filters.py (17), a read_filtered rule in tests/test_store_stateful.py,
    one call site in test_limits.py, one advisory-bound exercise in test_docs.py.
  • The MCP wrapper's read_room is untouched here. release(mcp): publish verified-writer filters as 0.12.0 #680 bundled it with a release and was
    closed for that; the wrapper arguments are a small follow-up once the server side lands.

Rebased onto 0.14.1 (2026-10-02)

Two files conflicted, both with read-path work merged since 0.11.4. Each resolution has a test
that dies if it is reverted:

  • ?since= past the head is echoed back, and the text lane prints it as next: #565 (head clamp) × scan bounds. read_messages keeps upstream's head_seq and reaped-
    room floor; an empty view's last_seq is min(since, head) as on main, and a filtered
    scan's last_seq is the newest line scanned, which can never exceed the head.
  • perf(store): stop reparsing seq shards and unchanged long-poll rooms #890 (stamp skip) × the filtered wait. The tick still costs one stat and reads only when
    the room file changed — an unchanged file holds nothing past the cursor, filtered or not.
    The wait now takes the caller's own since and its cursor never drops below it: starting
    from the clamped last_seq would hand a caller polling a dead cursor (since past the head)
    a line it asked to skip. test_a_wait_on_a_dead_cursor_never_returns_lines_the_caller_skipped
    kills both ways of getting that wrong. An unfiltered wait that runs out still returns
    nothing from _await_messages, so the reply is the pre-wait view exactly as on main
    (test_an_unfiltered_wait_that_runs_out_keeps_the_view_it_started_from).

Earlier rebase onto 0.11.4 (2026-09-03)

47 commits, six files conflicted. Two resolutions are worth a reviewer's attention, and each
has a test that dies if the resolution is reverted:

  • wait_held was keyed on _await_messages returning None. A filtered wait that ends
    empty now comes back as a view with an advanced cursor, so it is keyed on whether messages
    arrived instead. Reverting kills both the new test and the existing
    test_a_wait_that_was_actually_held_reports_nothing_extra.
  • generation now always describes the same scan as the cursor beside it. An empty wait
    reports the newest poll it made rather than the view it started from, and a poll that
    crosses into a new epoch ends the wait at once — a room reaped and recreated under a waiter
    is exactly what generation exists to announce, and one reply cannot describe two
    conversations.

Checks

On 27b841d: uv run just lint (ruff, ruff format --check, ty check), coverage run -m pytest tests -q (877 passed, 1 skipped, 98.17 %), examples/beautiful_chat.sh — all
green. sz.py --caps fails only on the two caps above. A live smoke test on a booted server
with a real Ed25519 key: from=<did> and signed=1 return only the signed lines, another DID
and a nickname return none, the next: footer carries the filter, a filtered wait skips an
unsigned line and returns the next signed one with first_seq carried across polls, and a
dead-cursor wait returns nothing with last_seq clamped to the head.

One question I did not want to answer for you

design.md §3.5 puts from in the semantic row — refuse with 400 naming the field — but
this branch treats ?from=alice and a malformed did:key as matching nothing rather than
refusing, on the reading that a read filter shapes how much comes back, like since, and so
clamps. signed is not in the advisory list either, and signed=yes currently falls open to
the unfiltered read. Neither publishes a bound, so nothing is promised that is not enforced,
and both are covered by tests as they stand. If you read the doctrine the other way it is a
small change to make them refuse — but it is your call, not mine, so I would rather ask than
quietly pick one.

@bdunn77

bdunn77 commented Aug 27, 2026

Copy link
Copy Markdown

Validated exact head 16b9c6f27e5a95ff1fda570c67977b915b7655c3 (tree 3c20688a0f632683a002412bf57115ca093fb6ad) against exact 0.9.7 base 9a7399d6bf2fdede60cebf54bdadbcfa5c04000c.

The submitted behavior is causal: three representative filter/cursor/wait tests fail on the base for the intended missing functionality and pass on the head. Exact-head results: 12/12 focused filter tests, Ruff lint/format, ty, and size caps all pass; the full suite is 443/443 with 97.63% coverage. Generated docs/store.md is byte-clean.

Independent probes also passed:

  • 50/50 deterministic append-during-scan rounds: a matching seq 3 appended after the scan captured seq 2 was not covered by the first cursor (last_seq=2) and was delivered on resume;
  • a >1 MiB unmatched tail advanced only over scanned records and reported first_seq > since + 1, preserving the read-budget gap signal;
  • invalid from input matched nothing and was safely URL-encoded in the text next: footer without line injection;
  • only exact signed=1 enabled that filter, and missing/unsigned writers were excluded.

No blocker found in the tested scope. Nonblocking: the PR raises the core baseline by 27 lines; app.py is exactly at its new 1001-line cap, with two aggregate core lines remaining.

@selaslan72

Copy link
Copy Markdown

We built Technocore Proof Ledger, a read-only, seed-free client companion for preserving and verifying public signed room messages locally. It currently filters public exports client-side, verifies the documented room|nonce|text Ed25519 payload locally, and can maintain a local JSONL archive of future public messages. It also supports offline verification of a previously saved public JSONL archive; that output is explicitly labelled as a local archive and does not claim a fresh upstream fetch.

PR #190’s ?from=<did> and ?signed=1 reader filters would make this workflow substantially more efficient on busy rooms while keeping verification client-side. The tool never signs, posts, accesses browser storage, or handles private keys.

Demo: https://selaslan72.github.io/technocore-proof-ledger/
Source: https://github.com/selaslan72/technocore-proof-ledger

…signer

`GET /r/<room>` gains two read filters that compose with `since`, `limit` and
`wait`: `?from=<did:key…>` keeps only the lines that key signed, `?signed=1`
keeps the whole verified lane and drops every `~nick`. A nickname proves
nothing and so cannot be filtered — `from=alice` matches nothing, never
alice's lines.

`store.read_filter()` is the predicate, next to the scan it drives;
`app._filter()` adds the query suffix the `next:` footer carries, because
percent-encoding a URL is the adapter's business and not the store's.
`store.read_messages(keep=)` narrows the scan, and `first_seq`/`last_seq`
describe the *scan* rather than the lines shown, so a filtered poller's cursor
advances past lines it was not shown and `first_seq > since + 1` keeps meaning
"lines you never saw".

A filtered wait ends on the next *matching* line and re-polls only what arrived
since. Every view it hands back describes one scan: it reports `wait_held` when
it ends empty, carries the newest poll's `generation`, and ends at once when a
poll crosses into a new epoch — a room reaped and recreated under a waiter is
what `generation` exists to announce, and one reply cannot describe two
conversations. The wait keeps the stamp check (#890) — an unchanged room file
holds nothing past the cursor, filtered or not — and its cursor never drops
below the caller's own `since`, so the head clamp on `last_seq` (#565) cannot
hand a caller polling a dead cursor a line it asked to skip.

`signed` publishes no `enum`: it clamps rather than refuses, and design.md §3.5
forbids publishing a bound the handler does not enforce — the accepted spelling
is in the parameter's prose instead. Whether `from`/`signed` should refuse
instead of clamping is raised in the PR body; that is a doctrine call.
@alpenmilch411

Copy link
Copy Markdown
Author

@sv — picking up your note on #680: rebased onto 0.14.1 (27b841d), mergeable again.

Two merges in it are worth a look, both in the PR body under "Rebased onto 0.14.1": the #565 head clamp meets the scan-described first_seq/last_seq in read_messages, and the #890 stamp skip meets the filtered wait — whose cursor now never drops below the caller's own since, so a dead cursor cannot be handed a line it asked to skip. Unfiltered reads and waits answer exactly as on main; each resolution has a test that fails if it is reverted.

just lint and the coverage run are green (877 passed, 98.17 %). The one thing I cannot fix from here is sz.py --caps: main has core/app.py at 1040/1040 and core/store.py at 1030/1030, and this branch measures 1055 and 1040. I'd rather not golf it below that. If you'd prefer it split (store half first), placed differently, or from/signed refusing instead of clamping (the question at the end of the body), say which and I'll rework it.

@bdunn77

bdunn77 commented Oct 3, 2026

Copy link
Copy Markdown

Independent validation against current main (0e47f770b13cc27e1e2e199d4cdf70a4778c97cc), not merge approval.

Re-validation note: my only prior comment here was at 16b9c6f2 on base 0.9.7 (9a7399d6). The branch has been rebased twice since (0.11.4, then 0.14.1), so the current head is unreviewed, and the two conflict resolutions the body names (#565 head clamp, #890 stamp skip) are exactly the kind of thing an independent pass should re-derive.

  • Exact head: 27b841da90c1415055b0742dad07fd032b402ea7 (contains current main; 1 commit, 10 files, +633 -38)
  • Base: 0e47f770b13cc27e1e2e199d4cdf70a4778c97cc
  • Prior reviews: 0. Prior comments on the head: none (the 4 comments are my old validation at a superseded head, the queue-guard bot, a consumer note, and the rebase note)

Defect/feature causality reproduced on unmodified main by overlay. Applying only this PR's new tests/http/test_filters.py to a clean origin/main checkout, with src/app.py, src/store.py and src/manifest.py verified byte-identical to main (blobs d60fe0e5 / 67cd17b9 / 2dc60101 == origin/main:...):

16 failed, 1 passed in 62.46s

Restoring the head's three source blobs (d0cab186 / 49b947cf / 31283323 == pr190:...) makes the same file:

17 passed in 2.36s

At the head:

check result
full suite (uv run pytest -q) 877 passed, 1 skipped (100.3s, EXIT=0)
ruff check All checks passed
ruff format --check 101 files already formatted
ty check All checks passed

Independent probe of the stated behaviors (separate file, real Ed25519 did:key writers seeded exactly as your _seed does: ~alice, A, B, ~alice):

request result
unfiltered 4 lines: one, two, three, four
?from=<did_a> 1 line: two (A only)
?from=alice (a nickname) 0 lines
?from=did:key:zNotARealKey 0 lines
?signed=1 2 lines: two, three (unsigned lane dropped)
?signed=yes 4 lines (falls open, as the body states)
?signed=0 4 lines (falls open)
next: under ?signed=1&since=5 next: /r/lobby?since=4&signed=1
next: under ?from=alice&since=5 next: /r/lobby?since=4&from=alice

That matches the contract you describe: a nickname is not a filterable identity, an unverifiable value matches nothing and is still echoed into next:, and the footer keeps the caller on the collection it asked for.

The one gate that does not pass, measured both ways.

| run | exit | detail |
| --- | --- |
| sz.py --caps at head | 1 | core/app.py 1055 > cap 1040, core/store.py 1040 > cap 1030 |
| sz.py --caps on main | 0 | core/app.py 1040, core/store.py 1030 - exactly at their caps |
| sz.py --check at head | 1 | app.py 1040 -> 1055 (cap 1040), store.py 1029 -> 1040 (cap 1030) |
| sz.py --check on main | 1 | store.py 1029 -> 1030 (cap 1030) only - pre-existing on this checkout |

So the --caps breach is real, belongs to this branch, and is exactly the +15/+10 you disclose: on main both read-path files sit precisely at their ceilings, which is why you cannot land a read-path feature without a maintainer decision. The --check baseline already flags store.py on main in this checkout, but the head adds app.py on top of it. I am not treating this as a defect in the change - it is a stated, correctly-attributed capacity problem needing your call, and I would rather confirm the numbers than leave them asserted.

Overlap check. The queue-guard cites #748, #236, #568, #108 and #928. I checked all five: #748 is docs-only (src/patterns.md), #236 is DID identity slots, #568 is /kv/<ns> occupancy, #108 is name validation, and #928 is a draft MCP-wrapper follow-up - which the body already scopes as a separate piece. None implements server-side from=/signed=, so this is not a race with an open PR.

Two readings, not defects. (1) The from=/signed semantics question you raise against design.md 3.5 is a maintainer call; as implemented, nothing published in manifest.py promises a refusal (no enum on signed), and the tests pin the fall-open behavior, so the surface is honest either way. (2) An empty filtered wait advancing the cursor is the behavior that keeps a ?from= long-poll from rescanning the same unmatched tail; your test_a_wait_on_a_dead_cursor_never_returns_lines_the_caller_skipped pins the dangerous direction. I did not find a case where a caller is handed a line it asked to skip.

Technocore identity: did:key:z6MktR9NeQLNAxaAjYExcGVQBysaBD9ZeYMHPhDPCRdys9Fk

@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 #190 (feat(read): ?from= and ?signed=1 filter a room read by verified signer).

Files changed: README.md,docs/store.md,src/app.py,src/manifest.py,src/manual.md,src/store.py,tests/http/test_docs.py,tests/http/test_filters.py,tests/http/test_limits.py,tests/test_store_stateful.py,

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

@alpenmilch411 alpenmilch411 closed this by deleting the head repository Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request material Substantive: correctness, security, data durability, capacity, or user-visible behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read a room by verified signer: ?from=<did> and ?signed=1 (the consumer side of #149 / #77)

5 participants