Skip to content

Probe resumed sockets before waiting for reconnect - #4650

Merged
SawyerHood merged 1 commit into
mainfrom
perf/probe-resumed-sockets
Oct 1, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
perf/probe-resumed-sockets

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

When a tab or phone resumes, its realtime socket is often half-dead: still OPEN to the browser, but nothing arrives. The app only noticed after the regular ping cycle and its 5 s pong timeout, then waited out the reconnect backoff, so the first seconds after resume showed stale threads.

What changed

Split out of #4532 (commit 631124e, unchanged). Part 1 of 6.

  • apps/app/src/lib/ws.ts: on becoming visible or coming back online, probe the open socket with a 1.5 s pong timeout and reconnect at once if it does not answer. Tabs that start hidden are tracked too. First reconnect delay drops from 1 s to 250–500 ms (per-client jitter) with a growth factor of 2 up to the same 30 s cap. An online event in a hidden tab no longer probes.
  • apps/app/src/hooks/realtime-cache-effects.ts, cache-owners/system-cache-effects.ts: after a resume of at least 5 s hidden, refetch the active timeline, thread and sidebar queries right away instead of waiting for the socket verdict.

No server, host daemon or wire change. Known trade-off: on a link slower than 1.5 s after wake, the probe reconnects a socket that would have answered.

How you verified

  • pnpm exec turbo run typecheck lint --filter=@bb/app: pass (0 lint errors).
  • vitest run src/lib/ws.test.ts src/hooks/realtime-cache-effects.test.ts src/hooks/system-cache-effects.test.ts: 104/104 pass, including the new resume probe, initially-hidden and stale-resume-state cases.
  • Not re-measured on this base. Speed up thread switching, resume, realtime, and composer #4532 measured half-dead socket resume to fresh data at 8,289 ms → 223 ms on its older baseline. Not checked on a real phone.

🤖 Generated with Claude Code

AGENT GENERATED

Detect half-dead connections after a tab resumes and refresh active queries immediately. Cover initially hidden tabs and clear stale resume state when disconnected.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T21:54:22.198096Z 1c80720 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SawyerHood
SawyerHood merged commit f8d225d into main Oct 1, 2026
21 checks passed
@SawyerHood
SawyerHood deleted the perf/probe-resumed-sockets branch October 1, 2026 22:37
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.

2 participants