Repository navigation
Conversation
… on every path spelling The local API's checks compared the request path as the client wrote it. The SDK router's trie drops empty path segments, so /v1/chat/completions/ and //v1/chat/completions resolved to the same route but skipped the JSON nesting and NUL scan, the batch count and the tool-call arguments check, and were served by the SDK handler. That reopened #2130, #2143 and #2188 for a caller holding the local API key. Only Hummingbird's 2 MiB body ceiling held. LocalRoute reads a path the way the trie does, and LocalIngress.admit applies the route's limits to the body before any parser reads it. A route with no limits of its own, including one a later SDK adds, gets the default ceiling and the nesting scan instead of none. LocalIngressTests reads the routes from the real router and checks every body route on four spellings against five over-limit bodies, in process and over a loopback connection. Limits, statuses and error bodies on the exact paths are unchanged, and nothing a coordinator sees changes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e, sharper comments) Independent behaviour-preserving cleanup of the previous commit. - LocalRouterResponder: the LocalRoute parameter is apiRoute. A later local named route (the saved LocalSettings.Route) shadowed it, so one name meant two things. - LocalIngress: the header said no check compares a path; that holds for the limits and the local router, and now says so. - LocalInferenceHTTP: the stack comment records that a layer above the interception that reads a body must take it from admit. - The router differential gains a dot-dot row and says why its rows stay ASCII. Docs and changelog: grammar, and OPTIONS is answered by CORS before the guard. A differential of 5,390 method and path cases between LocalRoute and the real router found no disagreement. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…coded LocalIngress.itemCount returned 0 for an array that starts with a UTF-8 byte-order mark, and Foundation's parsers skip that mark. So a batch of more than 64 items behind one was decoded before its count was checked, the ordering #2188 fixed, surviving through three bytes. With items that do not decode it answered a decode error instead of batch_too_large. The counter on dev had the same gap. The counter now skips the mark. A differential holds it at or above what JSONSerialization and JSONDecoder read over six prefixes and six lists. The nesting scan was never affected: it reads every byte. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…oute table The assertion that the nesting scan is not fooled by a leading byte-order mark was a single direct call. It is now an over-limit body in the table, so it is checked on every body route and every path spelling like the others. The item counter also gets a short exact case behind a mark. Test-only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The local API's request checks compared the request path as the client wrote it. The SDK router's trie drops empty path segments, so
/v1/chat/completions/and//v1/chat/completionsresolved to the same route but skipped the JSON nesting and NUL scan, the batch count and the tool-callargumentscheck, and were served by the SDK handler. That reopened #2130, #2143 and #2188 for a caller holding the local API key. Hummingbird's 2 MiB body ceiling still held.Those three fixes each placed a check by hand on a list of paths. This PR replaces the list with one guard keyed on the route the router actually resolves:
LocalRoutereads a path the way the trie does.LocalIngress.admitapplies the route's limits to the body before any parser reads it: body ceiling, then nesting scan, then item count without decoding.Scope of the exposure: the Mac's own local API, to a holder of its local API key. Nothing a coordinator sees changes.
Linked issue
Part of #2524 (decision 6: route and ingress are resolved once, at the boundary). Independent of the other PRs in the epic.
Before
flowchart LR classDef bad fill:#cf222e,stroke:#82071e,color:#ffffff classDef ok fill:#1a7f37,stroke:#0f5323,color:#ffffff classDef step fill:#0969da,stroke:#0a3069,color:#ffffff R["Request to the local API"]:::step --> P{"Path equals a listed path, exactly"} P -- "yes" --> G["Nesting scan, batch count, body ceiling"]:::ok P -- "no: extra slash, or a route nobody listed" --> T["Router trie drops empty segments"]:::step G --> H["Handler"]:::step T --> U["SDK handler parses the body unchecked"]:::badBehaviour:
POST /v1/chat/completions/with a body nested 65 deep reached engine acquire and answered 404 "Requested model is unavailable", where the exact path answers 400 at the guard. Code flow: path predicates in three files, each added by a separate fix.After
flowchart LR classDef bad fill:#cf222e,stroke:#82071e,color:#ffffff classDef ok fill:#1a7f37,stroke:#0f5323,color:#ffffff classDef step fill:#0969da,stroke:#0a3069,color:#ffffff classDef note fill:#9a6700,stroke:#633c01,color:#ffffff R["Request to the local API"]:::step --> L["LocalRoute: path read as the trie reads it"]:::step L --> K{"Route"} K -- "has limits of its own" --> A["LocalIngress.admit with the route's limits"]:::ok K -- "any other route or method" --> D["LocalIngress.admit with the default limits"]:::note A --> C{"Within limits"} D --> C C -- "yes" --> H["Handler reads the admitted body"]:::step C -- "no" --> X["400 or 413, before any parser"]:::badBehaviour: every spelling of a path gets its route's limits and answers. Code flow: one guard, two call sites (the local router before a pass-on, and the engine routes); the per-endpoint predicates are deleted. Sources: 5 files, 248 lines added and 167 removed, including the new
LocalIngress.swift.What a client sees
POST /v1/responses/{id}/cancel, an unserved path, PUT or DELETE, with a body over 2 MiB or nested past 64batch_too_largebefore decodingTest plan
Red, on unmodified
dev(0f78662e6b) plus the new test file only. 741 issues: every POST route, on a trailing slash, a doubled leading slash and a doubled inner slash, in process and over a loopback connection. Sample:The oracle,
LocalIngressTests, reads the routes from the real router (MLXServerApplication.buildRouter(...).routes), so a route a later SDK adds joins the table without anyone listing it. It checks every body route x 4 spellings x 8 over-limit bodies for the exact status and message, the same answer as the exact path, zero engine acquires and nothing passed on.Would it have caught the earlier fixes? By construction: the depth and NUL rows fail when no scan runs (#2130), 65 items reach acquire (#2143), and undecodable items answer a type mismatch instead of
batch_too_largeon a decode-first path (#2188).Byte-order mark, red then green:
swift build --jobs 6 --build-tests: completeswift test --skip-build --no-parallel --filter 'LocalIngressTests|LocalRequestNestingTests|LocalRouterTests|LocalChatBatchLimitTests': 45 tests in 4 suites pass (rerun independently after the last commit)ClusterPairMemberRelayTests; they hardcode the binary namedarkbloom, a default build ondevisdarkbloom-dev, and they fail identically on unmodified sourcemake docs-check(216 OK),make changelog-check(61 valid),make docs-impact-check BASE=origin/dev(OK)Refactor pass
Done by an independent reviewer, second commit. Verdict: the design holds.
LocalRouteand the real router found no disagreement.itemCountwas byte-identical to the counter it replaced.admit, and one more row in the router differential.devhas too. It is fixed in the third commit, test-first, because counting before decoding on every input is what this PR claims.Limitations and what this PR leaves open
admithas two call sites, not one. A single guard in front of the router would change the pair gate's 503 precedence and the error envelopes. Nothing mechanical stops a future layer above the guard from reading a body; a comment says it must not.GET /metrics/with a trailing slash skipsLocalMetricsResponder(the same exact-path compare, in a file this PR does not own) and returns SDK metrics without the MTP lines./health/requires a key, which fails closed.,]are refused. It errs toward refusing.Components touched
Protocol / interface changes
Local HTTP API only, as in the table above. No WebSocket message, coordinator-visible status, heartbeat field or config key changes. No version bump.
Documentation impact
docs/provider/direct-mode.md, new "Request limits" section (rule "provider local API")Changelog:
changelog.d/local-api-request-limits-every-path-spelling.md.🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.