Skip to content

perf(web): window focus probes instead of resyncing; desktop wake reconnects at once - #220

Merged
tusharbhardwaj-bk merged 1 commit into
expbkmainfrom
t3code/perf-5-focus-wake
Sep 26, 2026
Merged

tusharbhardwaj-bk merged 1 commit into
expbkmainfrom
t3code/perf-5-focus-wake

Conversation

@tusharbhardwaj-bk

@tusharbhardwaj-bk tusharbhardwaj-bk commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The client-sync audit (~/perf-audit-bkt3/30-client-sync.md, F6) found two problems.

  1. Every alt-tab resynced everything. Fork commit 4cbe7bf made window focus fire application-active unconditionally. That wakeup:
    • probes the connection;
    • restarts the shell subscription, which on the server means a full shell build;
    • restarts every mounted thread subscription (replay stats plus a replay of up to 1,000 events each);
    • flips those threads to "synchronizing".
  2. Coming back from sleep waited 15 s on a dead socket. The desktop window stays visible across a sleep, so only the focus probe noticed the dead socket, after its full CONNECTION_PROBE_TIMEOUT (15 s). The OS resume event only reached telemetry (DesktopTelemetryPublisher.ts:187-190).

Fix

Focus probes; a real return resyncs.

  • New wakeup reason application-focus, marked in client-runtime/connection/wakeups.ts.
    • The supervisor probes the session for it (15 s timeout) and it cuts a retry wait short, exactly like application-active.
    • It is excluded from shouldResubscribeAfterWakeup, so streams are not restarted.
    • A failed probe still reconnects without the first backoff rung.
  • The web platform (apps/web/src/connection/platform.ts, marked block, helper focusWakeup.expbkt3.ts) tracks when the window was blurred or hidden. A focus after ≥ 60 s away emits application-active (resync as before); a shorter absence emits application-focus.
  • A visibilitychange to visible still emits application-active (upstream) and clears the tracker, so the focus that follows only probes rather than resyncing twice.

Desktop resume/unlock reconnects at once.

  • New fork layer apps/desktop/src/power/SystemResumeForwarder.expbkt3.ts forwards powerMonitor resume and unlock-screen to every window on desktop:system-resumed. A sliding queue of 1 means a resume and an unlock that fire together produce one message.
  • Wiring: marked onSystemResumed in preload.ts, an optional onSystemResumed? field in contracts/ipc.ts, and one line in main.ts.
  • The web platform maps it to application-active-reconnect, which replaces the lease immediately. The supervisor already interrupts an in-flight probe for that reason.

Surfaces

  • Web (browser tabs): focus behaviour changes as above. Visibility and online wakeups are unchanged.
  • Desktop: focus change plus resume/unlock. This reaches users only with the next desktop build: the desktop app loads its bundled web UI, so deploying the server does not change connected desktop clients.
  • Mobile: unchanged. It has its own AppState wakeups and never emits application-focus.
  • Server: unchanged.

Evidence

  • client-runtime/src/connection/supervisor.expbkt3.test.ts:
    • predicate checks;
    • application-focus probes the live session without replacing it (1 session, 0 releases);
    • a failed focus probe reconnects with no TestClock advance.
    • Together with the existing supervisor.test.ts: 46 pass.
  • apps/web/src/connection/focusWakeup.expbkt3.test.ts, 4 pass:
    • a quick alt-tab probes;
    • ≥ 60 s away resyncs once;
    • a visibility resync is not doubled;
    • a focus with no recorded absence probes.
  • vp run typecheck is clean in packages/contracts, packages/client-runtime, apps/desktop and apps/web. Lint is clean and the fork-marker check passes.

No screenshots: nothing visible changes. The effect is fewer "synchronizing" flips and faster reconnects. I have not exercised it in a real desktop client, because that needs a desktop build.

Model/harness: Claude Opus 5.5 via Claude Code in T3 Code.

🤖 Generated with 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.

…onnects at once

Every window focus fired "application-active", so each alt-tab rebuilt the
shell subscription and replayed every open thread. Focus now emits a new
probe-only "application-focus" wakeup unless the window was blurred or
hidden for at least 60 s.

After sleep the desktop window stays visible, so the focus probe waited out
its 15 s timeout on a dead socket. The desktop shell now forwards the OS
resume and unlock-screen events to the renderer, which reconnects at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Sep 26, 2026
@github-actions

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 13.8 KiB — 15.1 KiB ✅
Codex Thread snapshot wire — 7.3 KiB — 7.8 KiB ✅
Codex Live turn WebSocket wire — 6.5 KiB — 7.8 KiB ✅
Codex Live turn WebSocket decoded — 57.0 KiB — 66.4 KiB ✅
Codex Live turn messages — 8 — 21 ✅
Claude Total thread wire — 13.8 KiB — 15.1 KiB ✅
Claude Thread snapshot wire — 7.3 KiB — 7.8 KiB ✅
Claude Live turn WebSocket wire — 6.5 KiB — 7.8 KiB ✅
Claude Live turn WebSocket decoded — 57.9 KiB — 66.4 KiB ✅
Claude Live turn messages — 9 — 21 ✅

Baseline: unavailable · PR result: e4860d8 · 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: 114.9 KiB
  • Claude decoded thread snapshot: 115.6 KiB

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

@tusharbhardwaj-bk
tusharbhardwaj-bk merged commit 37f0683 into expbkmain Sep 26, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 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.

2 participants