fix: address Copilot review round 3 on #2318

- fetchTracking: the close report is guarded so a throwing listener
  cannot become an unhandled rejection off the discarded watcher; a
  bare CR that is the last byte of the stream terminates its event; a
  moving event count is coalesced to one report per interval (default
  250ms, 0 in tests), with the open and the close still immediate.
- MessageTrackingTransport rolls back a request whose signal was already
  aborted before the send began, and suppresses the rollback only for an
  abort that lands during the send.
- useTickingClock takes an `enabled` flag; Connection Info installs no
  interval when there is no activity section.
- The diagnostics-callbacks test justifies its private-seam cast.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01APKSYHGxXBUpnR7ErFiLJn
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-09-13 22:53:08 -04:00
commit ec09628705

View file

@ -30,10 +30,11 @@ export interface MessageTrackingCallbacks {
* `trackRequest` already recorded it, so a consumer keeping "requests still
* awaiting a response" can roll that entry back — a request that never went
* out is not unanswered (#2318). Not fired when the caller aborted the
* request through `requestSignal`: the modern transport aborts an in-flight
* request's own stream to cancel it (and the SDK does the same on a
* per-request timeout), and a request that was sent and then given up on
* is exactly the unanswered kind.
* request through `requestSignal` *during* the send: the modern transport
* aborts an in-flight request's own stream to cancel it (and the SDK does
* the same on a per-request timeout), and a request that was sent and then
* given up on is exactly the unanswered kind. A signal already aborted
* before the send began is a failed send like any other.
*/
trackSendFailure?: (message: JSONRPCRequest, error: unknown) => void;
}
@ -109,8 +110,13 @@ export class MessageTrackingTransport implements Transport {
} else if ("method" in message) {
const request = message as JSONRPCRequest;
this.callbacks.trackRequest?.(request, "client");
// A signal already aborted here means the frame will not go out at
// all — that is a failed send. One that becomes aborted while the
// send is in flight is a cancellation of a request that may well
// have reached the server, which stays unanswered.
const abortedBeforeSend = options?.requestSignal?.aborted === true;
return this.baseTransport.send(message, options).catch((err) => {
if (!options?.requestSignal?.aborted) {
if (abortedBeforeSend || !options?.requestSignal?.aborted) {
this.callbacks.trackSendFailure?.(request, err);
}
throw err;