Skip to content

Serve bounded-stale public reads during database outages - #167

Merged
kiwidream merged 1 commit into
2.x.xfrom
state-bounded-stale-public-reads
Aug 20, 2026
Merged

kiwidream merged 1 commit into
2.x.xfrom
state-bounded-stale-public-reads

Conversation

@kiwidream

@kiwidream kiwidream commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Closes #164.

Problem

In PRISM_PUBLIC_REPLICA_MODE=off, the readiness probe could correctly report PostgreSQL unavailable while /public/v1 continued calling the database or silently serving a warm cache entry without stating the outage.

Design

  • Classify database-backed routes from the endpoint registry; mining configuration and immutable content-addressed artifacts remain exempt.
  • While readiness is unhealthy, serve an exact warm cache hit only inside its existing TTL and published staleness budget.
  • Label that response with Warning: 110 qbit-prism "database unavailable; serving cached response", X-Prism-Database-State: unavailable, Age, and the existing staleness-budget header.
  • Refuse cold, bypassed, expired, and past-budget requests with the existing public 503 schema and Cache-Control: no-store, without calling the database or refreshing the cache.
  • Keep PRISM_PUBLIC_REPLICA_MODE=require on its existing stricter replica-freshness gate.
  • Add counters for degraded responses and database-outage refusals.

Verification

  • python3 -m unittest tests.test_prism_public_read_service — 95 tests passed.
  • Adjacent dashboard API, endpoint registry, public API contract, and compose-profile suites passed (155 tests plus one existing expected failure).
  • Docker Python compile passed across docker, lab, tests, examples, and scripts.
  • Docker Ruff 0.12.5 with E4,E7,E9,F passed on both changed files.
  • Mutation checks proved the new tests fail if the outage gate, no-origin rule, exempt-route classification, coalesced-response handling, or Warning header is removed.

Residual risk

The live primary/standby replica gate was not run because it requires that topology. Its require-mode refusal remains ahead of and unchanged by this availability path, and focused coverage pins that a warm cache does not soften it.


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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 025b4d9113

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +852 to +858
if degraded and cache_state == "HIT":
# A cached body, inside the budget the same response publishes,
# served with the outage stated rather than implied. The
# shared-cache headers are deliberately left as they were: the
# CDN TTL is the route's own, which the registry derives at a
# third of the budget or less, so a downstream cache cannot
# carry this body past the bound stated on it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove stale-while-revalidate from degraded responses

When a CDN honors the unchanged shared-cache headers during an outage, several default routes can be served beyond their published budget: the ordinary policy is max-age=5, stale-while-revalidate=30, while routes such as /public/v1/blocks advertise a 15-second budget. After revalidation begins returning 503, the CDN may therefore continue serving the degraded body until it is 35 seconds old, even though this branch claims downstream caching cannot carry it past the bound. Strip or cap stale-while-revalidate for degraded responses so the advertised staleness contract is enforceable.

Useful? React with 👍 / 👎.

An unclassified path is not database-backed here because dispatch() 404s it
before it can read anything.
"""
endpoint = endpoint_registry.endpoint_for_request_path(path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat artifact lookups as database-backed

On a cold or expired /public/v1/artifacts/{sha256} request during a database outage, this exemption still calls public_api.dispatch(), whose artifact handler invokes PsqlShareLedger.dashboard_public_artifact_document() and immediately runs a database query before it can resolve an externalized body. Consequently the supposedly outage-exempt route retries the unavailable database and becomes a generic 500; the new test misses this because its fake artifact ledger remains callable when the simulated database is taken down.

Useful? React with 👍 / 👎.

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