Repository navigation
feat(admin): serve the console's HTTP surface from the relay's one listener - #1192
Conversation
…stener The crate grows from Phase-1 stubs to the 30 routes of src/routes/admin/index.ts: the session model, the two limiters, the settings writer over nostream_config::store, the settings audit, the probe ring, the SSE metrics stream and the static console. The relay gains a peeked-head dispatch so one TcpListener answers both the WebSocket wire and the admin HTTP surface; nostreamd composes the admin state and serves hyper per socket behind that dispatch. ADR 0014 records the thirteen decisions.
…e all 26 console_parity reads resources/admin at test time; the other targets pin the session, the limiters, the 26 shapes, the capture's query messages, the settings writer, the SSE frame and the page's assets. The daemon test proves one port serves both protocols. ADR 0014 and the changeset land with the tests that quote their decisions.
…ext read A PATCH with value null now removes the key from the user document and validates against the defaults, which is what the capture's undefined does; the unit test that builds the merged document by hand passes the defaults explicitly.
The oracle's only bar was status < 500, so a path the router does not serve answered the fallback's 404 and counted as served (review-code.md Finding 1). Each derived route is now held to the statuses its R5 row names, and a miss is recorded in unserved and fails.
…rride The capture's schema is z.custom(v => v !== undefined), so null reaches the validator and answers 400 Validation failed with 'Expected string, got null' (review-code.md Finding 2); the test asserts the status and the issue text. The defaults filter keeps the capture's rule with no admin escape, the session parser reads the expiry as Number() does, and the layer-ordering comment now says what the code does.
…dmin escape A defaults document without an key drops the user's admin.passwordHash; the escape that kept it is the divergence the round-2 review named, and this case is RED with the escape re-added. Also drops the oracle's duplicated unserved line.
… worker The rework the architecture and performance reviews asked for, with the operator's ruling on the limiter. - The private sliding-window store in AdminState is gone: hit_rate_limit runs nostream_relay::limits::RateLimiter behind the Limiter trait, and limits.rateLimiter.strategy selects EWMA (the factory's default) or the sliding window per request, rebuilt when the setting changes. Refusal follows the capture's limiter: a refused hit advances the rate, and a stale key resets. AC12 is re-derived: EWMA admits 30 admin hits and 10 login hits at the shipped settings, and the 31st/11th are the first refusals. - append_audit is one OpenOptions::append + one write per request, with the 2,000-entry cap kept by a compaction once per 2,000 appends. Measured 34.5 s -> 0.29 s over 2,000 appends at a full file. - GET /ops/storage/counts gathers its per-kind queries under one 5,000 ms deadline. - The login's scrypt runs on spawn_blocking behind a semaphore of four, with the ADMIN_PASSWORD override still first; the daemon answers HTTP while a verification is in flight. - ADR 0014 records D14 to D17, including why a third store was the defect and that the lens's remedy was not taken.
…ound With four runtime workers the D15 case passed whether or not the verification ran on the runtime, and `is_finished()` is a race. The daemon now starts with WORKER_COUNT=1 (what main.rs hands `.worker_threads`) and a `GET /admin/session` during a login must answer within 500 ms: measured 12.96 ms with the offload, 1.7108 s without it. The ADR's Context counts seventeen decisions, not thirteen.
…ccurately The record said the review asked to port the sliding window under the private store; it asked for the tree's already-ported limiter (the sliding window existed at the base). It also called the Limiter trait the guarantee, where what confines the rule is the concrete RateLimiter that from_settings builds. Corrected on round 6's architecture finding; no code changed.
🦋 Changeset detectedLatest commit: d29e4a7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
[High impact] The latest changes appear safe to merge, with no new blocking issues found.
|
What this does
Serves the admin console's HTTP surface from the relay's own listener, so the unmodified static console in
resources/admindrives the Rust relay.Upgrade: websocketrequest goes to the relay unchanged, everything else to an axum router. A second port would have changed the console's URL and its session cookie'sPath.SECRET,<expiresAt>.<hex>, bearer-then-cookie, scrypt verification with theADMIN_PASSWORDoverride, the capture's cookie flags and TTL fallback, and the middleware chain's statuses (the 404 gate when admin is disabled, 415 on the JSON body middleware but not on login, 429 with per-scope keys and the whitelist bypass).crates/nostream-adminis real code now: 576 lines of Phase-1 stubs became the router, state, middleware, 26 controllers and the tests;nostreamdcomposes it and remains the only crate that binds a socket.docs/rewrite/decisions/0014-admin-http-surface.md(D1–D17, seventeen decisions with their evidence), one empty changeset, and the stub labels that remain label what is still unported.The oracle
cargo test -p nostream-admin --test console_parityderives the route set from the console's own JS at test time (derived: 26 calls over 24 paths + 2 page + 7 assets) and holds each call to the status the spec's route table names for it; deleting a route's registration fails it with a non-emptyunserved.cargo test -p nostreamd --test admin_httpproves the one-port claim against the real binary, WebSocket challenge included.Gate
cargo fmt --all --check· both clippy passes ·cargo test --workspace --all-features→ 95 targets, 1,509 passed, 0 failed, 6 ignored (base 84 / 1,352) ·cargo build --workspace --all-features --release· the two oracle targets. Re-measured after the last change by the code gate and again by the approver.Review record
Six rounds, five lenses each, the code lens as the gate (a round's other lenses start only when the gate passes, so they read the tree that survives).
status < 500) could not fail on a missing route, and anullsettings value answered200where the capture answers400. Deleting a route's registration now exits 101 withunserved: 1.EwmaRateLimiter, which deleted a private store, madelimits.rateLimiter.strategylive, and turned four performance findings into measured closures (the audit append went from34.5 sto0.29 sover 2,000 appends; the closing lens re-measured 462× fewer bytes read and written, 1,430× less CPU).Static analysis (guarded clippy projection) was clean in all six rounds. The review's non-blocking notes are issues, not prose: #1187 (audit file mode, amended — the compaction re-creates
0644), #1188 (no bounded wait on the verification pool), #1189 (the shared store's cap can be spent), #1190 (the limiter fails open on a store error where the capture fails closed), #1191 (compaction is one mutex, not one process; the cap rests on an in-process counter).Two counts that are base-relative — read them against this branch's base
ls docs/rewrite/decisions | grep -c '^0012-'prints 2: true at this branch's base (f01cb5f3), where two0012files exist. Upstreamrewrite/mainhas since moved to37e5d8c1(docs(rewrite): two decision records are numbered 0012 #1185 renamed the duplicate), and the merged tree holds one0012-(0012-nip50-search-index.md) beside0013-pg-to-lmdb-migration.md. This branch adds none, so both numbers are given rather than the criterion being edited.grep -c '^0013-'prints 0: true at the base, 1 in the merged tree, where0013-pg-to-lmdb-migrationexists alongside this branch's0014.This branch's record is
0014-admin-http-surface.md; it neither renames nor edits any existing record, so the rename lands clean.git merge-tree --write-tree origin/rewrite/main HEADat37e5d8c1exits 0 and the merged decisions directory reads one0012-, one0013-, one0014-.Not in this PR
The other two families #867 bundles are their own issues, cut from the same measurement: #1183 (the
nostream-adminMCP server — seven tool families, no TypeScript counterpart and no oracle to inherit) and #1184 (the 3,216-LOC CLI port —nostream-clicovers three commands today, 19 TS CLI specs are its inheritable oracle). The five review notes above are likewise their own issues rather than prose here.Closes #867is inert on this repository because the PR targetsrewrite/main, not the default branch; the issue is closed by hand with the merge sha once this lands.