oira666_pi-subagent 0.7.9 → 0.7.10

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/README.md CHANGED
@@ -196,7 +196,7 @@ Source organization:
196
196
  | Directory | Responsibility |
197
197
  | --- | --- |
198
198
  | `extension/` | Tool registration, session lifecycle, policy, recovery provider, steering |
199
- | `runner/` | Child launch, RPC events, watchdogs, process cleanup |
199
+ | `runner/` | Child launch, RPC events, startup timeout, process cleanup |
200
200
  | `storage/` | Budget ledger, name registry, session files and validation |
201
201
  | `types/` | Runtime contracts, transcript parsing, outcomes, usage aggregation |
202
202
  | `ui/` | Transcript views, trees, navigation and overlays |
@@ -20,7 +20,7 @@ Configure task count through `limits.tasksPerCall`, `PI_SUBAGENT_MAX_TASKS_PER_C
20
20
  - Async batches release each completed worker's transcript before waiting for slower siblings. They retain full final output, failure explanations, own usage, subtree usage, and recovery references. Canonical summaries and non-enumerable compatibility usage totals retain descendant charges. The completion callback receives the original result before release. Synchronous runner callers keep their existing transcript behavior unless they opt into `compactCompletedResults`.
21
21
  - Async per-worker updates no longer build a usage tree just to replace one batch slot. Calls without a progress observer construct no per-event details. The existing batch throttle still controls tree snapshots; all independent jobs now also share a 100 ms footer refresh throttle. Accounting updates happen immediately, not on that timer.
22
22
  - Nested progress retains async job/task identities and custom completion details. This fixes partial-sibling accounting at ancestors. Finalized message projections use weak keys. Progress skips serialization while stdout needs draining, rather than accumulating transient snapshots behind a blocked protocol pipe. A later heartbeat retries; durable messages and completion delivery do not use this drop policy.
23
- - Protocol activity detection retains one fixed-size digest per nested call, not a serialized tree. Unchanged snapshots from interleaved siblings no longer reset the semantic watchdog. Resolved attempts ignore late protocol records. Progress callbacks also reject old lifecycle generations before touching accounting or UI callbacks.
23
+ - Protocol activity detection retains one fixed-size digest per nested call, not a serialized tree. Unchanged snapshots from interleaved siblings do not count as new actions. Resolved attempts ignore late protocol records. Progress callbacks also reject old lifecycle generations before touching accounting or UI callbacks.
24
24
  - Completion reservations maintain their current-generation count without scanning the pending map for every reserve/release. An old same-key background job cannot delete its replacement's accounting. Completed jobs leave the registry after cleanup.
25
25
  - Async owners enable `cancelOnError`. Infrastructure failures cancel and drain sibling subprocesses before background tracking disappears. A throwing handle callback now terminates its child. Attempt settlement destroys its streams and removes its abort listener; existing timeout and steering cleanup remains in place. Disposed progress coalescers release their callback reference.
26
26
  - Repeated completion text no longer causes the message index to discard a different execution's durable accounting. Completion publication retains stderr-only failure explanations without retaining the original transcript in its delivery callback.
@@ -59,7 +59,6 @@ For each setting, an explicitly set environment variable wins over JSON, then th
59
59
  "models": { "intelligence": true },
60
60
  "runner": {
61
61
  "startupTimeoutMs": 120000,
62
- "idleTimeoutMs": 1200000,
63
62
  "startupRetries": 2
64
63
  }
65
64
  }
@@ -80,7 +79,6 @@ For each setting, an explicitly set environment variable wins over JSON, then th
80
79
  | `models.intelligence` | `PI_SUBAGENT_INTELLIGENCE` | `true` |
81
80
  | `models.fallback` | `PI_SUBAGENT_FALLBACK_MODEL` | No configured fallback |
82
81
  | `runner.startupTimeoutMs` | `PI_SUBAGENT_STARTUP_TIMEOUT` | `120000` |
83
- | `runner.idleTimeoutMs` | `PI_SUBAGENT_IDLE_TIMEOUT` | `1200000` |
84
82
  | `runner.startupRetries` | `PI_SUBAGENT_STARTUP_RETRIES` | `2` |
85
83
  | `runner.command` | `PI_SUBAGENT_PI_COMMAND` | Current runtime |
86
84
  | `runner.argsPrefix` | `PI_SUBAGENT_PI_ARGS_PREFIX` | Current entrypoint |
@@ -228,11 +226,10 @@ Cycle-blocked tasks fail individually; legal siblings still run. A nested tool e
228
226
  | --- | --- | --- |
229
227
  | `PI_SUBAGENT_STARTUP_TIMEOUT` | `120000` | Milliseconds to first model turn; `0` disables |
230
228
  | `PI_SUBAGENT_STARTUP_RETRIES` | `2` | Fresh retries after startup timeout |
231
- | `PI_SUBAGENT_IDLE_TIMEOUT` | `1200000` | Milliseconds without agent activity; `0` disables |
232
229
  | `PI_SUBAGENT_PI_COMMAND` | Current runtime | Explicit launch command for embedded hosts |
233
230
  | `PI_SUBAGENT_PI_ARGS_PREFIX` | Current entrypoint | JSON argument array for the explicit command |
234
231
 
235
- The idle watchdog pauses during tool execution. When the last concurrent tool finishes, a fresh idle window starts. Agent events and changed nested-worker state reset it; unchanged heartbeats do not. Timeout and cancellation terminate the process tree and bound cleanup even if the OS never reports closure.
232
+ Once a worker has started its first turn, it is never killed for being quiet. Tools, rate-limit waits and the agent itself may run indefinitely; provider stalls are bounded inside Pi by its HTTP/WebSocket idle timeouts and retries. Use `stop_subagent` to end a worker you no longer need. Startup timeout and cancellation terminate the process tree and bound cleanup even if the OS never reports closure. The former `runner.idleTimeoutMs` / `PI_SUBAGENT_IDLE_TIMEOUT` setting was removed and is ignored.
236
233
 
237
234
  Worker-turn completion waits for `agent_settled`, not `agent_end`, because Pi may retry, compact, or continue after a low-level run ends. This wait happens in the background, not inside the lead's launch or messaging tool call.
238
235
 
@@ -49,7 +49,6 @@ Profile a long-running, nested workload before expanding this patch. In particul
49
49
  - `runner/single.ts` still builds each child's live details for every accepted semantic event. Batch coalescing limits downstream work, not this per-child cost.
50
50
  - Progress still recursively projects the structural tree, and `runner/protocol.ts` serializes that projection again to detect changes. Large delegation trees and long task prompts can remain expensive even after body payloads are removed.
51
51
  - `render.ts` builds tree nodes on repeated collapsed renders, and `ui/tree-build.ts` scans histories to build nested children and previews. Consider width/content caching with correct invalidation if a profile attributes substantial CPU here.
52
- - `runner/attempt.ts` clears and allocates an inactivity timer on each streaming delta. A mutable deadline and one timer would avoid that churn, but must preserve retry grace and active-tool exemptions.
53
52
  - Session header/settings reads load whole transcripts. Registry and budget operations use synchronous filesystem work. These can block the event loop, though disk waits alone do not explain sustained CPU saturation.
54
53
 
55
54
  For a follow-up measurement, record parent-process CPU and event-loop delay with representative transcript sizes and nesting. Compare progress enabled and disabled, and interactive and non-interactive runs. Capture a Node CPU profile of the parent to distinguish JSON processing, tree rendering and filesystem work from Pi's own costs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oira666_pi-subagent",
3
- "version": "0.7.9",
3
+ "version": "0.7.10",
4
4
  "description": "Subagent extension for Pi coding agent. Delegate tasks to specialized agents.",
5
5
  "type": "module",
6
6
  "main": "startup.js",
@@ -64,8 +64,6 @@ export class AttemptParking {
64
64
  this.requested = true;
65
65
  state.stopping = true;
66
66
  state.forcedExitCode = 0;
67
- if (state.idleTimer) clearTimeout(state.idleTimer);
68
- state.idleTimer = undefined;
69
67
  // Broker-owned descendants are separate root children, not members of this process group.
70
68
  // Do not run extension shutdown hooks, which could cancel durable child jobs.
71
69
  try {
@@ -16,6 +16,5 @@ export interface AttemptState {
16
16
  pendingAgentSettled?: boolean;
17
17
  stopping?: boolean;
18
18
  startupTimer?: ReturnType<typeof setTimeout>;
19
- idleTimer?: ReturnType<typeof setTimeout>;
20
19
  killTimer?: ReturnType<typeof setTimeout>;
21
20
  }
package/runner/attempt.ts CHANGED
@@ -10,8 +10,6 @@ import {
10
10
  SIGKILL_TIMEOUT_MS,
11
11
  DEFAULT_STARTUP_TIMEOUT_MS,
12
12
  SUBAGENT_STARTUP_TIMEOUT_ENV,
13
- DEFAULT_IDLE_TIMEOUT_MS,
14
- SUBAGENT_IDLE_TIMEOUT_ENV,
15
13
  MAX_CAPTURED_STDERR_CHARS,
16
14
  } from "./constants.js";
17
15
  import { getPiSpawnCommand, stopProcessTree, killProcessTreeImmediately } from "./launch.js";
@@ -30,8 +28,7 @@ export async function runAttempt(
30
28
  attempt: number,
31
29
  emitUpdate: () => void,
32
30
  ): Promise<{ exitCode: number; startupTimedOut: boolean; wasAborted: boolean; parked?: boolean }> {
33
- const { piCommandOverride, startupTimeoutMsOverride, idleTimeoutMsOverride, terminationTimeoutMsOverride, signal } =
34
- opts;
31
+ const { piCommandOverride, startupTimeoutMsOverride, terminationTimeoutMsOverride, signal } = opts;
35
32
  const state: AttemptState = {
36
33
  resolved: false,
37
34
  receivedFirstEvent: false,
@@ -99,10 +96,6 @@ export async function runAttempt(
99
96
  clearTimeout(state.startupTimer);
100
97
  state.startupTimer = undefined;
101
98
  }
102
- if (state.idleTimer) {
103
- clearTimeout(state.idleTimer);
104
- state.idleTimer = undefined;
105
- }
106
99
  if (state.killTimer) {
107
100
  clearTimeout(state.killTimer);
108
101
  state.killTimer = undefined;
@@ -135,36 +128,6 @@ export async function runAttempt(
135
128
  }, terminationTimeoutMsOverride ?? SIGKILL_TIMEOUT_MS);
136
129
  };
137
130
 
138
- const idleTimeoutMs =
139
- idleTimeoutMsOverride !== undefined
140
- ? Math.max(0, idleTimeoutMsOverride)
141
- : configuredNonNegativeInt(SUBAGENT_IDLE_TIMEOUT_ENV, DEFAULT_IDLE_TIMEOUT_MS, false, opts.settings);
142
-
143
- const noteSemanticActivity = (minimumQuietPeriodMs = 0) => {
144
- if (state.idleTimer) {
145
- clearTimeout(state.idleTimer);
146
- state.idleTimer = undefined;
147
- }
148
- if (!state.receivedFirstEvent || idleTimeoutMs === 0 || state.resolved || state.waitingForChildren) return;
149
- // The idle timeout measures the agent itself, not tools it has invoked.
150
- // A tool may legitimately be silent for longer than the configured
151
- // timeout, so leave the watchdog disarmed until every concurrent tool
152
- // execution has ended. tool_execution_end will call this again and
153
- // start a fresh full inactivity window.
154
- if (state.activeToolCallIds.size > 0) return;
155
- const quietPeriodMs = Math.max(idleTimeoutMs, minimumQuietPeriodMs);
156
- state.idleTimer = setTimeout(() => {
157
- if (state.resolved) return;
158
- const message = `Subagent inactivity timeout: no agent activity for ${quietPeriodMs}ms.`;
159
- state.forcedExitCode = 1;
160
- result.stopReason = "error";
161
- result.errorMessage = message;
162
- appendBoundedStderr(result, `\n[pi-subagent] Killed: ${message}`);
163
- emitUpdate();
164
- forceStopAndSettle();
165
- }, quietPeriodMs);
166
- };
167
-
168
131
  const parking = new AttemptParking(opts, state, proc, result);
169
132
  const flushLine = createProtocolHandler({
170
133
  state,
@@ -173,7 +136,6 @@ export async function runAttempt(
173
136
  onLeadMessage: opts.onLeadMessage,
174
137
  onWaitingForChildren: (waiting) => parking.waiting(waiting, () => forceStopAndSettle(1, true)),
175
138
  emitUpdate,
176
- noteSemanticActivity,
177
139
  stopChild,
178
140
  doResolve,
179
141
  forceStopAndSettle,
@@ -308,7 +270,6 @@ export async function runAttempt(
308
270
  result,
309
271
  promptRequestId,
310
272
  sendRpc,
311
- noteSemanticActivity,
312
273
  timeoutMs: opts.steeringTimeoutMsOverride,
313
274
  settleDeferred: () => flushLine(JSON.stringify({ type: "agent_settled" })),
314
275
  }),
@@ -16,15 +16,8 @@ export function configuredNonNegativeInt(
16
16
  }
17
17
 
18
18
  export const SIGKILL_TIMEOUT_MS = 5000;
19
- export const RETRY_WAIT_GRACE_MS = 60_000;
20
19
  export const DEFAULT_STARTUP_TIMEOUT_MS = 120_000; // only for startup (before first assistant turn)
21
20
  export const SUBAGENT_STARTUP_TIMEOUT_ENV = "PI_SUBAGENT_STARTUP_TIMEOUT";
22
- // Once startup succeeds, a child can otherwise remain alive forever if Pi loses
23
- // the next model/RPC turn after a tool result. Bound agent inactivity (not
24
- // repeated progress heartbeats), but never while one of its tools is executing:
25
- // tool runtimes are intentionally unbounded.
26
- export const DEFAULT_IDLE_TIMEOUT_MS = 20 * 60_000;
27
- export const SUBAGENT_IDLE_TIMEOUT_ENV = "PI_SUBAGENT_IDLE_TIMEOUT";
28
21
  // A startup timeout is almost always a transient cold-start stall (slow cli /
29
22
  // extension load, momentarily busy box) rather than a deterministic failure, so
30
23
  // re-spawn a clean child a few times before surfacing the error. This does NOT
package/runner/options.ts CHANGED
@@ -87,8 +87,6 @@ export interface RunAgentOptions {
87
87
  piCommandOverride?: { command: string; argsPrefix?: string[] };
88
88
  /** Test/debug override for startup timeout. */
89
89
  startupTimeoutMsOverride?: number;
90
- /** Test/debug override for post-startup semantic inactivity timeout. */
91
- idleTimeoutMsOverride?: number;
92
90
  /** Test/debug override for the steering acknowledgment timeout. Defaults to 30 seconds. */
93
91
  steeringTimeoutMsOverride?: number;
94
92
  /** Test/debug override for graceful-stop to SIGKILL escalation. */
@@ -1,7 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { getFinalOutput, isResultError, type SingleResult } from "../types.js";
3
3
  import { isRecord } from "../types/records.js";
4
- import { RETRY_WAIT_GRACE_MS } from "./constants.js";
5
4
  import { parseRpcEvent, processRpcEvent } from "./events.js";
6
5
  import { appendBoundedStderr } from "./result.js";
7
6
  import type { AttemptState } from "./attempt-state.js";
@@ -15,7 +14,6 @@ interface ProtocolOptions {
15
14
  onLeadMessage?: RunAgentOptions["onLeadMessage"];
16
15
  onWaitingForChildren?: (waiting: boolean) => void;
17
16
  emitUpdate(): void;
18
- noteSemanticActivity(minimumQuietPeriodMs?: number): void;
19
17
  stopChild(force: boolean): void;
20
18
  doResolve(code: number): void;
21
19
  forceStopAndSettle(code?: number): void;
@@ -23,13 +21,13 @@ interface ProtocolOptions {
23
21
 
24
22
  /** A stdin write is not delivery. Wait for prompt preflight to accept each request. */
25
23
  export function createSteeringHandle(
26
- options: Pick<ProtocolOptions, "state" | "result" | "promptRequestId" | "noteSemanticActivity"> & {
24
+ options: Pick<ProtocolOptions, "state" | "result" | "promptRequestId"> & {
27
25
  sendRpc(command: Record<string, unknown>): boolean;
28
26
  timeoutMs?: number;
29
27
  settleDeferred(): void;
30
28
  },
31
29
  ): RunningSubagentHandle {
32
- const { state, result, promptRequestId, sendRpc, noteSemanticActivity, settleDeferred } = options;
30
+ const { state, result, promptRequestId, sendRpc, settleDeferred } = options;
33
31
  const pending = (state.pendingSteeringRequests ??= new Map());
34
32
  let request = 0;
35
33
  return {
@@ -48,7 +46,6 @@ export function createSteeringHandle(
48
46
  // Preflight can answer after an older run's settlement but before
49
47
  // the new turn starts. Wait for that continuation's own settlement.
50
48
  state.pendingAgentSettled = false;
51
- noteSemanticActivity();
52
49
  } else if (pending.size === 0 && state.pendingAgentSettled) {
53
50
  state.pendingAgentSettled = false;
54
51
  settleDeferred();
@@ -71,7 +68,7 @@ export function createSteeringHandle(
71
68
 
72
69
  /** Interpret run boundaries and semantic activity independently of JSONL framing. */
73
70
  export function createProtocolHandler(options: ProtocolOptions): (line: string) => void {
74
- const { state, result, promptRequestId, emitUpdate, noteSemanticActivity, stopChild, doResolve, forceStopAndSettle } =
71
+ const { state, result, promptRequestId, emitUpdate, stopChild, doResolve, forceStopAndSettle } =
75
72
  options;
76
73
  // One bounded digest per active nested call, not a retained serialized tree.
77
74
  const nestedSignatures = new Map<string, string>();
@@ -105,7 +102,6 @@ export function createProtocolHandler(options: ProtocolOptions): (line: string)
105
102
  if (isLeadMessageEvent(event)) {
106
103
  if (state.resolved) return;
107
104
  result.lastActionAt = Date.now();
108
- if (!state.agentSettled) noteSemanticActivity();
109
105
  const reportError = () => appendBoundedStderr(result, "[pi-subagent] Lead message callback failed.\n");
110
106
  try {
111
107
  // Notifications must not block stream draining, settlement, or subsequent messages.
@@ -155,7 +151,6 @@ export function createProtocolHandler(options: ProtocolOptions): (line: string)
155
151
  // the direct cause of the WebSocket failures in the inspected session.
156
152
  if (event?.type === "agent_end") {
157
153
  result.lastActionAt = Date.now();
158
- noteSemanticActivity(event.willRetry === true ? RETRY_WAIT_GRACE_MS : 0);
159
154
  return;
160
155
  }
161
156
 
@@ -178,28 +173,16 @@ export function createProtocolHandler(options: ProtocolOptions): (line: string)
178
173
  // determines whether this old settlement is final or a new turn follows.
179
174
  state.pendingAgentSettled = true;
180
175
  if ((state.backgroundJobs ?? 0) > 0) state.waitingForChildren = true;
181
- if (state.idleTimer) clearTimeout(state.idleTimer);
182
- state.idleTimer = undefined;
183
176
  return;
184
177
  }
185
178
  // Async descendants may wake this idle RPC session with a completion.
186
179
  // Do not reap the process tree until that continuation has settled too.
187
180
  if ((state.backgroundJobs ?? 0) > 0) {
188
181
  state.waitingForChildren = true;
189
- if (state.idleTimer) clearTimeout(state.idleTimer);
190
- state.idleTimer = undefined;
191
182
  return;
192
183
  }
193
184
  state.agentSettled = true;
194
185
  result.lastActionAt = Date.now();
195
- // No semantic watchdog may fire while we are only waiting for the
196
- // deliberately terminated RPC process tree to close. On slower
197
- // launchers (notably Windows taskkill), that cleanup can outlast a
198
- // short idle timeout and overwrite a successful settled result.
199
- if (state.idleTimer) {
200
- clearTimeout(state.idleTimer);
201
- state.idleTimer = undefined;
202
- }
203
186
  if (result.stopReason === "length" && !result.errorMessage) {
204
187
  result.errorMessage = "Subagent output was incomplete because the model reached its output limit.";
205
188
  }
@@ -232,29 +215,21 @@ export function createProtocolHandler(options: ProtocolOptions): (line: string)
232
215
  }
233
216
  }
234
217
  // Parallel progress is emitted every second even when nothing changed.
235
- // Only a changed nested snapshot counts as activity, otherwise a dead
236
- // grandchild could keep every ancestor alive forever.
237
- let semanticActivity = true;
218
+ // Only a changed nested snapshot counts as a new action.
238
219
  if (event?.type === "subagent_progress") {
239
220
  const signature = createHash("sha256").update(JSON.stringify(event.details)).digest("hex");
240
221
  const id = typeof event.toolCallId === "string" ? event.toolCallId : "";
241
- semanticActivity = signature !== nestedSignatures.get(id);
222
+ if (signature === nestedSignatures.get(id)) result.lastActionAt = previousActionAt;
242
223
  nestedSignatures.set(id, signature);
243
- if (!semanticActivity) result.lastActionAt = previousActionAt;
244
224
  }
245
- if (semanticActivity) noteSemanticActivity();
246
225
  emitUpdate();
247
226
  } else if (state.receivedFirstEvent) {
248
227
  if (event?.type === "message_update" || event?.type === "tool_execution_update") {
249
228
  // Streaming deltas are intentionally not retained in result.messages,
250
229
  // but they prove the model/tool is still making real progress.
251
230
  result.lastActionAt = Date.now();
252
- noteSemanticActivity();
253
- } else if (event?.type === "auto_retry_start") {
254
- result.lastActionAt = Date.now();
255
- const delayMs = Number.isFinite(event.delayMs) ? Math.max(0, Number(event.delayMs)) : 0;
256
- noteSemanticActivity(delayMs + RETRY_WAIT_GRACE_MS);
257
231
  } else if (
232
+ event?.type === "auto_retry_start" ||
258
233
  event?.type === "auto_retry_end" ||
259
234
  event?.type === "compaction_start" ||
260
235
  event?.type === "compaction_end" ||
@@ -263,7 +238,6 @@ export function createProtocolHandler(options: ProtocolOptions): (line: string)
263
238
  event?.type === "summarization_retry_finished"
264
239
  ) {
265
240
  result.lastActionAt = Date.now();
266
- noteSemanticActivity();
267
241
  }
268
242
  }
269
243
  };
package/settings.ts CHANGED
@@ -17,7 +17,6 @@ export const SETTING_DEFINITIONS = [
17
17
  ["models", "intelligence", "PI_SUBAGENT_INTELLIGENCE", "boolean"],
18
18
  ["models", "fallback", "PI_SUBAGENT_FALLBACK_MODEL", "string"],
19
19
  ["runner", "startupTimeoutMs", "PI_SUBAGENT_STARTUP_TIMEOUT", "integer"],
20
- ["runner", "idleTimeoutMs", "PI_SUBAGENT_IDLE_TIMEOUT", "integer"],
21
20
  ["runner", "startupRetries", "PI_SUBAGENT_STARTUP_RETRIES", "integer"],
22
21
  ["runner", "command", "PI_SUBAGENT_PI_COMMAND", "string"],
23
22
  ["runner", "argsPrefix", "PI_SUBAGENT_PI_ARGS_PREFIX", "list"],
package/startup.js CHANGED
@@ -59,7 +59,6 @@ var SETTING_DEFINITIONS = [
59
59
  ["models", "intelligence", "PI_SUBAGENT_INTELLIGENCE", "boolean"],
60
60
  ["models", "fallback", "PI_SUBAGENT_FALLBACK_MODEL", "string"],
61
61
  ["runner", "startupTimeoutMs", "PI_SUBAGENT_STARTUP_TIMEOUT", "integer"],
62
- ["runner", "idleTimeoutMs", "PI_SUBAGENT_IDLE_TIMEOUT", "integer"],
63
62
  ["runner", "startupRetries", "PI_SUBAGENT_STARTUP_RETRIES", "integer"],
64
63
  ["runner", "command", "PI_SUBAGENT_PI_COMMAND", "string"],
65
64
  ["runner", "argsPrefix", "PI_SUBAGENT_PI_ARGS_PREFIX", "list"]
@@ -4516,11 +4515,8 @@ function configuredNonNegativeInt(name, fallback, warn = false, settings) {
4516
4515
  return parsed ?? fallback;
4517
4516
  }
4518
4517
  var SIGKILL_TIMEOUT_MS = 5e3;
4519
- var RETRY_WAIT_GRACE_MS = 6e4;
4520
4518
  var DEFAULT_STARTUP_TIMEOUT_MS = 12e4;
4521
4519
  var SUBAGENT_STARTUP_TIMEOUT_ENV = "PI_SUBAGENT_STARTUP_TIMEOUT";
4522
- var DEFAULT_IDLE_TIMEOUT_MS = 20 * 6e4;
4523
- var SUBAGENT_IDLE_TIMEOUT_ENV = "PI_SUBAGENT_IDLE_TIMEOUT";
4524
4520
  var DEFAULT_STARTUP_RETRIES = 2;
4525
4521
  var SUBAGENT_STARTUP_RETRIES_ENV = "PI_SUBAGENT_STARTUP_RETRIES";
4526
4522
  var STARTUP_RETRY_BASE_BACKOFF_MS = 1e3;
@@ -7123,8 +7119,6 @@ var AttemptParking = class {
7123
7119
  this.requested = true;
7124
7120
  state.stopping = true;
7125
7121
  state.forcedExitCode = 0;
7126
- if (state.idleTimer) clearTimeout(state.idleTimer);
7127
- state.idleTimer = void 0;
7128
7122
  try {
7129
7123
  if (process.platform === "win32") this.proc.kill("SIGKILL");
7130
7124
  else if (this.proc.pid) process.kill(-this.proc.pid, "SIGKILL");
@@ -7154,7 +7148,7 @@ var AttemptParking = class {
7154
7148
  // runner/protocol.ts
7155
7149
  import { createHash as createHash5 } from "node:crypto";
7156
7150
  function createSteeringHandle(options) {
7157
- const { state, result, promptRequestId, sendRpc, noteSemanticActivity, settleDeferred } = options;
7151
+ const { state, result, promptRequestId, sendRpc, settleDeferred } = options;
7158
7152
  const pending2 = state.pendingSteeringRequests ??= /* @__PURE__ */ new Map();
7159
7153
  let request = 0;
7160
7154
  return {
@@ -7171,7 +7165,6 @@ function createSteeringHandle(options) {
7171
7165
  if (state.resolved || state.stopping) return;
7172
7166
  if (accepted) {
7173
7167
  state.pendingAgentSettled = false;
7174
- noteSemanticActivity();
7175
7168
  } else if (pending2.size === 0 && state.pendingAgentSettled) {
7176
7169
  state.pendingAgentSettled = false;
7177
7170
  settleDeferred();
@@ -7192,7 +7185,7 @@ function createSteeringHandle(options) {
7192
7185
  };
7193
7186
  }
7194
7187
  function createProtocolHandler(options) {
7195
- const { state, result, promptRequestId, emitUpdate, noteSemanticActivity, stopChild, doResolve, forceStopAndSettle } = options;
7188
+ const { state, result, promptRequestId, emitUpdate, stopChild, doResolve, forceStopAndSettle } = options;
7196
7189
  const nestedSignatures = /* @__PURE__ */ new Map();
7197
7190
  return (line) => {
7198
7191
  if (state.resolved) return;
@@ -7218,7 +7211,6 @@ function createProtocolHandler(options) {
7218
7211
  if (isLeadMessageEvent(event)) {
7219
7212
  if (state.resolved) return;
7220
7213
  result.lastActionAt = Date.now();
7221
- if (!state.agentSettled) noteSemanticActivity();
7222
7214
  const reportError = () => appendBoundedStderr(result, "[pi-subagent] Lead message callback failed.\n");
7223
7215
  try {
7224
7216
  void Promise.resolve(options.onLeadMessage?.(event.message)).catch(reportError);
@@ -7259,7 +7251,6 @@ function createProtocolHandler(options) {
7259
7251
  }
7260
7252
  if (event?.type === "agent_end") {
7261
7253
  result.lastActionAt = Date.now();
7262
- noteSemanticActivity(event.willRetry === true ? RETRY_WAIT_GRACE_MS : 0);
7263
7254
  return;
7264
7255
  }
7265
7256
  if (event?.type === "agent_settled") {
@@ -7280,22 +7271,14 @@ ${output}`)).catch(reportError);
7280
7271
  if ((state.pendingSteeringRequests?.size ?? 0) > 0) {
7281
7272
  state.pendingAgentSettled = true;
7282
7273
  if ((state.backgroundJobs ?? 0) > 0) state.waitingForChildren = true;
7283
- if (state.idleTimer) clearTimeout(state.idleTimer);
7284
- state.idleTimer = void 0;
7285
7274
  return;
7286
7275
  }
