classifyProviderStall function
Classifies an error message into a ProviderStallEvent, or null when
the failure is NOT the stall family (transport drops, 5xx, rate limits,
auth — they belong to the existing ladders, E1's distinct policy
entries).
eventsSeen is how many SSE events the caller observed before the
failure: it splits the idle-watchdog wording into first-byte vs
mid-stream stall.
Implementation
ProviderStallEvent? classifyProviderStall(
String? errorMessage, {
int? eventsSeen,
}) {
if (errorMessage == null || errorMessage.isEmpty) return null;
if (errorMessage.contains(connectWatchdogTag)) {
return ProviderStallEvent(
kind: ProviderStallKind.connectStall,
message: errorMessage,
eventsSeen: null,
);
}
if (errorMessage.contains(idleStreamStallTag)) {
final seconds = _idleSecondsPattern.firstMatch(errorMessage)?.group(1);
return ProviderStallEvent(
kind: (eventsSeen ?? 0) > 0
? ProviderStallKind.midStreamIdleStall
: ProviderStallKind.firstByteStall,
message: errorMessage,
eventsSeen: eventsSeen,
idleSeconds: seconds == null ? null : int.tryParse(seconds),
);
}
return null;
}