Skip to content

The agent that grows with you

test(desktop): accept-then-close proxy must not reset gateway reconnect backoff (#83134)

kshitijk4poor04a8c014d689
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
index 908f885f4cc..fbb6eec67f7 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
@@ -1378,6 +1378,35 @@ describe('useGatewayBoot remote reconnect loop (real hook, fake socket)', () =>
expect(FakeWebSocket.instances.length).toBeGreaterThan(1)
})
+ it('#83134: a proxy that accepts then immediately closes every socket does not reset the backoff to attempt 0', async () => {
+ render(<Harness />)
+ await flushAsync()
+ expect($gatewayState.get()).toBe('open')
+ expect(FakeWebSocket.instances).toHaveLength(1)
+
+ // Deterministic full jitter: every delay is exactly half its ceiling, so
+ // attempt 0 costs 150ms and the ladder is 150, 300, 600, 1200, 2400, ...
+ vi.spyOn(Math, 'random').mockReturnValue(0.5)
+
+ // 12s of a proxy that ACCEPTS the upgrade and closes on the first frame:
+ // every socket opens and is dropped ~100ms later, never a stable 5s open.
+ for (let elapsed = 0; elapsed < 12_000; elapsed += 100) {
+ const latest = FakeWebSocket.instances.at(-1)
+
+ if (latest?.readyState === FakeWebSocket.OPEN) {
+ act(() => latest.drop())
+ }
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(100)
+ })
+ }
+
+ // Attempt 0 forever redials every 150ms (~80 sockets / 12s — the reporter's
+ // 55 opens / 12s). A climbing ladder reaches the 15s cap in ~7 dials.
+ expect(FakeWebSocket.instances.length).toBeLessThanOrEqual(10)
+ })
+
it('FIX: a successful reconnect after a prolonged drop restores the open gateway', async () => {
render(<Harness />)
await flushAsync()