7287
7276
  if ((state.backgroundJobs ?? 0) > 0) {
7288
7277
  state.waitingForChildren = true;
7289
- if (state.idleTimer) clearTimeout(state.idleTimer);
7290
- state.idleTimer = void 0;
7291
7278
  return;
7292
7279
  }
7293
7280
  state.agentSettled = true;
7294
7281
  result.lastActionAt = Date.now();
7295
- if (state.idleTimer) {
7296
- clearTimeout(state.idleTimer);
7297
- state.idleTimer = void 0;
7298
- }
7299
7282
  if (result.stopReason === "length" && !result.errorMessage) {
7300
7283
  result.errorMessage = "Subagent output was incomplete because the model reached its output limit.";
7301
7284
  }
@@ -7315,27 +7298,18 @@ ${output}`)).catch(reportError);
7315
7298
  state.startupTimer = void 0;
7316
7299
  }
7317
7300
  }
7318
- let semanticActivity = true;
7319
7301
  if (event?.type === "subagent_progress") {
7320
7302
  const signature2 = createHash5("sha256").update(JSON.stringify(event.details)).digest("hex");
7321
7303
  const id = typeof event.toolCallId === "string" ? event.toolCallId : "";
7322
- semanticActivity = signature2 !== nestedSignatures.get(id);
7304
+ if (signature2 === nestedSignatures.get(id)) result.lastActionAt = previousActionAt;
7323
7305
  nestedSignatures.set(id, signature2);
7324
- if (!semanticActivity) result.lastActionAt = previousActionAt;
7325
7306
  }
7326
- if (semanticActivity) noteSemanticActivity();
7327
7307
  emitUpdate();
7328
7308
  } else if (state.receivedFirstEvent) {
7329
7309
  if (event?.type === "message_update" || event?.type === "tool_execution_update") {
7330
7310
  result.lastActionAt = Date.now();
7331
- noteSemanticActivity();
7332
- } else if (event?.type === "auto_retry_start") {
7333
- result.lastActionAt = Date.now();
7334
- const delayMs = Number.isFinite(event.delayMs) ? Math.max(0, Number(event.delayMs)) : 0;
7335
- noteSemanticActivity(delayMs + RETRY_WAIT_GRACE_MS);
7336
- } else if (event?.type === "auto_retry_end" || event?.type === "compaction_start" || event?.type === "compaction_end" || event?.type === "summarization_retry_scheduled" || event?.type === "summarization_retry_attempt_start" || event?.type === "summarization_retry_finished") {
7311
+ } else if (event?.type === "auto_retry_start" || event?.type === "auto_retry_end" || event?.type === "compaction_start" || event?.type === "compaction_end" || event?.type === "summarization_retry_scheduled" || event?.type === "summarization_retry_attempt_start" || event?.type === "summarization_retry_finished") {
7337
7312
  result.lastActionAt = Date.now();
7338
- noteSemanticActivity();
7339
7313
  }
7340
7314
  }
7341
7315
  };
@@ -7343,7 +7317,7 @@ ${output}`)).catch(reportError);
7343
7317
 
