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

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 +12 -21
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -324,27 +324,18 @@ export const RateLimitFallback = async ({ client, directory }) => {
324
324
  catch (abortErr) {
325
325
  logToFile(`abort failed (non-critical): ${abortErr}`);
326
326
  }
327
- // await toast AFTER abort provides natural delay (~50ms) for abort flag to clear
328
- // before prompting. Without this delay, the new prompt gets immediately aborted.
329
- await toast("Retrying", `Using ${nextModel.providerID}/${nextModel.modelID}`, "info");
330
- // Try prompt (sync) first reliably triggers generation in TUI mode.
331
- // If it fails (e.g. run mode where server shuts down after abort),
332
- // fall back to promptAsync which fires before server can exit.
333
- try {
334
- await client.session.prompt({
335
- path: { id: sessionID },
336
- body: promptBody,
337
- });
338
- logToFile(`prompt completed successfully for session ${sessionID} with model ${nextModel.providerID}/${nextModel.modelID}`);
339
- }
340
- catch (promptErr) {
341
- logToFile(`prompt failed (${promptErr}), falling back to promptAsync`);
342
- await client.session.promptAsync({
343
- path: { id: sessionID },
344
- body: promptBody,
345
- });
346
- logToFile(`promptAsync sent successfully for session ${sessionID} with model ${nextModel.providerID}/${nextModel.modelID}`);
347
- }
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
+ await client.session.promptAsync({
335
+ path: { id: sessionID },
336
+ body: promptBody,
337
+ });
338
+ logToFile(`promptAsync sent successfully for session ${sessionID} with model ${nextModel.providerID}/${nextModel.modelID}`);
348
339
  toast("Fallback Successful", `Now using ${nextModel.modelID}`, "success").catch(() => { });
349
340
  retryState.delete(stateKey);
350
341
  // 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.13",
3
+ "version": "1.0.14",
4
4
  "description": "OpenCode plugin that automatically switches to fallback models when rate limited",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",