Commit 7a8016b
fix(realtime): prevent telemetry 401s on reconnection (#88)
## Summary
- `TelemetryReporter.stop()` now discards buffered data instead of
sending a final `keepalive` report
- Prevents `401 Unauthorized` errors on `POST /api/v1/telemetry` when
reconnecting with a fresh API key while the old reporter's final fetch
fires with a stale key
## Changes
| File | Change |
|------|--------|
| `telemetry-reporter.ts` | `stop()` clears buffers instead of calling
`sendReport(true)` |
| `unit.test.ts` | Updated 2 tests to assert `stop()` does not make
network requests |
## Design Decision
Telemetry is non-critical — losing one final batch (up to 10s) on
disconnect is acceptable. The three `stop()` call sites in `client.ts`
remain unchanged; the new contract is strictly simpler (never makes a
network call).
## Test plan
- [x] All 129 unit tests pass (`pnpm test`)
- [ ] Manual: connect → disconnect → reconnect with new key → no 401s in
DevTools Network tab
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk: changes are limited to realtime telemetry shutdown behavior
and related tests, trading a small amount of final telemetry for
avoiding unwanted requests during disconnect/reconnect flows.
>
> **Overview**
> Prevents stale API keys from triggering `401 Unauthorized` telemetry
posts during disconnect/reconnect by changing `TelemetryReporter.stop()`
to **never send a final report** and instead clear buffered
stats/diagnostics.
>
> Simplifies the reporter send path by removing `keepalive` handling
(including from `flush()` calls), and updates unit tests to assert that
disconnect/`stop()` discards pre-session and buffered telemetry without
making any network requests.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
2a2877c. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Adir Amsalem <adir@decart.ai>1 parent 70a01a0 commit 7a8016b
2 files changed
Lines changed: 16 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | | - | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| |||
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
151 | | - | |
152 | | - | |
153 | 152 | | |
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
157 | | - | |
158 | | - | |
159 | 156 | | |
160 | 157 | | |
161 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1618 | 1618 | | |
1619 | 1619 | | |
1620 | 1620 | | |
1621 | | - | |
| 1621 | + | |
1622 | 1622 | | |
1623 | 1623 | | |
1624 | 1624 | | |
| |||
1683 | 1683 | | |
1684 | 1684 | | |
1685 | 1685 | | |
| 1686 | + | |
| 1687 | + | |
1686 | 1688 | | |
1687 | 1689 | | |
1688 | | - | |
1689 | | - | |
1690 | | - | |
1691 | | - | |
1692 | | - | |
1693 | | - | |
1694 | | - | |
1695 | | - | |
1696 | | - | |
| 1690 | + | |
1697 | 1691 | | |
1698 | 1692 | | |
1699 | 1693 | | |
| |||
2306 | 2300 | | |
2307 | 2301 | | |
2308 | 2302 | | |
2309 | | - | |
2310 | 2303 | | |
2311 | 2304 | | |
2312 | 2305 | | |
| |||
2351 | 2344 | | |
2352 | 2345 | | |
2353 | 2346 | | |
2354 | | - | |
| 2347 | + | |
2355 | 2348 | | |
2356 | 2349 | | |
2357 | 2350 | | |
| |||
2375 | 2368 | | |
2376 | 2369 | | |
2377 | 2370 | | |
2378 | | - | |
2379 | | - | |
2380 | | - | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
2381 | 2377 | | |
2382 | 2378 | | |
2383 | 2379 | | |
| |||
0 commit comments