From 557d588e697263beea3c757dd83bee765ec8ec89 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:08:25 -0800 Subject: [PATCH] relay edge: tag auth-expiry closes and control opens with keepalive use and host silence (#40882) Desktop closes for expired relay authorization rose after the keepalive release (3/day to ~35/day on the edge cohort). The close metric now carries whether the control took the keepalive offer and how long the host had been silent, and control_active carries keepalive use, so the cause can be told apart (stalled desktop timers vs a control whose refresh stopped while it stayed live). --- cloud/apps/relay-edge/src/host-relay-handshake.ts | 2 +- cloud/apps/relay-edge/src/host-relay.ts | 3 ++- cloud/apps/relay-edge/src/metrics.ts | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cloud/apps/relay-edge/src/host-relay-handshake.ts b/cloud/apps/relay-edge/src/host-relay-handshake.ts index bc153be8a0c..22614a1fe85 100644 --- a/cloud/apps/relay-edge/src/host-relay-handshake.ts +++ b/cloud/apps/relay-edge/src/host-relay-handshake.ts @@ -191,7 +191,7 @@ export abstract class HostRelayHandshake extends HostRelayBase { }) // After the ack, which strict shipped parsers must see unchanged; only hosts that asked get it. if (a.clientKeepalive) { this.send(ws, { type: 'keepalive-offer', v: 1, intervalMs: this.config.pingIntervalMs }) } - metric(this.env, 'control_active', 1, rebind ? 'rebind' : 'new', [], '', a.place) + metric(this.env, 'control_active', 1, rebind ? 'rebind' : 'new', [], a.clientKeepalive ? 'keepalive' : 'legacy', a.place) await this.reschedule() } } diff --git a/cloud/apps/relay-edge/src/host-relay.ts b/cloud/apps/relay-edge/src/host-relay.ts index 958232f8ff4..14f5a0f544f 100644 --- a/cloud/apps/relay-edge/src/host-relay.ts +++ b/cloud/apps/relay-edge/src/host-relay.ts @@ -187,7 +187,8 @@ export class HostRelay extends HostRelayPhones { // Same order as the cells' heartbeat: expired auth past its grace, then the 6 h lease. if (now > a.claims.exp + CONTROL_CONTINUITY_LIMITS.expiredAuthExistingSpliceGraceMs) { const sinceRefreshS = a.lastRefreshAt === undefined ? -1 : Math.round((now - a.lastRefreshAt) / 1000) - metric(this.env, 'auth_expired_close', sinceRefreshS, a.lastRefreshAt === undefined ? 'never' : 'refreshed', [], '', a.place) + const seenAgoS = Math.round((now - seen) / 1000) + metric(this.env, 'auth_expired_close', sinceRefreshS, a.lastRefreshAt === undefined ? 'never' : 'refreshed', [seenAgoS], this.keepalive(a) ? 'keepalive' : 'legacy', a.place) this.close(ws, RELAY_CLOSE_CODE.BAD_OUTER_CREDENTIAL, 'relay authorization expired') await this.onSocketGone(ws, RELAY_CLOSE_CODE.BAD_OUTER_CREDENTIAL, '') continue diff --git a/cloud/apps/relay-edge/src/metrics.ts b/cloud/apps/relay-edge/src/metrics.ts index 7d87b759e4d..febc2bab77c 100644 --- a/cloud/apps/relay-edge/src/metrics.ts +++ b/cloud/apps/relay-edge/src/metrics.ts @@ -2,6 +2,7 @@ import type { Env } from './env' export type MetricEvent = + // label 'new' | 'rebind'; reason 'keepalive' | 'legacy' (took the keepalive offer or not). | 'control_active' | 'control_close' | 'phone_open' @@ -26,6 +27,7 @@ export type MetricEvent = | 'control_upgrade' // Control closed 4401 for expired authorization: value = seconds since its last extending // refresh, label 'refreshed'; -1 and label 'never' when this socket never extended its token. + // double2 = seconds since the host's last inbound frame or keepalive; reason 'keepalive' | 'legacy'. | 'auth_expired_close' // Pre-auth socket refused by the per-source limiter: label 'phone' | 'data' | 'health'. Unpushed-host phones: 'not_on_edge'. | 'preauth_limited'