Skip to content

Comments

fix(realtime): prevent telemetry 401s on reconnection#88

Draft
tomershlasky wants to merge 1 commit intomainfrom
fix/telemetry-401-on-reconnect
Draft

fix(realtime): prevent telemetry 401s on reconnection#88
tomershlasky wants to merge 1 commit intomainfrom
fix/telemetry-401-on-reconnect

Conversation

@tomershlasky
Copy link
Contributor

@tomershlasky tomershlasky commented Feb 22, 2026

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

  • All 129 unit tests pass (pnpm test)
  • Manual: connect → disconnect → reconnect with new key → no 401s in DevTools Network tab

Note

Low Risk
Behavior change is isolated to telemetry shutdown semantics; main risk is losing the last buffered telemetry batch on disconnect, which is non-critical.

Overview
Prevents realtime disconnect/reconnect flows from emitting a final telemetry fetch with a potentially stale API key by changing TelemetryReporter.stop() to clear buffers and never send a final keepalive report.

Updates unit tests to reflect the new contract: pre-session diagnostics are now discarded on disconnect, and stop() (and subsequent flush()) should not produce any network requests.

Written by Cursor Bugbot for commit 97ad940. This will update automatically on new commits. Configure here.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 22, 2026

Open in StackBlitz

npm i https://pkg.pr.new/DecartAI/sdk/@decartai/sdk@88

commit: 97ad940

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

}
this.sendReport(true);
this.statsBuffer = [];
this.diagnosticsBuffer = [];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendReport keepalive parameter is now dead code

Low Severity

The keepalive parameter of sendReport is now always false since stop() no longer calls sendReport(true) and flush() always passes false. This makes the keepalive parameter, the isLast computation on line 152, and the keepalive: keepalive && isLast expression dead code that could confuse future readers into thinking there's still a keepalive code path.

Fix in Cursor Fix in Web

@tomershlasky tomershlasky marked this pull request as draft February 22, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant