@azumag/opencode-rate-limit-fallback 1.0.14 → 1.0.15

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 +9 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -316,7 +316,15 @@ export const RateLimitFallback = async ({ client, directory }) => {
316
316
  parts: parts,
317
317
  model: { providerID: nextModel.providerID, modelID: nextModel.modelID },
318
318
  };
319
- // Abort to cancel the retry loop
319
+ toast("Retrying", `Using ${nextModel.providerID}/${nextModel.modelID}`, "info").catch(() => { });
320
+ // Abort to cancel the retry loop, then promptAsync immediately.
321
+ // CRITICAL: no delay between abort and promptAsync.
322
+ // - In headless (opencode run), server disposes ~8ms after session idle.
323
+ // Any delay (even 50ms) means promptAsync arrives after server is dead.
324
+ // - promptAsync returns immediately (just queues), so it fires before
325
+ // the server can shut down.
326
+ // - Do NOT use prompt (sync) here — it causes abort flag race condition
327
+ // in TUI mode (prompt immediately interrupted).
320
328
  try {
321
329
  await client.session.abort({ path: { id: sessionID } });
322
330
  logToFile(`abort succeeded for session ${sessionID}`);
@@ -324,13 +332,6 @@ export const RateLimitFallback = async ({ client, directory }) => {
324
332
  catch (abortErr) {
325
333
  logToFile(`abort failed (non-critical): ${abortErr}`);
326
334
  }
327
- // Wait for abort to fully complete before sending new prompt.
328
- // Toast alone (~50ms) is insufficient — the abort flag may still be set,
329
- // causing the new prompt to be immediately interrupted.
330
- await new Promise(resolve => setTimeout(resolve, 500));
331
- toast("Retrying", `Using ${nextModel.providerID}/${nextModel.modelID}`, "info").catch(() => { });
332
- // Use promptAsync — returns immediately, compatible with both TUI and headless modes.
333
- // prompt (sync) causes race condition: abort flag not yet cleared → prompt interrupted.
334
335
  await client.session.promptAsync({
335
336
  path: { id: sessionID },
336
337
  body: promptBody,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azumag/opencode-rate-limit-fallback",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "OpenCode plugin that automatically switches to fallback models when rate limited",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",