feat(kv-bridge): Terminal KV fallback sink — POST state snapshots when Upstash ceiling hit#42
Merged
Conversation
Add POST/GET/health kv-bridge API with Bearer or HMAC auth, allowlisted keys, file-backed store (KV_BRIDGE_PATH), TTL on read, GI_STATE OAA_MEMORY note, client helpers for Terminal, Render KV_BRIDGE_SECRET, and Vitest coverage.
kaizencycle
marked this pull request as ready for review
April 19, 2026 22:07
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.
Summary
Adds a warm KV bridge on OAA so the Mobius Civic AI Terminal can persist and read allowlisted hot-state keys when Upstash hits its monthly request ceiling (or other primary-KV failures). Writes are authenticated; reads and health are public so the Terminal can recover without sharing the secret on GET.
API
/api/kv-bridge/writeAuthorization: Bearer <KV_BRIDGE_SECRET>orx-hmac-sha256over exactJSON.stringify(req.body)ttl_seconds/api/kv-bridge/read?key=returns entry or 404; omitkeyfor key summary/api/kv-bridge/healthFiles
lib/kv-bridge/constants.ts— key allowlistlib/kv-bridge/store.ts—KV_BRIDGE_PATH(defaultdata/kv-bridge.json)lib/kv-bridge/auth.ts— Bearer + HMAC verificationlib/kv-bridge/giMemoryNote.ts—GI_STATE→ append note toOAA_MEMORY.json(non-blocking, last 200 notes trimmed)pages/api/kv-bridge/{write,read,health}.tslib/kv-bridge/client.ts—kvBridgeWrite/kvBridgeReadfor Terminal (OAA_API_BASE_URLorOAA_API_BASE)Env (Render / local)
KV_BRIDGE_SECRET— required for writes (added torender.yamlforoaa-hubwithgenerateValue: true)KV_BRIDGE_PATH— optional override for store file pathRepo hygiene
data/kv-bridge.jsonis gitignored (runtime store; created on first write)Tests
Not in this PR
lib/kv/withFallback.tsin mobius-civic-ai-terminal (separate repo) — wire Terminal to these endpoints using the same env names aslib/kv-bridge/client.ts.Acceptance
key_not_allowedttl_secondssetGI_STATEtriggers OAA memory observation note whenglobal_integrityis present