Skip to content

chore(client): refuse an index no resolver serves (#1006) - #1022

Closed
drewlyton wants to merge 3 commits into
mainfrom
t3/de6bfc24
Closed

drewlyton wants to merge 3 commits into
mainfrom
t3/de6bfc24

Conversation

@drewlyton

Copy link
Copy Markdown
Contributor

Summary

An index name that no resolver serves is now author error, refused where the author wrote it. An index that has a resolver which answers null for a change keeps #961's declarer breadth, untouched.

query declares index ─┬─ resolver exists ──┬─ change resolves to keys → touch those declarers
                      │                    └─ change answers null    → touch every declarer  (#961, kept)
                      └─ no resolver ──────┬─ development → throw UnknownIndexError at add()  (new)
                                           └─ production  → touch every declarer            (#961, kept)
createChangeDispatcher({ requireResolvers: devWatchdog() })      subscriptions.ts
  add(entry, indexDependencies(entry))
    requireResolvers && resolverFor(index) === null
      → throw UnknownIndexError        before drop(), so nothing is half-applied
    registry re-states it with entry.key → "declared by \"<key>\""  (the query to go fix)

The failure mode, and why this one. The issue left it open (throw vs. a loud one-time diagnostic). Throwing at registration wins because the mistake is made at authoring time and the only person who can fix it is the author, at the line where they wrote the index name. A diagnostic puts the correction behind whoever reads logs later, and a per-subscription warning would need to survive coalescing to honour "one report per offending subscription" — machinery to keep a message nobody is looking for. The cost of throwing is that a shipped app could crash on a name it cannot serve, so the throw is gated on the existing devWatchdog(): production keeps the conservative breadth rather than failing to open a read. Hand-built dispatchers (tests, the benchmark) pass no flag, so they stay lenient — which is what keeps a test-only dispatcher usable.

The check lives in dispatcher.add, the single seam both open and depend route through, not in each resolver.

Two consequences the issue did not anticipate, argued rather than hidden:

  1. relation:typo/typo — the issue's own example — is served, not a typo. relation:*, exists:* and scope are registered namespace names, so any relation:<as>/<type> is answerable. Only a whole-family name (existence:todo/due, relations:…) is catchable today. The tests say so explicitly and use a catchable name at the registry seam; the issue's literal example can only be refused on a hand-built dispatcher with a narrower resolver set. Widening the check to validate <as>/<type> against the schema is a different change — it needs the schema at the dispatcher, which the registry does not pass.
  2. A refused declaration had to become atomic. The registry mutated the entry before re-indexing, so throwing there would have left a half-applied move. depend now snapshots what the move overwrites and restores it; a refused open removes the entry and marks it terminal. UnknownIndexError is exported because it escapes subscribe and depend.

Evidence

  • Before: a declared index with no resolver was indistinguishable from a resolver answering null — every declarer touched, silent. Covered by the pre-existing treats a declared index with no resolver as unresolvable, left unchanged and still green.
  • After: pnpm --filter @ebbjs/client test → 71 files, 1258 tests pass (was 1251 before this branch). Typecheck clean, pnpm lint 0 errors, pnpm fmt:check clean.
  • Red-first verified: stashing only the source files fails the 6 new refusal tests while the three that pin unchanged behaviour (namespace-served, null-breadth, production fallback) keep passing.
  • packages/client/src/benchmark/replica-read-model.ts not touched, so pnpm client:benchmark was not re-run and its previously reported sections stand.
  • New tests:
    • dependency-index.test.ts: refuses a declared index no resolver serves when the resolver set is complete, accepts a declared index a namespace resolver serves, keeps the declarer breadth when a served resolver answers null
    • subscriptions.test.ts (subscription registry: an index no resolver serves (#1006)): refuses the declaration in development, keeps what the entry held when a later declaration is refused, leaves no subscription behind when opening is refused, keeps the fallback in a production build

Merge Danger

Door: two-way — additive requireResolvers option and a new exported error class; no existing signature changed, and the changeset is a minor bump for @ebbjs/client precisely because the error is newly exported.

Blast Radius: narrow — one dispatcher option, one registry gate, one error type.

Development builds now throw where they previously degraded silently. That is the point, but it can surface a latent typo'd index in an app that has been shipping with one; the message names the index, the known indices, and the subscription key that declared it. A production bundle is unaffected.

Issue #1006 is referenced, not autoclosed.

Drew Lyton added 3 commits November 27, 2026 13:33
A declared index name nothing serves used to be treated exactly like a
resolver answering null: every declarer was touched. Correct but silent, so
a typo cost speed and told nobody.

A dispatcher built with requireResolvers refuses such a declaration in add
with UnknownIndexError naming the index and the resolvers it does have. The
check runs before the entry is re-indexed, so a refusal leaves the
dispatcher and the entry's previous indexing untouched.

The subscription registry sets the flag from its existing dev gate, so a
development build fails at subscribe time while a production build keeps
the conservative breadth. A served resolver answering null still touches
every declarer (#961).
… from (#1006)

Review follow-ups on the unknown-index refusal:

- `UnknownIndexError` carries the subscription key, and the registry re-states
  the refusal with it, so the author is told which query to go and fix rather
  than only which index name. `createChangeDispatcher` indexes an opaque entry,
  so the key can only come from the registry.
- The refused-declaration rollback in `depend` captures one snapshot instead of
  six loose locals, and says in the comment why a key-only move restores the
  claim bookkeeping too.
- `UnknownIndexError` is exported: it escapes `subscribe` and `depend`, so a
  caller opening reads programmatically can catch it. That makes the change a
  minor bump, not a patch.
- The tests assert the error's fields instead of pinning the registry's whole
  resolver inventory and order into a message regex.
@netlify

netlify Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for ebbjs-www ready!

Name Link
🔨 Latest commit 977eda9
🔍 Latest deploy log https://app.netlify.com/projects/ebbjs-www/deploys/6b098b72f978d8a64e98f1e5
😎 Deploy Preview https://deploy-preview-1022--ebbjs-www.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@drewlyton

Copy link
Copy Markdown
Contributor Author

ADR 0006 landed on main (#1027). It makes IndexResolver total: no null, byIndexAll deleted, and an unknown index name throws in every build.

That supersedes this PR's split (throw in development for unserved names, keep the null fallback in production). Please do not rebase it as-is.

The valuable parts should move into #1025: UnknownIndexError, the atomic refusal in add/depend, and the tests proving a refused declaration leaves nothing half-applied. Recommend closing this once #1025 carries them.

@drewlyton

Copy link
Copy Markdown
Contributor Author

Closing this unmerged rather than rebasing it onto ADR 0006.

The branch stays (t3/de6bfc24, tip 977eda9) and its content has been lifted into #1025's "Salvage from PR #1022" section: UnknownIndexError with the subscription subject, knownIndexErrorFor, the atomic refusal in depend (snapshot and restore suppliedIndices, dependencies, reads, generation, claimsSince, warnedAt), the terminal refusal in open, the dispatcher.add placement, and the three tests that pin those.

Dropped with it: the requireResolvers option, the devWatchdog() gate, and the three tests that pin the null fallback this supersedes.

The one finding that outlived the PR is tracked as #1028: relation:<as>/<type> cannot be refused while relation:* is a namespace resolver.

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