Skip to content

feat(cloud): reclaim realtime connections via foreground lease#507

Merged
Neonforge98 merged 8 commits into
developfrom
codex/reclaim-cloud-realtime-connections
Jul 24, 2026
Merged

feat(cloud): reclaim realtime connections via foreground lease#507
Neonforge98 merged 8 commits into
developfrom
codex/reclaim-cloud-realtime-connections

Conversation

@Neonforge98

Copy link
Copy Markdown
Collaborator

Summary

  • Foreground lease for the billable Supabase Realtime socket: focused window holds the connection; hidden releases immediately; blurred-but-visible releases after a 45s one-shot grace timer (cancelled on refocus). Cuts fleet peak-connection billing without the alt-tab teardown/recovery storms of a zero-grace release, and keeps presence viewer chips stable across focus flips.
  • Event-driven scheduling only — the recurring 60s/5min cloud pass is gone. Outbound pushes (EventStore writes, project outbox) now run even while hidden, so a minimized agent run stays visible to teammates.
  • SUBSCRIBED-edge recovery policy (org2CloudRealtimeRecovery.ts): short disconnects (<5min) and rejoin storms (<30s cooldown) recover via delta cursors; only long gaps run the full listings + entitlement refresh. Full recovery force-fetches the active session's comment thread past the 30s TTL.
  • Retry hardening: jittered reconnectAfterMs (fleet was phase-locked on realtime-js's fixed schedule), exponential backoff for the comments error loop (10s → 5min cap).
  • Restart write-storm fix: seedFromRemoteSummary now seeds the full-payload metadata hash (and the missing avatarUrl), so restarts no longer re-upsert byte-identical metadata for every pushed session.
  • Full-listing scoping: start/online/roster recovery issues the complete collab listing only for the active org; background orgs use their delta cursors and get an authoritative listing on activation.
  • UI: dropdown option lists restore their visible-scrollbar styling (scrollbar-width: thin made newer WebKit ignore the ::-webkit-scrollbar rules — an overflowing sidebar org selector looked complete at 4 rows).
  • Docs: full three-part scalability audit + fix log under docs/cloud-scalability-audit-2026-07-23/.

Server-side counterparts (lock-order fix, O(1) storage accounting, materialized comment counters, signal debounce, indexes) shipped separately in ORGII-cloud-infra as migration 0003_scalability_p0.sql.

Test plan

  • tsc clean; Org2Cloud suite 659/659 incl. new tests for the lease grace state machine (fake timers), recovery decision policy, and seed-suppresses-upsert regression.
  • Real-machine verification on the dual-instance setup (API Calls panel + ps sampling): idle CPU 0% / RSS stable on both instances, 8 focus flips with no socket churn, one bounded burst on cloud-org activation then complete silence, 0 likely polling.

🤖 Generated with Claude Code

Pre-commit hook ran. Total eslint: 0, total circular: 0
Pre-commit hook ran. Total eslint: 0, total circular: 0
Pre-commit hook ran. Total eslint: 0, total circular: 0
Pre-commit hook ran. Total eslint: 0, total circular: 0
Pre-commit hook ran. Total eslint: 1, total circular: 0
Pre-commit hook ran. Total eslint: 1, total circular: 0
Pre-commit hook ran. Total eslint: 1, total circular: 0
Pre-commit hook ran. Total eslint: 1, total circular: 0
@Neonforge98
Neonforge98 merged commit f207fa0 into develop Jul 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant