Repository navigation
feat(D147): meter stored objects; host routes in the ingest scope; mounted route scopes - #549
Conversation
…unted scopes - ingest_stored measures a metered deployment's object exactly as ingest does (the managed text profile: native text up to 10 MB). A larger object is refused before it is read into memory; an accepted one is measured from the spooled copy and released to the raw store on approval. - build_api(ingest_scope_routes=...) / SelfHostProfile.api(...) let an ingest credential reach a host's own routes mounted in the app. - Route scopes and the healthz exemption are matched on the router's own path, so an app mounted under a prefix keeps its narrow credentials working (they all needed write before). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
…ttern Codex round 1: a listed template also matched other handlers (a static /uploads/admin/complete) and could override the built-in read table. The grant now compares the route FastAPI selected (method and declared template) and applies only to routes the table leaves at WRITE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Codex review round 1 (gpt-6.1-sol, max effort)VERDICT: REQUEST_CHANGES
297 targeted tests passed; 16 ingest-equivalence probes matched. Mounted healthz, narrow scopes, and spend-lease checks passed. No new D56 reuse boundary found. Database tests were left to CI; no containers started or repository files changed. Disposition (Claude)
|
Codex review round 2 (gpt-6.1-sol, max effort)VERDICT: REQUEST_CHANGES
The round-1 scope finding is fixed: grants match the selected method/template, preserve READ and Validation: 339 targeted tests, 51 ingest-equivalence probes, and 17 mounted scope probes passed. The exact 10 MB boundary behaved correctly. Worker/surface database CI remains pending. No containers started or repository files modified. Disposition (Claude): finalRound 2 verified the scope fix and found no other regressions. The only open item is the one I declined in round 1. I'm keeping that decision; the owner's simplicity rule gives me the last word, and here is the reason:
If streaming metering is wanted later, it belongs in a metering-design change, not in this seam. Merging after green CI. |
These fix two blockers umc-runtime hit while building the shared API on #545 and #547. Both fixes are generic.
1.
ingest_storedon a metered deploymentBefore this PR,
ingest_storedrefused any deployment with managed text metering (meter_scope). Now it measures the object exactly asingestdoes, through the same_prepare_managed_text, classifier and measurement draft:DOC_TEXT_MAX_SOURCE_BYTES(10 MB). A larger stored object is refused withManagedTextClassificationError("source_bytes_limit_exceeded"), the same codeingestgives, before anything is read into memory.raw_uri, which is the client's key. The object is already there, so the write is the usualObjectAlreadyExistsErrorno-op, and the convert work opens.2. Host routes in the ingest scope
The new parameter
build_api(..., ingest_scope_routes: Collection[tuple[str, str]] = ())is also exposed asSelfHostProfile.api(ingest_scope_routes=...).(METHOD, "/path/{param}"), written exactly as each host route is declared in the app. An ingest-scoped credential may call those routes as it may callPOST /ingest.scope["route"]: its method and declared template), never a path pattern, so a listed template can't cover another handler._ROUTE_DECIDES.3. Route scopes on a mounted app
_perimeterclassified scopes onrequest.url.path, and the gate's healthz exemption usedscope["path"]. Under a mount such as/d/<id>, neither matched, so every narrow credential (read or ingest) fell through to WRITE and got 403. Both now use Starlette'sget_route_path, the router's own path, as the spend lease already did since #540.Tests
test_managed_metering_sql.py:classify_doc_text, is held pending, then approved.source_bytes_limit_exceeded.test_per_request_perimeter.py: with the app mounted at/d/oneandingest_scope_routes=(("POST", "/uploads/{upload_id}/complete"),):completeand gets 403 on another host route;test_openapi_export: the new parameter is classified as a policy knob, and the OpenAPI output is unchanged.Checks
ruff, pyright (0), unit lane (3152 passed)
DB tests: CI only, because local Docker is down
Codex review
I have read and agree to the RememberStack Contributor License Agreement v1.0.
🤖 Generated with Claude Code
https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm