Files
t3code/packages/client-runtime/src/connection/wakeups.ts
T
b603bacfd0 fix(mobile): probe on network path changes, report leases on reconnect
Rebuilt on main after #5561 and #5404 landed overlapping reconnect
work. What main already covers is dropped from this branch: the backoff
ladder rework replaces our jitter, wakeProbeFailed replaces our
probe-failure fast path, and the authoritative-session guard replaces
our shell warm-cache short-circuit.

What remains is the mobile-specific delta:

- New advisory `network-path-changed` wakeup: WiFi<->cellular keeps
  isConnected true while invalidating the socket's path, so the mobile
  adapter emits a wakeup on interface-type changes while active and the
  supervisor probes the session (3s bound) instead of waiting for the
  ping timeout. A failed probe rides main's wakeProbeFailed fast path;
  flapping interfaces cannot cut backoff delays short.
- Client activity is re-reported on every newly connected session
  generation; the AppState-triggered report races the reconnect and is
  dropped, leaving provider/VCS work paused server-side for up to 25s
  after a resume. Generation dedup is per-supervisor since replacements
  restart the counter.
- The RPC onPingTimeout hook is wired to logging so zombie-socket
  disconnects are distinguishable from ordinary closes.
- Server websocket idleTimeout drops to 30s from Bun's 120s default
  (clients ping every 5s, so live connections never idle), releasing a
  suspended phone's half-dead socket and buffers four times sooner.

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-authored-by: codex <[email protected]>
2026-08-10 12:58:27 +02:00

40 lines
1.4 KiB
TypeScript

import * as Context from "effect/Context";
import * as Layer from "effect/Layer";
import type * as Stream from "effect/Stream";
export type ConnectionWakeup =
| "application-active"
| "application-active-probe"
| "application-active-reconnect"
// Advisory: the network path changed shape (e.g. WiFi to cellular) while
// still nominally online. The old socket often survives in appearance only,
// so the supervisor probes it instead of waiting for a ping timeout. It is
// ignored outside the connected state: a flapping interface must not cut
// backoff delays short.
| "network-path-changed"
| "credentials-changed";
export function isApplicationActiveWakeup(reason: ConnectionWakeup): boolean {
return (
reason === "application-active" ||
reason === "application-active-probe" ||
reason === "application-active-reconnect"
);
}
export function shouldResubscribeAfterWakeup(reason: ConnectionWakeup): boolean {
return reason === "application-active" || reason === "application-active-probe";
}
export class ConnectionWakeups extends Context.Service<
ConnectionWakeups,
{
readonly changes: Stream.Stream<ConnectionWakeup>;
}
>()("@t3tools/client-runtime/connection/wakeups/ConnectionWakeups") {}
export const make = (service: ConnectionWakeups["Service"]) => ConnectionWakeups.of(service);
export const layer = (service: ConnectionWakeups["Service"]) =>
Layer.succeed(ConnectionWakeups, make(service));