@monotykamary/pi-retry 0.3.10 → 0.3.11

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/package.json +1 -1
  2. package/retry.ts +13 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monotykamary/pi-retry",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "description": "Extension suite for pi coding agent that handles 400/413 errors and connection errors with automatic retry",
5
5
  "type": "module",
6
6
  "author": "Tom X Nguyen",
package/retry.ts CHANGED
@@ -90,7 +90,9 @@ Agent.prototype.continue = function (this: Agent) {
90
90
  lastMsg.stopReason !== 'stop' &&
91
91
  lastMsg.stopReason !== 'aborted') {
92
92
  // Agent was mid-task (toolUse, length, or error) — fall back to prompt([])
93
- if (!_continueInProgress) {
93
+ // Guard: if triggerInvisibleContinue() just completed (within 500ms),
94
+ // the agent already continued — skip to avoid double continuation.
95
+ if (!_continueInProgress && Date.now() - _lastInvisibleContinueTime > 500) {
94
96
  _continueInProgress = true;
95
97
  try {
96
98
  await self.prompt([]);
@@ -127,6 +129,11 @@ const stateContinuation = new ContinuationState();
127
129
  // producing "Agent is already processing".
128
130
  let _continueInProgress = false;
129
131
 
132
+ // Timestamp of the last completed triggerInvisibleContinue().
133
+ // Used by the continue() monkey-patch to avoid double continuation when
134
+ // triggerInvisibleContinue just ran and the session's continue() unblocks.
135
+ let _lastInvisibleContinueTime = 0;
136
+
130
137
  // Sleep helper
131
138
  function sleep(ms: number): Promise<void> {
132
139
  return new Promise(resolve => setTimeout(resolve, ms));
@@ -361,6 +368,7 @@ export default function (pi: ExtensionAPI) {
361
368
  stateOther.reset();
362
369
  stateContinuation.reset();
363
370
  _continueInProgress = false;
371
+ _lastInvisibleContinueTime = 0;
364
372
  });
365
373
 
366
374
  // Resume the agent loop invisibly — no message injected into context.
@@ -395,6 +403,10 @@ export default function (pi: ExtensionAPI) {
395
403
  }
396
404
  } finally {
397
405
  _continueInProgress = false;
406
+ // Record completion time so the continue() monkey-patch can
407
+ // detect that an invisible continue just ran and avoid firing
408
+ // a duplicate prompt([]) (RC7: double continuation guard).
409
+ _lastInvisibleContinueTime = Date.now();
398
410
  }
399
411
  }
400
412
  }