Skip to content

Commit 28fd4e8

Browse files
committed
docs: document request attempt budget helpers
1 parent dd2f672 commit 28fd4e8

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

lib/request/request-attempt-budget.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ const MAX_TOTAL_OUTBOUND_REQUEST_ATTEMPTS = 6;
22
const MAX_STREAM_FAILOVERS = 1;
33
const MAX_STREAM_FAILOVER_CANDIDATES = 2;
44

5+
/**
6+
* Clamp configured stream failover retries to the conservative runtime cap.
7+
*/
58
export 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+
*/
1220
export 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+
*/
5267
export function buildStreamFailoverCandidateOrder(
5368
primaryIndex: number,
5469
accountIndices: number[],

0 commit comments

Comments
 (0)