Skip to content

fix(app): reconnect quickly after phone sleep - #43

Merged
frahlg merged 4 commits into
mainfrom
agent/fast-app-resume
Aug 11, 2026
Merged

fix(app): reconnect quickly after phone sleep#43
frahlg merged 4 commits into
mainfrom
agent/fast-app-resume

Conversation

@frahlg

@frahlg frahlg commented Aug 11, 2026

Copy link
Copy Markdown
Member

What

  • replace a stale foreground WebSocket when no fresh box frame arrives within 2.5 seconds
  • give the first Noise handshake after a wake a 3-second deadline instead of inheriting the 12-second background wait
  • react to visibility, page restore and network-online events without redialling a healthy stream
  • add local performance marks for app open, key readiness, reconnect and first live frame
  • include the safe automatic service-worker handover and visible build identity from the prior verified commit

Why

A real app wake took 20–40 seconds before fresh data appeared. The source path could wait for a 12-second Noise deadline and then 3/6/12-second retry windows while a browser still reported a dead socket as open.

The new foreground path gives a healthy stream one normal telemetry beat to answer. If it stays quiet, the app replaces the carrier instead of waiting for those stale timers.

Evidence

Before: the old retry chain allowed waits in the reported 20–40 second range.

After, deterministic tests assert:

  • a healthy resumed stream keeps its socket
  • a silent open stream redials at exactly 2.5 seconds
  • a network change redials at once
  • a foreground Noise handshake times out at 3 seconds
  • duplicate lifecycle wake events create only one new relay dial

No phone trace is claimed here because Chrome DevTools remote tracing was unavailable in this environment.

Verification

  • npm run verify
  • Svelte check: 0 errors, 0 warnings
  • Vitest: 88 files passed, 1 skipped; 860 tests passed, 1 skipped
  • production Vite build passed
  • relay integration test passed with its local loopback port
  • git diff --check

Cloudflare branch builds now use wrangler versions upload; only main uses wrangler deploy.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 11, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ftw-webapp 617a2f4 Commit Preview URL

Branch Preview URL
Aug 11 2026, 12:12 PM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f7103e5192

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib/state/site.svelte.ts Outdated
Comment on lines +250 to +251
pageShown(): void {
if (!this.documentVisible || this.#resumeWaiting) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Refresh visibility before handling pageshow

When a page was previously hidden and is restored without a visibilitychange event—the exact fallback this method is intended to provide—documentVisible remains false, so this guard discards pageshow and never starts the reconnect watchdog. Read the current document.visibilityState here, or have the pageshow handler synchronize visibility before calling this method, so a restored stale socket is actually replaced.

Useful? React with 👍 / 👎.

@frahlg
frahlg merged commit e8958e9 into main Aug 11, 2026
3 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