Server admin 22: apps/fluxer administration runtime (#690) #741

Closed
charles wants to merge 0 commits from serveradmin-22-runtime into serveradmin
Owner

What this builds

apps/fluxer/src/admin_rt.rs, the server administration runtime (Server administration 22, spec §9, §12):

  • admin_rt::perform(client, files, sudo, request): one fluxer-api call for each of the 22 ApiRequests of Task 9a, answered with its ApiResult. runtime.rs routes them with one arm (admin_rt::handles). The 501 CLIENT_NOT_WIRED stubs of Task 9a are gone.
  • UpdateGuild with a picked icon or banner reads the file through the existing UploadReader into a data: URI (reuses dailyuse_rt::image_data_uri).
  • Identity check: the SudoAnswer is merged into the body (SudoVerification) of UpdateGuild, DeleteGuild and TransferOwnership, then dropped. The token is held in memory only, by admin_rt::SudoTokens. It is sent as X-Fluxer-Sudo-Mode-JWT on those three requests and replaced by the token each later answer carries. It is dropped 4.5 minutes after it was received (AuthSudo.ts), when the server answers SUDO_MODE_REQUIRED (the original's sudo.invalidate(), RestTransport.ts), and when the session token changes (logout or another account). Answers to requests from an earlier session cannot bring a token back. The store hears only CoreEvent::SudoToken { valid_until }, sent through the same epoch-checked channel as the answer.
  • --record: mfa_code joins the secret keys (password was already one). The content of a data: URI is redacted, so a community icon or banner never reaches a recording. Headers are never recorded, so the sudo header does not appear in either direction.
  • Handle::admin_script() (devserver builds): what the devserver accepted, for the tests.

How it was tested

apps/fluxer/tests/admin_runtime.rs, 14 tests against the in-process devserver (serveradmin scenario):

  • Through the whole runtime (UserAction, request, answer and gateway event back in the store). These cover requests the merged core already emits: guild_overview_save_round_trip, icon_sent_as_data_uri, member_role_toggle_round_trip, channel_move_round_trip.
  • Through admin_rt::perform directly, with a signed-in client and SudoTokens::with_clock (a fake clock). This covers requests whose core tasks (12, 14–17, 19) are not merged yet: role_create_edit_reorder_round_trip, channel_edit_and_overwrites_round_trip, timeout_kick_ban_round_trip, bans_and_invites_lists, members_search_round_trip, delete_guild_asks_sudo_then_succeeds, second_sudo_action_within_4_5_minutes_is_not_asked, token_dropped_after_expiry_and_on_logout, record_file_has_no_password_code_or_token, no_request_answers_501.
  • Unit tests in admin_rt.rs (expiry, late answers from an ended session, SUDO_MODE_REQUIRED drops the token, Debug hides the token) and in record.rs (identity-check answers and data URIs are redacted).

All tests failed against the stub (first commit) and pass now. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci passes locally. No display tests (FLUXER_DESKTOP_TESTS) apply; I ran none. No new goldens.

Deviations from the plan

  • The signature is perform(client, files, sudo: &SudoScope, req), not perform(request). The sudo scope carries the token holder and the reporter for CoreEvent::SudoToken, which is sent before the request's own answer.
  • The core sudo machine (Task 19) is not merged yet, so the store cannot submit an answer. The sudo, expiry and record tests therefore drive admin_rt::perform directly, not the whole runtime. "Dropped on logout" is tested at the SudoTokens::end_session level; the Executor calls it on every session-token change, next to uploads.cancel_all().
  • record.rs also redacts data: URI content. update_guild is an observed exchange, unlike the daily-use icon calls, which bypass the observer.
  • runtime.rs change: besides the routing arm, the Executor holds the SudoTokens, perform takes the scope, and the devserver View tuple gains AdminScript.

Closes #690

🤖 Generated with Claude Code

https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K

## What this builds `apps/fluxer/src/admin_rt.rs`, the server administration runtime (Server administration 22, spec §9, §12): - `admin_rt::perform(client, files, sudo, request)`: one `fluxer-api` call for each of the 22 `ApiRequest`s of Task 9a, answered with its `ApiResult`. `runtime.rs` routes them with one arm (`admin_rt::handles`). The 501 `CLIENT_NOT_WIRED` stubs of Task 9a are gone. - `UpdateGuild` with a picked icon or banner reads the file through the existing `UploadReader` into a `data:` URI (reuses `dailyuse_rt::image_data_uri`). - Identity check: the `SudoAnswer` is merged into the body (`SudoVerification`) of `UpdateGuild`, `DeleteGuild` and `TransferOwnership`, then dropped. The token is held in memory only, by `admin_rt::SudoTokens`. It is sent as `X-Fluxer-Sudo-Mode-JWT` on those three requests and replaced by the token each later answer carries. It is dropped 4.5 minutes after it was received (`AuthSudo.ts`), when the server answers `SUDO_MODE_REQUIRED` (the original's `sudo.invalidate()`, `RestTransport.ts`), and when the session token changes (logout or another account). Answers to requests from an earlier session cannot bring a token back. The store hears only `CoreEvent::SudoToken { valid_until }`, sent through the same epoch-checked channel as the answer. - `--record`: `mfa_code` joins the secret keys (`password` was already one). The content of a `data:` URI is redacted, so a community icon or banner never reaches a recording. Headers are never recorded, so the sudo header does not appear in either direction. - `Handle::admin_script()` (devserver builds): what the devserver accepted, for the tests. ## How it was tested `apps/fluxer/tests/admin_runtime.rs`, 14 tests against the in-process devserver (`serveradmin` scenario): - **Through the whole runtime** (UserAction, request, answer and gateway event back in the store). These cover requests the merged core already emits: `guild_overview_save_round_trip`, `icon_sent_as_data_uri`, `member_role_toggle_round_trip`, `channel_move_round_trip`. - **Through `admin_rt::perform` directly**, with a signed-in client and `SudoTokens::with_clock` (a fake clock). This covers requests whose core tasks (12, 14–17, 19) are not merged yet: `role_create_edit_reorder_round_trip`, `channel_edit_and_overwrites_round_trip`, `timeout_kick_ban_round_trip`, `bans_and_invites_lists`, `members_search_round_trip`, `delete_guild_asks_sudo_then_succeeds`, `second_sudo_action_within_4_5_minutes_is_not_asked`, `token_dropped_after_expiry_and_on_logout`, `record_file_has_no_password_code_or_token`, `no_request_answers_501`. - **Unit tests** in `admin_rt.rs` (expiry, late answers from an ended session, `SUDO_MODE_REQUIRED` drops the token, `Debug` hides the token) and in `record.rs` (identity-check answers and data URIs are redacted). All tests failed against the stub (first commit) and pass now. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` passes locally. No display tests (`FLUXER_DESKTOP_TESTS`) apply; I ran none. No new goldens. ## Deviations from the plan - The signature is `perform(client, files, sudo: &SudoScope, req)`, not `perform(request)`. The sudo scope carries the token holder and the reporter for `CoreEvent::SudoToken`, which is sent before the request's own answer. - The core sudo machine (Task 19) is not merged yet, so the store cannot submit an answer. The sudo, expiry and record tests therefore drive `admin_rt::perform` directly, not the whole runtime. "Dropped on logout" is tested at the `SudoTokens::end_session` level; the Executor calls it on every session-token change, next to `uploads.cancel_all()`. - `record.rs` also redacts `data:` URI content. `update_guild` is an observed exchange, unlike the daily-use icon calls, which bypass the observer. - `runtime.rs` change: besides the routing arm, the `Executor` holds the `SudoTokens`, `perform` takes the scope, and the devserver `View` tuple gains `AdminScript`. Closes #690 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
The admin_rt module is a stub that answers every request 501; the runtime
routes the administration requests to it and the devserver's admin script is
reachable from the Handle.

Refs #690

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
admin_rt::perform carries out every ApiRequest of Server administration 9a
with one fluxer-api call; a community icon or banner is read through the
UploadReader into a data: URI. The identity check's answer is merged into the
body and dropped; the sudo token lives only in SudoTokens (memory), is sent on
the sudo-capable requests, replaced by the next one received, dropped after
4.5 minutes (AuthSudo.ts), on SUDO_MODE_REQUIRED and when the session ends,
and reported to the store as CoreEvent::SudoToken { valid_until }. --record
redacts mfa_code (password already) and data: URI content; headers, the sudo
header included, are never recorded. The 501 stubs of Task 9a are gone.

Refs #690

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Author
Owner

Independent review — Server admin 22 (runtime)

Scope: git diff 4785d780..origin/serveradmin-22-runtime (apps/fluxer only: admin_rt.rs, runtime.rs, record.rs, lib.rs, README, tests/admin_runtime.rs).

(1) Plan tests. All 14 tests named by Task 22 exist in apps/fluxer/tests/admin_runtime.rs and assert what the plan says (round trips through the devserver with recorded bodies; icon_sent_as_data_uri; the three sudo tests; the record test; no_request_answers_501 covers every administration request). Plus unit tests in admin_rt.rs for expiry at exactly 270 s, SUDO_MODE_REQUIRED invalidation (and not on INVALID_FORM_BODY), late-answer-after-session-end, and Debug hiding the token.

(2) Interfaces. admin_rt::perform exists with the shape of the existing dailyuse_rt::perform (client, files, sudo scope, req -> Result<ApiResult, ApiError>), one fluxer-api call per Task 9a request; images via the existing UploadReader and dailyuse_rt::image_data_uri; CoreEvent::SudoToken { valid_until } reported; the 501 stubs of 9a are gone (the 501 remains only as the unreachable fallback of admin_rt::perform).

(3) Invariants. No core/ui/proto change; no new fixture; no new dependency. Secrets: SudoToken, SudoTokens, SudoScope, Secret all print no value under Debug; the token header is set sensitive; nothing logs a request or body (only %error and a fixed "holding a sudo token" debug line).

(4) Parity spot-checks (fork fluxer_app/src):

  • features/auth/state/AuthSudo.ts setToken: 4.5 × 60 × 1000 ms → SUDO_TOKEN_LIFETIME = 270 s. ✔
  • features/platform/transport/RestTransport.ts:48 header x-fluxer-sudo-mode-jwt → fluxer_api::SUDO_MODE_HEADER. ✔
  • RestTransport.ts:345-348 sudo.invalidate() on SUDO_MODE_REQUIRED → SudoScope::failed. ✔ (native invalidates on any SUDO_MODE_REQUIRED, the original only in phase fresh; equivalent in effect, since a re-prompted request carries no token of its own.)
  • packages/schema/src/domains/auth/AuthSchemas.ts SudoVerificationSchema: {password} / {mfa_method: "totp", mfa_code} merged in the body → asserted byte-for-byte by delete_guild_asks_sudo_then_succeeds and second_sudo_action_within_4_5_minutes_is_not_asked. ✔

(5) Review Focus 6 (identity check).

  • Password/code: SudoAnswer is moved into the request body (into_verification) and the body is dropped right after the call; never in App (that is Task 19's test), never persisted, never logged. --record: password and the new mfa_code are secret keys; headers are not recorded at all, so X-Fluxer-Sudo-Mode-JWT is absent both ways; record_file_has_no_password_code_or_token asserts no wrong password, no sent token and ≥3 redacted verification fields in the real rest.jsonl. data: URIs are additionally redacted. ✔
  • Token in runtime memory only (Executor.sudo: SudoTokens), sent only on the three sudo-capable calls (with_sudo_token), replaced by each answer's token. ✔
  • Dropped on expiry: current() refuses and clears an expired token, so it is never sent after 270 s (tested). ✔
  • Dropped on SUDO_MODE_REQUIRED: ✔ (unit test).
  • Dropped on session change: Executor calls end_session() wherever the session token changes (logout or another account, alongside the epoch bump and uploads.cancel_all()); the session counter stops a request in flight from the old session bringing a token back, and its SudoToken report is discarded by the epoch check. ✔ (tested at the SudoTokens level; the Executor wiring is not exercised by a test, see N2.)

Findings

  • N1 (minor, non-blocking): an expired token is cleared lazily (on the next current()), not by a timer, so its bytes stay in process memory until the next sudo-capable request or session end. Same as the original (getValidToken never clears either) and it is never sent; mentioned only because Review Focus 6 says "dropped on expiry".
  • N2 (minor, non-blocking): no test drives a logout through the real Runtime and checks the token is gone; the end_session() call in Executor is verified by reading only. A one-line assertion in the acceptance task (35) would cover it.
  • N3 (info): the store is not told when the runtime invalidates the token on SUDO_MODE_REQUIRED, so admin.sudo.token_valid_until can claim a token the runtime has dropped. Harmless today (nothing gates on it; the prompt opens from the error anyway), but Task 19/33 should not use it to skip a prompt.

CI

FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci on 4169b741 in a clean review worktree: all steps passed (fmt, clippy, deny, core isolation, parity, tests incl. admin_runtime and the screenshot suite).

Verdict: approved — zero blocking findings, CI green.

## Independent review — Server admin 22 (runtime) Scope: `git diff 4785d780..origin/serveradmin-22-runtime` (apps/fluxer only: `admin_rt.rs`, `runtime.rs`, `record.rs`, `lib.rs`, README, `tests/admin_runtime.rs`). **(1) Plan tests.** All 14 tests named by Task 22 exist in `apps/fluxer/tests/admin_runtime.rs` and assert what the plan says (round trips through the devserver with recorded bodies; `icon_sent_as_data_uri`; the three sudo tests; the record test; `no_request_answers_501` covers every administration request). Plus unit tests in `admin_rt.rs` for expiry at exactly 270 s, `SUDO_MODE_REQUIRED` invalidation (and not on `INVALID_FORM_BODY`), late-answer-after-session-end, and `Debug` hiding the token. **(2) Interfaces.** `admin_rt::perform` exists with the shape of the existing `dailyuse_rt::perform` (`client, files, sudo scope, req -> Result<ApiResult, ApiError>`), one `fluxer-api` call per Task 9a request; images via the existing `UploadReader` and `dailyuse_rt::image_data_uri`; `CoreEvent::SudoToken { valid_until }` reported; the 501 stubs of 9a are gone (the 501 remains only as the unreachable fallback of `admin_rt::perform`). **(3) Invariants.** No core/ui/proto change; no new fixture; no new dependency. Secrets: `SudoToken`, `SudoTokens`, `SudoScope`, `Secret` all print no value under `Debug`; the token header is set `sensitive`; nothing logs a request or body (only `%error` and a fixed "holding a sudo token" debug line). **(4) Parity spot-checks** (fork `fluxer_app/src`): - `features/auth/state/AuthSudo.ts` `setToken`: 4.5 × 60 × 1000 ms → `SUDO_TOKEN_LIFETIME = 270 s`. ✔ - `features/platform/transport/RestTransport.ts:48` header `x-fluxer-sudo-mode-jwt` → `fluxer_api::SUDO_MODE_HEADER`. ✔ - `RestTransport.ts:345-348` `sudo.invalidate()` on `SUDO_MODE_REQUIRED` → `SudoScope::failed`. ✔ (native invalidates on any `SUDO_MODE_REQUIRED`, the original only in phase `fresh`; equivalent in effect, since a re-prompted request carries no token of its own.) - `packages/schema/src/domains/auth/AuthSchemas.ts` `SudoVerificationSchema`: `{password}` / `{mfa_method: "totp", mfa_code}` merged in the body → asserted byte-for-byte by `delete_guild_asks_sudo_then_succeeds` and `second_sudo_action_within_4_5_minutes_is_not_asked`. ✔ **(5) Review Focus 6 (identity check).** - Password/code: `SudoAnswer` is moved into the request body (`into_verification`) and the body is `drop`ped right after the call; never in `App` (that is Task 19's test), never persisted, never logged. `--record`: `password` and the new `mfa_code` are secret keys; headers are not recorded at all, so `X-Fluxer-Sudo-Mode-JWT` is absent both ways; `record_file_has_no_password_code_or_token` asserts no wrong password, no sent token and ≥3 redacted verification fields in the real `rest.jsonl`. `data:` URIs are additionally redacted. ✔ - Token in runtime memory only (`Executor.sudo: SudoTokens`), sent only on the three sudo-capable calls (`with_sudo_token`), replaced by each answer's token. ✔ - Dropped on expiry: `current()` refuses and clears an expired token, so it is never sent after 270 s (tested). ✔ - Dropped on `SUDO_MODE_REQUIRED`: ✔ (unit test). - Dropped on session change: `Executor` calls `end_session()` wherever the session token changes (logout or another account, alongside the epoch bump and `uploads.cancel_all()`); the session counter stops a request in flight from the old session bringing a token back, and its `SudoToken` report is discarded by the epoch check. ✔ (tested at the `SudoTokens` level; the `Executor` wiring is not exercised by a test, see N2.) ### Findings - **N1 (minor, non-blocking):** an expired token is cleared lazily (on the next `current()`), not by a timer, so its bytes stay in process memory until the next sudo-capable request or session end. Same as the original (`getValidToken` never clears either) and it is never sent; mentioned only because Review Focus 6 says "dropped on expiry". - **N2 (minor, non-blocking):** no test drives a logout through the real `Runtime` and checks the token is gone; the `end_session()` call in `Executor` is verified by reading only. A one-line assertion in the acceptance task (35) would cover it. - **N3 (info):** the store is not told when the runtime invalidates the token on `SUDO_MODE_REQUIRED`, so `admin.sudo.token_valid_until` can claim a token the runtime has dropped. Harmless today (nothing gates on it; the prompt opens from the error anyway), but Task 19/33 should not use it to skip a prompt. ### CI `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` on 4169b741 in a clean review worktree: **all steps passed** (fmt, clippy, deny, core isolation, parity, tests incl. `admin_runtime` and the screenshot suite). **Verdict: approved — zero blocking findings, CI green.**
Author
Owner

Merged into serveradmin by hand (the merge API returns 405); the commits are in the branch.

Merged into `serveradmin` by hand (the merge API returns 405); the commits are in the branch.
charles closed this pull request 2026-11-16 03:57:25 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.