pi-better-harness 0.45.3 → 0.45.5

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.45.5] - 2026-11-13
4
+
5
+ ### Fixed
6
+
7
+ - Bundle Subagents 0.32.4 so a worker checkpoints a settled wait before exiting. (#734)
8
+
9
+ ## [0.45.4] - 2026-11-13
10
+
11
+ ### Fixed
12
+
13
+ - Bundle Background Tasks 0.15.3 and Subagents 0.32.3 to reduce idle Pi CPU use from repeated outbox polling. (#732)
14
+
3
15
  ## [0.45.3] - 2026-11-13
4
16
 
5
17
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-background-tasks",
3
- "version": "0.15.2",
3
+ "version": "0.15.3",
4
4
  "description": "Pi extension for durable background shell tasks, watchers, logs, and status inspection.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -3378,16 +3378,9 @@ export class ObservedWaitHost {
3378
3378
  private async dispatchOutbox(): Promise<void> {
3379
3379
  const store = this.store;
3380
3380
  if (!store || this.closed) return;
3381
- const pending = store.listOutbox({ state: "pending" });
3381
+ const pending = store.listDispatchableOutboxRecipients();
3382
3382
  if (pending.length === 0) return;
3383
- const byRecipient = new Map<string, { owner: OwnerIdentity; events: OutboxEventRecord[] }>();
3384
- for (const event of pending) {
3385
- const key = ownerKey(event.recipient);
3386
- const entry = byRecipient.get(key) ?? { owner: event.recipient, events: [] };
3387
- entry.events.push(event);
3388
- byRecipient.set(key, entry);
3389
- }
3390
- for (const { owner, events } of byRecipient.values()) {
3383
+ for (const { recipient: owner, count } of pending) {
3391
3384
  // Foreign parents cannot receive a handoff here. Leave their events pending
3392
3385
  // without taking a write lock on every reconciliation pass.
3393
3386
  if (owner.kind === "parent-session") {
@@ -3403,7 +3396,7 @@ export class ObservedWaitHost {
3403
3396
  recipient: owner,
3404
3397
  claimToken,
3405
3398
  claimedBy: this.hostId,
3406
- limit: Math.min(events.length, 20),
3399
+ limit: Math.min(count, 20),
3407
3400
  });
3408
3401
  } catch (error) {
3409
3402
  this.options.logger?.(`observed waits: outbox claim failed: ${oneLine(String(error), 160)}`);
@@ -24,11 +24,12 @@ import { StoreError } from "./errors.ts";
24
24
  import {
25
25
  dependencyState,
26
26
  mapOutbox,
27
+ ownerFromRow,
27
28
  readOperationEvidence,
28
29
  readOutboxRow,
29
30
  requireWaitRow,
30
31
  } from "./rows.ts";
31
- import { columnJson, columnNullableText, columnText, getRows, run, type StoreContext } from "./sqlite.ts";
32
+ import { columnJson, columnNullableText, columnNumber, columnText, getRows, run, type StoreContext } from "./sqlite.ts";
32
33
  import type {
33
34
  ClaimOutboxInput,
34
35
  OutboxDispatchClaim,
@@ -280,6 +281,23 @@ export function listOutbox(ctx: StoreContext, filter: OutboxFilter = {}): Outbox
280
281
  ).map((row) => mapOutbox(ctx, row));
281
282
  }
282
283
 
284
+ /** Find recipients with deliverable dependencies without loading each event's evidence. */
285
+ export function listDispatchableOutboxRecipients(ctx: StoreContext): Array<{ recipient: OwnerIdentity; count: number }> {
286
+ return getRows(
287
+ ctx,
288
+ `SELECT recipient_kind, recipient_session_id, recipient_workspace, recipient_branch_id, recipient_goal_id,
289
+ count(*) AS pending_count
290
+ FROM outbox_events
291
+ WHERE state = 'pending' AND event_type = 'dependency-ready'
292
+ AND EXISTS (SELECT 1 FROM waits w WHERE w.wait_id = outbox_events.wait_id
293
+ AND w.generation = outbox_events.generation
294
+ AND w.phase IN (${placeholders(DELIVERABLE_WAIT_PHASES.length)}))
295
+ GROUP BY recipient_kind, recipient_session_id, recipient_workspace, recipient_branch_id, recipient_goal_id
296
+ ORDER BY min(created_at), min(event_id)`,
297
+ ...DELIVERABLE_WAIT_PHASES,
298
+ ).map((row) => ({ recipient: ownerFromRow(row, "recipient"), count: columnNumber(row, "pending_count") }));
299
+ }
300
+
283
301
  function readDispatchClaim(row: Record<string, unknown>): OutboxDispatchClaim | null {
284
302
  return columnJson<OutboxDispatchClaim>(row, "dispatch_claim_json");
285
303
  }
@@ -58,6 +58,7 @@ import {
58
58
  } from "./waits.ts";
59
59
  import {
60
60
  claimOutbox as writeOutboxClaim,
61
+ listDispatchableOutboxRecipients as readDispatchableOutboxRecipients,
61
62
  listOutbox as readOutbox,
62
63
  markOutboxDelivered as writeOutboxDelivery,
63
64
  releaseOutbox as writeOutboxRelease,
@@ -272,6 +273,8 @@ export interface Store {
272
273
  // ---- outbox ----
273
274
 
274
275
  listOutbox(filter?: OutboxFilter): OutboxEventRecord[];
276
+ /** Lightweight dispatch candidates; evidence is read only after a claim succeeds. */
277
+ listDispatchableOutboxRecipients(): Array<{ recipient: OwnerIdentity; count: number }>;
275
278
  /** Claim pending deliveries for a `ready`/`resuming` generation. */
276
279
  claimOutbox(input: ClaimOutboxInput): OutboxEventRecord[];
277
280
  /** Mark a claimed delivery delivered; the result is still unconsumed. */
@@ -457,6 +460,10 @@ export function openStore(options: StoreOptions): Store {
457
460
  alive();
458
461
  return readOutbox(ctx, filter);
459
462
  },
463
+ listDispatchableOutboxRecipients() {
464
+ alive();
465
+ return readDispatchableOutboxRecipients(ctx);
466
+ },
460
467
  claimOutbox(input) {
461
468
  alive();
462
469
  return writeOutboxClaim(ctx, input);
@@ -51,6 +51,7 @@ import {
51
51
  findBridgeEnvironmentKey,
52
52
  isLaunchTool,
53
53
  normalizeWaitForOperationsResult,
54
+ requiresParkCheckpoint,
54
55
  parseBridgeEndpoint,
55
56
  validateJsonSchemaSupport,
56
57
  redactSecret,
@@ -1012,7 +1013,7 @@ export function installChildOperationBridge(
1012
1013
  toolCallId,
1013
1014
  },
1014
1015
  };
1015
- const shouldPark = normalized.result.park && !normalized.result.settled;
1016
+ const shouldPark = requiresParkCheckpoint(normalized.result);
1016
1017
  if (shouldPark) {
1017
1018
  if (!state.descriptor?.capabilities.parking) {
1018
1019
  throw new OperationToolError("the parent asked this worker to park without a parking capability");
@@ -959,6 +959,11 @@ export interface NormalizedWaitResult {
959
959
  continuationNote?: string;
960
960
  }
961
961
 
962
+ /** Settled dependencies do not bypass a checkpoint while the writer is still parking. */
963
+ export function requiresParkCheckpoint(wait: NormalizedWaitResult): boolean {
964
+ return wait.park && (wait.phase === "parking" || !wait.settled);
965
+ }
966
+
962
967
  export function normalizeWaitForOperationsResult(value: unknown): { ok: true; result: NormalizedWaitResult } | { ok: false; message: string } {
963
968
  if (!value || typeof value !== "object" || Array.isArray(value)) return { ok: false, message: "wait result must be an object" };
964
969
  const record = value as JsonRecord;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-subagents",
3
- "version": "0.32.2",
3
+ "version": "0.32.4",
4
4
  "description": "Pi extension for detached, sandboxed subagent runs that keep the foreground session free.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,11 +24,12 @@ import { StoreError } from "./errors.ts";
24
24
  import {
25
25
  dependencyState,
26
26
  mapOutbox,
27
+ ownerFromRow,
27
28
  readOperationEvidence,
28
29
  readOutboxRow,
29
30
  requireWaitRow,
30
31
  } from "./rows.ts";
31
- import { columnJson, columnNullableText, columnText, getRows, run, type StoreContext } from "./sqlite.ts";
32
+ import { columnJson, columnNullableText, columnNumber, columnText, getRows, run, type StoreContext } from "./sqlite.ts";
32
33
  import type {
33
34
  ClaimOutboxInput,
34
35
  OutboxDispatchClaim,
@@ -280,6 +281,23 @@ export function listOutbox(ctx: StoreContext, filter: OutboxFilter = {}): Outbox
280
281
  ).map((row) => mapOutbox(ctx, row));
281
282
  }
282
283
 
284
+ /** Find recipients with deliverable dependencies without loading each event's evidence. */
285
+ export function listDispatchableOutboxRecipients(ctx: StoreContext): Array<{ recipient: OwnerIdentity; count: number }> {
286
+ return getRows(
287
+ ctx,
288
+ `SELECT recipient_kind, recipient_session_id, recipient_workspace, recipient_branch_id, recipient_goal_id,
289
+ count(*) AS pending_count
290
+ FROM outbox_events
291
+ WHERE state = 'pending' AND event_type = 'dependency-ready'
292
+ AND EXISTS (SELECT 1 FROM waits w WHERE w.wait_id = outbox_events.wait_id
293
+ AND w.generation = outbox_events.generation
294
+ AND w.phase IN (${placeholders(DELIVERABLE_WAIT_PHASES.length)}))
295
+ GROUP BY recipient_kind, recipient_session_id, recipient_workspace, recipient_branch_id, recipient_goal_id
296
+ ORDER BY min(created_at), min(event_id)`,
297
+ ...DELIVERABLE_WAIT_PHASES,
298
+ ).map((row) => ({ recipient: ownerFromRow(row, "recipient"), count: columnNumber(row, "pending_count") }));
299
+ }
300
+
283
301
  function readDispatchClaim(row: Record<string, unknown>): OutboxDispatchClaim | null {
284
302
  return columnJson<OutboxDispatchClaim>(row, "dispatch_claim_json");
285
303
  }
@@ -58,6 +58,7 @@ import {
58
58
  } from "./waits.ts";
59
59
  import {
60
60
  claimOutbox as writeOutboxClaim,
61
+ listDispatchableOutboxRecipients as readDispatchableOutboxRecipients,
61
62
  listOutbox as readOutbox,
62
63
  markOutboxDelivered as writeOutboxDelivery,
63
64
  releaseOutbox as writeOutboxRelease,
@@ -272,6 +273,8 @@ export interface Store {
272
273
  // ---- outbox ----
273
274
 
274
275
  listOutbox(filter?: OutboxFilter): OutboxEventRecord[];
276
+ /** Lightweight dispatch candidates; evidence is read only after a claim succeeds. */
277
+ listDispatchableOutboxRecipients(): Array<{ recipient: OwnerIdentity; count: number }>;
275
278
  /** Claim pending deliveries for a `ready`/`resuming` generation. */
276
279
  claimOutbox(input: ClaimOutboxInput): OutboxEventRecord[];
277
280
  /** Mark a claimed delivery delivered; the result is still unconsumed. */
@@ -457,6 +460,10 @@ export function openStore(options: StoreOptions): Store {
457
460
  alive();
458
461
  return readOutbox(ctx, filter);
459
462
  },
463
+ listDispatchableOutboxRecipients() {
464
+ alive();
465
+ return readDispatchableOutboxRecipients(ctx);
466
+ },
460
467
  claimOutbox(input) {
461
468
  alive();
462
469
  return writeOutboxClaim(ctx, input);
@@ -45,6 +45,7 @@ import {
45
45
  isValidTaskId,
46
46
  normalizeToolDescriptors,
47
47
  normalizeWaitForOperationsResult,
48
+ requiresParkCheckpoint,
48
49
  operationBridgeErrorBody,
49
50
  redactSecret,
50
51
  validateCheckpointParams,
@@ -890,7 +891,7 @@ export async function createOperationBridgeHost(
890
891
  if (tool === "wait_for_operations") {
891
892
  const wait = normalizeWaitForOperationsResult(cloned);
892
893
  if (!wait.ok) throw new OperationBridgeError("response-invalid", wait.message);
893
- if (wait.result.park && !wait.result.settled) {
894
+ if (requiresParkCheckpoint(wait.result)) {
894
895
  run.issuedWaits.set(wait.result.waitId, {
895
896
  generation: wait.result.generation,
896
897
  requestId: envelope.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-harness",
3
- "version": "0.45.3",
3
+ "version": "0.45.5",
4
4
  "description": "Pi extension bundle for a write sandbox, subagents, background tasks, SSH, goals, model routing, and Outcome & Todo.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -58,13 +58,13 @@
58
58
  "test": "node --import tsx --import ../../scripts/isolate-registry.mjs --test test/*.test.mjs test/*.test.ts test/task-context/*.test.ts"
59
59
  },
60
60
  "dependencies": {
61
- "pi-better-background-tasks": "0.15.2",
61
+ "pi-better-background-tasks": "0.15.3",
62
62
  "pi-better-goal": "0.13.1",
63
63
  "pi-better-model-router": "0.1.4",
64
64
  "pi-ollama-cloud": "0.13.1",
65
65
  "pi-better-sandbox": "0.14.1",
66
66
  "pi-better-ssh": "0.1.5",
67
- "pi-better-subagents": "0.32.2",
67
+ "pi-better-subagents": "0.32.4",
68
68
  "proper-lockfile": "^4.1.2",
69
69
  "shell-quote": "1.12.0",
70
70
  "smol-toml": "1.9.0",