@azumag/opencode-rate-limit-fallback 1.0.17 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +20 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -316,32 +316,35 @@ export const RateLimitFallback = async ({ client, directory }) => {
|
|
|
316
316
|
parts: parts,
|
|
317
317
|
model: { providerID: nextModel.providerID, modelID: nextModel.modelID },
|
|
318
318
|
};
|
|
319
|
-
// CRITICAL PATH:
|
|
319
|
+
// CRITICAL PATH: promptAsync BEFORE abort.
|
|
320
320
|
//
|
|
321
|
-
// In headless mode (opencode run),
|
|
322
|
-
//
|
|
323
|
-
// promptAsync
|
|
321
|
+
// In headless mode (opencode run), abort → promptAsync fails because:
|
|
322
|
+
// 1. abort triggers server dispose sequence
|
|
323
|
+
// 2. promptAsync is accepted and message created
|
|
324
|
+
// 3. Server starts processing (busy) but dispose interrupts it (idle)
|
|
325
|
+
// 4. server.instance.disposed — all within ~6ms
|
|
326
|
+
//
|
|
327
|
+
// By sending promptAsync FIRST, the server knows there is pending work
|
|
328
|
+
// before abort triggers the dispose check. When abort cancels the retry
|
|
329
|
+
// loop and the session goes idle, the server should process the queued
|
|
330
|
+
// prompt instead of disposing.
|
|
324
331
|
//
|
|
325
332
|
// promptAsync: HTTP POST /session/{id}/prompt_async → 204 (SDK sdk.gen.js).
|
|
326
|
-
// prompt (sync): blocks until generation completes
|
|
327
|
-
// server dispose in headless. Do NOT use.
|
|
333
|
+
// prompt (sync): blocks until generation completes — do NOT use.
|
|
328
334
|
const t0 = Date.now();
|
|
335
|
+
await client.session.promptAsync({
|
|
336
|
+
path: { id: sessionID },
|
|
337
|
+
body: promptBody,
|
|
338
|
+
});
|
|
339
|
+
logToFile(`promptAsync completed for session ${sessionID} (${Date.now() - t0}ms) with model ${nextModel.providerID}/${nextModel.modelID}`);
|
|
340
|
+
const t1 = Date.now();
|
|
329
341
|
try {
|
|
330
342
|
await client.session.abort({ path: { id: sessionID } });
|
|
331
|
-
logToFile(`abort succeeded for session ${sessionID} (${Date.now() - t0}ms)`);
|
|
343
|
+
logToFile(`abort succeeded for session ${sessionID} (${Date.now() - t1}ms, total ${Date.now() - t0}ms)`);
|
|
332
344
|
}
|
|
333
345
|
catch (abortErr) {
|
|
334
|
-
|
|
335
|
-
// We still send promptAsync as best-effort: when the retry loop eventually
|
|
336
|
-
// completes (timeout or success), the queued prompt should be processed.
|
|
337
|
-
logToFile(`abort failed (${Date.now() - t0}ms): ${abortErr} — sending promptAsync as best-effort`);
|
|
346
|
+
logToFile(`abort failed (${Date.now() - t1}ms): ${abortErr}`);
|
|
338
347
|
}
|
|
339
|
-
const t1 = Date.now();
|
|
340
|
-
await client.session.promptAsync({
|
|
341
|
-
path: { id: sessionID },
|
|
342
|
-
body: promptBody,
|
|
343
|
-
});
|
|
344
|
-
logToFile(`promptAsync completed for session ${sessionID} (${Date.now() - t1}ms, total ${Date.now() - t0}ms) with model ${nextModel.providerID}/${nextModel.modelID}`);
|
|
345
348
|
// Toast is best-effort notification. The toast() function (line ~185) has
|
|
346
349
|
// built-in fallback: showToast failure → app.log. After promptAsync the
|
|
347
350
|
// server may already be disposing, so both showToast and app.log could fail.
|
package/package.json
CHANGED