7344
7318
  // runner/attempt.ts
7345
7319
  async function runAttempt(opts, result, piArgs, prompt, attempt, emitUpdate) {
7346
- const { piCommandOverride, startupTimeoutMsOverride, idleTimeoutMsOverride, terminationTimeoutMsOverride, signal } = opts;
7320
+ const { piCommandOverride, startupTimeoutMsOverride, terminationTimeoutMsOverride, signal } = opts;
7347
7321
  const state = {
7348
7322
  resolved: false,
7349
7323
  receivedFirstEvent: false,
@@ -7405,10 +7379,6 @@ async function runAttempt(opts, result, piArgs, prompt, attempt, emitUpdate) {
7405
7379
  clearTimeout(state.startupTimer);
7406
7380
  state.startupTimer = void 0;
7407
7381
  }
7408
- if (state.idleTimer) {
7409
- clearTimeout(state.idleTimer);
7410
- state.idleTimer = void 0;
7411
- }
7412
7382
  if (state.killTimer) {
7413
7383
  clearTimeout(state.killTimer);
7414
7384
  state.killTimer = void 0;
@@ -7436,27 +7406,6 @@ async function runAttempt(opts, result, piArgs, prompt, attempt, emitUpdate) {
7436
7406
  doResolve(settleCode);
7437
7407
  }, terminationTimeoutMsOverride ?? SIGKILL_TIMEOUT_MS);
7438
7408
  };
7439
- const idleTimeoutMs = idleTimeoutMsOverride !== void 0 ? Math.max(0, idleTimeoutMsOverride) : configuredNonNegativeInt(SUBAGENT_IDLE_TIMEOUT_ENV, DEFAULT_IDLE_TIMEOUT_MS, false, opts.settings);
7440
- const noteSemanticActivity = (minimumQuietPeriodMs = 0) => {
7441
- if (state.idleTimer) {
7442
- clearTimeout(state.idleTimer);
7443
- state.idleTimer = void 0;
7444
- }
7445
- if (!state.receivedFirstEvent || idleTimeoutMs === 0 || state.resolved || state.waitingForChildren) return;
7446
- if (state.activeToolCallIds.size > 0) return;
7447
- const quietPeriodMs = Math.max(idleTimeoutMs, minimumQuietPeriodMs);
7448
- state.idleTimer = setTimeout(() => {
7449
- if (state.resolved) return;
7450
- const message = `Subagent inactivity timeout: no agent activity for ${quietPeriodMs}ms.`;
7451
- state.forcedExitCode = 1;
7452
- result.stopReason = "error";
7453
- result.errorMessage = message;
7454
- appendBoundedStderr(result, `
7455
- [pi-subagent] Killed: ${message}`);
7456
- emitUpdate();
7457
- forceStopAndSettle();
7458
- }, quietPeriodMs);
7459
- };
7460
7409
  const parking = new AttemptParking(opts, state, proc, result);
7461
7410
  const flushLine = createProtocolHandler({
7462
7411
  state,
@@ -7465,7 +7414,6 @@ async function runAttempt(opts, result, piArgs, prompt, attempt, emitUpdate) {
7465
7414
  onLeadMessage: opts.onLeadMessage,
7466
7415
  onWaitingForChildren: (waiting) => parking.waiting(waiting, () => forceStopAndSettle(1, true)),
7467
7416
  emitUpdate,
7468
- noteSemanticActivity,
7469
7417
  stopChild,
7470
7418
  doResolve,
7471
7419
  forceStopAndSettle
@@ -7584,7 +7532,6 @@ async function runAttempt(opts, result, piArgs, prompt, attempt, emitUpdate) {
7584
7532
  result,
7585
7533
  promptRequestId,
7586
7534
  sendRpc,
7587
- noteSemanticActivity,
7588
7535
  timeoutMs: opts.steeringTimeoutMsOverride,
7589
7536
  settleDeferred: () => flushLine(JSON.stringify({ type: "agent_settled" }))
7590
7537
  }),