pi-harness-runtime 1.1.485 → 1.1.486
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 +63 -0
- package/harness/provider-failure.ts +3 -0
- package/harness/provider-recovery-runtime.ts +480 -0
- package/index.ts +138 -231
- 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/dist/continuation-controller.d.ts +8 -0
- package/packages/jev-judge/dist/continuation-controller.d.ts.map +1 -1
- package/packages/jev-judge/dist/continuation-controller.js +10 -0
- package/packages/jev-judge/dist/continuation-controller.js.map +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/jev-judge/src/continuation-controller.ts +11 -0
- 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/package.json +1 -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
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
createPendingActionTicker,
|
|
61
61
|
} from "./harness/pending-actions.ts";
|
|
62
62
|
import { classifyProviderFailure, usesBoundedRecovery } from "./harness/provider-failure.ts";
|
|
63
|
+
import { ProviderRecoveryRuntime } from "./harness/provider-recovery-runtime.ts";
|
|
63
64
|
import type { ProviderFailure } from "./harness/provider-failure.ts";
|
|
64
65
|
import {
|
|
65
66
|
createProviderRecoveryController,
|
|
@@ -108,6 +109,7 @@ import { registerGithubLoginCommand } from "./packages/clipboard/dist/src/github
|
|
|
108
109
|
import {
|
|
109
110
|
MAX_PROACTIVE_COMPACT_FAILURES,
|
|
110
111
|
OUTPUT_LIMIT_RESUME_PROMPT,
|
|
112
|
+
PROVIDER_OVERLOAD_AUTO_RESUME_LIMIT,
|
|
111
113
|
PROVIDER_OVERLOAD_RESUME_PROMPT,
|
|
112
114
|
getProviderOverloadResumeDelayMs,
|
|
113
115
|
PROACTIVE_COMPACT_COOLDOWN_MS,
|
|
@@ -381,41 +383,47 @@ const PROVIDER_RECOVERY_ACTION_ID = "provider-recovery";
|
|
|
381
383
|
const PROVIDER_BLOCKED_ACTION_ID = "provider-blocked";
|
|
382
384
|
|
|
383
385
|
/**
|
|
384
|
-
* The
|
|
386
|
+
* The runtime of the automatic resumes after a provider failure.
|
|
385
387
|
*
|
|
386
|
-
* The
|
|
387
|
-
*
|
|
388
|
+
* The runtime owns the sequence of a failure: it waits for the settled
|
|
389
|
+
* boundary, and it checks that a scheduled resume still owns the session
|
|
390
|
+
* before it dispatches. The Jev scope uses it to cancel the pending
|
|
391
|
+
* resumes when the user pauses the work.
|
|
388
392
|
*/
|
|
389
|
-
|
|
393
|
+
let providerRecoveryRuntime: ProviderRecoveryRuntime | null = null;
|
|
390
394
|
|
|
391
395
|
/**
|
|
392
|
-
* The
|
|
396
|
+
* The continuation controller of the todos.
|
|
393
397
|
*
|
|
394
|
-
*
|
|
398
|
+
* The runtime reads the pause state of the user through this handle: the
|
|
399
|
+
* injected resume is a resume, and a resume that ignores a pause overrides
|
|
400
|
+
* the decision of the user.
|
|
395
401
|
*/
|
|
396
|
-
let
|
|
402
|
+
let todoContinuationHandle: { isExplicitlyPaused(): boolean } | null = null;
|
|
397
403
|
|
|
398
404
|
/**
|
|
399
|
-
* The
|
|
405
|
+
* The context of the running extension.
|
|
400
406
|
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
407
|
+
* The context knows whether messages wait in the queue. A resume that
|
|
408
|
+
* injects itself while the user is typing competes with the user.
|
|
403
409
|
*/
|
|
404
|
-
let
|
|
410
|
+
let activeExtensionContext: ExtensionContext | null = null;
|
|
405
411
|
|
|
406
412
|
/**
|
|
407
|
-
*
|
|
413
|
+
* The controller of the bounded recovery cycles.
|
|
408
414
|
*
|
|
409
|
-
* The
|
|
410
|
-
*
|
|
415
|
+
* The controller decides the deadlines of the attempts; the executor that
|
|
416
|
+
* owns the resume stays the only owner of the execution.
|
|
411
417
|
*/
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
418
|
+
const providerRecovery = createProviderRecoveryController();
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* The counter of the failures that carry no identity.
|
|
422
|
+
*
|
|
423
|
+
* A failure without a response id still needs its own identity, so a copy
|
|
424
|
+
* of it cannot be mistaken for a later attempt.
|
|
425
|
+
*/
|
|
426
|
+
let providerFailureCounter = 0;
|
|
419
427
|
|
|
420
428
|
/**
|
|
421
429
|
* The identity of the pending action of the decision of the judge.
|
|
@@ -1570,6 +1578,9 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1570
1578
|
|
|
1571
1579
|
// Capture UI context from session_start
|
|
1572
1580
|
pi.on("session_start", (_event, ctx) => {
|
|
1581
|
+
// The context of the running extension: a resume checks it
|
|
1582
|
+
// before it dispatches, so it does not compete with the user.
|
|
1583
|
+
activeExtensionContext = ctx;
|
|
1573
1584
|
// The session of the runtime: the countdown of a question belongs
|
|
1574
1585
|
// to the session that asked it.
|
|
1575
1586
|
const sessionId = (
|
|
@@ -1632,7 +1643,10 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1632
1643
|
pendingActionTicker.stop();
|
|
1633
1644
|
pendingActions.clear();
|
|
1634
1645
|
providerRecovery.clear();
|
|
1635
|
-
|
|
1646
|
+
// The pending resumes die with the session: a restart does not
|
|
1647
|
+
// inherit a countdown, a blocked provider, or a resume that would
|
|
1648
|
+
// inject itself into the new session.
|
|
1649
|
+
providerRecoveryRuntime?.reset();
|
|
1636
1650
|
setPendingActionsStatus?.(undefined);
|
|
1637
1651
|
setPendingActionsStatus = null;
|
|
1638
1652
|
activeSessionId = "";
|
|
@@ -1946,6 +1960,9 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1946
1960
|
// so nothing but an explicit resume directive clears
|
|
1947
1961
|
// it.
|
|
1948
1962
|
(sharedState.todoContinuationController as any)?.explicitPause?.();
|
|
1963
|
+
// The user took over: a pending resume of the provider
|
|
1964
|
+
// would inject itself against the decline.
|
|
1965
|
+
providerRecoveryRuntime?.cancel();
|
|
1949
1966
|
logToFile(
|
|
1950
1967
|
"[auto-continue]",
|
|
1951
1968
|
"The reply declined the proposal; the work is paused",
|
|
@@ -2471,6 +2488,9 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
2471
2488
|
validationLedger,
|
|
2472
2489
|
}
|
|
2473
2490
|
);
|
|
2491
|
+
// The runtime of the provider recovery reads the pause state
|
|
2492
|
+
// of the user through this handle.
|
|
2493
|
+
todoContinuationHandle = todoContinuationController;
|
|
2474
2494
|
logToFile("[auto-continue]", "Todo continuation controller initialized");
|
|
2475
2495
|
} catch (err) {
|
|
2476
2496
|
logToFile("[auto-continue]", "Failed to create todo continuation controller:", String(err));
|
|
@@ -2483,6 +2503,7 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
2483
2503
|
// keep a timer alive nor block a later continuation.
|
|
2484
2504
|
todoContinuationController?.dispose?.();
|
|
2485
2505
|
todoContinuationController = null;
|
|
2506
|
+
todoContinuationHandle = null;
|
|
2486
2507
|
sharedState.validationLedger = null;
|
|
2487
2508
|
});
|
|
2488
2509
|
|
|
@@ -2555,6 +2576,9 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
2555
2576
|
todoContinuationController.explicitPause();
|
|
2556
2577
|
logToFile("[auto-continue]", "Explicit pause/stop detected");
|
|
2557
2578
|
}
|
|
2579
|
+
// The user took over: a pending resume would inject
|
|
2580
|
+
// itself against the decision of the user.
|
|
2581
|
+
providerRecoveryRuntime?.cancel();
|
|
2558
2582
|
// Invalidate any pending Jev evaluations to prevent late dispatch
|
|
2559
2583
|
if (taskIntakeController) {
|
|
2560
2584
|
taskIntakeController.invalidatePending();
|
|
@@ -6379,7 +6403,61 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6379
6403
|
});
|
|
6380
6404
|
|
|
6381
6405
|
// --- Auto-track every assistant message ------------------------------
|
|
6406
|
+
// The runtime of the automatic resumes after a provider failure.
|
|
6407
|
+
//
|
|
6408
|
+
// The runtime owns the sequence of a failure: the failure waits for the
|
|
6409
|
+
// settled boundary, because Pi retries a failed turn internally first,
|
|
6410
|
+
// and a scheduled resume checks that it still owns the session before it
|
|
6411
|
+
// dispatches. The resume itself goes through the executor below, so
|
|
6412
|
+
// there is no second resume loop.
|
|
6413
|
+
providerRecoveryRuntime = new ProviderRecoveryRuntime({
|
|
6414
|
+
controller: providerRecovery,
|
|
6415
|
+
actions: pendingActions,
|
|
6416
|
+
recoveryActionId: PROVIDER_RECOVERY_ACTION_ID,
|
|
6417
|
+
blockedActionId: PROVIDER_BLOCKED_ACTION_ID,
|
|
6418
|
+
overloadActionId: PROVIDER_OVERLOAD_ACTION_ID,
|
|
6419
|
+
maxAttempts: MAX_RECOVERY_ATTEMPTS,
|
|
6420
|
+
context: () => ({
|
|
6421
|
+
sessionId: activeSessionId,
|
|
6422
|
+
explicitlyPaused: todoContinuationHandle?.isExplicitlyPaused() ?? false,
|
|
6423
|
+
questionPending:
|
|
6424
|
+
sharedState.pqController?.hasPendingQuestion?.() ?? false,
|
|
6425
|
+
}),
|
|
6426
|
+
resetEvidence: (failure) => applicableResetEvidence(failure),
|
|
6427
|
+
overloadDelayMs: () => getProviderOverloadResumeDelayMs(),
|
|
6428
|
+
overloadMaxAttempts: PROVIDER_OVERLOAD_AUTO_RESUME_LIMIT,
|
|
6429
|
+
dispatch: async (reason) => {
|
|
6430
|
+
// The user is typing: a resume that injects itself now competes
|
|
6431
|
+
// with the user.
|
|
6432
|
+
if (activeExtensionContext?.hasPendingMessages()) {
|
|
6433
|
+
logToFile("[pi-harness]", "Resume skipped: hasPendingMessages=true");
|
|
6434
|
+
return;
|
|
6435
|
+
}
|
|
6436
|
+
await queueAutoResume(reason, PROVIDER_OVERLOAD_RESUME_PROMPT, "followUp");
|
|
6437
|
+
},
|
|
6438
|
+
log: (message) => logToFile("[pi-harness]", message),
|
|
6439
|
+
});
|
|
6440
|
+
|
|
6441
|
+
// The run settled: the internal retries of Pi are over, so a failure
|
|
6442
|
+
// that waited for the boundary is final and the recovery starts now.
|
|
6443
|
+
//
|
|
6444
|
+
// An aborted run is a decision of the user, not a failure of the
|
|
6445
|
+
// provider: an automatic resume would fight the user.
|
|
6446
|
+
pi.on("agent_settled", (event) => {
|
|
6447
|
+
// The flag of the abort is optional: the installed core of Pi does
|
|
6448
|
+
// not carry it yet, a newer one does. The check reads it when it is
|
|
6449
|
+
// there, and it never assumes that it is.
|
|
6450
|
+
if ("aborted" in event && event.aborted === true) {
|
|
6451
|
+
providerRecoveryRuntime?.cancel();
|
|
6452
|
+
return;
|
|
6453
|
+
}
|
|
6454
|
+
providerRecoveryRuntime?.noteSettled();
|
|
6455
|
+
});
|
|
6456
|
+
|
|
6382
6457
|
pi.on("message_end", async (event, ctx) => {
|
|
6458
|
+
// The context of the running extension: the resume checks it before
|
|
6459
|
+
// it dispatches, so it does not compete with the user.
|
|
6460
|
+
activeExtensionContext = ctx;
|
|
6383
6461
|
if (isOutputLimitResumePromptMessage(event.message)) {
|
|
6384
6462
|
pendingOutputLimitResumeAfterSettled = false;
|
|
6385
6463
|
return;
|
|
@@ -6424,23 +6502,39 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6424
6502
|
})();
|
|
6425
6503
|
|
|
6426
6504
|
if (providerFailure) {
|
|
6427
|
-
// The
|
|
6428
|
-
//
|
|
6429
|
-
//
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6505
|
+
// The failure is a candidate: the recovery starts when the run
|
|
6506
|
+
// settles, because Pi retries a failed turn internally first.
|
|
6507
|
+
// A recovery that starts at the message of the failed attempt is
|
|
6508
|
+
// a competing continuation.
|
|
6509
|
+
let failureKey =
|
|
6510
|
+
typeof m.responseId === "string" && m.responseId.length > 0
|
|
6511
|
+
? m.responseId
|
|
6512
|
+
: "";
|
|
6513
|
+
if (!failureKey) {
|
|
6514
|
+
providerFailureCounter += 1;
|
|
6515
|
+
failureKey = `${activeSessionId}:${providerFailureCounter}`;
|
|
6516
|
+
}
|
|
6517
|
+
if (providerFailure.retryable) {
|
|
6518
|
+
// The identity of the failure keeps a repeated copy of the
|
|
6519
|
+
// same error from starting a second cycle.
|
|
6520
|
+
const overloadEligible =
|
|
6521
|
+
providerFailure.kind === "overload" &&
|
|
6522
|
+
!isProviderRetryFailedReport(readMessageText(event.message)) &&
|
|
6523
|
+
shouldQueueProviderOverloadResume(
|
|
6524
|
+
m,
|
|
6525
|
+
providerRecoveryRuntime?.overloadAttemptCount ?? 0,
|
|
6526
|
+
ctx.hasPendingMessages(),
|
|
6527
|
+
{ detected: true },
|
|
6528
|
+
);
|
|
6529
|
+
providerRecoveryRuntime?.noteFailure(providerFailure, failureKey, {
|
|
6530
|
+
...(typeof m.provider === "string" ? { provider: m.provider } : {}),
|
|
6531
|
+
overloadEligible,
|
|
6532
|
+
// The classification owns the policy: a rate limit and an
|
|
6533
|
+
// exhausted plan join the cycle, an overload keeps its own
|
|
6534
|
+
// executor. One failure has one executor.
|
|
6535
|
+
boundedEligible: usesBoundedRecovery(providerFailure),
|
|
6536
|
+
});
|
|
6537
|
+
} else {
|
|
6444
6538
|
// No automatic retry can fix this failure: the row says that
|
|
6445
6539
|
// nothing is scheduled.
|
|
6446
6540
|
pendingActions.register({
|
|
@@ -6476,46 +6570,16 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6476
6570
|
requirement: "Session output",
|
|
6477
6571
|
error: `Attempt ${outputLimitResumeAttempts}`,
|
|
6478
6572
|
});
|
|
6479
|
-
} else if (
|
|
6480
|
-
shouldQueueProviderOverloadResume(
|
|
6481
|
-
m,
|
|
6482
|
-
providerOverloadResumeAttempts,
|
|
6483
|
-
ctx.hasPendingMessages(),
|
|
6484
|
-
{
|
|
6485
|
-
// The classification may know an overload that the text
|
|
6486
|
-
// of the answer does not repeat. A report of exhausted
|
|
6487
|
-
// retries of the SDK is not a fresh failure.
|
|
6488
|
-
detected:
|
|
6489
|
-
providerFailure?.kind === "overload" &&
|
|
6490
|
-
!isProviderRetryFailedReport(readMessageText(event.message)),
|
|
6491
|
-
},
|
|
6492
|
-
)
|
|
6493
|
-
) {
|
|
6494
|
-
providerOverloadResumeAttempts += 1;
|
|
6495
|
-
logToFile("[pi-harness]", `Scheduling provider overload resume #${providerOverloadResumeAttempts}`);
|
|
6496
|
-
scheduleProviderOverloadResume(() => ctx.hasPendingMessages());
|
|
6497
6573
|
} else if (m.stopReason === "stop") {
|
|
6498
6574
|
outputLimitResumeAttempts = 0;
|
|
6499
6575
|
pendingOutputLimitResumeAfterSettled = false;
|
|
6500
|
-
if (providerOverloadResumeAttempts > 0) {
|
|
6501
|
-
logToFile("[pi-harness]", `Counter reset (stopReason=stop), was=${providerOverloadResumeAttempts}`);
|
|
6502
|
-
}
|
|
6503
|
-
providerOverloadResumeAttempts = 0;
|
|
6504
|
-
clearProviderOverloadResume();
|
|
6505
6576
|
// The turn completed: the provider works again. The recovery
|
|
6506
6577
|
// cycle ends with it, so the next failure starts at the first
|
|
6507
|
-
// attempt, and a pending attempt of the cycle is cancelled.
|
|
6508
|
-
|
|
6509
|
-
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
});
|
|
6513
|
-
}
|
|
6514
|
-
clearProviderRecoveryAttempt();
|
|
6515
|
-
// The turn completed: a provider that was blocked is not blocked
|
|
6516
|
-
// any more. The row of the blocked provider leaves with it.
|
|
6517
|
-
pendingActions.removeWhere(
|
|
6518
|
-
(action) => action.owner === "provider" && action.state === "blocked",
|
|
6578
|
+
// attempt, and a pending attempt of the cycle is cancelled. A
|
|
6579
|
+
// provider that was blocked is not blocked any more, and its row
|
|
6580
|
+
// leaves with it.
|
|
6581
|
+
providerRecoveryRuntime?.noteSuccess(
|
|
6582
|
+
typeof m.provider === "string" ? m.provider : undefined,
|
|
6519
6583
|
);
|
|
6520
6584
|
|
|
6521
6585
|
// --- Auto-Continue: Check todos and keep going -------------------------------
|
|
@@ -6737,8 +6801,6 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6737
6801
|
let outputLimitResumeAttempts = 0;
|
|
6738
6802
|
let pendingOutputLimitResumeAfterCompact = false;
|
|
6739
6803
|
let pendingOutputLimitResumeAfterSettled = false;
|
|
6740
|
-
let providerOverloadResumeAttempts = 0;
|
|
6741
|
-
let providerOverloadResumeTimer: ReturnType<typeof setTimeout> | null = null;
|
|
6742
6804
|
|
|
6743
6805
|
// --- Context-usage escalating warning tiers -----------------------------
|
|
6744
6806
|
// Amber at 75%, red at 85%. No notify above 90% (proactive compact handles it).
|
|
@@ -7951,16 +8013,6 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7951
8013
|
}
|
|
7952
8014
|
}, MINIMAX_REFRESH_MIN_INTERVAL_MS);
|
|
7953
8015
|
|
|
7954
|
-
function clearProviderOverloadResume(): void {
|
|
7955
|
-
if (providerOverloadResumeTimer) {
|
|
7956
|
-
clearTimeout(providerOverloadResumeTimer);
|
|
7957
|
-
providerOverloadResumeTimer = null;
|
|
7958
|
-
}
|
|
7959
|
-
// The pending action goes with the timer: a cancelled resume has no
|
|
7960
|
-
// countdown any more.
|
|
7961
|
-
pendingActions.remove(PROVIDER_OVERLOAD_ACTION_ID);
|
|
7962
|
-
}
|
|
7963
|
-
|
|
7964
8016
|
/**
|
|
7965
8017
|
* The reset of the provider that applies to a failure.
|
|
7966
8018
|
*
|
|
@@ -7995,151 +8047,6 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7995
8047
|
};
|
|
7996
8048
|
}
|
|
7997
8049
|
|
|
7998
|
-
/**
|
|
7999
|
-
* React to a provider failure that the bounded recovery may retry.
|
|
8000
|
-
*
|
|
8001
|
-
* The cycle decides the deadline of the attempt; the existing
|
|
8002
|
-
* auto-resume executor sends the resume, so there is no second resume
|
|
8003
|
-
* loop. The pending action shows the exact deadline the executor uses.
|
|
8004
|
-
*/
|
|
8005
|
-
function scheduleProviderRecovery(
|
|
8006
|
-
failure: ProviderFailure,
|
|
8007
|
-
failureKey: string,
|
|
8008
|
-
): void {
|
|
8009
|
-
const provider = failure.provider ?? "provider";
|
|
8010
|
-
const outcome = providerRecovery.noteFailure(
|
|
8011
|
-
{
|
|
8012
|
-
failureKey,
|
|
8013
|
-
sessionId: activeSessionId,
|
|
8014
|
-
// The cycle is keyed by the id of the provider, so a cycle of
|
|
8015
|
-
// "MiniMax" and a successful turn of "minimax" are the same
|
|
8016
|
-
// cycle.
|
|
8017
|
-
provider: provider.toLowerCase(),
|
|
8018
|
-
kind: failure.kind,
|
|
8019
|
-
...(failure.window ? { window: failure.window } : {}),
|
|
8020
|
-
...(failure.retryAfterMs !== undefined
|
|
8021
|
-
? { retryAfterAt: Date.now() + failure.retryAfterMs }
|
|
8022
|
-
: {}),
|
|
8023
|
-
},
|
|
8024
|
-
applicableResetEvidence(failure),
|
|
8025
|
-
);
|
|
8026
|
-
|
|
8027
|
-
if (outcome.outcome === "scheduled") {
|
|
8028
|
-
logToFile(
|
|
8029
|
-
"[pi-harness]",
|
|
8030
|
-
`Provider recovery attempt ${outcome.attempt}/${MAX_RECOVERY_ATTEMPTS} at ${new Date(outcome.dueAt).toISOString()} (bound=${outcome.boundBy})`,
|
|
8031
|
-
);
|
|
8032
|
-
startProviderRecoveryAttempt(outcome.dueAt, outcome.attempt, failure);
|
|
8033
|
-
return;
|
|
8034
|
-
}
|
|
8035
|
-
|
|
8036
|
-
if (outcome.outcome === "blocked") {
|
|
8037
|
-
logToFile(
|
|
8038
|
-
"[pi-harness]",
|
|
8039
|
-
`Provider recovery exhausted after ${outcome.attempt} attempts`,
|
|
8040
|
-
);
|
|
8041
|
-
pendingActions.register({
|
|
8042
|
-
id: PROVIDER_BLOCKED_ACTION_ID,
|
|
8043
|
-
sessionId: activeSessionId,
|
|
8044
|
-
owner: "provider",
|
|
8045
|
-
kind: "retry",
|
|
8046
|
-
state: "blocked",
|
|
8047
|
-
...(failure.provider ? { provider: failure.provider } : {}),
|
|
8048
|
-
...(failure.code ? { code: failure.code } : {}),
|
|
8049
|
-
reason: `recovery attempts exhausted (${outcome.attempt}/${MAX_RECOVERY_ATTEMPTS})`,
|
|
8050
|
-
});
|
|
8051
|
-
return;
|
|
8052
|
-
}
|
|
8053
|
-
|
|
8054
|
-
// "already-scheduled" and "duplicate": the cycle does not move. The
|
|
8055
|
-
// row of the pending attempt is already there.
|
|
8056
|
-
logToFile(
|
|
8057
|
-
"[pi-harness]",
|
|
8058
|
-
`Provider recovery unchanged (${outcome.outcome}), attempt ${outcome.attempt}`,
|
|
8059
|
-
);
|
|
8060
|
-
}
|
|
8061
|
-
|
|
8062
|
-
/**
|
|
8063
|
-
* Start the timer of a recovery attempt.
|
|
8064
|
-
*
|
|
8065
|
-
* The timer is the executor, so it owns the deadline: the row of the
|
|
8066
|
-
* pending action shows the deadline the timer really uses.
|
|
8067
|
-
*/
|
|
8068
|
-
function startProviderRecoveryAttempt(
|
|
8069
|
-
dueAt: number,
|
|
8070
|
-
attempt: number,
|
|
8071
|
-
failure: ProviderFailure,
|
|
8072
|
-
): void {
|
|
8073
|
-
clearProviderRecoveryAttempt();
|
|
8074
|
-
pendingActions.register({
|
|
8075
|
-
id: PROVIDER_RECOVERY_ACTION_ID,
|
|
8076
|
-
sessionId: activeSessionId,
|
|
8077
|
-
owner: "provider-recovery",
|
|
8078
|
-
kind: "retry",
|
|
8079
|
-
state: "scheduled",
|
|
8080
|
-
dueAt,
|
|
8081
|
-
attempt,
|
|
8082
|
-
maxAttempts: MAX_RECOVERY_ATTEMPTS,
|
|
8083
|
-
...(failure.provider ? { provider: failure.provider } : {}),
|
|
8084
|
-
...(failure.code ? { code: failure.code } : {}),
|
|
8085
|
-
reason: failure.reason,
|
|
8086
|
-
});
|
|
8087
|
-
const delayMs = Math.max(0, dueAt - Date.now());
|
|
8088
|
-
providerRecoveryTimer = setTimeout(() => {
|
|
8089
|
-
providerRecoveryTimer = null;
|
|
8090
|
-
// The row leaves when the attempt runs: a countdown must not stay
|
|
8091
|
-
// at 00:00.
|
|
8092
|
-
pendingActions.remove(PROVIDER_RECOVERY_ACTION_ID);
|
|
8093
|
-
void queueAutoResume(
|
|
8094
|
-
"provider-recovery",
|
|
8095
|
-
PROVIDER_OVERLOAD_RESUME_PROMPT,
|
|
8096
|
-
"followUp",
|
|
8097
|
-
);
|
|
8098
|
-
}, delayMs);
|
|
8099
|
-
}
|
|
8100
|
-
|
|
8101
|
-
function scheduleProviderOverloadResume(
|
|
8102
|
-
hasPendingMessages: () => boolean,
|
|
8103
|
-
): void {
|
|
8104
|
-
clearProviderOverloadResume();
|
|
8105
|
-
const delayMs = getProviderOverloadResumeDelayMs();
|
|
8106
|
-
const delayMinutes = Math.max(1, Math.round(delayMs / 60_000));
|
|
8107
|
-
logToFile(
|
|
8108
|
-
"[pi-harness]",
|
|
8109
|
-
`Provider overloaded; scheduling resume in ${delayMinutes} min (${delayMs}ms) attempt=${providerOverloadResumeAttempts}`,
|
|
8110
|
-
);
|
|
8111
|
-
// The timer is the executor of the resume, so the timer owns the
|
|
8112
|
-
// deadline: the row of the pending action shows the deadline the
|
|
8113
|
-
// timer really uses, never another one.
|
|
8114
|
-
const dueAt = Date.now() + delayMs;
|
|
8115
|
-
pendingActions.register({
|
|
8116
|
-
id: PROVIDER_OVERLOAD_ACTION_ID,
|
|
8117
|
-
sessionId: activeSessionId,
|
|
8118
|
-
owner: "provider-overload",
|
|
8119
|
-
kind: "retry",
|
|
8120
|
-
state: "scheduled",
|
|
8121
|
-
dueAt,
|
|
8122
|
-
attempt: providerOverloadResumeAttempts,
|
|
8123
|
-
reason: "the provider is overloaded",
|
|
8124
|
-
});
|
|
8125
|
-
providerOverloadResumeTimer = setTimeout(() => {
|
|
8126
|
-
providerOverloadResumeTimer = null;
|
|
8127
|
-
// The action leaves the row when it fires: the countdown must
|
|
8128
|
-
// not stay at 00:00.
|
|
8129
|
-
pendingActions.remove(PROVIDER_OVERLOAD_ACTION_ID);
|
|
8130
|
-
logToFile("[pi-harness]", 'Provider resume timer fired, sending "resume"');
|
|
8131
|
-
if (hasPendingMessages()) {
|
|
8132
|
-
logToFile("[pi-harness]", "Resume skipped: hasPendingMessages=true");
|
|
8133
|
-
return;
|
|
8134
|
-
}
|
|
8135
|
-
void queueAutoResume(
|
|
8136
|
-
"provider-overload",
|
|
8137
|
-
PROVIDER_OVERLOAD_RESUME_PROMPT,
|
|
8138
|
-
"followUp",
|
|
8139
|
-
);
|
|
8140
|
-
}, delayMs);
|
|
8141
|
-
}
|
|
8142
|
-
|
|
8143
8050
|
async function queueAutoResume(
|
|
8144
8051
|
reason: string,
|
|
8145
8052
|
content: string,
|
package/package.json
CHANGED
|
@@ -210,6 +210,14 @@ export declare class TodoContinuationController {
|
|
|
210
210
|
* User explicitly paused - only this clears on explicit resume
|
|
211
211
|
*/
|
|
212
212
|
explicitPause(): void;
|
|
213
|
+
/**
|
|
214
|
+
* Whether the user paused the work explicitly.
|
|
215
|
+
*
|
|
216
|
+
* Only an explicit resume clears the pause. The harness reads the state
|
|
217
|
+
* before it injects a resume: the injected message is a resume, and a
|
|
218
|
+
* resume that ignores a pause overrides the decision of the user.
|
|
219
|
+
*/
|
|
220
|
+
isExplicitlyPaused(): boolean;
|
|
213
221
|
/**
|
|
214
222
|
* Resume from explicit pause
|
|
215
223
|
*/
|