Skip to content

Phase B3b: admin quality views by stamp (#2324) - #2390

Merged
neuromechanist merged 19 commits into
feature/issue-2324-epic-pipeline-progressfrom
feature/issue-2324-b3b-admin-views
Nov 26, 2026
Merged

neuromechanist merged 19 commits into
feature/issue-2324-epic-pipeline-progressfrom
feature/issue-2324-b3b-admin-views

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Phase B3b of #2324: the admin half of #2384. It adds an admin mount that serves a run's quality record and files by stamp, canaries included, for the website's W9 drill-down. The private mount stays in #2384.

What changed

  • GET /admin/compute/pipeline/runs/:stamp/quality/record/<recording> and .../quality/file/<sha256>/<recording> (backend/src/routes/admin/quality-views.ts), registered on the admin router after its authMiddleware, adminMiddleware and cookieOriginGuard, and after the B3 run-quality page.
  • Resolved by stamp in one D1 statement. The derivative is the stamp's own row, bound to the stamp's dataset. It is served only when state = 'stored' and expires_at has not passed, of any retention (canary, catalog or published, superseded included). Every other case gets a fixed word and no store read: stamp_not_found, derivative_not_keyed, derivative_copying, derivative_failed or views_expired.
  • B2's steps 4 and 5 are now one function, serveRecordingViews (backend/src/services/quality-serve.ts), and both mounts call it. It does the full schema check, recording scope only, the record's own dataset and recording, the row's quality_plugins, one file per digest, declared files only, the size bounds, a re-hash before serving, nosniff, and an attachment for unlisted formats. The public route keeps its gate and cache. The refactor does not change its behavior: B2's suites pass unchanged.
  • Nothing public. The admin mount never calls cache.match or cache.put. Every answer, refusals included, is no-store, with no Cache-Tag, no ETag and no public address.
  • Contract (shared/contract/quality-route.ts): QUALITY_ADMIN_ROUTE_WORDS (the public words plus the five state words, method_not_allowed 405 and quality_unavailable 503), the path builders, and qualityAdminRest, which holds the grammar below.
  • Changelog entry, the admin route inventory (+1 entry, with an order test), and a pointer in compute-pipeline.ts's header.

The path grammar W9's proxy must enforce

rest is the raw, still percent-encoded path after /admin/compute/pipeline/runs/<stamp>/quality/. It must be exactly one of:

record/<recording>
file/<64 lowercase hex>/<recording>
  • <recording> is one or more /-separated segments.
  • Each segment is non-empty and is not . or ...
  • Each segment matches ^(?:[A-Za-z0-9._~!$&'()*+,;=:@-]|%[0-9A-Fa-f]{2})+$.
  • A segment carries no %2F, %5C or %2E (any case), and no encoded control character (%00-%1F, %7F).
  • The recording is at most 1024 characters once decoded.
  • No query string, and the method is GET only.

The proxy can call qualityAdminRest(rest) from the shared contract; it returns null for anything outside the grammar. The backend enforces the same grammar, then checks that the recording is one the public route takes (isRecordingPath).

Security points (a) to (f)

  • (a) The grammar is documented here, in the contract and in the changelog. The backend refuses anything outside it, a query string, and any method but GET (HEAD gets 405).
  • (b) The router middleware resolves the caller's own key from D1 on every request. Tests cover a key revoked between two requests and an admin demoted between two requests; both are refused at the next request, with no store read.
  • (c) Only stored, in-date rows are served. Copying, failed, expired, and a canary past its date that has not been marked expired all get their word, with no store read.
  • (d) The admin mount never reads or writes the edge cache. A counting real cache shows zero calls, and the same derivative through the public route does write to it. Mutants M15 and M16 confirm this.
  • (e) B2's re-hash, declared-files-only rule and size bounds are the same code, and mutants M20 to M23 confirm them.
  • (f) Anonymous-deposit fixture (anonymous = 1, private, never published): an admin gets 200 with private headers and no public path in the body, and a member is refused. The public route refuses the same deposit, and nothing is cached.

Mutation table

Script: kept in the session scratchpad (b3b-mutations.py). Each mutant edits one gate, runs the targeted suites, and is reverted.

Mutant Result
M01 no method check killed
M02 no query check killed
M03 no recording-path check killed
M04 grammar: encoded / \ . allowed killed
M05 grammar: . and .. segments allowed killed
M06 grammar: any digest killed
M07 grammar: no length bound killed
M08 failed row read killed
M09 past row read killed
M10 copying row read killed
M11 not-stored fallback dropped killed (by a direct test of runViewRefusal; the table's CHECK holds four states)
M12 row of another dataset than the stamp killed
M13 expires_at ignored killed
M14 refusal words ignored killed
M15 admin writes the edge cache killed
M16 admin reads the edge cache killed
M17 public cache header killed
M18 Cache-Tag on admin answer killed
M19 refusal cacheable killed
M20 no re-hash killed
M21 undeclared files served killed
M22 no size check killed
M23 no record bound killed
M24 no plugins check killed
M25 no identity check killed
M26 no full schema check killed
M27 no scope rule killed
M28 nosniff dropped from file headers killed
M29 mount before the router middleware killed

Tests

  • bun run typecheck
  • Biome on every changed file
  • Backend: quality-admin-views (new, 20 tests), quality-route, quality-cache-purge, quality-admin-route, quality-documents, metadata-json-quality: 134 pass
  • Root: quality-route-contract, admin-route-inventory, api-export-surface, quality-documents-contract, compute-admin-contract: 207 pass
  • Full bun test: not run, per the epic's test-cost rule (it runs at epic to dev)

All tests run on real D1 (bun:sqlite with every migration), real hashed API keys through the real admin router, and Miniflare R2 holding nemar-ica's real product. Nothing touches a remote resource.

Refs #2324, #2384.

Agentic AI tools were used.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2390

Version: 0.10.40-PR2390.c98a85f
Commit: c98a85f


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit 6a88f88 into feature/issue-2324-epic-pipeline-progress Nov 26, 2026
48 of 53 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2324-b3b-admin-views branch November 26, 2026 02:57

This branch was previously deployed

1 inactive deployment
npm — c98a85f6 Deployed Nov 26, 2026 by neuromechanist via publish #4945
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