@azumag/opencode-rate-limit-fallback 1.0.16 → 1.0.17

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.
Files changed (2) hide show
  1. package/dist/index.js +15 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -318,33 +318,34 @@ export const RateLimitFallback = async ({ client, directory }) => {
318
318
  };
319
319
  // CRITICAL PATH: abort → promptAsync with NO delay between them.
320
320
  //
321
- // In headless mode (opencode run), the server disposes within milliseconds
322
- // after session goes idle (observed ~8ms in production logs this is not
323
- // a guaranteed bound, just empirically observed). Any delay (setTimeout,
324
- // awaited toast, etc.) means promptAsync arrives after the server is dead.
321
+ // In headless mode (opencode run), the server disposes shortly after
322
+ // session goes idle. Any delay (setTimeout, awaited toast, etc.) risks
323
+ // promptAsync arriving after the server is dead.
325
324
  //
326
- // The await on promptAsync waits for the HTTP round-trip (server acknowledgment),
327
- // NOT for prompt completion generation runs asynchronously on the server.
328
- //
329
- // Do NOT use prompt() (sync) here — it triggers the abort flag race condition
330
- // in TUI mode, causing the new prompt to be immediately interrupted.
325
+ // promptAsync: HTTP POST /session/{id}/prompt_async 204 (SDK sdk.gen.js).
326
+ // prompt (sync): blocks until generation completes abort flag race in TUI,
327
+ // server dispose in headless. Do NOT use.
328
+ const t0 = Date.now();
331
329
  try {
332
330
  await client.session.abort({ path: { id: sessionID } });
333
- logToFile(`abort succeeded for session ${sessionID}`);
331
+ logToFile(`abort succeeded for session ${sessionID} (${Date.now() - t0}ms)`);
334
332
  }
335
333
  catch (abortErr) {
336
334
  // If abort fails, the session may still be in its retry loop.
337
335
  // We still send promptAsync as best-effort: when the retry loop eventually
338
336
  // completes (timeout or success), the queued prompt should be processed.
339
- logToFile(`abort failed: ${abortErr} — sending promptAsync as best-effort`);
337
+ logToFile(`abort failed (${Date.now() - t0}ms): ${abortErr} — sending promptAsync as best-effort`);
340
338
  }
339
+ const t1 = Date.now();
341
340
  await client.session.promptAsync({
342
341
  path: { id: sessionID },
343
342
  body: promptBody,
344
343
  });
345
- logToFile(`promptAsync sent for session ${sessionID} with model ${nextModel.providerID}/${nextModel.modelID}`);
346
- // Toasts are fire-and-forget: placed AFTER the critical path so they cannot
347
- // interfere with the abortpromptAsync timing, even if they fail in headless.
344
+ logToFile(`promptAsync completed for session ${sessionID} (${Date.now() - t1}ms, total ${Date.now() - t0}ms) with model ${nextModel.providerID}/${nextModel.modelID}`);
345
+ // Toast is best-effort notification. The toast() function (line ~185) has
346
+ // built-in fallback: showToast failure app.log. After promptAsync the
347
+ // server may already be disposing, so both showToast and app.log could fail.
348
+ // The outer .catch() ensures even total toast() failure never blocks or throws.
348
349
  toast("Fallback Active", `Now using ${nextModel.modelID}`, "success").catch(() => { });
349
350
  retryState.delete(stateKey);
350
351
  // Clear fallback flag to allow next fallback if needed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azumag/opencode-rate-limit-fallback",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "OpenCode plugin that automatically switches to fallback models when rate limited",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",