Skip to content

fix(relay): sweep expired state hourly instead of every five minutes - #101

Merged
rynfar merged 1 commit into
pylonfrom
fix/relay-prune-cron-hourly
Aug 26, 2026
Merged

fix(relay): sweep expired state hourly instead of every five minutes#101
rynfar merged 1 commit into
pylonfrom
fix/relay-prune-cron-hourly

Conversation

@rynfar

@rynfar rynfar commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

What Changed

infra/relay/src/worker.ts: the housekeeping cron goes from */5 * * * * to 0 * * * *, 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:

  • DPoP replay is an INSERT … ON CONFLICT DO NOTHING on 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 Live Activity rows stop rendering after TERMINAL_AGENT_ACTIVITY_DISPLAY_TTL_MS (15 min, AgentActivityPublisher.ts:232) and are excluded from live-work checks by isTerminalPhase/isExpiredAgentActivityState — all based on updatedAt, 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

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (no UI change)
  • I included a video for animation/interaction changes (no motion change)

Model: Claude Fable 5 · Harness: Claude Code


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

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.
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XS labels Aug 26, 2026
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 13.3 KiB 13.2 KiB −100 B (−0.7%) 15.1 KiB
Codex Thread snapshot wire 6.9 KiB 6.9 KiB +8 B (+0.1%) 7.3 KiB
Codex Live turn WebSocket wire 6.4 KiB 6.3 KiB −108 B (−1.7%) 7.8 KiB
Codex Live turn WebSocket decoded 55.5 KiB 54.7 KiB −822 B (−1.4%) 66.4 KiB
Codex Live turn messages 9 9 0 (0.0%) 21
Claude Total thread wire 13.3 KiB 13.3 KiB +3 B (+0.0%) 15.1 KiB
Claude Thread snapshot wire 6.9 KiB 6.9 KiB +3 B (+0.0%) 7.3 KiB
Claude Live turn WebSocket wire 6.4 KiB 6.4 KiB 0 B (0.0%) 7.8 KiB
Claude Live turn WebSocket decoded 56.3 KiB 56.3 KiB 0 B (0.0%) 66.4 KiB
Claude Live turn messages 9 9 0 (0.0%) 21

Baseline: 486065e · PR result: e0ff0a3 · Source CI: success

Scenario and decoded snapshot size

10 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.

  • Codex decoded thread snapshot: 109.4 KiB
  • Claude decoded thread snapshot: 110.0 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@rynfar
rynfar merged commit 37208c9 into pylon Aug 26, 2026
20 of 21 checks passed
@rynfar
rynfar deleted the fix/relay-prune-cron-hourly branch August 26, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant