Summary
Retire the leftover inbox KV write helpers now that reads/writes have moved to D1, so the legacy KV path can't quietly come back.
Background
In April the account was billed ~$386 for KV on the inbox path — $211.50 for 422M KV reads + $175.00 for 34M KV writes (invoice IN-63836588). Cause: the inbox lived in KV with a hand-rolled index — listing an inbox read the inbox:agent:{addr} id-array plus one kv.get per message, every send rewrote that array, and a per-request circuit-breaker did a KV read-modify-write.
That was fixed by migrating the inbox to D1 (#745/#746), replacing the circuit-breaker KV-RMW with the ratelimits binding (#894), and moving hot COUNT(*)s to an O(1) agent_inbox_stats table (#845). Per lib/inbox/kv-helpers.ts:193, KV writes for inbox:agent:{btcAddress} stopped 2026-05-11T14:24Z. Production KV is back under the free tier.
Residual
lib/inbox/kv-helpers.ts still exports the legacy write helpers:
storeMessage (kv-helpers.ts:107)
storeReply (kv-helpers.ts:181)
updateAgentInbox (kv-helpers.ts:237) — the per-agent index array RMW
updateSentIndex (kv-helpers.ts:307)
Current volume is trivial/free, but leaving these callable keeps the expensive index-array pattern one wiring mistake away from returning.
Proposed action
- Confirm these helpers have no remaining live callers on the send/reply write path (D1 is the source of truth).
- Delete the dead ones (or gate behind an explicit dual-write flag that's off in prod), mirroring
#893 ("delete dead count*FromD1 helpers").
- Keep only the KV usage that's still legitimately needed (e.g. staged x402 payment keys, if any).
Cleanup only — no active cost — but it closes out the KV inbox migration.
Summary
Retire the leftover inbox KV write helpers now that reads/writes have moved to D1, so the legacy KV path can't quietly come back.
Background
In April the account was billed ~$386 for KV on the inbox path — $211.50 for 422M KV reads + $175.00 for 34M KV writes (invoice
IN-63836588). Cause: the inbox lived in KV with a hand-rolled index — listing an inbox read theinbox:agent:{addr}id-array plus onekv.getper message, every send rewrote that array, and a per-request circuit-breaker did a KV read-modify-write.That was fixed by migrating the inbox to D1 (
#745/#746), replacing the circuit-breaker KV-RMW with theratelimitsbinding (#894), and moving hotCOUNT(*)s to an O(1)agent_inbox_statstable (#845). Perlib/inbox/kv-helpers.ts:193, KV writes forinbox:agent:{btcAddress}stopped2026-05-11T14:24Z. Production KV is back under the free tier.Residual
lib/inbox/kv-helpers.tsstill exports the legacy write helpers:storeMessage(kv-helpers.ts:107)storeReply(kv-helpers.ts:181)updateAgentInbox(kv-helpers.ts:237) — the per-agent index array RMWupdateSentIndex(kv-helpers.ts:307)Current volume is trivial/free, but leaving these callable keeps the expensive index-array pattern one wiring mistake away from returning.
Proposed action
#893("delete dead count*FromD1 helpers").Cleanup only — no active cost — but it closes out the KV inbox migration.