Closes#127. FPRD-001b, CARD-13. This is a breaking change for RC.1.
What changes
Before, two sibling routes could match the same request and the router picked one by registration order or precedence, with nothing reported. Now createApp refuses two cases. Mesh splicing refuses the same two cases between routes from different teapots.
Ambiguous. Two constrained siblings whose constraints accept a common segment, where the rest of both patterns can match one request. The error names both declarations and gives a witness segment with an example request.
Unreachable. A plain :param next to a constraint that accepts every segment and outranks it. On WebSocket, it is also a constrained param declared after a plain one. The error names the dead route and the route that wins.
The fallback pattern (/u/:id(\d+) + /u/:slug) still boots, and its routing is unchanged.
Conflict definition (as implemented)
Two routes are checked when they have the same method and share a lookup table:
HTTP: every transport except ws.
WebSocket: ws and negotiate. @Stream is in both tables and is checked under both.
Each table uses its own precedence. HTTP uses specificity, then registration order. WebSocket uses declaration order only (matchWsRoute, frozen in matcher-ws.json).
Siblings at k.k is the first segment whose shape differs. Every segment before k has the same shape, so both routes are in the same radix node. At k both segments are params and at least one is constrained.
A static at k is not a sibling param. It wins on the raw segment, and a constrained twin is still reachable by a percent-encoded spelling: /u/me vs /u/:id(me) is reachable through /u/%6De.
A catch-all at k is not a sibling param either.
Ambiguous. Both are constrained (different sources). The intersection of their languages is non-empty, and the rest of the two patterns can match one request:
every later segment pair overlaps (static/static equal, a static accepted by a param, or a non-empty intersection of two params);
a catch-all absorbs whatever the other side still needs.
So /u/:id(\d+)/a + /u/:n(\d{1,3})/b boots, and /u/:id(\d+)/a + /u/:n(\d{1,3})/:x fails with witness /u/0/a.
Unreachable. One is constrained and one is plain. The winner of the branch must match every request the loser matches:
Under specificity the constrained one wins, unless exactly one route is a catch-all; then the exact route wins outright. The winning constraint must accept every segment.
Under registration order the earlier route wins.
Later segments must be included one by one: equal statics; anything under a plain param; a static the constraint matches; the same constraint source; or anything under a constraint that accepts every segment.
Universe. What the router hands a param: a decoded, non-empty segment. It may contain any Unicode scalar value, including / from %2F. It is never . or .., because normalization resolves those. Witnesses come from this universe, so each one is a request that really reaches both routes.
Implementation: routeConflict in src/http/route-conflicts.ts, which also documents the definition. It is wired into assertRouteAvailable (local) and spliceRemoteScopes (remote vs remote).
Decision procedure and complexity
Atoms to character sets. Each atom becomes a set of code points under u-flag semantics: \d \D \w \W \s \S, unescaped . (which excludes line terminators), escaped literals, and [...] classes with ranges, negation and escapes (\b \cX \0 \xHH \uHHHH, surrogate pairs, \u{...}). \p{...} / \P{...} are not modelled. For those, the engine is asked once per code point, cached per source, in about 28 ms. Sets were checked against the engine on every BMP code point plus an astral stride and every range edge.
Constraint to blocks. Each constraint becomes a list of blocks, one (set, min, max) per atom. The same CONSTRAINT_ATOM / CONSTRAINT_QUANTIFIER regexes are now exported from router.ts, so the reader cannot drift from assertSafeConstraint.
Intersection with a witness. A product walk runs over entry states (block a, block b, which side just entered, all-dots-so-far). Each state holds a set of counter values for the other side. Unbounded blocks clamp the counter at min. Runs inside one block pair are handled as intervals, and a union-find fill marks each value once. Optional blocks are skipped one at a time by zero-length moves. The all-dot strings are handled exactly in closed form, because their lengths form an interval on each side.
Cost: O(|A|·|B|·(|A|+|B|)·K) per pair, with K ≤ 2048 (the subset's quantifier bound) and |A|, |B| ≤ 128 blocks.
Accepts every segment. This is closed form, O(n). It holds when some block is Σ with no upper bound, every block with min ≥ 1 is Σ, and the mins sum to at most 1. The proof of both directions is in the code comment.
Not decided. Inclusion between two different constraints at a later segment of an unreachable candidate. I don't know a polynomial algorithm for it in this grammar. Such a route counts as not included and boots, as before. This is documented in the code, CHANGELOG and tests.
Per request. Nothing here runs per request, and the lookup path is untouched. router.ts only gains the two exported regex constants.
Test cases (card T1–T9), exact messages
#
Declarations
Result
T1
GET /algo/:id, GET /algo/:a(.*)
boots — see Deviation./algo/x → :a, /algo/%0A → :id
T1b
GET /algo/:id, GET /algo/:a([^]*)
unreachable route GET /algo/:id at Routes.h0: GET /algo/:a([^]*) at Routes.h1 matches every request it would, and wins each one — its constraint accepts every segment, and a constrained parameter outranks a plain one. Remove one of them, or narrow the constraint
T2
GET /u/:id(\d+), GET /u/:n(\d{1,3})
ambiguous route GET /u/:n(\d{1,3}) at Routes.h1 conflicts with GET /u/:id(\d+) at Routes.h0: both match '0' (GET /u/0), so only declaration order would choose between them — give the constraints disjoint languages, or merge the routes
T3
GET /u/:id(\d+), GET /u/:id([0-9]+)
ambiguous route GET /u/:id([0-9]+) at Routes.h1 conflicts with GET /u/:id(\d+) at Routes.h0: both match '0' (GET /u/0), … (same tail)
T4
GET /u/:id(\d+), GET /u/:slug
boots, in both declaration orders; /u/42 → :id, /u/bob → :slug
T5
GET /u/:id(\d+), GET /u/:s([a-z]+)
boots
T6
GET /u/:id(\d+), POST /u/:n(\d{1,3})
boots
T7
WS /r/:id, WS /r/:a(.*)
unreachable route WS /r/:a(.*) at Routes.h1: WS /r/:id at Routes.h0 matches every request it would, and wins each one — WebSocket routes are matched in declaration order, and it is declared first. Remove one of them, or narrow the constraint
T8
two teapots, one exporting GET /u/:id(\d+) and one GET /u/:n(\d{1,3})
mesh: ambiguous remote route 'GET /u/:n(\d{1,3})' from <teapot2> conflicts with 'GET /u/:id(\d+)' from <teapot1>: both match '0' (GET /u/0) — green-tea will not choose one for you. Export only one of them, or give their constraints disjoint languages.
T9
GET /t/:a(\d{0,2048}), GET /t/:b([0-9]{0,2048})
ambiguous route GET /t/:b([0-9]{0,2048}) … both match '0' (GET /t/0) …
Further cases:
WS ambiguity.
WS and HTTP routes are not compared with each other (they are different tables).
@Stream + WS uses declaration order.
A remote unreachable pair is refused.
A remote fallback pair boots and routes.
Local vs remote boots, with the local override.
Ambiguity is checked against the whole pattern, catch-all included.
Different radix nodes and an exact route vs a catch-all route are not conflicts.
T9 boot time, measured with tsx on Node 22.22.2 / Apple M4 Max, with each conflict check timed alone:
Pair
First call (includes parsing)
Median of 15
\d{0,2048} vs [0-9]{0,2048} (ambiguous)
0.38 ms
0.04 ms
\d{0,2048} vs [a-z]{0,2048} (disjoint)
0.04 ms
0.02 ms
Largest product the 128-character limit allows (\d{0,2048}×12+a vs [0-9]{0,2048}×9+b, empty, so every state is visited)
94.7 ms
85.9 ms
A whole createApp for the T9 pair takes 0.3 ms. The first version of the walk fanned out to every block it could skip to and took 3.5 s on that worst case. Skipping one optional block at a time brought it down to about 90 ms.
Property test. The walk is checked against brute-force enumeration over short strings, with a fixed seed (13127) and 300 generated constraint pairs.
Every witness is accepted by both engines and lies in the universe.
Every brute-force hit is also found by the walk.
Both outcomes are exercised: more than 30 pairs intersect and more than 30 do not.
Deviation: T1
The card expects T1 to fail as unreachable, because (.*) "accepts every segment". It does not. Without the s flag, . excludes \n, \r, U+2028 and U+2029. A request for /algo/%0A reaches :id today, as the T1 test shows through app.fetch. Failing boot would mean the error claims something false, and the card asks for no heuristics, so T1 boots.
A constraint that really accepts every segment ([^]*, [\s\S]+) fails as unreachable (T1b). WS T7 fails anyway, because the plain WS route is declared first.
If the owner wants .* to count as covering, the change is one line: drop line terminators from the universe. The unreachable message would then need to say "except line terminators". Owner decision requested.
Owner approval required
The corpus is affected in one place, in its own commit e41d956:
test/router-parity/app-fixture.ts: ParityHttp.nCode goes from GET /n/:code([0-9a-f]+) to GET /n/:code([a-f]+).
The original overlaps nNum's \d+. That is now a boot error, so the fixture app (app-fetch.json, app-node.json, and the Deno/Bun/workerd parity runs) could not boot.
No frozen JSON changes. The two frozen requests on this pair, /n/42 → nNum and /n/ff → nCode, return identical captures.
What is lost is an app-level instance of the equal-rank registration tie between overlapping constraints. CARD-13 now forbids that tie at boot. It stays covered at matcher level (matcher-hand.json, which never boots an app).
No other frozen file changes. boot-app.json and boot-mesh.json still pass as captured: B16 \d+ vs [a-z]+ is disjoint and still boots.
Gates
npm run lint: 0 errors. The 50 warnings are pre-existing no-explicit-any.
format:check: clean, and prettier ran on the changed tests.
build, then typecheck, then typecheck:bench: clean.
npm test: 915/915. The baseline was 822, plus 93 new tests.
test:deno: 36 passed.
test:bun: 26 passed.
test:edge: PASS, including 1158 matcher cases and 55 app.fetch parity cases.
parity:mutants: 21/21 killed, with a clean src diff.
The README note was added under Routing. The README paragraph just below it still says "Matching is still a linear scan", which is stale since the radix index. I left it untouched as out of scope.
Closes #127. FPRD-001b, CARD-13. This is a **breaking change** for RC.1.
## What changes
Before, two sibling routes could match the same request and the router picked one by registration order or precedence, with nothing reported. Now `createApp` refuses two cases. Mesh splicing refuses the same two cases between routes from different teapots.
- **Ambiguous.** Two constrained siblings whose constraints accept a common segment, where the rest of both patterns can match one request. The error names both declarations and gives a witness segment with an example request.
- **Unreachable.** A plain `:param` next to a constraint that accepts every segment and outranks it. On WebSocket, it is also a constrained param declared after a plain one. The error names the dead route and the route that wins.
The fallback pattern (`/u/:id(\d+)` + `/u/:slug`) still boots, and its routing is unchanged.
## Conflict definition (as implemented)
Two routes are checked when they have the same method and share a lookup table:
- HTTP: every transport except `ws`.
- WebSocket: `ws` and `negotiate`. `@Stream` is in both tables and is checked under both.
Each table uses its own precedence. HTTP uses specificity, then registration order. WebSocket uses declaration order only (`matchWsRoute`, frozen in `matcher-ws.json`).
- **Siblings at k.** `k` is the first segment whose shape differs. Every segment before `k` has the same shape, so both routes are in the same radix node. At `k` both segments are params and at least one is constrained.
- A static at `k` is not a sibling param. It wins on the raw segment, and a constrained twin is still reachable by a percent-encoded spelling: `/u/me` vs `/u/:id(me)` is reachable through `/u/%6De`.
- A catch-all at `k` is not a sibling param either.
- **Ambiguous.** Both are constrained (different sources). The intersection of their languages is non-empty, and the rest of the two patterns can match one request:
- every later segment pair overlaps (static/static equal, a static accepted by a param, or a non-empty intersection of two params);
- a catch-all absorbs whatever the other side still needs.
So `/u/:id(\d+)/a` + `/u/:n(\d{1,3})/b` boots, and `/u/:id(\d+)/a` + `/u/:n(\d{1,3})/:x` fails with witness `/u/0/a`.
- **Unreachable.** One is constrained and one is plain. The winner of the branch must match every request the loser matches:
- Under specificity the constrained one wins, unless exactly one route is a catch-all; then the exact route wins outright. The winning constraint must accept every segment.
- Under registration order the earlier route wins.
- Later segments must be included one by one: equal statics; anything under a plain param; a static the constraint matches; the same constraint source; or anything under a constraint that accepts every segment.
- **Universe.** What the router hands a param: a decoded, non-empty segment. It may contain any Unicode scalar value, including `/` from `%2F`. It is never `.` or `..`, because normalization resolves those. Witnesses come from this universe, so each one is a request that really reaches both routes.
Implementation: `routeConflict` in `src/http/route-conflicts.ts`, which also documents the definition. It is wired into `assertRouteAvailable` (local) and `spliceRemoteScopes` (remote vs remote).
## Decision procedure and complexity
- **Atoms to character sets.** Each atom becomes a set of code points under `u`-flag semantics: `\d \D \w \W \s \S`, unescaped `.` (which excludes line terminators), escaped literals, and `[...]` classes with ranges, negation and escapes (`\b \cX \0 \xHH \uHHHH`, surrogate pairs, `\u{...}`). `\p{...}` / `\P{...}` are not modelled. For those, the engine is asked once per code point, cached per source, in about 28 ms. Sets were checked against the engine on every BMP code point plus an astral stride and every range edge.
- **Constraint to blocks.** Each constraint becomes a list of blocks, one (set, min, max) per atom. The same `CONSTRAINT_ATOM` / `CONSTRAINT_QUANTIFIER` regexes are now exported from `router.ts`, so the reader cannot drift from `assertSafeConstraint`.
- **Intersection with a witness.** A product walk runs over entry states `(block a, block b, which side just entered, all-dots-so-far)`. Each state holds a set of counter values for the other side. Unbounded blocks clamp the counter at `min`. Runs inside one block pair are handled as intervals, and a union-find fill marks each value once. Optional blocks are skipped one at a time by zero-length moves. The all-dot strings are handled exactly in closed form, because their lengths form an interval on each side.
- Cost: **O(|A|·|B|·(|A|+|B|)·K)** per pair, with K ≤ 2048 (the subset's quantifier bound) and |A|, |B| ≤ 128 blocks.
- **Accepts every segment.** This is closed form, O(n). It holds when some block is Σ with no upper bound, every block with `min ≥ 1` is Σ, and the mins sum to at most 1. The proof of both directions is in the code comment.
- **Not decided.** Inclusion between two *different* constraints at a later segment of an unreachable candidate. I don't know a polynomial algorithm for it in this grammar. Such a route counts as not included and boots, as before. This is documented in the code, CHANGELOG and tests.
- **Per request.** Nothing here runs per request, and the lookup path is untouched. `router.ts` only gains the two exported regex constants.
## Test cases (card T1–T9), exact messages
| # | Declarations | Result |
|---|---|---|
| T1 | `GET /algo/:id`, `GET /algo/:a(.*)` | **boots — see Deviation.** `/algo/x` → `:a`, `/algo/%0A` → `:id` |
| T1b | `GET /algo/:id`, `GET /algo/:a([^]*)` | `unreachable route GET /algo/:id at Routes.h0: GET /algo/:a([^]*) at Routes.h1 matches every request it would, and wins each one — its constraint accepts every segment, and a constrained parameter outranks a plain one. Remove one of them, or narrow the constraint` |
| T2 | `GET /u/:id(\d+)`, `GET /u/:n(\d{1,3})` | `ambiguous route GET /u/:n(\d{1,3}) at Routes.h1 conflicts with GET /u/:id(\d+) at Routes.h0: both match '0' (GET /u/0), so only declaration order would choose between them — give the constraints disjoint languages, or merge the routes` |
| T3 | `GET /u/:id(\d+)`, `GET /u/:id([0-9]+)` | `ambiguous route GET /u/:id([0-9]+) at Routes.h1 conflicts with GET /u/:id(\d+) at Routes.h0: both match '0' (GET /u/0), …` (same tail) |
| T4 | `GET /u/:id(\d+)`, `GET /u/:slug` | boots, in both declaration orders; `/u/42` → `:id`, `/u/bob` → `:slug` |
| T5 | `GET /u/:id(\d+)`, `GET /u/:s([a-z]+)` | boots |
| T6 | `GET /u/:id(\d+)`, `POST /u/:n(\d{1,3})` | boots |
| T7 | WS `/r/:id`, WS `/r/:a(.*)` | `unreachable route WS /r/:a(.*) at Routes.h1: WS /r/:id at Routes.h0 matches every request it would, and wins each one — WebSocket routes are matched in declaration order, and it is declared first. Remove one of them, or narrow the constraint` |
| T8 | two teapots, one exporting `GET /u/:id(\d+)` and one `GET /u/:n(\d{1,3})` | `mesh: ambiguous remote route 'GET /u/:n(\d{1,3})' from <teapot2> conflicts with 'GET /u/:id(\d+)' from <teapot1>: both match '0' (GET /u/0) — green-tea will not choose one for you. Export only one of them, or give their constraints disjoint languages.` |
| T9 | `GET /t/:a(\d{0,2048})`, `GET /t/:b([0-9]{0,2048})` | `ambiguous route GET /t/:b([0-9]{0,2048}) … both match '0' (GET /t/0) …` |
Further cases:
- WS ambiguity.
- WS and HTTP routes are not compared with each other (they are different tables).
- `@Stream` + WS uses declaration order.
- A remote unreachable pair is refused.
- A remote fallback pair boots and routes.
- Local vs remote boots, with the local override.
- Ambiguity is checked against the whole pattern, catch-all included.
- Different radix nodes and an exact route vs a catch-all route are not conflicts.
**T9 boot time**, measured with `tsx` on Node 22.22.2 / Apple M4 Max, with each conflict check timed alone:
| Pair | First call (includes parsing) | Median of 15 |
|---|---|---|
| `\d{0,2048}` vs `[0-9]{0,2048}` (ambiguous) | 0.38 ms | 0.04 ms |
| `\d{0,2048}` vs `[a-z]{0,2048}` (disjoint) | 0.04 ms | 0.02 ms |
| Largest product the 128-character limit allows (`\d{0,2048}`×12+`a` vs `[0-9]{0,2048}`×9+`b`, empty, so every state is visited) | 94.7 ms | 85.9 ms |
A whole `createApp` for the T9 pair takes 0.3 ms. The first version of the walk fanned out to every block it could skip to and took 3.5 s on that worst case. Skipping one optional block at a time brought it down to about 90 ms.
**Property test.** The walk is checked against brute-force enumeration over short strings, with a fixed seed (`13127`) and 300 generated constraint pairs.
- Every witness is accepted by both engines and lies in the universe.
- Every brute-force hit is also found by the walk.
- Both outcomes are exercised: more than 30 pairs intersect and more than 30 do not.
## Deviation: T1
The card expects T1 to fail as unreachable, because `(.*)` "accepts every segment". It does not. Without the `s` flag, `.` excludes `\n`, `\r`, U+2028 and U+2029. A request for `/algo/%0A` reaches `:id` today, as the T1 test shows through `app.fetch`. Failing boot would mean the error claims something false, and the card asks for no heuristics, so T1 boots.
A constraint that really accepts every segment (`[^]*`, `[\s\S]+`) fails as unreachable (T1b). WS T7 fails anyway, because the plain WS route is declared first.
If the owner wants `.*` to count as covering, the change is one line: drop line terminators from the universe. The `unreachable` message would then need to say "except line terminators". **Owner decision requested.**
## Owner approval required
The corpus is affected in one place, in its own commit `e41d956`:
- `test/router-parity/app-fixture.ts`: `ParityHttp.nCode` goes from `GET /n/:code([0-9a-f]+)` to `GET /n/:code([a-f]+)`.
- The original overlaps `nNum`'s `\d+`. That is now a boot error, so the fixture app (`app-fetch.json`, `app-node.json`, and the Deno/Bun/workerd parity runs) could not boot.
- **No frozen JSON changes.** The two frozen requests on this pair, `/n/42` → `nNum` and `/n/ff` → `nCode`, return identical captures.
- What is lost is an app-level instance of the equal-rank registration tie between overlapping constraints. CARD-13 now forbids that tie at boot. It stays covered at matcher level (`matcher-hand.json`, which never boots an app).
No other frozen file changes. `boot-app.json` and `boot-mesh.json` still pass as captured: B16 `\d+` vs `[a-z]+` is disjoint and still boots.
## Gates
- `npm run lint`: 0 errors. The 50 warnings are pre-existing `no-explicit-any`.
- `format:check`: clean, and prettier ran on the changed tests.
- `build`, then `typecheck`, then `typecheck:bench`: clean.
- `npm test`: 915/915. The baseline was 822, plus 93 new tests.
- `test:deno`: 36 passed.
- `test:bun`: 26 passed.
- `test:edge`: PASS, including 1158 matcher cases and 55 `app.fetch` parity cases.
- `parity:mutants`: **21/21 killed**, with a clean `src` diff.
- `complexity:check`: every function ≤ 25.
- `npm audit --audit-level=moderate`: 0 vulnerabilities.
## Notes
- The README note was added under Routing. The README paragraph just below it still says "Matching is still a linear scan", which is stale since the radix index. I left it untouched as out of scope.
- The docs companion PR, Expressive-Tea/green-tea-docs#24 (https://github.com/Expressive-Tea/green-tea-docs/pull/24), adds a routing-guide section on these boot errors, with the T4 fallback example.
The frozen app fixture declares GET /n/:num(\d+) and GET /n/:code([0-9a-f]+).
Both constraints accept digits, so CARD-13 (#127) makes this pair a boot error,
and the fixture app could no longer start. That would fail app-fetch.json and
app-node.json, and the Deno, Bun and workerd parity runs that boot the same app.
Narrow nCode to [a-f]+. The two frozen requests on this pair still get the
captured answers: /n/42 goes to nNum and /n/ff goes to nCode, with the same
params. No frozen JSON file changes.
What is lost at app level is the equal-rank registration tie between two
overlapping constraints. CARD-13 now forbids that tie at boot. The tie stays
covered by matcher-hand.json, which calls the matcher without booting an app.
Owner approval required (CARD-08 rule): this edits a file under
test/router-parity/.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Before, when two sibling routes could match the same request, the router
picked one by registration order or precedence, and nothing reported it.
Boot now refuses two cases between routes of the same method that branch at
the same segment under the same prefix:
- ambiguous: both params are constrained, the constraints accept a common
segment, and the rest of both patterns can match one request. The error
names both declarations and a witness segment with an example path.
- unreachable: a plain param sits next to a constraint that accepts every
segment, and the constraint wins every request the plain param could take.
A plain param next to a constraint that leaves some segments over is the
documented fallback pattern and still boots.
The check is exact. assertSafeConstraint admits only a linear, group-free
subset, so every constraint reads back as a sequence of (character set, min,
max) blocks. Atom sets follow u-flag semantics. \p{...} is the one construct
that is not modelled, and for it the engine is asked once per code point. A
product walk over two block sequences finds a common segment, or proves none
exists, in O(|A|*|B|*(|A|+|B|)*K) with K <= 2048. "Accepts every segment" is
a closed-form test on the blocks. Both are measured against what the router
hands a param: a decoded, non-empty segment that is never "." or "..".
The check runs per table under that table's own precedence. HTTP ranks by
specificity. WebSocket takes the first declared match. @Stream routes sit in
both tables. Routes exported by different teapots are checked against each
other. Local against remote keeps the local override and its warning.
The lookup path is unchanged. router.ts only exports the two token regexes,
so the boot check and assertSafeConstraint read atoms the same way.
BREAKING CHANGE: an app that declares two overlapping constrained siblings
(e.g. /u/:id(\d+) and /u/:n(\d{1,3})), or a plain param beside a constraint
that accepts every segment, now fails createApp. So do a plain WebSocket param
declared before a constrained sibling, and such pairs across mesh teapots.
Refs: #127
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The README still said matching was a linear scan with a radix tree as
post-beta work; CARD-07 (#128) shipped the radix index.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
T1 deviation accepted.(.*) is not treated as covering every segment, because an unescaped . does not match line terminators. A constraint that does accept every segment, such as ([^]*), still fails boot as unreachable.
WebSocket precedence accepted. WebSocket routes apply the rules with their frozen declaration-order precedence, so a plain WS param declared before a constrained one fails boot.
Frozen fixture change approved.e41d956 changes test/router-parity/app-fixture.ts so that nCode is [a-f]+ instead of [0-9a-f]+. No frozen JSON changes.
README: the stale "linear scan" sentence now describes radix lookup (84e6f07).
Owner decisions (2026-10-13):
- **T1 deviation accepted.** `(.*)` is not treated as covering every segment, because an unescaped `.` does not match line terminators. A constraint that does accept every segment, such as `([^]*)`, still fails boot as unreachable.
- **WebSocket precedence accepted.** WebSocket routes apply the rules with their frozen declaration-order precedence, so a plain WS param declared before a constrained one fails boot.
- **Frozen fixture change approved.** `e41d956` changes `test/router-parity/app-fixture.ts` so that `nCode` is `[a-f]+` instead of `[0-9a-f]+`. No frozen JSON changes.
- **README:** the stale "linear scan" sentence now describes radix lookup (`84e6f07`).
chrnx
merged commit 539f287a67 into develop2026-10-14 02:22:30 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Closes #127. FPRD-001b, CARD-13. This is a breaking change for RC.1.
What changes
Before, two sibling routes could match the same request and the router picked one by registration order or precedence, with nothing reported. Now
createApprefuses two cases. Mesh splicing refuses the same two cases between routes from different teapots.:paramnext to a constraint that accepts every segment and outranks it. On WebSocket, it is also a constrained param declared after a plain one. The error names the dead route and the route that wins.The fallback pattern (
/u/:id(\d+)+/u/:slug) still boots, and its routing is unchanged.Conflict definition (as implemented)
Two routes are checked when they have the same method and share a lookup table:
ws.wsandnegotiate.@Streamis in both tables and is checked under both.Each table uses its own precedence. HTTP uses specificity, then registration order. WebSocket uses declaration order only (
matchWsRoute, frozen inmatcher-ws.json).Siblings at k.
kis the first segment whose shape differs. Every segment beforekhas the same shape, so both routes are in the same radix node. Atkboth segments are params and at least one is constrained.kis not a sibling param. It wins on the raw segment, and a constrained twin is still reachable by a percent-encoded spelling:/u/mevs/u/:id(me)is reachable through/u/%6De.kis not a sibling param either.Ambiguous. Both are constrained (different sources). The intersection of their languages is non-empty, and the rest of the two patterns can match one request:
So
/u/:id(\d+)/a+/u/:n(\d{1,3})/bboots, and/u/:id(\d+)/a+/u/:n(\d{1,3})/:xfails with witness/u/0/a.Unreachable. One is constrained and one is plain. The winner of the branch must match every request the loser matches:
Universe. What the router hands a param: a decoded, non-empty segment. It may contain any Unicode scalar value, including
/from%2F. It is never.or.., because normalization resolves those. Witnesses come from this universe, so each one is a request that really reaches both routes.Implementation:
routeConflictinsrc/http/route-conflicts.ts, which also documents the definition. It is wired intoassertRouteAvailable(local) andspliceRemoteScopes(remote vs remote).Decision procedure and complexity
u-flag semantics:\d \D \w \W \s \S, unescaped.(which excludes line terminators), escaped literals, and[...]classes with ranges, negation and escapes (\b \cX \0 \xHH \uHHHH, surrogate pairs,\u{...}).\p{...}/\P{...}are not modelled. For those, the engine is asked once per code point, cached per source, in about 28 ms. Sets were checked against the engine on every BMP code point plus an astral stride and every range edge.CONSTRAINT_ATOM/CONSTRAINT_QUANTIFIERregexes are now exported fromrouter.ts, so the reader cannot drift fromassertSafeConstraint.(block a, block b, which side just entered, all-dots-so-far). Each state holds a set of counter values for the other side. Unbounded blocks clamp the counter atmin. Runs inside one block pair are handled as intervals, and a union-find fill marks each value once. Optional blocks are skipped one at a time by zero-length moves. The all-dot strings are handled exactly in closed form, because their lengths form an interval on each side.min ≥ 1is Σ, and the mins sum to at most 1. The proof of both directions is in the code comment.router.tsonly gains the two exported regex constants.Test cases (card T1–T9), exact messages
GET /algo/:id,GET /algo/:a(.*)/algo/x→:a,/algo/%0A→:idGET /algo/:id,GET /algo/:a([^]*)unreachable route GET /algo/:id at Routes.h0: GET /algo/:a([^]*) at Routes.h1 matches every request it would, and wins each one — its constraint accepts every segment, and a constrained parameter outranks a plain one. Remove one of them, or narrow the constraintGET /u/:id(\d+),GET /u/:n(\d{1,3})ambiguous route GET /u/:n(\d{1,3}) at Routes.h1 conflicts with GET /u/:id(\d+) at Routes.h0: both match '0' (GET /u/0), so only declaration order would choose between them — give the constraints disjoint languages, or merge the routesGET /u/:id(\d+),GET /u/:id([0-9]+)ambiguous route GET /u/:id([0-9]+) at Routes.h1 conflicts with GET /u/:id(\d+) at Routes.h0: both match '0' (GET /u/0), …(same tail)GET /u/:id(\d+),GET /u/:slug/u/42→:id,/u/bob→:slugGET /u/:id(\d+),GET /u/:s([a-z]+)GET /u/:id(\d+),POST /u/:n(\d{1,3})/r/:id, WS/r/:a(.*)unreachable route WS /r/:a(.*) at Routes.h1: WS /r/:id at Routes.h0 matches every request it would, and wins each one — WebSocket routes are matched in declaration order, and it is declared first. Remove one of them, or narrow the constraintGET /u/:id(\d+)and oneGET /u/:n(\d{1,3})mesh: ambiguous remote route 'GET /u/:n(\d{1,3})' from <teapot2> conflicts with 'GET /u/:id(\d+)' from <teapot1>: both match '0' (GET /u/0) — green-tea will not choose one for you. Export only one of them, or give their constraints disjoint languages.GET /t/:a(\d{0,2048}),GET /t/:b([0-9]{0,2048})ambiguous route GET /t/:b([0-9]{0,2048}) … both match '0' (GET /t/0) …Further cases:
@Stream+ WS uses declaration order.T9 boot time, measured with
tsxon Node 22.22.2 / Apple M4 Max, with each conflict check timed alone:\d{0,2048}vs[0-9]{0,2048}(ambiguous)\d{0,2048}vs[a-z]{0,2048}(disjoint)\d{0,2048}×12+avs[0-9]{0,2048}×9+b, empty, so every state is visited)A whole
createAppfor the T9 pair takes 0.3 ms. The first version of the walk fanned out to every block it could skip to and took 3.5 s on that worst case. Skipping one optional block at a time brought it down to about 90 ms.Property test. The walk is checked against brute-force enumeration over short strings, with a fixed seed (
13127) and 300 generated constraint pairs.Deviation: T1
The card expects T1 to fail as unreachable, because
(.*)"accepts every segment". It does not. Without thesflag,.excludes\n,\r, U+2028 and U+2029. A request for/algo/%0Areaches:idtoday, as the T1 test shows throughapp.fetch. Failing boot would mean the error claims something false, and the card asks for no heuristics, so T1 boots.A constraint that really accepts every segment (
[^]*,[\s\S]+) fails as unreachable (T1b). WS T7 fails anyway, because the plain WS route is declared first.If the owner wants
.*to count as covering, the change is one line: drop line terminators from the universe. Theunreachablemessage would then need to say "except line terminators". Owner decision requested.Owner approval required
The corpus is affected in one place, in its own commit
e41d956:test/router-parity/app-fixture.ts:ParityHttp.nCodegoes fromGET /n/:code([0-9a-f]+)toGET /n/:code([a-f]+).nNum's\d+. That is now a boot error, so the fixture app (app-fetch.json,app-node.json, and the Deno/Bun/workerd parity runs) could not boot./n/42→nNumand/n/ff→nCode, return identical captures.matcher-hand.json, which never boots an app).No other frozen file changes.
boot-app.jsonandboot-mesh.jsonstill pass as captured: B16\d+vs[a-z]+is disjoint and still boots.Gates
npm run lint: 0 errors. The 50 warnings are pre-existingno-explicit-any.format:check: clean, and prettier ran on the changed tests.build, thentypecheck, thentypecheck:bench: clean.npm test: 915/915. The baseline was 822, plus 93 new tests.test:deno: 36 passed.test:bun: 26 passed.test:edge: PASS, including 1158 matcher cases and 55app.fetchparity cases.parity:mutants: 21/21 killed, with a cleansrcdiff.complexity:check: every function ≤ 25.npm audit --audit-level=moderate: 0 vulnerabilities.Notes
Before, when two sibling routes could match the same request, the router picked one by registration order or precedence, and nothing reported it. Boot now refuses two cases between routes of the same method that branch at the same segment under the same prefix: - ambiguous: both params are constrained, the constraints accept a common segment, and the rest of both patterns can match one request. The error names both declarations and a witness segment with an example path. - unreachable: a plain param sits next to a constraint that accepts every segment, and the constraint wins every request the plain param could take. A plain param next to a constraint that leaves some segments over is the documented fallback pattern and still boots. The check is exact. assertSafeConstraint admits only a linear, group-free subset, so every constraint reads back as a sequence of (character set, min, max) blocks. Atom sets follow u-flag semantics. \p{...} is the one construct that is not modelled, and for it the engine is asked once per code point. A product walk over two block sequences finds a common segment, or proves none exists, in O(|A|*|B|*(|A|+|B|)*K) with K <= 2048. "Accepts every segment" is a closed-form test on the blocks. Both are measured against what the router hands a param: a decoded, non-empty segment that is never "." or "..". The check runs per table under that table's own precedence. HTTP ranks by specificity. WebSocket takes the first declared match. @Stream routes sit in both tables. Routes exported by different teapots are checked against each other. Local against remote keeps the local override and its warning. The lookup path is unchanged. router.ts only exports the two token regexes, so the boot check and assertSafeConstraint read atoms the same way. BREAKING CHANGE: an app that declares two overlapping constrained siblings (e.g. /u/:id(\d+) and /u/:n(\d{1,3})), or a plain param beside a constraint that accepts every segment, now fails createApp. So do a plain WebSocket param declared before a constrained sibling, and such pairs across mesh teapots. Refs: #127 Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>Owner decisions (2026-10-13):
(.*)is not treated as covering every segment, because an unescaped.does not match line terminators. A constraint that does accept every segment, such as([^]*), still fails boot as unreachable.e41d956changestest/router-parity/app-fixture.tsso thatnCodeis[a-f]+instead of[0-9a-f]+. No frozen JSON changes.84e6f07).