fix(relay): sweep expired state hourly instead of every five minutes - #101
Merged
Conversation
The relay's housekeeping cron ran every five minutes, and Neon's Free plan suspends the compute after five idle minutes, so the database never slept: about 180 CU-hours a month at the minimum compute size against a 100 CU-hour allowance. It ran dry on 2026-08-26 and took the relay down. Nothing depends on the sweep's timing: DPoP replay detection is an insert conflict on the proof id, and terminal Live Activity rows stop rendering after TERMINAL_AGENT_ACTIVITY_DISPLAY_TTL_MS regardless of when the row is deleted. Hourly keeps the same tables tidy for roughly 15 CU-hours a month.
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
4 tasks
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.
What Changed
infra/relay/src/worker.ts: the housekeeping cron goes from*/5 * * * *to0 * * * *, with a comment explaining why. It still does exactly the same two things — delete expired DPoP replay rows and delete terminal agent-activity rows older than 30 minutes.Why
Neon's Free plan suspends the compute after five idle minutes and allows 100 CU-hours a month. A sweep every five minutes means the compute is woken 288 times a day and effectively never sleeps: 0.25 CU × 24 h × 30 d ≈ 180 CU-hours/month at the minimum size. The project ran dry on 2026-08-26 and the relay went down with
database_unavailable.Hourly costs ~24 short wakeups a day ≈ 15 CU-hours/month for housekeeping, leaving the budget for actual use.
Nothing depends on the sweep's timing:
INSERT … ON CONFLICT DO NOTHINGon the proof id (auth/DpopProofs.ts:56-79); a reused id conflicts whether or not the expired row has been swept. Proofs expire after 5 minutes, so the table holds at most an hour of a single user's traffic.TERMINAL_AGENT_ACTIVITY_DISPLAY_TTL_MS(15 min,AgentActivityPublisher.ts:232) and are excluded from live-work checks byisTerminalPhase/isExpiredAgentActivityState— all based onupdatedAt, not on whether the row still exists. The sweep only reclaims space.Not in this PR (console settings, not code): pin the Neon compute to a fixed 0.25 CU so bursts can't autoscale to 2 CU.
Checklist
Model: Claude Fable 5 · Harness: Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.