pi-harness-runtime 1.1.482 → 1.1.483
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/CHANGELOG.md +60 -0
- package/harness/pending-actions.ts +408 -0
- package/harness/provider-failure.ts +344 -0
- package/harness/provider-recovery.ts +351 -0
- package/index.ts +363 -0
- package/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/dist/harness-footer.d.ts +10 -0
- package/packages/tui/dist/harness-footer.d.ts.map +1 -1
- package/packages/tui/dist/harness-footer.js +16 -1
- package/packages/tui/dist/harness-footer.js.map +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/tui/src/harness-footer.ts +18 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/write-review/package.json +1 -1
package/index.ts
CHANGED
|
@@ -55,6 +55,18 @@ import {
|
|
|
55
55
|
PendingQuestionCountdown,
|
|
56
56
|
type CountdownView,
|
|
57
57
|
} from "./harness/pending-countdown.ts";
|
|
58
|
+
import {
|
|
59
|
+
createPendingActionRegistry,
|
|
60
|
+
createPendingActionTicker,
|
|
61
|
+
} from "./harness/pending-actions.ts";
|
|
62
|
+
import { classifyProviderFailure } from "./harness/provider-failure.ts";
|
|
63
|
+
import type { ProviderFailure } from "./harness/provider-failure.ts";
|
|
64
|
+
import {
|
|
65
|
+
createProviderRecoveryController,
|
|
66
|
+
MAX_RECOVERY_ATTEMPTS,
|
|
67
|
+
type RecoveryResetEvidence,
|
|
68
|
+
} from "./harness/provider-recovery.ts";
|
|
69
|
+
import { HARNESS_ACTIONS_STATUS_KEY } from "./packages/tui/dist/harness-footer.js";
|
|
58
70
|
import { endPendingWait, releaseWait } from "./harness/pending-wait.ts";
|
|
59
71
|
import { isChannelDisabled, setChannelDisabled } from "./harness/notification-settings.ts";
|
|
60
72
|
import {
|
|
@@ -319,6 +331,102 @@ function keyFileFixesOrFallback(feature: string, labels: string[]): string[] {
|
|
|
319
331
|
return fallbackKeyFileFixes(feature, labels, harnessKeysDir());
|
|
320
332
|
}
|
|
321
333
|
|
|
334
|
+
/**
|
|
335
|
+
* The pending automatic actions of the session.
|
|
336
|
+
*
|
|
337
|
+
* The registry is the shared view of the automatic actions: every executor
|
|
338
|
+
* registers the deadline it scheduled, the rows are drawn from the
|
|
339
|
+
* registry, and nothing here dispatches an action. A row never claims a
|
|
340
|
+
* deadline that does not exist - an action without one shows its real state
|
|
341
|
+
* (queued, running, blocked).
|
|
342
|
+
*/
|
|
343
|
+
const pendingActions = createPendingActionRegistry();
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* The session of the Pi runtime. The pending actions belong to it.
|
|
347
|
+
*/
|
|
348
|
+
let activeSessionId = "";
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Publishes the rows of the pending actions in the footer.
|
|
352
|
+
*
|
|
353
|
+
* The rows go into their own status key, so the harness footer renders them
|
|
354
|
+
* on their own row: a blocked provider stays visible next to the other
|
|
355
|
+
* statuses.
|
|
356
|
+
*/
|
|
357
|
+
let setPendingActionsStatus: ((value: string | undefined) => void) | null = null;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* The ticker of the rows of the pending actions.
|
|
361
|
+
*
|
|
362
|
+
* The ticker draws the rows once per second while an action is pending and
|
|
363
|
+
* stops itself when there is nothing to draw. A tick never dispatches an
|
|
364
|
+
* action, never sends a message and never notifies a channel.
|
|
365
|
+
*/
|
|
366
|
+
const pendingActionTicker = createPendingActionTicker({
|
|
367
|
+
registry: pendingActions,
|
|
368
|
+
render: (rows) => {
|
|
369
|
+
setPendingActionsStatus?.(rows.join("\n"));
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
/** The identity of the pending action of the provider overload resume. */
|
|
374
|
+
const PROVIDER_OVERLOAD_ACTION_ID = "provider-overload-resume";
|
|
375
|
+
|
|
376
|
+
/** The identity of the pending action of the bounded provider recovery. */
|
|
377
|
+
const PROVIDER_RECOVERY_ACTION_ID = "provider-recovery";
|
|
378
|
+
|
|
379
|
+
/** The identity of the pending action of a provider that cannot be retried. */
|
|
380
|
+
const PROVIDER_BLOCKED_ACTION_ID = "provider-blocked";
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* The controller of the bounded recovery cycles.
|
|
384
|
+
*
|
|
385
|
+
* The controller decides the deadlines of the attempts; the executor that
|
|
386
|
+
* owns the resume stays the only owner of the execution.
|
|
387
|
+
*/
|
|
388
|
+
const providerRecovery = createProviderRecoveryController();
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* The timer of the pending recovery attempt.
|
|
392
|
+
*
|
|
393
|
+
* It is the executor of the attempt, so it owns the deadline it shows.
|
|
394
|
+
*/
|
|
395
|
+
let providerRecoveryTimer: ReturnType<typeof setTimeout> | null = null;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* The counter of the failures that carry no identity.
|
|
399
|
+
*
|
|
400
|
+
* A failure without a response id still needs its own identity, so a copy
|
|
401
|
+
* of it cannot be mistaken for a later attempt.
|
|
402
|
+
*/
|
|
403
|
+
let providerFailureCounter = 0;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Cancel a pending recovery attempt.
|
|
407
|
+
*
|
|
408
|
+
* The cycle ends with it: a cancelled attempt is not an attempt of the
|
|
409
|
+
* budget.
|
|
410
|
+
*/
|
|
411
|
+
function clearProviderRecoveryAttempt(): void {
|
|
412
|
+
if (providerRecoveryTimer) {
|
|
413
|
+
clearTimeout(providerRecoveryTimer);
|
|
414
|
+
providerRecoveryTimer = null;
|
|
415
|
+
}
|
|
416
|
+
pendingActions.remove(PROVIDER_RECOVERY_ACTION_ID);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* The identity of the pending action of the decision of the judge.
|
|
421
|
+
*
|
|
422
|
+
* The request is part of the identity: a question that replaces another one
|
|
423
|
+
* has its own row, and the row of the replaced question is not cleared by
|
|
424
|
+
* the stop of the new countdown.
|
|
425
|
+
*/
|
|
426
|
+
function jevDecisionActionId(requestId: string): string {
|
|
427
|
+
return `jev-decision:${requestId}`;
|
|
428
|
+
}
|
|
429
|
+
|
|
322
430
|
// Shared state for callback handlers (accessible across init functions)
|
|
323
431
|
const sharedState = {
|
|
324
432
|
/**
|
|
@@ -1185,6 +1293,19 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1185
1293
|
waitMinutes: MIN_WAIT_MINUTES,
|
|
1186
1294
|
render: (view: CountdownView) => {
|
|
1187
1295
|
_countdownRowRequestId = view.requestId;
|
|
1296
|
+
// The countdown owns the deadline of the decision, so the row
|
|
1297
|
+
// of the pending action shows the same deadline. The request
|
|
1298
|
+
// is part of the identity of the action: a question that
|
|
1299
|
+
// replaces another one has its own row.
|
|
1300
|
+
pendingActions.register({
|
|
1301
|
+
id: jevDecisionActionId(view.requestId),
|
|
1302
|
+
sessionId: _piSessionId,
|
|
1303
|
+
owner: "jev-decision",
|
|
1304
|
+
kind: "jev-decision",
|
|
1305
|
+
state: "scheduled",
|
|
1306
|
+
dueAt: Date.now() + view.remainingMs,
|
|
1307
|
+
reason: "the decision of the judge",
|
|
1308
|
+
});
|
|
1188
1309
|
updateAutoContinueStatus(
|
|
1189
1310
|
"WAITING",
|
|
1190
1311
|
view.requestId.slice(0, 8),
|
|
@@ -1234,6 +1355,9 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1234
1355
|
// of that countdown is cleared: a row of another state - the
|
|
1235
1356
|
// judge continues, for example - belongs to that state, and
|
|
1236
1357
|
// the row of a newer question belongs to that question.
|
|
1358
|
+
if (requestId) {
|
|
1359
|
+
pendingActions.remove(jevDecisionActionId(requestId));
|
|
1360
|
+
}
|
|
1237
1361
|
if (_countdownRowRequestId && requestId && _countdownRowRequestId !== requestId) {
|
|
1238
1362
|
return;
|
|
1239
1363
|
}
|
|
@@ -1370,9 +1494,18 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1370
1494
|
endWait("session-switched");
|
|
1371
1495
|
}
|
|
1372
1496
|
_piSessionId = sessionId;
|
|
1497
|
+
activeSessionId = sessionId;
|
|
1373
1498
|
}
|
|
1374
1499
|
if (ctx.hasUI && ctx.ui) {
|
|
1375
1500
|
_setAutoContinueStatus = ctx.ui.setStatus.bind(ctx.ui, "harness-auto-continue");
|
|
1501
|
+
// The pending actions of the session get their own row of the
|
|
1502
|
+
// footer: a blocked provider stays visible next to the other
|
|
1503
|
+
// statuses.
|
|
1504
|
+
setPendingActionsStatus = ctx.ui.setStatus.bind(
|
|
1505
|
+
ctx.ui,
|
|
1506
|
+
HARNESS_ACTIONS_STATUS_KEY,
|
|
1507
|
+
);
|
|
1508
|
+
pendingActionTicker.start();
|
|
1376
1509
|
// A session without a TUI collected the state already: it is
|
|
1377
1510
|
// shown as soon as the UI is there.
|
|
1378
1511
|
if (_currentAutoContinueState) {
|
|
@@ -1404,6 +1537,16 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1404
1537
|
}
|
|
1405
1538
|
_currentAutoContinueState = "";
|
|
1406
1539
|
|
|
1540
|
+
// The pending actions die with the session: a restart does not
|
|
1541
|
+
// inherit a countdown or a blocked provider.
|
|
1542
|
+
pendingActionTicker.stop();
|
|
1543
|
+
pendingActions.clear();
|
|
1544
|
+
providerRecovery.clear();
|
|
1545
|
+
clearProviderRecoveryAttempt();
|
|
1546
|
+
setPendingActionsStatus?.(undefined);
|
|
1547
|
+
setPendingActionsStatus = null;
|
|
1548
|
+
activeSessionId = "";
|
|
1549
|
+
|
|
1407
1550
|
// Reset state
|
|
1408
1551
|
_inferenceInProgress = false;
|
|
1409
1552
|
});
|
|
@@ -6159,6 +6302,8 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6159
6302
|
role?: string;
|
|
6160
6303
|
stopReason?: unknown;
|
|
6161
6304
|
errorMessage?: unknown;
|
|
6305
|
+
responseId?: string;
|
|
6306
|
+
provider?: string;
|
|
6162
6307
|
content?: unknown;
|
|
6163
6308
|
usage?: {
|
|
6164
6309
|
input?: number;
|
|
@@ -6169,6 +6314,52 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6169
6314
|
};
|
|
6170
6315
|
};
|
|
6171
6316
|
|
|
6317
|
+
// A provider failure is classified before anything else happens. The
|
|
6318
|
+
// classification reads the error of the turn; the text of an answer
|
|
6319
|
+
// is only read when it names a known provider failure, so a sentence
|
|
6320
|
+
// about an error is not a failure.
|
|
6321
|
+
const providerErrorText =
|
|
6322
|
+
typeof m.errorMessage === "string" ? m.errorMessage : "";
|
|
6323
|
+
const providerFailure = providerErrorText
|
|
6324
|
+
? classifyProviderFailure(providerErrorText)
|
|
6325
|
+
: (() => {
|
|
6326
|
+
const fromText = classifyProviderFailure(readMessageText(event.message));
|
|
6327
|
+
return fromText && fromText.kind !== "unknown" ? fromText : null;
|
|
6328
|
+
})();
|
|
6329
|
+
|
|
6330
|
+
if (providerFailure) {
|
|
6331
|
+
const recoverable =
|
|
6332
|
+
providerFailure.recovery === "bounded-recovery" ||
|
|
6333
|
+
providerFailure.recovery === "retry-after";
|
|
6334
|
+
if (recoverable) {
|
|
6335
|
+
// The bounded recovery cycle decides the deadline of the next
|
|
6336
|
+
// attempt. The identity of the failure keeps a repeated copy
|
|
6337
|
+
// of the same error from starting a second cycle.
|
|
6338
|
+
let failureKey =
|
|
6339
|
+
typeof m.responseId === "string" && m.responseId.length > 0
|
|
6340
|
+
? m.responseId
|
|
6341
|
+
: "";
|
|
6342
|
+
if (!failureKey) {
|
|
6343
|
+
providerFailureCounter += 1;
|
|
6344
|
+
failureKey = `${activeSessionId}:${providerFailureCounter}`;
|
|
6345
|
+
}
|
|
6346
|
+
scheduleProviderRecovery(providerFailure, failureKey);
|
|
6347
|
+
} else if (!providerFailure.retryable) {
|
|
6348
|
+
// No automatic retry can fix this failure: the row says that
|
|
6349
|
+
// nothing is scheduled.
|
|
6350
|
+
pendingActions.register({
|
|
6351
|
+
id: PROVIDER_BLOCKED_ACTION_ID,
|
|
6352
|
+
sessionId: activeSessionId,
|
|
6353
|
+
owner: "provider",
|
|
6354
|
+
kind: "retry",
|
|
6355
|
+
state: "blocked",
|
|
6356
|
+
...(providerFailure.provider ? { provider: providerFailure.provider } : {}),
|
|
6357
|
+
...(providerFailure.code ? { code: providerFailure.code } : {}),
|
|
6358
|
+
reason: providerFailure.reason,
|
|
6359
|
+
});
|
|
6360
|
+
}
|
|
6361
|
+
}
|
|
6362
|
+
|
|
6172
6363
|
if (
|
|
6173
6364
|
shouldQueueOutputLimitResume(
|
|
6174
6365
|
m,
|
|
@@ -6203,6 +6394,21 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6203
6394
|
}
|
|
6204
6395
|
providerOverloadResumeAttempts = 0;
|
|
6205
6396
|
clearProviderOverloadResume();
|
|
6397
|
+
// The turn completed: the provider works again. The recovery
|
|
6398
|
+
// cycle ends with it, so the next failure starts at the first
|
|
6399
|
+
// attempt, and a pending attempt of the cycle is cancelled.
|
|
6400
|
+
if (typeof m.provider === "string" && m.provider.length > 0) {
|
|
6401
|
+
providerRecovery.noteSuccess({
|
|
6402
|
+
sessionId: activeSessionId,
|
|
6403
|
+
provider: m.provider.toLowerCase(),
|
|
6404
|
+
});
|
|
6405
|
+
}
|
|
6406
|
+
clearProviderRecoveryAttempt();
|
|
6407
|
+
// The turn completed: a provider that was blocked is not blocked
|
|
6408
|
+
// any more. The row of the blocked provider leaves with it.
|
|
6409
|
+
pendingActions.removeWhere(
|
|
6410
|
+
(action) => action.owner === "provider" && action.state === "blocked",
|
|
6411
|
+
);
|
|
6206
6412
|
|
|
6207
6413
|
// --- Auto-Continue: Check todos and keep going -------------------------------
|
|
6208
6414
|
// If the agent stopped naturally AND the response mentions pending todos,
|
|
@@ -7633,6 +7839,146 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7633
7839
|
clearTimeout(providerOverloadResumeTimer);
|
|
7634
7840
|
providerOverloadResumeTimer = null;
|
|
7635
7841
|
}
|
|
7842
|
+
// The pending action goes with the timer: a cancelled resume has no
|
|
7843
|
+
// countdown any more.
|
|
7844
|
+
pendingActions.remove(PROVIDER_OVERLOAD_ACTION_ID);
|
|
7845
|
+
}
|
|
7846
|
+
|
|
7847
|
+
/**
|
|
7848
|
+
* The reset of the provider that applies to a failure.
|
|
7849
|
+
*
|
|
7850
|
+
* The reset only applies when it is fresh, when it belongs to the same
|
|
7851
|
+
* provider and to the same window as the failure, and when it lies in
|
|
7852
|
+
* the future. A failure that names no window has no window, so no reset
|
|
7853
|
+
* applies to it: the quota row is an observation, not a proof about the
|
|
7854
|
+
* limit that the provider reported.
|
|
7855
|
+
*/
|
|
7856
|
+
function applicableResetEvidence(
|
|
7857
|
+
failure: ProviderFailure,
|
|
7858
|
+
): RecoveryResetEvidence | undefined {
|
|
7859
|
+
if (!failure.window || !failure.provider) return undefined;
|
|
7860
|
+
const mirror = mirrorStore.readProvider(failure.provider.toLowerCase());
|
|
7861
|
+
if (!mirror) return undefined;
|
|
7862
|
+
if (mirrorStore.freshness(mirror, Date.now()) !== "fresh") return undefined;
|
|
7863
|
+
const resetAt =
|
|
7864
|
+
failure.window === "weekly"
|
|
7865
|
+
? mirror.weekly_resets_at_epoch
|
|
7866
|
+
: failure.window === "h5"
|
|
7867
|
+
? mirror.h5_resets_at_epoch
|
|
7868
|
+
: undefined;
|
|
7869
|
+
if (!resetAt || resetAt <= Date.now()) return undefined;
|
|
7870
|
+
const observedAt = Date.parse(mirror.synced_at);
|
|
7871
|
+
if (!Number.isFinite(observedAt)) return undefined;
|
|
7872
|
+
return {
|
|
7873
|
+
provider: failure.provider,
|
|
7874
|
+
window: failure.window,
|
|
7875
|
+
resetAt,
|
|
7876
|
+
observedAt,
|
|
7877
|
+
source: mirror.source,
|
|
7878
|
+
};
|
|
7879
|
+
}
|
|
7880
|
+
|
|
7881
|
+
/**
|
|
7882
|
+
* React to a provider failure that the bounded recovery may retry.
|
|
7883
|
+
*
|
|
7884
|
+
* The cycle decides the deadline of the attempt; the existing
|
|
7885
|
+
* auto-resume executor sends the resume, so there is no second resume
|
|
7886
|
+
* loop. The pending action shows the exact deadline the executor uses.
|
|
7887
|
+
*/
|
|
7888
|
+
function scheduleProviderRecovery(
|
|
7889
|
+
failure: ProviderFailure,
|
|
7890
|
+
failureKey: string,
|
|
7891
|
+
): void {
|
|
7892
|
+
const provider = failure.provider ?? "provider";
|
|
7893
|
+
const outcome = providerRecovery.noteFailure(
|
|
7894
|
+
{
|
|
7895
|
+
failureKey,
|
|
7896
|
+
sessionId: activeSessionId,
|
|
7897
|
+
// The cycle is keyed by the id of the provider, so a cycle of
|
|
7898
|
+
// "MiniMax" and a successful turn of "minimax" are the same
|
|
7899
|
+
// cycle.
|
|
7900
|
+
provider: provider.toLowerCase(),
|
|
7901
|
+
kind: failure.kind,
|
|
7902
|
+
...(failure.window ? { window: failure.window } : {}),
|
|
7903
|
+
...(failure.retryAfterMs !== undefined
|
|
7904
|
+
? { retryAfterAt: Date.now() + failure.retryAfterMs }
|
|
7905
|
+
: {}),
|
|
7906
|
+
},
|
|
7907
|
+
applicableResetEvidence(failure),
|
|
7908
|
+
);
|
|
7909
|
+
|
|
7910
|
+
if (outcome.outcome === "scheduled") {
|
|
7911
|
+
logToFile(
|
|
7912
|
+
"[pi-harness]",
|
|
7913
|
+
`Provider recovery attempt ${outcome.attempt}/${MAX_RECOVERY_ATTEMPTS} at ${new Date(outcome.dueAt).toISOString()} (bound=${outcome.boundBy})`,
|
|
7914
|
+
);
|
|
7915
|
+
startProviderRecoveryAttempt(outcome.dueAt, outcome.attempt, failure);
|
|
7916
|
+
return;
|
|
7917
|
+
}
|
|
7918
|
+
|
|
7919
|
+
if (outcome.outcome === "blocked") {
|
|
7920
|
+
logToFile(
|
|
7921
|
+
"[pi-harness]",
|
|
7922
|
+
`Provider recovery exhausted after ${outcome.attempt} attempts`,
|
|
7923
|
+
);
|
|
7924
|
+
pendingActions.register({
|
|
7925
|
+
id: PROVIDER_BLOCKED_ACTION_ID,
|
|
7926
|
+
sessionId: activeSessionId,
|
|
7927
|
+
owner: "provider",
|
|
7928
|
+
kind: "retry",
|
|
7929
|
+
state: "blocked",
|
|
7930
|
+
...(failure.provider ? { provider: failure.provider } : {}),
|
|
7931
|
+
...(failure.code ? { code: failure.code } : {}),
|
|
7932
|
+
reason: `recovery attempts exhausted (${outcome.attempt}/${MAX_RECOVERY_ATTEMPTS})`,
|
|
7933
|
+
});
|
|
7934
|
+
return;
|
|
7935
|
+
}
|
|
7936
|
+
|
|
7937
|
+
// "already-scheduled" and "duplicate": the cycle does not move. The
|
|
7938
|
+
// row of the pending attempt is already there.
|
|
7939
|
+
logToFile(
|
|
7940
|
+
"[pi-harness]",
|
|
7941
|
+
`Provider recovery unchanged (${outcome.outcome}), attempt ${outcome.attempt}`,
|
|
7942
|
+
);
|
|
7943
|
+
}
|
|
7944
|
+
|
|
7945
|
+
/**
|
|
7946
|
+
* Start the timer of a recovery attempt.
|
|
7947
|
+
*
|
|
7948
|
+
* The timer is the executor, so it owns the deadline: the row of the
|
|
7949
|
+
* pending action shows the deadline the timer really uses.
|
|
7950
|
+
*/
|
|
7951
|
+
function startProviderRecoveryAttempt(
|
|
7952
|
+
dueAt: number,
|
|
7953
|
+
attempt: number,
|
|
7954
|
+
failure: ProviderFailure,
|
|
7955
|
+
): void {
|
|
7956
|
+
clearProviderRecoveryAttempt();
|
|
7957
|
+
pendingActions.register({
|
|
7958
|
+
id: PROVIDER_RECOVERY_ACTION_ID,
|
|
7959
|
+
sessionId: activeSessionId,
|
|
7960
|
+
owner: "provider-recovery",
|
|
7961
|
+
kind: "retry",
|
|
7962
|
+
state: "scheduled",
|
|
7963
|
+
dueAt,
|
|
7964
|
+
attempt,
|
|
7965
|
+
maxAttempts: MAX_RECOVERY_ATTEMPTS,
|
|
7966
|
+
...(failure.provider ? { provider: failure.provider } : {}),
|
|
7967
|
+
...(failure.code ? { code: failure.code } : {}),
|
|
7968
|
+
reason: failure.reason,
|
|
7969
|
+
});
|
|
7970
|
+
const delayMs = Math.max(0, dueAt - Date.now());
|
|
7971
|
+
providerRecoveryTimer = setTimeout(() => {
|
|
7972
|
+
providerRecoveryTimer = null;
|
|
7973
|
+
// The row leaves when the attempt runs: a countdown must not stay
|
|
7974
|
+
// at 00:00.
|
|
7975
|
+
pendingActions.remove(PROVIDER_RECOVERY_ACTION_ID);
|
|
7976
|
+
void queueAutoResume(
|
|
7977
|
+
"provider-recovery",
|
|
7978
|
+
PROVIDER_OVERLOAD_RESUME_PROMPT,
|
|
7979
|
+
"followUp",
|
|
7980
|
+
);
|
|
7981
|
+
}, delayMs);
|
|
7636
7982
|
}
|
|
7637
7983
|
|
|
7638
7984
|
function scheduleProviderOverloadResume(
|
|
@@ -7645,8 +7991,25 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7645
7991
|
"[pi-harness]",
|
|
7646
7992
|
`Provider overloaded; scheduling resume in ${delayMinutes} min (${delayMs}ms) attempt=${providerOverloadResumeAttempts}`,
|
|
7647
7993
|
);
|
|
7994
|
+
// The timer is the executor of the resume, so the timer owns the
|
|
7995
|
+
// deadline: the row of the pending action shows the deadline the
|
|
7996
|
+
// timer really uses, never another one.
|
|
7997
|
+
const dueAt = Date.now() + delayMs;
|
|
7998
|
+
pendingActions.register({
|
|
7999
|
+
id: PROVIDER_OVERLOAD_ACTION_ID,
|
|
8000
|
+
sessionId: activeSessionId,
|
|
8001
|
+
owner: "provider-overload",
|
|
8002
|
+
kind: "retry",
|
|
8003
|
+
state: "scheduled",
|
|
8004
|
+
dueAt,
|
|
8005
|
+
attempt: providerOverloadResumeAttempts,
|
|
8006
|
+
reason: "the provider is overloaded",
|
|
8007
|
+
});
|
|
7648
8008
|
providerOverloadResumeTimer = setTimeout(() => {
|
|
7649
8009
|
providerOverloadResumeTimer = null;
|
|
8010
|
+
// The action leaves the row when it fires: the countdown must
|
|
8011
|
+
// not stay at 00:00.
|
|
8012
|
+
pendingActions.remove(PROVIDER_OVERLOAD_ACTION_ID);
|
|
7650
8013
|
logToFile("[pi-harness]", 'Provider resume timer fired, sending "resume"');
|
|
7651
8014
|
if (hasPendingMessages()) {
|
|
7652
8015
|
logToFile("[pi-harness]", "Resume skipped: hasPendingMessages=true");
|
package/package.json
CHANGED