@azumag/opencode-rate-limit-fallback 1.0.18 → 1.0.19

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 +13 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -316,35 +316,28 @@ export const RateLimitFallback = async ({ client, directory }) => {
316
316
  parts: parts,
317
317
  model: { providerID: nextModel.providerID, modelID: nextModel.modelID },
318
318
  };
319
- // CRITICAL PATH: promptAsync BEFORE abort.
319
+ // abort promptAsync: works in TUI, fails in headless (server disposes)
320
+ // promptAsync → abort: fails in TUI (abort kills the new prompt too)
320
321
  //
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.
322
+ // Use abort promptAsync as the primary path (TUI confirmed working).
323
+ // Headless mode (opencode run) is a known limitation — the server
324
+ // dispose sequence interrupts the new prompt before it can complete.
331
325
  //
332
326
  // promptAsync: HTTP POST /session/{id}/prompt_async → 204 (SDK sdk.gen.js).
333
- // prompt (sync): blocks until generation completes — do NOT use.
334
327
  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();
341
328
  try {
342
329
  await client.session.abort({ path: { id: sessionID } });
343
- logToFile(`abort succeeded for session ${sessionID} (${Date.now() - t1}ms, total ${Date.now() - t0}ms)`);
330
+ logToFile(`abort succeeded for session ${sessionID} (${Date.now() - t0}ms)`);
344
331
  }
345
332
  catch (abortErr) {
346
- logToFile(`abort failed (${Date.now() - t1}ms): ${abortErr}`);
333
+ logToFile(`abort failed (${Date.now() - t0}ms): ${abortErr}`);
347
334
  }
335
+ const t1 = Date.now();
336
+ await client.session.promptAsync({
337
+ path: { id: sessionID },
338
+ body: promptBody,
339
+ });
340
+ logToFile(`promptAsync completed for session ${sessionID} (${Date.now() - t1}ms, total ${Date.now() - t0}ms) with model ${nextModel.providerID}/${nextModel.modelID}`);
348
341
  // Toast is best-effort notification. The toast() function (line ~185) has
349
342
  // built-in fallback: showToast failure → app.log. After promptAsync the
350
343
  // server may already be disposing, so both showToast and app.log could fail.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azumag/opencode-rate-limit-fallback",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "OpenCode plugin that automatically switches to fallback models when rate limited",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",