Skip to content

feat(admin): serve the console's HTTP surface from the relay's one listener - #1192

Merged
chappie-daemon merged 16 commits into
rewrite/mainfrom
factory/032-admin-console-parity
Nov 19, 2026
Merged

chappie-daemon merged 16 commits into
rewrite/mainfrom
factory/032-admin-console-parity

Conversation

@chappie-daemon

Copy link
Copy Markdown
Collaborator

What this does

Serves the admin console's HTTP surface from the relay's own listener, so the unmodified static console in resources/admin drives the Rust relay.

  • One listener, one port. Each accepted socket's head is peeked without consuming it: an Upgrade: websocket request 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's Path.
  • The console's own contract. 26 API calls over 24 paths, plus the page and seven assets, taken from the console's JavaScript at this branch's base rather than from the TypeScript snapshot: the console grew after the capture, and eleven of those routes have no capture-era counterpart.
  • The capture's session model, not an approximation. HMAC-SHA256 over SECRET, <expiresAt>.<hex>, bearer-then-cookie, scrypt verification with the ADMIN_PASSWORD override, 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).
  • Settings written back through the filesystem — backup, restore, validation against the merged document, a separate admin audit JSONL, and the reload class the console reads.
  • crates/nostream-admin is real code now: 576 lines of Phase-1 stubs became the router, state, middleware, 26 controllers and the tests; nostreamd composes it and remains the only crate that binds a socket.
  • Record: 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_parity derives 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-empty unserved. cargo test -p nostreamd --test admin_http proves 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).

  • Round 1 fixed the oracle itself: its bar (status < 500) could not fail on a missing route, and a null settings value answered 200 where the capture answers 400. Deleting a route's registration now exits 101 with unserved: 1.
  • Rounds 2–5 closed record-only findings (a quoted command that filtered its own target, two count mismatches, the ADR's "thirteen decisions" over seventeen headings, a test that could not discriminate) and one architecture finding — the operator then ruled the rate limiter must be the shared EwmaRateLimiter, which deleted a private store, made limits.rateLimiter.strategy live, and turned four performance findings into measured closures (the audit append went from 34.5 s to 0.29 s over 2,000 appends; the closing lens re-measured 462× fewer bytes read and written, 1,430× less CPU).
  • Round 6 passed all five lenses; the architecture lens's only blocking findings were two record sentences that contradicted the code (spec R4 still called the admin limit a sliding window after D14, and the ADR misattributed the review's ask). Both are corrected in a separate record-only commit, dated, and re-read by the same lens.

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

  • The spec's AC23 asserts ls docs/rewrite/decisions | grep -c '^0012-' prints 2: true at this branch's base (f01cb5f3), where two 0012 files exist. Upstream rewrite/main has since moved to 37e5d8c1 (docs(rewrite): two decision records are numbered 0012 #1185 renamed the duplicate), and the merged tree holds one 0012- (0012-nip50-search-index.md) beside 0013-pg-to-lmdb-migration.md. This branch adds none, so both numbers are given rather than the criterion being edited.
  • The spec's AC23 also asserts grep -c '^0013-' prints 0: true at the base, 1 in the merged tree, where 0013-pg-to-lmdb-migration exists alongside this branch's 0014.

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 HEAD at 37e5d8c1 exits 0 and the merged decisions directory reads one 0012-, one 0013-, one 0014-.

Not in this PR

The other two families #867 bundles are their own issues, cut from the same measurement: #1183 (the nostream-admin MCP server — seven tool families, no TypeScript counterpart and no oracle to inherit) and #1184 (the 3,216-LOC CLI port — nostream-cli covers 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 #867 is inert on this repository because the PR targets rewrite/main, not the default branch; the issue is closed by hand with the merge sha once this lands.

…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-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d29e4a7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When 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

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 967e65f6-5a07-4e5f-b53b-2a33438268c3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@socket-security

socket-security Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcargo/​axum@​0.8.99710093100100
Addedcargo/​scrypt@​0.11.010010093100100
Addedcargo/​hmac@​0.12.110010093100100

View full report

@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The latest changes appear safe to merge, with no new blocking issues found.

Summary

The PR serves the admin console beside WebSockets on the relay’s existing listener. The latest update fixes saves blocked by leftover temporary files.

  • The relay serves admin HTTP and WebSocket connections from the same listener.
  • The admin console has a mounted page, assets, and authenticated routes.
  • The admin console shows relay health, activity, and operations data.
  • Admin settings and moderation changes are checked, saved, and recorded.
  • Operators can list NIP-05 checks and re-run a check for one record.

No new actionable issues found. The numbered previous finding is addressed.

chappie-daemon explicitly defers audit-file permissions (#1187), unbounded login waits (#1188), exhaustion of the limiter’s key cap (#1189), limiter errors allowing requests through (#1190), and cross-process audit compaction (#1191). ADR 0014 records the relay-path behavior as intentional.

Reviews (3) · Last reviewed commit: "fix(config): step over a taken temporary..." · Reviewed by Greptile

Comment thread crates/nostream-config/src/store.rs Resolved
Comment thread crates/nostream-config/src/store.rs Resolved
Comment thread crates/nostream-config/src/store.rs Resolved
@chappie-daemon
chappie-daemon merged commit 9a7c318 into rewrite/main Nov 19, 2026
17 checks passed
@chappie-daemon
chappie-daemon deleted the factory/032-admin-console-parity branch November 19, 2026 20:47
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