One hive RPC per MCP handshake; backoff on the SPA /ws reconnect - #24
Open
tieguy wants to merge 1 commit into
Open
One hive RPC per MCP handshake; backoff on the SPA /ws reconnect#24tieguy wants to merge 1 commit into
tieguy wants to merge 1 commit into
Conversation
Per-minute analytics identified the cold-start driver behind the quota burn: HiveDO wakes in a quantum of exactly THREE requests every 60-90 seconds, around the clock — one full MCP handshake per reconnecting client (the claude.ai connector plus each open Claude Code session, two distinct signatures overlapping in the same minutes). Every handshake lands a fresh SessionDO whose init() made three separate hive RPCs (registerSession, getRecentActivity, getMaintenanceStatus), the first an unconditional storage.put. The reconnect cadence belongs to the clients; the per-handshake cost is the only lever the server owns. So: - getSessionBriefing(sessionId): registration + working-memory + maintenance briefing in ONE RPC. registerSession becomes a no-op read when the session is already current, so a re-handshake of a known session writes nothing. (A SessionDO-side cache was rejected: each re-handshake lands a fresh SessionDO with a new id, so a per-DO cache can never hit.) - SPA /ws reconnect: 3s doubling to 60s with jitter, reset on open. The flat 3s retry meant a parked tab hammered a down worker 1,200x/hr, and every /ws attempt wakes the hive. A dead tab now costs ~60/hr; a live one still recovers in seconds. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rf5RTB7iigiMpoArYzdUKN
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.
The problem
Companion to #23 (independent — either lands alone). With per-wake cost fixed, the wake rate is the other half: per-minute Cloudflare analytics show HiveDO waking in a quantum of exactly three requests every 60–90 seconds, around the clock. That's one full MCP handshake per reconnecting client — the claude.ai connector and every open Claude Code session re-handshake on their own schedule, and each handshake lands a fresh SessionDO whose
init()made three separate hive RPCs (registerSession,getRecentActivity,getMaintenanceStatus), the first of which was an unconditionalstorage.put.The reconnect cadence belongs to the clients; the per-handshake cost is the only lever the server owns.
The fix
getSessionBriefing(sessionId): session registration (scratchpad fanout) + working-memory + maintenance briefing in one RPC.registerSessionbecomes a no-op read when the session is already current, so a re-handshake of a known session writes nothing; a genuinely new session still writes once. (A SessionDO-side cache was considered and rejected: each re-handshake lands a fresh SessionDO with a new id, so a per-DO cache can never hit.)SPA
/wsreconnect backoff: the retry was a flat 3s with no backoff — a parked tab hammers a down worker 1,200×/hr, and every/wsattempt wakes the hive DO. Now 3s doubling to 60s with jitter, reset on successful open: a dead tab costs ~60 attempts/hr, a live one still recovers in seconds. (During a quota outage this matters doubly: the flat retry burns the freshly-reset budget the moment the cap clears.)Tests
session-briefing.test.ts: briefing shape + registration in one call; a repeat briefing for an already-registered session performs zerostorage.putcalls (spied), while a new session still registers. Existingmcp-contract/scratchpad/memorysuites pass unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_01Rf5RTB7iigiMpoArYzdUKN