From a997e35162f9879f3603579936da952bd373dbcc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 12:00:05 +0000 Subject: [PATCH] Add JSDoc clarification for callback snapshot behavior Co-authored-by: Sunwuyuan <88357633+Sunwuyuan@users.noreply.github.com> --- src/utils/serverRotation.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/serverRotation.js b/src/utils/serverRotation.js index 90a181e..ee0c286 100644 --- a/src/utils/serverRotation.js +++ b/src/utils/serverRotation.js @@ -32,6 +32,7 @@ export function getServerList(provider) { * @param {Object} options - Options * @param {string} options.provider - Provider type (optional, defaults to current setting) * @param {Function} options.onServerTried - Callback called when a server is tried (optional) + * Receives: { url, status, tried } where tried is a snapshot of attempts * @returns {Promise} Result from the first successful server, or throws the last error */ export async function tryWithRotation(operation, options = {}) { @@ -47,6 +48,7 @@ export async function tryWithRotation(operation, options = {}) { try { triedServers.push({ url: serverUrl, status: "trying" }); if (hasCallback) { + // Provide a snapshot to prevent callback from mutating internal state onServerTried({ url: serverUrl, status: "trying", tried: [...triedServers] }); }