Skip to content

refactor(server): registry drives dispatch and the read-only gate (#1344) - #1437

Merged
ajianaz merged 1 commit into
developfrom
refactor/registry-drives-dispatch-1344
Oct 12, 2026
Merged

ajianaz merged 1 commit into
developfrom
refactor/registry-drives-dispatch-1344

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

What

Makes crates/uteke-server/src/api_registry.rs (ENDPOINTS) the table the router and the read-only gate actually read, and deletes the test that grepped handlers.rs source text.

  • New per-row writes: bool (#[serde(skip)], so GET /routes, docs/api-reference.md and docs/core-contract.json are unchanged).
  • The read-only-token gate in handlers::route is now api_registry::read_only_allows(method, path), derived from writes. The hard-coded 16-path read_only_post_paths array is gone.
  • The router consults the table first: a (method, path) with no row is answered 404 Not found before any handler runs. A handler can no longer be reachable while unregistered or ungated.
  • registry_covers_handler_routes (source-text scan) is deleted, along with the six "build the URL separately so the route scanner does not trip" workarounds in handler tests.
  • New tests, all built from the table: every row has a handler arm (via a test-only probe on the match fallback); (method, path) pairs absent from the table 404 without reaching a handler; the read-only token gets the gate 403 on exactly the non-GET rows that are not non-writing POST rows; GET rows never write; rows are unique; a reviewed pin of the 16 read-only POST rows so that flipping a writes flag is a deliberate, visible edit.

Behaviour is preserved bit-for-bit, including two quirks of the old gate: it matched the raw path (query string included) and ignored the request verb for the read-only POST paths (so PUT /list still passes the gate and then 404s).

Refs #1344 (not Closes, see "Remaining").

Why

api_registry.rs was a second hand-maintained route list kept in sync by a source-grepping test, and the read-only gate was a third list. Now one table drives /routes, docgen, reachability and the gate, so a new write route is read-only-gated by construction: it needs a row to be reachable at all, and writes: true is what the gate reads.

Testing

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace, cargo test -p uteke-core --no-default-features --features "onnx,vecq" --lib: all pass.
  • cargo run -p docgen: docs/ unchanged (no diff in docs/api-reference.md or docs/core-contract.json).
  • Differential end to end: uteke-serve built from origin/develop and from this branch, fresh UTEKE_HOME each, --auth-token T1 --read-only-token T2, python fake OpenAI embedder (768-dim). For every one of the 78 rows of GET /routes: minimal request ({} body and no body for non-GET) with no token / read-only token / full token, plus every other method on the same path in the three modes, plus extras (query-string gate quirk, /recallfoo, /api/v1|v2 prefixes, PATCH, unknown paths). 1146 cases, 0 differences in status and normalised body (ids/timestamps masked). GET /routes is byte-identical (20197 bytes) between the two servers.

Gate vs writes flag: owner decisions

writes was set to match today's gating exactly (to keep behaviour), so nothing disagrees in effect. But these POST rows are blocked for the read-only token although their handler does not obviously mutate, i.e. writes = true is conservative for them. Left as is; an owner decision whether any should become read-only:

  • POST /verify (the handler comment calls it a read-only check, deliberately a write-token endpoint)
  • POST /context (builds a context string)
  • POST /dream (dry_run: true does not mutate; otherwise it does)
  • POST /extract, POST /mcp (the bridge can reach both reads and writes)

No GET row writes (enforced by a test).

Remaining for a follow-up (why this is not Closes)

The table does not yet hold a typed handler: the dispatch is still the ~80-arm match (method, path) in handlers::route, and request_type is still a string. Converting each arm into a function with a row-owned handler pointer touches ~2800 lines of inline handlers and was not a safe single slice. After this PR there is no second source of truth for reachability, /routes, docgen or the gate, only the arm bodies remain to be moved behind the table (the every_registry_row_has_a_handler_arm test covers the interim sync).

🤖 Generated with Claude Code

)

The api_registry table is now consulted by the router (unregistered
method+path is a 404 before any handler runs) and by the read-only-token
gate (derived from a new per-row writes flag). The source-scanning
coverage test is replaced by tests built from the table.

Refs #1344

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

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