pi-harness-runtime 1.1.486 → 1.1.487
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 +64 -0
- package/harness/pi-retry-policy.ts +142 -0
- package/harness/pi-retry-visibility.ts +8 -0
- package/harness/provider-recovery-runtime.ts +30 -0
- package/index.ts +73 -7
- 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/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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,70 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.1.487](https://github.com/ManotLuijiu/pi-harness-runtime/compare/v1.1.448...v1.1.487) (2026-11-09)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **actions:** register the job resume, the GLM countdown and the queued continuations ([177c964](https://github.com/ManotLuijiu/pi-harness-runtime/commit/177c964555b0057e6bc7d293dafab10c95eabbf9))
|
|
11
|
+
* **delegation:** a child is only a child when it really ran ([ac4e678](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ac4e6782d7d4bc4941e458425c8a9f38a51fc9d4))
|
|
12
|
+
* **delegation:** the scope of a request is measured before it is judged ([684b6a5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/684b6a55184f63d3be24c48dcecfb0b13410dc15))
|
|
13
|
+
* **honcho:** the memory service speaks the native MCP of Pi ([f9f740c](https://github.com/ManotLuijiu/pi-harness-runtime/commit/f9f740c12869bae4c4380afbe8c76e12388bb744))
|
|
14
|
+
* **jev:** one decision per question, bound to the question it was evaluated for ([03448aa](https://github.com/ManotLuijiu/pi-harness-runtime/commit/03448aaa17f2d0c3bcf644b0b1d5949727dfff8c))
|
|
15
|
+
* **jev:** the evaluation of a choice sees what the options mean ([f0c207e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/f0c207e074701e6b7dab0965170ec39453d9d502))
|
|
16
|
+
* **jev:** the pending question carries the ask and the answer ([a792133](https://github.com/ManotLuijiu/pi-harness-runtime/commit/a792133e517fb8c12d3363e98942f3af30270f27))
|
|
17
|
+
* **jev:** the pending question counts down to the decision ([d0cc171](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d0cc171223986b2d32c670b6c1c74712fe0a4ad8))
|
|
18
|
+
* **keys:** tell the user what to do about an exposed key file ([7031003](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7031003574307351b7a8f28ee14159b58e17b793))
|
|
19
|
+
* **keys:** the key files are repaired when their permissions are unsafe ([e9c2c26](https://github.com/ManotLuijiu/pi-harness-runtime/commit/e9c2c26b287665b56ed749de269737e8403bb8af))
|
|
20
|
+
* **mcp:** the harness connects the registered servers when nobody else does ([7fef951](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7fef95137ad4664df57f045cd91b7d233315b0bc))
|
|
21
|
+
* **merge:** a manual run can leave the merge to the pull request event ([b3d1950](https://github.com/ManotLuijiu/pi-harness-runtime/commit/b3d1950b5941c78ccd56951acdafd1d4afbe1bff))
|
|
22
|
+
* **phase:** the agent owns the todo list and the harness says so ([c489370](https://github.com/ManotLuijiu/pi-harness-runtime/commit/c489370bd7926aece8cb1a77aa20ca2d2672f1fb))
|
|
23
|
+
* **providers:** a shared registry of the pending automatic actions and a bounded recovery ([c5f955b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/c5f955bc82adcb6999a89d5bc278fa87fccee022))
|
|
24
|
+
* **providers:** one failure has one executor, and the retry bridge is checked ([e73c4c7](https://github.com/ManotLuijiu/pi-harness-runtime/commit/e73c4c76ff20a9708083659bdcefe74870a84837))
|
|
25
|
+
* **review:** the review starts on its own when the implementation is done ([04f51f5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/04f51f599cd3222b6c74dd8fadb1373bd72d9bd7))
|
|
26
|
+
* **status:** the status line names the phase, the progress and the children ([0167bf3](https://github.com/ManotLuijiu/pi-harness-runtime/commit/0167bf396a0b987c1d44f3b869351976a951dd65))
|
|
27
|
+
* **test:** the task waits for the final tier of the validation plan ([fa147db](https://github.com/ManotLuijiu/pi-harness-runtime/commit/fa147dbf7d50d56e6ea48c6d8fbb4fcb190caf8a))
|
|
28
|
+
* **validation:** a large job starts with a measured pilot ([425964b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/425964b04a3d4fa02adfabed47ff62c5ec2b9c28))
|
|
29
|
+
* **validation:** the size of a job is a fact, not a phrase ([8aa6c11](https://github.com/ManotLuijiu/pi-harness-runtime/commit/8aa6c119565d0f8412dc8aeafa6b295d47d3f093))
|
|
30
|
+
* **workspace:** a Frappe bench names the mode of the workspace ([9d58517](https://github.com/ManotLuijiu/pi-harness-runtime/commit/9d585172063a330992fee933316e268ae9985e3c))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* **ci:** every run of a required check counts, and the worst one decides ([da9e0da](https://github.com/ManotLuijiu/pi-harness-runtime/commit/da9e0da6b0ca29cb320764fd5fc1b8a8dee8b1e0))
|
|
36
|
+
* **ci:** the newest attempt of a run decides, not the attempt that failed ([9d7adcc](https://github.com/ManotLuijiu/pi-harness-runtime/commit/9d7adcc31cbacc517c3c1a9bcd3956be94c908ef))
|
|
37
|
+
* **honcho:** a probe that the end of the session cuts off is not a failure ([493fd93](https://github.com/ManotLuijiu/pi-harness-runtime/commit/493fd938ba09fdcf57bed4aaf259d81c4040909e))
|
|
38
|
+
* **honcho:** a tools listing that the end of the session cuts off is not a failure ([62cc8c3](https://github.com/ManotLuijiu/pi-harness-runtime/commit/62cc8c376aade01c953ce2a1c6501ed07b74a1e9))
|
|
39
|
+
* **honcho:** the report names the state of the MCP server, not the registration ([762f4d5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/762f4d59e4eabcab9a1c21a61aa522c3267621b3))
|
|
40
|
+
* **hooks:** a tag is checked through the commit behind it ([c823e8e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/c823e8e1f6973c62b5449a97c101759a4d5cbba5))
|
|
41
|
+
* **jev:** a prohibition must not hide a destructive action ([78a6cc1](https://github.com/ManotLuijiu/pi-harness-runtime/commit/78a6cc199e647f812e145483f7e94991358d8f34))
|
|
42
|
+
* **jev:** a refusal without punctuation, and only a decline of an action ([ef3dbf8](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ef3dbf87a2a1725373281613a0d48881ed5d2239))
|
|
43
|
+
* **jev:** a rejection during the countdown pauses the work ([9b018ce](https://github.com/ManotLuijiu/pi-harness-runtime/commit/9b018ce1152b6724dee73cdc901b8a360ecc91ab))
|
|
44
|
+
* **jev:** a session switch ends the wait of the old session ([ca03d39](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ca03d399c0d4a1b2dd428ac39836ab53c0e51ab6))
|
|
45
|
+
* **jev:** keep a comparative caveat with the option it constrains ([7be306b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7be306b0d0872713ebca9386d613ae5a8da9d5b6))
|
|
46
|
+
* **jev:** the action of the question on its own text, and a reply is not an authorization ([7c3fdd6](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7c3fdd6822b58bd6ccfa3bcdf1c5282cb3db52dd))
|
|
47
|
+
* **jev:** the action of the question, and an open question blocks the work ([1f9ff39](https://github.com/ManotLuijiu/pi-harness-runtime/commit/1f9ff39efc4ee17464c54c2ca9b583245093dbac))
|
|
48
|
+
* **jev:** the alternatives of a question are parsed without a quadratic pattern ([63016a3](https://github.com/ManotLuijiu/pi-harness-runtime/commit/63016a3f0488acb801990dd46770c00d382b5858))
|
|
49
|
+
* **jev:** the facts of an option survive the wording of the agent ([5a6250c](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5a6250c07aa8d965bc6ae242cccbf519477598f8))
|
|
50
|
+
* **keys:** the key directory is audited as a tree ([081cc75](https://github.com/ManotLuijiu/pi-harness-runtime/commit/081cc75ac8ceff36b0d619c3f76371dc08459d3c))
|
|
51
|
+
* **mcp:** the connector and the watcher stop with the session ([4d1b87d](https://github.com/ManotLuijiu/pi-harness-runtime/commit/4d1b87d14d015749025b62bf54d6d0b6137295f7))
|
|
52
|
+
* **mcp:** the connector survives a runtime that cannot list the servers ([d0f555f](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d0f555fa14f51de33591e572a41ded5b59a3e4dd))
|
|
53
|
+
* **merge:** the boolean input is read as a boolean ([971b716](https://github.com/ManotLuijiu/pi-harness-runtime/commit/971b7169a43db382dbdeb6bb9bab02ab56e0351c))
|
|
54
|
+
* **merge:** the manual job needs the right of the merge ([7ba685e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7ba685ec43d815f90aa35b742579e87e76c69209))
|
|
55
|
+
* **merge:** the merge of the pull request is the GraphQL mutation ([972bab4](https://github.com/ManotLuijiu/pi-harness-runtime/commit/972bab4b0f7faf1b0047f3bb767ef6db3de4b2fa))
|
|
56
|
+
* **merge:** the workflow merges the pull request the gates cleared ([d7639ec](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d7639ec9b83723510acb4a5c4e23d5d6167c3af6))
|
|
57
|
+
* **providers:** the escape of the user stops the recovery, and a permanent failure clears it ([cfe5797](https://github.com/ManotLuijiu/pi-harness-runtime/commit/cfe57976bf463c327e45b874fd297c3e942246b8))
|
|
58
|
+
* **providers:** the pause wins over a retry, and the retry starts when the run settles ([e016dd2](https://github.com/ManotLuijiu/pi-harness-runtime/commit/e016dd2a5add5b0f3c848a225a28a59e0f5fc7f3))
|
|
59
|
+
* **release:** a manual release keeps the version of its manifest ([122e661](https://github.com/ManotLuijiu/pi-harness-runtime/commit/122e661ea48cb8aff14c71dbd0221a4cf0ba4c8e))
|
|
60
|
+
* **release:** the alignment names the reason of a failure ([5814dd0](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5814dd0b780f5839cf8011ed0cbbbb31e7eb0418))
|
|
61
|
+
* **release:** the channels of the package name the release ([a7a273f](https://github.com/ManotLuijiu/pi-harness-runtime/commit/a7a273ffe8398e2b5b07ef1c321777de41792c6e))
|
|
62
|
+
* **release:** the release publishes and leaves the channels alone ([5871746](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5871746589c1281d855dbeb591b02419fa43f22e))
|
|
63
|
+
* **release:** the release pull request names the version of its branch ([a846e83](https://github.com/ManotLuijiu/pi-harness-runtime/commit/a846e83e6de6e529f4bca05e869db0b5eebb37c5))
|
|
64
|
+
* **release:** the release scans the tree of the commit it publishes ([7d47a0b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7d47a0b5406480a1e1d3a52623a76aabd1e2d0ba))
|
|
65
|
+
* **workspace:** a strong bench signal decides, and the question is not a fact of an option ([303a828](https://github.com/ManotLuijiu/pi-harness-runtime/commit/303a828f55aa7c4e0a611231f482489b530ff5a3))
|
|
66
|
+
* **workspace:** keep a client name out of the comment about the search depth ([b572e0a](https://github.com/ManotLuijiu/pi-harness-runtime/commit/b572e0af16ff562203bda2b5c47b41807cff5a95))
|
|
67
|
+
* **workspace:** the repository names the mode before the mode stays unknown ([188a32c](https://github.com/ManotLuijiu/pi-harness-runtime/commit/188a32c7a6af1465dd24714278fccc73d06f6477))
|
|
68
|
+
|
|
5
69
|
### [1.1.486](https://github.com/ManotLuijiu/pi-harness-runtime/compare/v1.1.448...v1.1.486) (2026-11-09)
|
|
6
70
|
|
|
7
71
|
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Pi itself does with a failed turn.
|
|
3
|
+
*
|
|
4
|
+
* The installed core of Pi retries a failed turn internally before the
|
|
5
|
+
* session settles. The extension API of Pi does not report that retry:
|
|
6
|
+
* `auto_retry_start` and `auto_retry_end` are session events, and the
|
|
7
|
+
* whitelist that forwards the events to the extensions does not name them
|
|
8
|
+
* (see `harness/pi-retry-visibility.ts`).
|
|
9
|
+
*
|
|
10
|
+
* The harness therefore infers the retry from the facts it can observe:
|
|
11
|
+
*
|
|
12
|
+
* - the settings of Pi decide whether the retry exists at all,
|
|
13
|
+
* - the kind of the failure decides whether the retry applies to it,
|
|
14
|
+
* - a retry attempt produces another failed message in the same run.
|
|
15
|
+
*
|
|
16
|
+
* The inference exists for one decision only: a retry delay that the user
|
|
17
|
+
* cancelled (Escape) must not leave an automatic resume behind. The
|
|
18
|
+
* harness cannot observe the cancellation directly, so it observes the
|
|
19
|
+
* consequence: Pi announced a retry and never made the attempt.
|
|
20
|
+
*/
|
|
21
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
22
|
+
import { homedir } from "node:os";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The retry settings of Pi.
|
|
27
|
+
*
|
|
28
|
+
* The names and the defaults are the ones of the installed core
|
|
29
|
+
* (`settings.retry`): the retry is on, it makes three attempts, and the
|
|
30
|
+
* first delay is two seconds.
|
|
31
|
+
*/
|
|
32
|
+
export interface PiRetrySettings {
|
|
33
|
+
/** Whether Pi retries a failed turn at all. */
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
/** How many attempts Pi makes after the first one. */
|
|
36
|
+
maxRetries: number;
|
|
37
|
+
/** The delay of the first attempt, doubled for every attempt. */
|
|
38
|
+
baseDelayMs: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The defaults of the installed core.
|
|
43
|
+
*/
|
|
44
|
+
export const DEFAULT_PI_RETRY_SETTINGS: PiRetrySettings = {
|
|
45
|
+
enabled: true,
|
|
46
|
+
maxRetries: 3,
|
|
47
|
+
baseDelayMs: 2000,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The kinds of failure that Pi retries itself.
|
|
52
|
+
*
|
|
53
|
+
* The transient patterns of the core name a rate limit, an overload, a
|
|
54
|
+
* server error, and a transport failure. An exhausted plan and a
|
|
55
|
+
* credential failure are not among them: the core gives up on them at
|
|
56
|
+
* once, so there is no retry delay that a user could cancel.
|
|
57
|
+
*/
|
|
58
|
+
export function piRetriesFailure(kind: string): boolean {
|
|
59
|
+
return kind === "rate-limit" || kind === "overload";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether Pi would retry this failure.
|
|
64
|
+
*
|
|
65
|
+
* A failure that Pi does not retry has no retry delay, so a cancellation
|
|
66
|
+
* of that delay is impossible and the harness must not read one into it.
|
|
67
|
+
*/
|
|
68
|
+
export function expectsPiRetry(
|
|
69
|
+
failure: { kind: string },
|
|
70
|
+
settings: PiRetrySettings,
|
|
71
|
+
): boolean {
|
|
72
|
+
return settings.enabled && piRetriesFailure(failure.kind);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Read the retry settings of the installed Pi.
|
|
77
|
+
*
|
|
78
|
+
* The settings of Pi live in the settings of the agent (`settings.json`)
|
|
79
|
+
* and in the settings of the project (`<cwd>/.pi/settings.json`). The
|
|
80
|
+
* project overrides the agent. A file that is missing or unreadable
|
|
81
|
+
* leaves the default of the core in place: the retry of Pi is on unless
|
|
82
|
+
* the user turns it off.
|
|
83
|
+
*/
|
|
84
|
+
export function readPiRetrySettings(options?: {
|
|
85
|
+
cwd?: string;
|
|
86
|
+
agentDir?: string;
|
|
87
|
+
readFile?: (path: string) => string | undefined;
|
|
88
|
+
}): PiRetrySettings {
|
|
89
|
+
const read =
|
|
90
|
+
options?.readFile ??
|
|
91
|
+
((path: string): string | undefined => {
|
|
92
|
+
try {
|
|
93
|
+
if (!existsSync(path)) return undefined;
|
|
94
|
+
return readFileSync(path, "utf8");
|
|
95
|
+
} catch {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const home = process.env.HOME || process.env.USERPROFILE || homedir();
|
|
101
|
+
// The core of Pi reads the agent directory from this variable, so the
|
|
102
|
+
// harness reads the same settings file as the core.
|
|
103
|
+
const agentDir =
|
|
104
|
+
options?.agentDir ??
|
|
105
|
+
process.env.PI_CODING_AGENT_DIR ??
|
|
106
|
+
join(home, ".pi", "agent");
|
|
107
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
108
|
+
|
|
109
|
+
const global = readSettings(read(join(agentDir, "settings.json")));
|
|
110
|
+
const project = readSettings(read(join(cwd, ".pi", "settings.json")));
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
enabled: project?.retry?.enabled ?? global?.retry?.enabled ?? DEFAULT_PI_RETRY_SETTINGS.enabled,
|
|
114
|
+
maxRetries:
|
|
115
|
+
project?.retry?.maxRetries ?? global?.retry?.maxRetries ?? DEFAULT_PI_RETRY_SETTINGS.maxRetries,
|
|
116
|
+
baseDelayMs:
|
|
117
|
+
project?.retry?.baseDelayMs ??
|
|
118
|
+
global?.retry?.baseDelayMs ??
|
|
119
|
+
DEFAULT_PI_RETRY_SETTINGS.baseDelayMs,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface RetrySettingsFile {
|
|
124
|
+
retry?: {
|
|
125
|
+
enabled?: boolean;
|
|
126
|
+
maxRetries?: number;
|
|
127
|
+
baseDelayMs?: number;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Read the retry part of a settings file. A broken file is no file.
|
|
133
|
+
*/
|
|
134
|
+
function readSettings(text: string | undefined): RetrySettingsFile | undefined {
|
|
135
|
+
if (!text) return undefined;
|
|
136
|
+
try {
|
|
137
|
+
const parsed = JSON.parse(text) as RetrySettingsFile;
|
|
138
|
+
return parsed && typeof parsed === "object" ? parsed : undefined;
|
|
139
|
+
} catch {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -11,6 +11,14 @@
|
|
|
11
11
|
* countdown of the internal retry of Pi. Its own bounded recovery is
|
|
12
12
|
* *additional* to that retry, never a replacement for it.
|
|
13
13
|
*
|
|
14
|
+
* Two signals of the installed core do report the cancellation of the
|
|
15
|
+
* user, and the harness uses them: the abort signal of the run
|
|
16
|
+
* (`ctx.signal`) and the stop reason of an aborted turn
|
|
17
|
+
* (`stopReason === "aborted"`). The delay of the retry of Pi produces
|
|
18
|
+
* neither of them, so the harness infers that delay from the settings of
|
|
19
|
+
* Pi, from the kind of the failure, and from the attempts that Pi made
|
|
20
|
+
* (see `harness/pi-retry-policy.ts`).
|
|
21
|
+
*
|
|
14
22
|
* This module reads the declarations of the installed core, so the finding
|
|
15
23
|
* stays a checked fact instead of a belief. A newer core that exposes the
|
|
16
24
|
* events changes the verdict, and the harness can wire the bridge.
|
|
@@ -104,6 +104,22 @@ export interface ProviderFailureCandidate {
|
|
|
104
104
|
* failure joins neither.
|
|
105
105
|
*/
|
|
106
106
|
boundedEligible: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Whether Pi would retry this failure itself.
|
|
109
|
+
*
|
|
110
|
+
* A failure that Pi retries has a retry delay, and the user can cancel
|
|
111
|
+
* that delay. A failure that Pi does not retry has no delay, so no
|
|
112
|
+
* cancellation can be read into it.
|
|
113
|
+
*/
|
|
114
|
+
piRetryExpected: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Whether Pi made an internal retry attempt after this failure.
|
|
117
|
+
*
|
|
118
|
+
* A retry attempt produces another failed message in the same run, so
|
|
119
|
+
* the harness counts the attempts. When Pi would retry and never did,
|
|
120
|
+
* the delay was cancelled.
|
|
121
|
+
*/
|
|
122
|
+
piRetryAttempted: boolean;
|
|
107
123
|
}
|
|
108
124
|
|
|
109
125
|
/**
|
|
@@ -183,6 +199,8 @@ export class ProviderRecoveryRuntime {
|
|
|
183
199
|
provider?: string;
|
|
184
200
|
overloadEligible?: boolean;
|
|
185
201
|
boundedEligible?: boolean;
|
|
202
|
+
piRetryExpected?: boolean;
|
|
203
|
+
piRetryAttempted?: boolean;
|
|
186
204
|
} = {},
|
|
187
205
|
): void {
|
|
188
206
|
this.candidate = {
|
|
@@ -191,6 +209,8 @@ export class ProviderRecoveryRuntime {
|
|
|
191
209
|
provider: (options.provider ?? failure.provider ?? "provider").toLowerCase(),
|
|
192
210
|
overloadEligible: options.overloadEligible === true,
|
|
193
211
|
boundedEligible: options.boundedEligible === true,
|
|
212
|
+
piRetryExpected: options.piRetryExpected === true,
|
|
213
|
+
piRetryAttempted: options.piRetryAttempted === true,
|
|
194
214
|
};
|
|
195
215
|
}
|
|
196
216
|
|
|
@@ -205,6 +225,16 @@ export class ProviderRecoveryRuntime {
|
|
|
205
225
|
this.candidate = null;
|
|
206
226
|
if (!candidate) return;
|
|
207
227
|
|
|
228
|
+
if (candidate.piRetryExpected && !candidate.piRetryAttempted) {
|
|
229
|
+
// Pi would retry this failure and never made the attempt: the
|
|
230
|
+
// delay of the retry was cancelled, and the user decided that.
|
|
231
|
+
// An automatic resume would fight that decision.
|
|
232
|
+
this.log(
|
|
233
|
+
`Pi's internal retry was cancelled: no recovery for ${candidate.failure.kind}`,
|
|
234
|
+
);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
208
238
|
if (candidate.overloadEligible) {
|
|
209
239
|
this.startOverloadResume();
|
|
210
240
|
return;
|
package/index.ts
CHANGED
|
@@ -60,6 +60,10 @@ import {
|
|
|
60
60
|
createPendingActionTicker,
|
|
61
61
|
} from "./harness/pending-actions.ts";
|
|
62
62
|
import { classifyProviderFailure, usesBoundedRecovery } from "./harness/provider-failure.ts";
|
|
63
|
+
import {
|
|
64
|
+
expectsPiRetry,
|
|
65
|
+
readPiRetrySettings,
|
|
66
|
+
} from "./harness/pi-retry-policy.ts";
|
|
63
67
|
import { ProviderRecoveryRuntime } from "./harness/provider-recovery-runtime.ts";
|
|
64
68
|
import type { ProviderFailure } from "./harness/provider-failure.ts";
|
|
65
69
|
import {
|
|
@@ -425,6 +429,25 @@ const providerRecovery = createProviderRecoveryController();
|
|
|
425
429
|
*/
|
|
426
430
|
let providerFailureCounter = 0;
|
|
427
431
|
|
|
432
|
+
/**
|
|
433
|
+
* The number of provider failures of the current run.
|
|
434
|
+
*
|
|
435
|
+
* Pi retries a failed turn internally. Every attempt of that retry
|
|
436
|
+
* produces another failed message, so the counter tells the harness
|
|
437
|
+
* whether Pi made a retry attempt after the failure that it holds.
|
|
438
|
+
*/
|
|
439
|
+
let providerFailureAttemptsInRun = 0;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* The abort signal of the run that is going.
|
|
443
|
+
*
|
|
444
|
+
* The signal of the context is the signal of the active run. The user
|
|
445
|
+
* aborts a run with Escape, and the aborted signal is the way the harness
|
|
446
|
+
* learns about it: the installed core does not carry an abort flag on the
|
|
447
|
+
* settled event.
|
|
448
|
+
*/
|
|
449
|
+
let activeRunAbortSignal: AbortSignal | undefined;
|
|
450
|
+
|
|
428
451
|
/**
|
|
429
452
|
* The identity of the pending action of the decision of the judge.
|
|
430
453
|
*
|
|
@@ -6440,24 +6463,37 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6440
6463
|
|
|
6441
6464
|
// The run settled: the internal retries of Pi are over, so a failure
|
|
6442
6465
|
// 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
6466
|
pi.on("agent_settled", (event) => {
|
|
6447
|
-
//
|
|
6448
|
-
//
|
|
6449
|
-
//
|
|
6450
|
-
|
|
6467
|
+
// An aborted run is a decision of the user, not a failure of the
|
|
6468
|
+
// provider: an automatic resume would fight the user.
|
|
6469
|
+
//
|
|
6470
|
+
// The installed core of Pi does not carry an abort flag on this
|
|
6471
|
+
// event. The signal of the run is the way the harness learns about
|
|
6472
|
+
// it: the signal belongs to the run that is going, and Escape
|
|
6473
|
+
// aborts it. The optional flag of a newer core is read when it is
|
|
6474
|
+
// there, and it is never assumed.
|
|
6475
|
+
const abortedRun =
|
|
6476
|
+
("aborted" in event && event.aborted === true) ||
|
|
6477
|
+
activeRunAbortSignal?.aborted === true;
|
|
6478
|
+
activeRunAbortSignal = undefined;
|
|
6479
|
+
if (abortedRun) {
|
|
6451
6480
|
providerRecoveryRuntime?.cancel();
|
|
6481
|
+
providerFailureAttemptsInRun = 0;
|
|
6452
6482
|
return;
|
|
6453
6483
|
}
|
|
6454
6484
|
providerRecoveryRuntime?.noteSettled();
|
|
6485
|
+
// The run is over: the streak of its failures ends with it, so the
|
|
6486
|
+
// next run starts its own count.
|
|
6487
|
+
providerFailureAttemptsInRun = 0;
|
|
6455
6488
|
});
|
|
6456
6489
|
|
|
6457
6490
|
pi.on("message_end", async (event, ctx) => {
|
|
6458
6491
|
// The context of the running extension: the resume checks it before
|
|
6459
6492
|
// it dispatches, so it does not compete with the user.
|
|
6460
6493
|
activeExtensionContext = ctx;
|
|
6494
|
+
// The signal of the run that is going: the user aborts a run with
|
|
6495
|
+
// Escape, and the signal is the way the harness learns about it.
|
|
6496
|
+
activeRunAbortSignal = ctx.signal ?? activeRunAbortSignal;
|
|
6461
6497
|
if (isOutputLimitResumePromptMessage(event.message)) {
|
|
6462
6498
|
pendingOutputLimitResumeAfterSettled = false;
|
|
6463
6499
|
return;
|
|
@@ -6488,6 +6524,15 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6488
6524
|
};
|
|
6489
6525
|
};
|
|
6490
6526
|
|
|
6527
|
+
// An aborted turn is a decision of the user, not a failure of the
|
|
6528
|
+
// provider. The candidate of an earlier failure dies with it: an
|
|
6529
|
+
// automatic resume would fight the decision of the user.
|
|
6530
|
+
if (m.stopReason === "aborted" || ctx.signal?.aborted === true) {
|
|
6531
|
+
providerRecoveryRuntime?.cancel();
|
|
6532
|
+
providerFailureAttemptsInRun = 0;
|
|
6533
|
+
return;
|
|
6534
|
+
}
|
|
6535
|
+
|
|
6491
6536
|
// A provider failure is classified before anything else happens. The
|
|
6492
6537
|
// classification reads the error of the turn; the text of an answer
|
|
6493
6538
|
// is only read when it names a known provider failure, so a sentence
|
|
@@ -6506,6 +6551,7 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6506
6551
|
// settles, because Pi retries a failed turn internally first.
|
|
6507
6552
|
// A recovery that starts at the message of the failed attempt is
|
|
6508
6553
|
// a competing continuation.
|
|
6554
|
+
providerFailureAttemptsInRun += 1;
|
|
6509
6555
|
let failureKey =
|
|
6510
6556
|
typeof m.responseId === "string" && m.responseId.length > 0
|
|
6511
6557
|
? m.responseId
|
|
@@ -6533,10 +6579,25 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6533
6579
|
// exhausted plan join the cycle, an overload keeps its own
|
|
6534
6580
|
// executor. One failure has one executor.
|
|
6535
6581
|
boundedEligible: usesBoundedRecovery(providerFailure),
|
|
6582
|
+
// Whether Pi would retry this failure itself, and whether
|
|
6583
|
+
// it made the attempt. A retry that Pi announces and never
|
|
6584
|
+
// makes was cancelled by the user.
|
|
6585
|
+
piRetryExpected: expectsPiRetry(
|
|
6586
|
+
providerFailure,
|
|
6587
|
+
readPiRetrySettings({ cwd: ctx.cwd }),
|
|
6588
|
+
),
|
|
6589
|
+
piRetryAttempted: providerFailureAttemptsInRun > 1,
|
|
6536
6590
|
});
|
|
6537
6591
|
} else {
|
|
6538
6592
|
// No automatic retry can fix this failure: the row says that
|
|
6539
6593
|
// nothing is scheduled.
|
|
6594
|
+
//
|
|
6595
|
+
// A permanent failure also supersedes the retry of an
|
|
6596
|
+
// earlier failure of the same run: a rate limit that was
|
|
6597
|
+
// followed by a credential error must not schedule a resume
|
|
6598
|
+
// when the run settles.
|
|
6599
|
+
providerRecoveryRuntime?.cancelPending();
|
|
6600
|
+
providerFailureAttemptsInRun = 0;
|
|
6540
6601
|
pendingActions.register({
|
|
6541
6602
|
id: PROVIDER_BLOCKED_ACTION_ID,
|
|
6542
6603
|
sessionId: activeSessionId,
|
|
@@ -6548,6 +6609,11 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6548
6609
|
reason: providerFailure.reason,
|
|
6549
6610
|
});
|
|
6550
6611
|
}
|
|
6612
|
+
} else {
|
|
6613
|
+
// A turn that is not a provider failure ends the streak of the
|
|
6614
|
+
// failures of the run: the next failure is the first attempt of
|
|
6615
|
+
// its own retry.
|
|
6616
|
+
providerFailureAttemptsInRun = 0;
|
|
6551
6617
|
}
|
|
6552
6618
|
|
|
6553
6619
|
if (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-harness/two-phase-review",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.487",
|
|
4
4
|
"description": "pi-harness-runtime — two-phase implementation and review workflow (queue review signals, gate the phase, scope the diff)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|