@monotykamary/pi-retry 0.3.3 → 0.3.4
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/package.json +1 -1
- package/retry.ts +14 -2
package/package.json
CHANGED
package/retry.ts
CHANGED
|
@@ -366,15 +366,27 @@ export default function (pi: ExtensionAPI) {
|
|
|
366
366
|
// Remove the error assistant message from the transcript so the LLM
|
|
367
367
|
// can retry from the same context. (The session's _prepareRetry does
|
|
368
368
|
// the same thing for built-in retries.)
|
|
369
|
+
//
|
|
370
|
+
// IMPORTANT: We must strip BEFORE calling prompt([]) — if prompt
|
|
371
|
+
// starts successfully, the LLM sees the context without the error
|
|
372
|
+
// and generates a fresh response. If prompt fails (swallowed by
|
|
373
|
+
// .catch()), we restore the message so the agent state stays
|
|
374
|
+
// consistent.
|
|
369
375
|
const messages = _agent.state.messages;
|
|
370
|
-
|
|
376
|
+
const hadErrorAssistant = messages.length > 0 && messages[messages.length - 1].role === "assistant";
|
|
377
|
+
if (hadErrorAssistant) {
|
|
371
378
|
_agent.state.messages = messages.slice(0, -1);
|
|
372
379
|
}
|
|
373
380
|
|
|
374
381
|
// Guard 4: .catch() swallows the "already processing" error as a
|
|
375
382
|
// last resort. agent.prompt() is async, so errors become rejected
|
|
376
383
|
// Promises — a try/catch around an un-awaited call catches nothing.
|
|
377
|
-
|
|
384
|
+
// If prompt failed, restore the stripped error message.
|
|
385
|
+
_agent.prompt([]).catch(() => {
|
|
386
|
+
if (hadErrorAssistant) {
|
|
387
|
+
_agent.state.messages = messages;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
378
390
|
} finally {
|
|
379
391
|
_continueInProgress = false;
|
|
380
392
|
}
|