Skip to content

fix!: limit ids and names, and require a plain since - #64

Merged
grrowl merged 7 commits into
mainfrom
fix/frame-guard-ids-since
Nov 17, 2026
Merged

grrowl merged 7 commits into
mainfrom
fix/frame-guard-ids-since

Conversation

@grrowl

@grrowl grrowl commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Two gaps in the server's frame guard, both found by reviewers of earlier work.

  • Ids had no length limit. A sub id is echoed in every frame for its subscription and stored with it. The only bound was the frame size.
  • since was parsed loosely. since: "1e400" became Infinity and the server answered uptodate without sending anything. since: "abc" got a snapshot.

What changed

  • Ids are at most 256 UTF-8 bytes and names at most 128. A frame whose id is over the limit gets that frame type's own refusal, with nothing stored: reset for a sub, an empty page for a fetch, rejected with LIMIT_EXCEEDED for a mutation or command. An unsub over the limit is ignored. The check for a transaction id runs after the dedup lookup, so a receipt stored under a longer id before this release still replays (ADR-0025's rule holds with no exception).
  • A table or command name over 128 bytes fails registerSync. That keeps every id the library's own client builds at 158 bytes or less.
  • since must be a plain decimal position: digits only, no sign, no leading zero, at most 19 digits. Anything else makes the frame malformed, and it is dropped with a log line. Transport.subscribe refuses such a since at the call, so a raw caller gets an error instead of waiting for ever.
  • A since above the head of the change log gets reset and a snapshot, where it got uptodate. A client of an object whose storage was recreated kept the old rows for ever.
  • The client sends a hydrated cursor in its plain form. A cursor in SSR meta written another way, such as "05", still resumes.

Breaking changes

  • An app with a table or command name over 128 bytes: registerSync throws.
  • An app that passes a transaction id over 256 bytes to createTransaction({ id }): the write is rejected with LIMIT_EXCEEDED.
  • A raw client with an id over 256 bytes, or a since that is not in the plain form.

A limit this does not close

After the reset for a since above the head, the client has the right rows on that connection, but its cursor still sits above the head. Each reconnect snapshots again until the object passes the cursor. If the object passes it while the client is away, the rows written in between are missed. This is the known limitation "No incarnation epoch" of ADR-0011. It is stated in the ADR and the changelog and pinned by a test written as an expected failure, so closing it later will flag itself.

Verification

  • Red tests first for each rule, with the edge of each limit in one, two and four byte characters.
  • An adversarial review by a different model, in two rounds, with its own runs in workerd. The first round found the cursor limit above, four log clipping tests that had stopped testing their own line because the new id refusal answered first, and an avoidable exception to ADR-0025. All are fixed. The second round removed each clipping call in turn and each time only its own test failed. Verdict: mergeable.
  • Typecheck and the full suite pass on @tanstack/db 1.0.0-rc.1.5 and 0.8.6.

Not verified by a run: an on-demand watch that meets the reset on a reconnect (read from the code), and a transaction id over SQLite's value cap of 2 200 000 bytes when a subclass has raised maxFrameBytes above it (it gets no reply, as before).

The decisions are a dated amendment to ADR-0012.

🤖 Generated with Claude Code

grrowl and others added 7 commits November 17, 2026 15:58
`since` was read with Number(), so "1e400" became Infinity and was answered
uptodate at the current position without sending anything, and "abc" became
NaN and got a snapshot. The frame guard now requires `since` to be a plain
decimal of at most 19 digits (SQLite's largest INTEGER) and drops any other
frame per ADR-0012 D1. A well formed since past the current position gets
reset and a snapshot instead of uptodate.

BREAKING CHANGE: a raw client that spells `since` any other way gets no reply
for that sub. The library's client always sends the plain decimal form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir own reply

A sub id was bounded only by the frame size, yet it is echoed in every frame
of its sub and stored in _sync_subs; a txId is stored in _sync_seen_tx; an
unknown collection or command name was quoted in a stored rejection.

An id (subId, fetchId, txId) may be at most 256 UTF-8 bytes and a collection
or command name at most 128. A frame over a limit gets its frame type's own
refusal, echoing the id once, with nothing stored: reset for a sub, an empty
page for a fetch, rejected LIMIT_EXCEEDED for a mut or call (before the
dedup lookup and not recorded), and an unsub is ignored. compileSchema
refuses a table or command name over 128 bytes, so every id the library's
client builds stays under the limit.

The two backstop tests that reached the _sync_subs row cap with a 600 KB sub
id now reach it with a predicate just under the cap.

BREAKING CHANGE: a raw client whose ids are over 256 bytes, or names over
128, is refused; an app supplied transaction id over 256 bytes is rejected
with LIMIT_EXCEEDED; a schema with a table or command name over 128 bytes
fails to register.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ast the head

The server now drops a since that is not plain decimal digits. parseSyncMeta
accepted any cursor BigInt parses (" 5", "05", "0x5") and the eager and
on-demand hydration paths sent it on unchanged, so changed meta would leave a
collection that silently stops receiving updates. parseSyncMeta now returns
the plain form and refuses a cursor past the largest the server accepts, like
an unparseable one; seedCursor refuses that cursor too.

The ADR-0012 amendment now states the reset for a since past the head as its
own decision, with what each kind of subscription does on it, pinned through
the real client for the eager sub and the hydration catch-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ce at subscribe

The txId length check now runs in #oncePerTx, after the dedup lookup and
before the txId is reserved, so ADR-0025's rule holds without exception: a
receipt stored under a long txId before the limit still replays, and a
refused txId is neither recorded nor left in flight.

Transport.subscribe refuses a since that is not a position in plain decimal
form, at the call, instead of sending a sub the server drops with no reply.
The pattern now lives in src/wire/frames.ts for both ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and an exact row cap

The id limit answered first for the tests that pinned the clip of the fetch
predicate refusal, the compiler's sub refusal and the malformed cursor, and
nothing pinned the txId refusal's clip. Each now has a test that asserts the
id's own clipped form, and fails when that one clip is removed.

L3 pins, as it.fails, that a reset for a since above the head does not repair
the cursor (ADR-0011 "No incarnation epoch"). The row cap helper imports
MAX_VALUE_BYTES and pads the stored form to exactly one byte under it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he id and name limits

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merges the frame guard change: ids at most 256 bytes and names at most 128,
refused with a reply; a since that is not a plain decimal position is a
malformed frame; a since above the head gets reset and a snapshot; the
client sends a hydrated cursor in its plain form. Adds the changelog
entries and two sentences the review asked for in ADR-0012.

BREAKING CHANGE: a table or command name over 128 bytes fails registerSync,
and an id over 256 bytes is refused.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@grrowl
grrowl merged commit 264de43 into main Nov 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant