Repository navigation
Map the PRISM public/operator endpoint split before extracting the read tier - #147
Merged
Merged
Conversation
…ad tier Issue #145 moves the public dashboard and audit read tier out of the coordinator process. That needs an explicit endpoint map first: some endpoints that look public are operator surfaces that merely share the listener today. Classify all 29 request paths the HTTP surface serves as public read, operator, or payout-affecting, with the evidence behind each call. The result is narrower than "move the read traffic": exactly the 13 /public/v1 routes are extracted, and everything else stays. Three findings drove the narrowing. The boundary is already written down and it excludes /audit/*. PRISM.md lists every /audit/* route, /healthz, /metrics and /owed-balances as the private audit/ops listener and says operators may expose only /public/v1. docs/public-dashboard-api/README.md repeats it as a contract and test_public_dashboard_api_contract.py enforces it. The published evidence content is public and already reaches callers content-addressed through /public/v1/artifacts/{sha256}, which resolves bodies from body_uri on disk; the /audit/* routes are internal tooling over the same data, in raw sats, unpaginated, carrying broadcast material. So the PRISM_PUBLIC_ARTIFACT_CACHE_* knobs move with the extracted service without widening the public surface. Two nominally public routes take the writer lock today. /public/v1/miners/{recipient_id}, the most-polled route on the surface, resolves an owed balance via current_owed_balances(), which returns every recipient's balance under the writer lock and filters in Python. /public/v1/blocks/{block_hash}/settlement-artifacts falls through to audit_bundle() under the writer lock for direct-coinbase blocks. Extracting the process without severing these would move the GIL contention but keep the lock contention, so both are recorded as extraction blockers. More routes are misfiled than the issue predicted. Beyond the drift count and the health probes: /owed, /owed-balances, the /payouts/{recipient_id}/status alias, and the whole /audit/* family. /miners/{recipient_id}/status is not in PRISM.md's inventory and has no consumer outside tests. Land the map as docs/prism-public-operator-endpoint-split.md and the classification as lab/prism/endpoint_registry.py, so a reviewer can disagree with one row without re-reading the HTTP layer. The registry is declarative and changes no request handling; AuditHttpFacade still owns dispatch. tests/test_prism_endpoint_registry.py pins the registry to the code in both directions: every classified path is really routed (driven through a bound server for the facade routes and through public_api.dispatch for the public ones), and every route literal in the HTTP layer is classified, so a new endpoint cannot be added without a classification. It also asserts the extracted set stays exactly /public/v1, that no /audit/ path is ever extracted, and that a writer-lock route cannot be marked for extraction without recording the blocker. Refs #145. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
The retention test captured time.monotonic() and asserted that a silent reconnect cycle at exactly +TTL still resumes, relying on the store's strictly-greater expiry comparison. That boundary arithmetic is not exact for an arbitrary float base: (start + 900.0) - start rounds above 900.0 for roughly one in five thousand captured clock values, which flips the boundary cycle to expired and fails the test. CI hit this on the push run for the map commit while the pull_request run of the same commit passed. Every record and lookup in the test runs under frozen_clock, so the base never needs to be a real monotonic reading. Pin it to an exactly-representable constant, making the boundary arithmetic exact. Refs #145.
The substring-based unclassified-route guard was prefix-permissive: a new route extending an existing literal (e.g. a new /public/v1/blocks/... sub-route) passed unclassified, which is exactly the drift the guard exists to catch ahead of the read-tier extraction. Replace it with frozen exact-set snapshots of the do_GET and dispatch route literals, pin the 13-extracted/31-total path counts, assert every registry path is matched by a literal in its owning dispatcher, and pin the GET-only assumption so a future verb method cannot bypass the registry.
Member
Author
|
Review follow-up: replaced the prefix-permissive unclassified-route guard with exact frozen literal-set snapshots for |
This was referenced Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First of two PRs for #145. This one only writes the boundary down; no request handling changes and no process moves.
Why a map first
Issue #145 says the public/operator split needs an explicit map before anything moves, because some endpoints that look public are operator surfaces that merely share the listener. That turned out to be right, and to cover more routes than the issue predicted.
All 31 request paths the HTTP surface serves are classified as public read, operator, or payout-affecting. The result is narrower than "move the read traffic":
Classification rationale
The boundary is already written down, and it excludes
/audit/*I started by classifying published audit evidence as public read surface — audit evidence is a public record, so the routes serving it looked public. That was wrong, and the repository already said so.
PRISM.mdstates the coordinator "exposes a private audit/ops listener and a dashboard-safe public API from the same process", lists every/audit/*route plus/healthz,/metricsand/owed-balancesas private/internal, and concludes: "operators can expose only/public/v1through a reverse proxy or dashboard frontend."docs/public-dashboard-api/README.mdrepeats it as a contract, andtests/test_public_dashboard_api_contract.pyenforces it by asserting the OpenAPI document contains no/audit/path.The distinction that resolves it: the evidence content is public; the
/audit/*routes are not. Published evidence already reaches callers content-addressed through/public/v1/artifacts/{sha256}, which resolves bodies frombody_urion disk and verifies them against the requested hash, with/public/v1/blocks/{block_hash}/settlement-artifactslinking to it. The/audit/*routes are internal tooling over the same data: rawsatsunits, no pagination, full broadcast-attempt histories,parent_coinbase_tx_hexandmanifest_set_jsonbroadcast material, and one caller-controlled unbounded window.This is why the
PRISM_PUBLIC_ARTIFACT_CACHE_*knobs can move with the extracted service, as the issue anticipated, without widening the public surface.Two nominally public routes take the writer lock today
This is the finding that most changes the shape of PR 2.
/public/v1/miners/{recipient_id}— the most-polled route on the surface — resolves an owed balance viaowed_balance_for_recipient()→current_owed_balances(), which returns every recipient's balance under the writer lock and then filters in Python./public/v1/blocks/{block_hash}/settlement-artifactsfalls through todirect_coinbase_settlement_payload()→audit_bundle()under the writer lock for direct-coinbase blocks.Moving the process without severing these would move the GIL contention but keep the lock contention. Both are recorded as extraction blockers rather than used to reclassify the routes as operator — audience and implementation disagree, and it is the implementation that has to change.
More routes are misfiled than the issue predicted
The issue named the drift count and the health probes. The sweep also found
/owedand/owed-balances(an O(recipients) balance dump under the writer lock), the/payouts/{recipient_id}/statusalias, and the entire/audit/*family./miners/{recipient_id}/statusis not inPRISM.md's endpoint inventory at all and has no consumer outside tests — legacy, superseded by/public/v1/miners/{recipient_id}.Payout-affecting
Live payout obligations — the state the settlement machinery acts on — are out of scope by the terms of the issue:
/owed,/owed-balances,/miners|payouts/{recipient_id}/status, and/audit/carry-forward-integrity(+ its/audit/ledger-integrityalias), which carries the drift count and theaudit_head_sha256operators are told to mirror after payout-affecting blocks.What landed
docs/prism-public-operator-endpoint-split.md— the map, with a per-route table carrying the evidence behind each call: which ledger methods are reached, whether each takes the writer lock or the bounded read slot, and what blocks extraction.lab/prism/endpoint_registry.py— the same classification, declarative. This is the code motion that makes the boundary explicit without moving the process.AuditHttpFacadestill owns dispatch; the registry changes no request handling.tests/test_prism_endpoint_registry.py— pins the registry to the code.docs/README.md— index entry.Ledger access, verified
The writer-lock reads reached from HTTP (
defline, then the line holding the gate, inlab/prism/share_ledger.py):current_owed_balances:4161:4172/owed,/owed-balances,/miners/{id}/status,/public/v1/miners/{id}carry_forward_integrity_report:4259:4261/audit/carry-forward-integrityaudit_share_window:4327:4353/audit/share-windowaudit_block_payouts:4365:4383/audit/blocks/{h}/payouts,/audit/block/{h}recipient_payout_history:4389:4418/miners/{id}/statusaudit_bundle:4906:4927/audit/blocks/{h}/bundle,/public/v1/blocks/{h}/settlement-artifactsaudit_bundle_by_commitment:4931:4958/audit/commitments/{leaf}/bundleEverything else on the surface uses
_run_read_json, which takes the bounded read semaphore (PRISM_POSTGRES_READ_CONCURRENCY, default 4) and is replica-eligible as written. No HTTP route on any path performs anINSERT,UPDATE,DELETEor advisory lock; the stored functions involved are all declaredSTABLE.public_api.pyalso carries pre-read-model fallbacks reachingrecipient_payout_historyandledger.all_shares(). On the productionPsqlShareLedgerevery read model exists, so those are unreachable — they matter only underPRISM_ALLOW_MEMORY_LEDGER=1. The extracted service must keep that true or it would reintroduce writer-lock reads on public routes.How the map is kept honest
tests/test_prism_endpoint_registry.pyasserts both directions, so the map cannot drift from the code:ThreadingHTTPServer,/public/v1routes throughpublic_api.dispatchagainst a coordinator whose ledger and RPC raise a sentinel, so reaching a handler is distinguishable from falling to the 404.audit_http.do_GETandpublic_api.dispatchis covered by a classification, so a new endpoint cannot be added without classifying it. (I mutation-checked this guard: the first version passed vacuously because a trailing placeholder left an empty-string fragment that matched every probe. Fixed and re-checked against/admin/reset,/public/v2/pool-summaryand/audit/secret-dump, which are now all correctly rejected.)/public/v1, no/audit/path is ever extracted, and theEndpointconstructor refuses to mark a writer-lock route for extraction without recording the blocker.Completeness
One HTTP-serving surface exists outside tests: the
AuditHttpFacadelistener, fed by_CoordinatorAuditHttpandpublic_api.dispatch.make_audit_handleris a compatibility factory over the same facade, not a second surface. The coordinator binds only the Stratum listener(s) and the audit HTTP port. No Rust crate serves HTTP. Every route string intests/,test/,docs/anddoc/falls inside the classified union; the only exception is a test-only/controlroute in the fake qbit RPC server.Staleness precedent, recorded for PR 2
The map records the contract PR 2 has to follow, already established in
lab/prism/observability.py:MINIMUM_HEALTH_STALE_SECONDS = 15.0,stale_after = max(3 * refresh_seconds, MINIMUM_HEALTH_STALE_SECONDS), and/metricsreturning503 if stale else 200while always emittingqbit_prism_metrics_snapshot_age_seconds. It also names the three staleness sources that compound for the extracted tier: the per-routePublicResponseCacheTTL, the 30s pool reward-window aggregate cache underneath every miner page, and replica lag once a replica exists.Verification
tests.test_prism_endpoint_registry(new, 17 tests),tests.test_prism_audit_http,tests.test_prism_audit_api,tests.test_prism_public_dashboard_api,tests.test_public_dashboard_api_contract,tests.test_prism_compose_profile— 141 tests, all pass.python -m compileall lab testsclean.docker compose config --quietclean for all four profiles;shellcheck -xandbash -nclean.What is not here
PR 2 does the extraction: the new process and compose service, the two writer-lock severances above, the
mining-configurationenv requirement, and the per-endpoint staleness contracts with contract tests pinning pre-extraction response equality.Replica wiring stays out of both.
prism-postgreshas a dedicated WAL volume (POSTGRES_INITDB_WALDIR) but nowal_level, replication slot, or standby service. My recommendation, argued in PR 2, is a third PR: the extracted service is worth landing on the primary first, since a separate process with its own connection pool already removes the GIL contention, and the replica is the part most likely to stall the rest.Refs #145.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.