Skip to content

Map the PRISM public/operator endpoint split before extracting the read tier - #147

Merged
kiwidream merged 3 commits into
2.x.xfrom
map-public-operator-endpoint-split
Aug 19, 2026
Merged

kiwidream merged 3 commits into
2.x.xfrom
map-public-operator-endpoint-split

Conversation

@kiwidream

@kiwidream kiwidream commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

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":

Exactly the 13 /public/v1/* routes are extracted. Everything else stays.

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.md states the coordinator "exposes a private audit/ops listener and a dashboard-safe public API from the same process", lists every /audit/* route plus /healthz, /metrics and /owed-balances as private/internal, and concludes: "operators can expose only /public/v1 through a reverse proxy or dashboard frontend." docs/public-dashboard-api/README.md repeats it as a contract, and tests/test_public_dashboard_api_contract.py enforces 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 from body_uri on disk and verifies them against the requested hash, with /public/v1/blocks/{block_hash}/settlement-artifacts linking to it. The /audit/* routes are internal tooling over the same data: raw sats units, no pagination, full broadcast-attempt histories, parent_coinbase_tx_hex and manifest_set_json broadcast 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 via owed_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-artifacts falls through to direct_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 /owed and /owed-balances (an O(recipients) balance dump under the writer lock), the /payouts/{recipient_id}/status alias, and the entire /audit/* family. /miners/{recipient_id}/status is not in PRISM.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-integrity alias), which carries the drift count and the audit_head_sha256 operators 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. AuditHttpFacade still 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 (def line, then the line holding the gate, in lab/prism/share_ledger.py):

Ledger method Definition Gate Reached by
current_owed_balances :4161 :4172 /owed, /owed-balances, /miners/{id}/status, /public/v1/miners/{id}
carry_forward_integrity_report :4259 :4261 /audit/carry-forward-integrity
audit_share_window :4327 :4353 /audit/share-window
audit_block_payouts :4365 :4383 /audit/blocks/{h}/payouts, /audit/block/{h}
recipient_payout_history :4389 :4418 /miners/{id}/status
audit_bundle :4906 :4927 /audit/blocks/{h}/bundle, /public/v1/blocks/{h}/settlement-artifacts
audit_bundle_by_commitment :4931 :4958 /audit/commitments/{leaf}/bundle

Everything 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 an INSERT, UPDATE, DELETE or advisory lock; the stored functions involved are all declared STABLE.

public_api.py also carries pre-read-model fallbacks reaching recipient_payout_history and ledger.all_shares(). On the production PsqlShareLedger every read model exists, so those are unreachable — they matter only under PRISM_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.py asserts both directions, so the map cannot drift from the code:

  • Every classified path is really routed — facade routes driven through a bound ThreadingHTTPServer, /public/v1 routes through public_api.dispatch against a coordinator whose ledger and RPC raise a sentinel, so reaching a handler is distinguishable from falling to the 404.
  • Every absolute-path literal in audit_http.do_GET and public_api.dispatch is 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-summary and /audit/secret-dump, which are now all correctly rejected.)
  • The extracted set stays exactly /public/v1, no /audit/ path is ever extracted, and the Endpoint constructor refuses to mark a writer-lock route for extraction without recording the blocker.

Completeness

One HTTP-serving surface exists outside tests: the AuditHttpFacade listener, fed by _CoordinatorAuditHttp and public_api.dispatch. make_audit_handler is 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 in tests/, test/, docs/ and doc/ falls inside the classified union; the only exception is a test-only /control route 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 /metrics returning 503 if stale else 200 while always emitting qbit_prism_metrics_snapshot_age_seconds. It also names the three staleness sources that compound for the extracted tier: the per-route PublicResponseCache TTL, 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 tests clean.
  • docker compose config --quiet clean for all four profiles; shellcheck -x and bash -n clean.

What is not here

PR 2 does the extraction: the new process and compose service, the two writer-lock severances above, the mining-configuration env requirement, and the per-endpoint staleness contracts with contract tests pinning pre-extraction response equality.

Replica wiring stays out of both. prism-postgres has a dedicated WAL volume (POSTGRES_INITDB_WALDIR) but no wal_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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

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.
@kiwidream

Copy link
Copy Markdown
Member Author

Review follow-up: replaced the prefix-permissive unclassified-route guard with exact frozen literal-set snapshots for do_GET and dispatch (a new route extending an existing literal now fails the snapshot equality), pinned the 13-extracted / 31-total path counts, asserted every registry path is matched by a literal in its owning dispatcher, and pinned the GET-only assumption on the handler. Also corrected the path count in the description (31, not 29 — the old number counted dispatch branches). Registry content unchanged.

@kiwidream
kiwidream merged commit ddff673 into 2.x.x Aug 19, 2026
11 checks passed
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