File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,13 +2,21 @@ const MAX_TOTAL_OUTBOUND_REQUEST_ATTEMPTS = 6;
22const MAX_STREAM_FAILOVERS = 1 ;
33const MAX_STREAM_FAILOVER_CANDIDATES = 2 ;
44
5+ /**
6+ * Clamp configured stream failover retries to the conservative runtime cap.
7+ */
58export function capStreamFailoverMax ( value : number ) : number {
69 return Math . max (
710 0 ,
811 Math . min ( MAX_STREAM_FAILOVERS , Math . floor ( Number . isFinite ( value ) ? value : 0 ) ) ,
912 ) ;
1013}
1114
15+ /**
16+ * Compute a finite per-request budget that bounds all outbound Responses API
17+ * fetches across account rotation, same-account retries, empty-response
18+ * retries, and stream failover.
19+ */
1220export function computeOutboundRequestAttemptBudget ( params : {
1321 accountCount : number ;
1422 maxSameAccountRetries : number ;
@@ -49,6 +57,13 @@ export function computeOutboundRequestAttemptBudget(params: {
4957 ) ;
5058}
5159
60+ /**
61+ * Build the ordered stream-failover candidate list for a request.
62+ *
63+ * The caller is expected to pass a valid primary account index from the
64+ * current account snapshot. This helper keeps the primary first and adds at
65+ * most one alternate account to avoid broad replay fan-out.
66+ */
5267export function buildStreamFailoverCandidateOrder (
5368 primaryIndex : number ,
5469 accountIndices : number [ ] ,
You can’t perform that action at this time.
0 commit comments