pi-better-server 0.5.0 → 0.6.0
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/package.json +4 -1
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +37 -5
- package/scripts/event-publication/writer.mjs +3 -8
- package/scripts/measure-full-runtime/probe.mjs +4 -2
- package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
- package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
- package/scripts/measure-shared-reads.mjs +2 -1
- package/scripts/private-runtime/package-lock.json +18 -0
- package/scripts/private-runtime/package.json +4 -1
- package/scripts/source-provenance.mjs +2 -2
- package/scripts/test-on-pi.sh +2 -9
- package/src/handshake.ts +1 -1
- package/src/hosted-session.ts +32 -4
- package/src/maintenance.ts +35 -7
- package/src/registry.ts +28 -4
- package/src/runtime/attempt-invalidation.ts +54 -0
- package/src/runtime/background-history.ts +151 -45
- package/src/runtime/background-policy.ts +9 -4
- package/src/runtime/background-tools.ts +131 -23
- package/src/runtime/background.ts +351 -68
- package/src/runtime/cancellation.ts +28 -7
- package/src/runtime/catalog-sources.ts +199 -0
- package/src/runtime/catalog.ts +53 -21
- package/src/runtime/client.ts +22 -2
- package/src/runtime/domain/assignment-inbox.mjs +119 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +43 -35
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +3 -3
- package/src/runtime/domain/background/registry.mjs +61 -3
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +1 -1
- package/src/runtime/domain/background-service/adapter-contract.ts +1 -1
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +35 -16
- package/src/runtime/domain/background-service/goal-provider.ts +31 -16
- package/src/runtime/domain/background-service/index.domain.mjs +6 -9
- package/src/runtime/domain/background-service/index.ts +6 -9
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +6 -3
- package/src/runtime/domain/background-service/managed-authority.ts +5 -3
- package/src/runtime/domain/background-service/managed-client.domain.mjs +21 -7
- package/src/runtime/domain/background-service/managed-client.ts +20 -7
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +75 -17
- package/src/runtime/domain/background-service/managed-frontend.ts +62 -17
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +16 -5
- package/src/runtime/domain/background-service/navigator-provider.ts +15 -5
- package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
- package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +170 -27
- package/src/runtime/domain/background-service/observed-waits.ts +154 -30
- package/src/runtime/domain/background-service/process-identity.domain.mjs +20 -2
- package/src/runtime/domain/background-service/process-identity.ts +18 -2
- package/src/runtime/domain/background-service/process.domain.mjs +3 -3
- package/src/runtime/domain/background-service/process.ts +3 -3
- package/src/runtime/domain/background-service/registry.domain.mjs +61 -3
- package/src/runtime/domain/background-service/registry.ts +53 -5
- package/src/runtime/domain/background-service/runtime.domain.mjs +32 -16
- package/src/runtime/domain/background-service/runtime.ts +19 -9
- package/src/runtime/domain/background-service/sandbox.domain.mjs +14 -15
- package/src/runtime/domain/background-service/sandbox.ts +14 -11
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +218 -13
- package/src/runtime/domain/background-service/shared-navigator.ts +197 -14
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +21 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +34 -8
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/background-service/shared-work-client.mjs +174 -7
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +3 -3
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +1 -1
- package/src/runtime/domain/background-service/task-diagnostics.ts +1 -1
- package/src/runtime/domain/background-service/tools.domain.mjs +31 -24
- package/src/runtime/domain/background-service/tools.ts +41 -38
- package/src/runtime/domain/background-service/types.domain.mjs +1 -0
- package/src/runtime/domain/background-service/types.ts +3 -1
- package/src/runtime/domain/background-service/work-observation.domain.mjs +46 -20
- package/src/runtime/domain/background-service/work-observation.ts +46 -19
- package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
- package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
- package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +11 -2
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +42 -21
- package/src/runtime/domain/coordinator/src/store.mjs +21 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +23 -1
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +50 -5
- package/src/runtime/domain/sandbox-policy/README.md +61 -63
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +11 -8
- package/src/runtime/domain/sandbox-policy/commands.ts +12 -7
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +53 -9
- package/src/runtime/domain/sandbox-policy/index.ts +52 -9
- package/src/runtime/domain/sandbox-policy/package.json +1 -1
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +5 -2
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +9 -2
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +56 -137
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +52 -130
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +1 -6
- package/src/runtime/domain/sandbox-policy/permissions.ts +1 -6
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +12 -1
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/README.md +1 -1
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +12 -6
- package/src/runtime/domain/subagents/assignment-outcomes.ts +11 -5
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +87 -24
- package/src/runtime/domain/subagents/assignment-report.ts +83 -19
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +21 -3
- package/src/runtime/domain/subagents/catalog-host-admission.ts +19 -3
- package/src/runtime/domain/subagents/catalog-preferences.ts +1 -1
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +35 -1
- package/src/runtime/domain/subagents/catalog-resolver.ts +35 -1
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +20 -22
- package/src/runtime/domain/subagents/catalog-store.ts +27 -20
- package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
- package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +27 -15
- package/src/runtime/domain/subagents/child-operations.domain.mjs +80 -2
- package/src/runtime/domain/subagents/child-operations.ts +80 -1
- package/src/runtime/domain/subagents/child-preflight.mjs +9 -2
- package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
- package/src/runtime/domain/subagents/child-process-list.ts +8 -0
- package/src/runtime/domain/subagents/config.domain.mjs +49 -2
- package/src/runtime/domain/subagents/config.ts +46 -2
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +5 -1
- package/src/runtime/domain/subagents/continuation-authority.ts +3 -1
- package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
- package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
- package/src/runtime/domain/subagents/extensions.mjs +11 -13
- package/src/runtime/domain/subagents/finalization.domain.mjs +12 -0
- package/src/runtime/domain/subagents/finalization.ts +15 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +44 -2
- package/src/runtime/domain/subagents/goal-provider.ts +44 -2
- package/src/runtime/domain/subagents/health-observation.domain.mjs +189 -190
- package/src/runtime/domain/subagents/health-observation.ts +43 -48
- package/src/runtime/domain/subagents/index.domain.mjs +296 -123
- package/src/runtime/domain/subagents/index.ts +257 -98
- package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
- package/src/runtime/domain/subagents/launch-context.ts +23 -0
- package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +85 -16
- package/src/runtime/domain/subagents/log-cursor.ts +91 -15
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +2 -2
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +6 -3
- package/src/runtime/domain/subagents/managed-launch-client.ts +6 -3
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +222 -14
- package/src/runtime/domain/subagents/managed-launch-host.ts +168 -15
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +1 -5
- package/src/runtime/domain/subagents/managed-launch-port.ts +4 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +27 -2
- package/src/runtime/domain/subagents/operation-bridge-types.ts +27 -2
- package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
- package/src/runtime/domain/subagents/owned-exit.ts +12 -0
- package/src/runtime/domain/subagents/package.json +1 -1
- package/src/runtime/domain/subagents/parse.domain.mjs +50 -5
- package/src/runtime/domain/subagents/parse.ts +48 -6
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +32 -8
- package/src/runtime/domain/subagents/permission-policy.ts +41 -8
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +47 -33
- package/src/runtime/domain/subagents/registry.ts +54 -33
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +6 -23
- package/src/runtime/domain/subagents/shared-catalog.ts +6 -14
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +218 -13
- package/src/runtime/domain/subagents/shared-navigator.ts +197 -14
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +21 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +34 -8
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/subagents/shared-task-exec.ts +12 -1
- package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/subagents/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/subagents/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/shared-work-client.mjs +174 -7
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +22 -38
- package/src/runtime/domain/subagents/subagent-tools.ts +28 -34
- package/src/runtime/domain/subagents/task-policy.domain.mjs +1 -1
- package/src/runtime/domain/subagents/task-policy.ts +3 -1
- package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
- package/src/runtime/domain/subagents/timing.ts +10 -1
- package/src/runtime/domain/subagents/work-observation.domain.mjs +77 -16
- package/src/runtime/domain/subagents/work-observation.ts +71 -16
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +9 -4
- package/src/runtime/domain/subagents/worker-operations-host.ts +12 -4
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +89 -35
- package/src/runtime/domain/subagents/worker-waits.ts +93 -34
- package/src/runtime/health-config.ts +27 -11
- package/src/runtime/log-checkpoints.ts +117 -0
- package/src/runtime/mutation-store.ts +5 -4
- package/src/runtime/queries.ts +25 -2
- package/src/runtime/query-executor.ts +149 -28
- package/src/runtime/query-worker.mjs +106 -21
- package/src/runtime/read-model.ts +846 -120
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +11 -4
- package/src/runtime/work-budget.ts +130 -0
- package/src/runtime/work-client.d.mts +8 -0
- package/src/runtime/work-client.mjs +150 -7
- package/src/server.ts +104 -23
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -29,15 +29,15 @@ import { randomUUID } from "node:crypto";
|
|
|
29
29
|
import { managedWorkerBridge } from "./managed-worker-bridge.domain.mjs";
|
|
30
30
|
import { realpathSync } from "node:fs";
|
|
31
31
|
import { join } from "node:path";
|
|
32
|
-
import { OPERATIONS_ATTEMPT_ID_ENV, OPERATIONS_CHILD_ID_ENV, OPERATIONS_CONVERSATION_ID_ENV, OPERATIONS_ENABLED_ENV, OPERATIONS_ENDPOINT_ENV, OPERATIONS_RUN_ID_ENV, OPERATIONS_TOKEN_ENV, OPERATIONS_WRITER_LEASE_ID_ENV, WAIT_OPERATIONS_TOOL, createToolDescriptor, extractResultTaskIds, normalizeWaitForOperationsResult, normalizeToolDescriptors, OperationBridgeError, } from "./operation-bridge-types.domain.mjs";
|
|
32
|
+
import { OPERATIONS_ATTEMPT_ID_ENV, OPERATIONS_CHILD_ID_ENV, OPERATIONS_DEADLINE_AT_ENV, OPERATIONS_CONVERSATION_ID_ENV, OPERATIONS_ENABLED_ENV, OPERATIONS_ENDPOINT_ENV, OPERATIONS_RUN_ID_ENV, OPERATIONS_TOKEN_ENV, OPERATIONS_WRITER_LEASE_ID_ENV, WAIT_OPERATIONS_TOOL, assertWaitToolDependencies, createToolDescriptor, extractResultTaskIds, normalizeWaitForOperationsResult, normalizeToolDescriptors, OperationBridgeError, } from "./operation-bridge-types.domain.mjs";
|
|
33
33
|
import { createOperationBridgeHost, } from "./worker-operations-host.domain.mjs";
|
|
34
34
|
import { captureParkCheckpoint, verifyParkCheckpoint } from "./park-checkpoint.domain.mjs";
|
|
35
35
|
import { findSavedConversation, readConversationLease } from "./continuation.domain.mjs";
|
|
36
36
|
import { commitAssignmentTerminal, readOutcome, coordinatorPath } from "./assignment-outcomes.domain.mjs";
|
|
37
37
|
import { openStore } from "./shared-operation-coordinator/index.domain.mjs";
|
|
38
|
-
import { recordAssignmentReport } from "./assignment-report.domain.mjs";
|
|
38
|
+
import { recordAssignmentReport, recordAssignmentReportRejection } from "./assignment-report.domain.mjs";
|
|
39
39
|
import { currentSandboxPermissions } from "./permission-policy.domain.mjs";
|
|
40
|
-
import { effectiveStatus, isPendingPark, listParkRecordCandidates,
|
|
40
|
+
import { effectiveStatus, isPendingPark, listParkRecordCandidates, scanParkRecords, listPendingParkedRuns, readMeta, readParkRecord, processStartToken, updateParkRecord, writeParkRecord, writeMeta, } from "./registry.domain.mjs";
|
|
41
41
|
import { processExists } from "./spawn.domain.mjs";
|
|
42
42
|
import { realProcessProbe } from "./health.domain.mjs";
|
|
43
43
|
import { stopRun } from "./stop.domain.mjs";
|
|
@@ -327,22 +327,22 @@ export function planWorkerBridgeTools(input) {
|
|
|
327
327
|
}
|
|
328
328
|
tools.push(name);
|
|
329
329
|
}
|
|
330
|
+
if (tools.includes(WAIT_OPERATIONS_TOOL)
|
|
331
|
+
&& (!tools.includes("acknowledge_operation_result") || !tools.some(name => name === "bg_task_status" || name === "bg_task_log"))
|
|
332
|
+
&& !(input.explicitTools && allow.has(WAIT_OPERATIONS_TOOL))) {
|
|
333
|
+
tools.splice(tools.indexOf(WAIT_OPERATIONS_TOOL), 1);
|
|
334
|
+
withheld.push({ name: WAIT_OPERATIONS_TOOL, reason: "the authorized tools cannot read and acknowledge terminal evidence" });
|
|
335
|
+
}
|
|
330
336
|
const has = (name) => tools.includes(name);
|
|
337
|
+
const capabilities = {
|
|
338
|
+
background: { spawn: has("bg_task_spawn"), watch: has("bg_task_watch"), status: has("bg_task_status"), log: has("bg_task_log") },
|
|
339
|
+
wait: has(WAIT_OPERATIONS_TOOL), acknowledge: has("acknowledge_operation_result"), parking: has(WAIT_OPERATIONS_TOOL),
|
|
340
|
+
};
|
|
341
|
+
assertWaitToolDependencies(capabilities, tools);
|
|
331
342
|
return {
|
|
332
343
|
tools,
|
|
333
344
|
withheld,
|
|
334
|
-
capabilities
|
|
335
|
-
background: {
|
|
336
|
-
spawn: has("bg_task_spawn"),
|
|
337
|
-
watch: has("bg_task_watch"),
|
|
338
|
-
status: has("bg_task_status"),
|
|
339
|
-
log: has("bg_task_log"),
|
|
340
|
-
},
|
|
341
|
-
wait: has(WAIT_OPERATIONS_TOOL),
|
|
342
|
-
acknowledge: has("acknowledge_operation_result"),
|
|
343
|
-
// The bridge derives `wait_for_operations` from `wait && parking`.
|
|
344
|
-
parking: has(WAIT_OPERATIONS_TOOL),
|
|
345
|
-
},
|
|
345
|
+
capabilities,
|
|
346
346
|
};
|
|
347
347
|
}
|
|
348
348
|
/** Production tool descriptors for bridge tools, from the parent's registrations. */
|
|
@@ -442,6 +442,7 @@ function scopeOf(registration) {
|
|
|
442
442
|
return {
|
|
443
443
|
runId: registration.runId,
|
|
444
444
|
conversationId: registration.conversationId,
|
|
445
|
+
...(registration.assignment && registration.attemptId ? { assignmentAttemptId: registration.attemptId } : {}),
|
|
445
446
|
workspace: registration.workspace,
|
|
446
447
|
authorityReference: registration.authorityReference,
|
|
447
448
|
branchId: registration.branchId ?? null,
|
|
@@ -506,6 +507,7 @@ export function createWorkerOperationsHost(options) {
|
|
|
506
507
|
return capability.service;
|
|
507
508
|
};
|
|
508
509
|
const register = async (registration) => {
|
|
510
|
+
assertWaitToolDependencies(registration.capabilities, registration.tools);
|
|
509
511
|
const supervised = registration.tools.some((name) => name !== "report_assignment_result");
|
|
510
512
|
if (supervised && !capability.available) {
|
|
511
513
|
const ready = await start();
|
|
@@ -536,6 +538,7 @@ export function createWorkerOperationsHost(options) {
|
|
|
536
538
|
tools: [...registration.tools],
|
|
537
539
|
capabilities: registration.capabilities,
|
|
538
540
|
assignmentOutcomesVersion: 1,
|
|
541
|
+
assignmentTaskOwnership: registration.assignment !== undefined,
|
|
539
542
|
owner,
|
|
540
543
|
...(registration.writerLeaseId ? { writerLeaseId: registration.writerLeaseId } : {}),
|
|
541
544
|
}) : { assignmentOutcomesVersion: 1 };
|
|
@@ -561,8 +564,9 @@ export function createWorkerOperationsHost(options) {
|
|
|
561
564
|
}
|
|
562
565
|
};
|
|
563
566
|
const handlers = {};
|
|
567
|
+
let onToolRejected;
|
|
564
568
|
if (registration.capabilities.reportAssignment && registration.assignment) {
|
|
565
|
-
|
|
569
|
+
const assertReportAuthority = (context) => {
|
|
566
570
|
const live = host.getRun(registration.runId);
|
|
567
571
|
const meta = readMeta(registration.runId);
|
|
568
572
|
if (!live || live.revoked || live.tokenGeneration !== context.tokenGeneration || context.signal.aborted
|
|
@@ -593,7 +597,22 @@ export function createWorkerOperationsHost(options) {
|
|
|
593
597
|
}
|
|
594
598
|
}
|
|
595
599
|
return meta;
|
|
596
|
-
}
|
|
600
|
+
};
|
|
601
|
+
handlers.report_assignment_result = async (params, context) => {
|
|
602
|
+
let permissions;
|
|
603
|
+
try {
|
|
604
|
+
permissions = currentSandboxPermissions(options.pi);
|
|
605
|
+
}
|
|
606
|
+
catch (error) {
|
|
607
|
+
recordAssignmentReportRejection(reasonOf(error), () => assertReportAuthority(context));
|
|
608
|
+
throw error;
|
|
609
|
+
}
|
|
610
|
+
return recordAssignmentReport(registration.runId, params, () => assertReportAuthority(context), permissions);
|
|
611
|
+
};
|
|
612
|
+
onToolRejected = (error, context) => {
|
|
613
|
+
if (context.tool === "report_assignment_result")
|
|
614
|
+
recordAssignmentReportRejection(error.message, () => assertReportAuthority(context));
|
|
615
|
+
};
|
|
597
616
|
}
|
|
598
617
|
const execute = (tool, params) => rpc.call("execute-tool", {
|
|
599
618
|
runId: registration.runId,
|
|
@@ -662,7 +681,7 @@ export function createWorkerOperationsHost(options) {
|
|
|
662
681
|
note: typeof params.note === "string" ? params.note : "",
|
|
663
682
|
owner,
|
|
664
683
|
});
|
|
665
|
-
const parked = parkedWaitByGeneration(waitId, generation);
|
|
684
|
+
const parked = await parkedWaitByGeneration(waitId, generation);
|
|
666
685
|
if (parked)
|
|
667
686
|
updateParkRecord(parked.runId, { phase: "consumed" });
|
|
668
687
|
return view;
|
|
@@ -777,6 +796,7 @@ export function createWorkerOperationsHost(options) {
|
|
|
777
796
|
tools: normalizeToolDescriptors(registration.schemas, registration.capabilities),
|
|
778
797
|
ownership: (taskId) => ownsTask(taskId),
|
|
779
798
|
handlers,
|
|
799
|
+
onToolRejected,
|
|
780
800
|
});
|
|
781
801
|
durable?.save(registration, handle.token);
|
|
782
802
|
return {
|
|
@@ -842,6 +862,7 @@ export function childEnvironment(token, endpoint, registration) {
|
|
|
842
862
|
[OPERATIONS_CONVERSATION_ID_ENV]: registration.conversationId,
|
|
843
863
|
[OPERATIONS_ATTEMPT_ID_ENV]: registration.attemptId,
|
|
844
864
|
[OPERATIONS_CHILD_ID_ENV]: `${registration.runId}:${randomUUID()}`,
|
|
865
|
+
...(registration.policy ? { [OPERATIONS_DEADLINE_AT_ENV]: String(registration.policy.deadlineAt ?? 0) } : {}),
|
|
845
866
|
};
|
|
846
867
|
}
|
|
847
868
|
/** Writer-lease id for a parked attempt, when the continuation path holds one. */
|
|
@@ -1111,8 +1132,9 @@ export async function requestResumeAdmission(pi, owner, options = {}) {
|
|
|
1111
1132
|
clearTimeout(timer);
|
|
1112
1133
|
resolve(value);
|
|
1113
1134
|
};
|
|
1114
|
-
|
|
1135
|
+
let timer = setTimeout(() => finish(null), timeoutMs);
|
|
1115
1136
|
timer.unref?.();
|
|
1137
|
+
let pending = false;
|
|
1116
1138
|
const request = {
|
|
1117
1139
|
version: 1,
|
|
1118
1140
|
owner: {
|
|
@@ -1121,6 +1143,15 @@ export async function requestResumeAdmission(pi, owner, options = {}) {
|
|
|
1121
1143
|
branchId: owner.branchId,
|
|
1122
1144
|
goalId: owner.goalId,
|
|
1123
1145
|
},
|
|
1146
|
+
pending: () => {
|
|
1147
|
+
if (pending || settled || options.pendingTimeoutMs === undefined)
|
|
1148
|
+
return;
|
|
1149
|
+
pending = true;
|
|
1150
|
+
clearTimeout(timer);
|
|
1151
|
+
const budget = Math.max(timeoutMs, Math.min(60_000, options.pendingTimeoutMs));
|
|
1152
|
+
timer = setTimeout(() => finish({ allowed: false, reason: `Workflow admission did not answer within ${budget} ms`, revision: 0 }), budget);
|
|
1153
|
+
timer.unref?.();
|
|
1154
|
+
},
|
|
1124
1155
|
reply: (gate) => {
|
|
1125
1156
|
if (!gate || typeof gate.allowed !== "boolean") {
|
|
1126
1157
|
finish({ allowed: false, reason: "Goal returned a malformed resume admission", revision: -1 });
|
|
@@ -1175,13 +1206,14 @@ export function parkedWaits() {
|
|
|
1175
1206
|
return parked;
|
|
1176
1207
|
}
|
|
1177
1208
|
export function parkedWaitForRun(runId) {
|
|
1178
|
-
|
|
1209
|
+
const meta = readMeta(runId);
|
|
1210
|
+
const record = meta && readParkRecord(runId);
|
|
1211
|
+
return meta && record && isPendingPark(record) ? parkedEntry(meta, record) : null;
|
|
1179
1212
|
}
|
|
1180
1213
|
/** A parked attempt's record for one wait generation, in any phase. */
|
|
1181
|
-
export function parkedWaitByGeneration(waitId, generation) {
|
|
1182
|
-
for (const meta of
|
|
1183
|
-
|
|
1184
|
-
if (!record || record.waitId !== waitId || record.generation !== generation)
|
|
1214
|
+
export async function parkedWaitByGeneration(waitId, generation) {
|
|
1215
|
+
for await (const { meta, record } of scanParkRecords()) {
|
|
1216
|
+
if (record.waitId !== waitId || record.generation !== generation)
|
|
1185
1217
|
continue;
|
|
1186
1218
|
return parkedEntry(meta, record);
|
|
1187
1219
|
}
|
|
@@ -1585,20 +1617,31 @@ export function createResumeOrchestration(options) {
|
|
|
1585
1617
|
}
|
|
1586
1618
|
};
|
|
1587
1619
|
const resume = (park) => options.dispatch
|
|
1588
|
-
? options.dispatch(park, () => resumeInScope(park))
|
|
1620
|
+
? options.dispatch(park, () => resumeInScope(park)).catch(error => hold(park, reasonOf(error)))
|
|
1589
1621
|
: resumeInScope(park);
|
|
1590
1622
|
const adapter = {
|
|
1591
1623
|
version: 1,
|
|
1592
1624
|
id: `subagents-continuation:${randomUUID()}`,
|
|
1593
1625
|
async onWaitReady(event) {
|
|
1594
|
-
|
|
1626
|
+
let park;
|
|
1627
|
+
if (event.parkedAttemptId !== undefined) {
|
|
1628
|
+
const meta = readMeta(event.parkedAttemptId);
|
|
1629
|
+
const record = meta && readParkRecord(meta.id);
|
|
1630
|
+
if (!meta || meta.sessionId !== event.owner.sessionId || !record
|
|
1631
|
+
|| record.waitId !== event.waitId || record.generation !== event.generation)
|
|
1632
|
+
return "deferred";
|
|
1633
|
+
park = parkedEntry(meta, record);
|
|
1634
|
+
}
|
|
1635
|
+
else {
|
|
1636
|
+
park = await parkedWaitByGeneration(event.waitId, event.generation);
|
|
1637
|
+
}
|
|
1595
1638
|
if (!park)
|
|
1596
1639
|
return "delivered";
|
|
1597
1640
|
const outcome = await resume(park);
|
|
1598
1641
|
return outcome === "skipped" ? "deferred" : "delivered";
|
|
1599
1642
|
},
|
|
1600
1643
|
async onWaitCancelled(event) {
|
|
1601
|
-
const park = parkedWaitByGeneration(event.waitId, event.generation);
|
|
1644
|
+
const park = await parkedWaitByGeneration(event.waitId, event.generation);
|
|
1602
1645
|
if (!park || park.record.phase === "cancelled")
|
|
1603
1646
|
return;
|
|
1604
1647
|
const cancellation = await stopPublishedAttempt(park, event.reason, options.stopAttempt, options.now);
|
|
@@ -1839,7 +1882,21 @@ export function conversationWriterLeaseLive(sessionId, probe = { pidExists: proc
|
|
|
1839
1882
|
* remain unchanged, even if writer exit cannot yet be proved.
|
|
1840
1883
|
*/
|
|
1841
1884
|
export async function settleResumedAttemptExit(input) {
|
|
1842
|
-
|
|
1885
|
+
if (input.priorPark) {
|
|
1886
|
+
const { runId, waitId, generation } = input.priorPark;
|
|
1887
|
+
const meta = readMeta(runId);
|
|
1888
|
+
const record = meta && readParkRecord(runId);
|
|
1889
|
+
if (!meta || !record || record.waitId !== waitId || record.generation !== generation || record.resumedBy !== input.attemptId) {
|
|
1890
|
+
return { outcome: "ignored" };
|
|
1891
|
+
}
|
|
1892
|
+
return settleResumedAttemptExitForParks(input, [parkedEntry(meta, record)]);
|
|
1893
|
+
}
|
|
1894
|
+
const candidates = [];
|
|
1895
|
+
for await (const { meta, record } of scanParkRecords()) {
|
|
1896
|
+
if (record.resumedBy === input.attemptId)
|
|
1897
|
+
candidates.push(parkedEntry(meta, record));
|
|
1898
|
+
}
|
|
1899
|
+
return settleResumedAttemptExitForParks(input, candidates);
|
|
1843
1900
|
}
|
|
1844
1901
|
async function settleResumedAttemptExitForParks(input, candidates) {
|
|
1845
1902
|
if (candidates.length === 0)
|
|
@@ -2100,14 +2157,11 @@ export async function reconcileParkedWaits(service, outerOptions) {
|
|
|
2100
2157
|
// Consumed waits cannot resume, but a missed exit observer may have left
|
|
2101
2158
|
// their published writer claim behind. Reconcile that exact claim once.
|
|
2102
2159
|
const candidates = [];
|
|
2103
|
-
for (const meta of
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
&& snapshot.resumeClaimId && snapshot.resumeExitReconciledClaimId !== snapshot.resumeClaimId)))
|
|
2160
|
+
for await (const { meta, record } of scanParkRecords()) {
|
|
2161
|
+
if (!isPendingPark(record) && !(record.phase === "consumed" && record.resumedBy
|
|
2162
|
+
&& record.resumeClaimId && record.resumeExitReconciledClaimId !== record.resumeClaimId))
|
|
2107
2163
|
continue;
|
|
2108
|
-
|
|
2109
|
-
if (record)
|
|
2110
|
-
candidates.push(parkedEntry(meta, record));
|
|
2164
|
+
candidates.push(parkedEntry(meta, record));
|
|
2111
2165
|
}
|
|
2112
2166
|
// Release earlier writers before admitting later waits in the conversation.
|
|
2113
2167
|
candidates.sort((a, b) => a.record.parkedAt - b.record.parkedAt);
|
|
@@ -32,6 +32,7 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
32
32
|
import {
|
|
33
33
|
OPERATIONS_ATTEMPT_ID_ENV,
|
|
34
34
|
OPERATIONS_CHILD_ID_ENV,
|
|
35
|
+
OPERATIONS_DEADLINE_AT_ENV,
|
|
35
36
|
OPERATIONS_CONVERSATION_ID_ENV,
|
|
36
37
|
OPERATIONS_ENABLED_ENV,
|
|
37
38
|
OPERATIONS_ENDPOINT_ENV,
|
|
@@ -39,6 +40,7 @@ import {
|
|
|
39
40
|
OPERATIONS_TOKEN_ENV,
|
|
40
41
|
OPERATIONS_WRITER_LEASE_ID_ENV,
|
|
41
42
|
WAIT_OPERATIONS_TOOL,
|
|
43
|
+
assertWaitToolDependencies,
|
|
42
44
|
createToolDescriptor,
|
|
43
45
|
extractResultTaskIds,
|
|
44
46
|
normalizeWaitForOperationsResult,
|
|
@@ -55,17 +57,20 @@ import {
|
|
|
55
57
|
type OperationBridgeLogger,
|
|
56
58
|
type OperationRunHandlers,
|
|
57
59
|
type OperationRunInfo,
|
|
60
|
+
type OperationRequestContext,
|
|
61
|
+
type OperationRunRegistration,
|
|
58
62
|
} from "./worker-operations-host.ts";
|
|
59
63
|
import { captureParkCheckpoint, verifyParkCheckpoint, type ParkCheckpoint } from "./park-checkpoint.ts";
|
|
60
64
|
import { findSavedConversation, readConversationLease } from "./continuation.ts";
|
|
61
65
|
import { commitAssignmentTerminal, readOutcome, coordinatorPath, type AssignmentBinding } from "./assignment-outcomes.ts";
|
|
62
66
|
import { openStore } from "./shared-operation-coordinator/index.ts";
|
|
63
|
-
import { recordAssignmentReport } from "./assignment-report.ts";
|
|
67
|
+
import { recordAssignmentReport, recordAssignmentReportRejection } from "./assignment-report.ts";
|
|
64
68
|
import { currentSandboxPermissions } from "./permission-policy.ts";
|
|
65
69
|
import {
|
|
66
70
|
effectiveStatus,
|
|
67
71
|
isPendingPark,
|
|
68
72
|
listParkRecordCandidates,
|
|
73
|
+
scanParkRecords,
|
|
69
74
|
listMetas,
|
|
70
75
|
listPendingParkedRuns,
|
|
71
76
|
readMeta,
|
|
@@ -328,6 +333,7 @@ export interface WorkerAcknowledgeView {
|
|
|
328
333
|
export interface WorkerWaitReadyEvent {
|
|
329
334
|
readonly waitId: string;
|
|
330
335
|
readonly generation: number;
|
|
336
|
+
readonly parkedAttemptId?: string;
|
|
331
337
|
readonly owner: { kind: string; sessionId: string; workspace: string; branchId?: string | null; goalId?: string | null };
|
|
332
338
|
readonly parentOrigin?: { cwd: string; sessionId?: string };
|
|
333
339
|
readonly taskIds: readonly string[];
|
|
@@ -651,22 +657,22 @@ export function planWorkerBridgeTools(input: {
|
|
|
651
657
|
}
|
|
652
658
|
tools.push(name);
|
|
653
659
|
}
|
|
660
|
+
if (tools.includes(WAIT_OPERATIONS_TOOL)
|
|
661
|
+
&& (!tools.includes("acknowledge_operation_result") || !tools.some(name => name === "bg_task_status" || name === "bg_task_log"))
|
|
662
|
+
&& !(input.explicitTools && allow.has(WAIT_OPERATIONS_TOOL))) {
|
|
663
|
+
tools.splice(tools.indexOf(WAIT_OPERATIONS_TOOL), 1);
|
|
664
|
+
withheld.push({ name: WAIT_OPERATIONS_TOOL, reason: "the authorized tools cannot read and acknowledge terminal evidence" });
|
|
665
|
+
}
|
|
654
666
|
const has = (name: OperationBridgeToolName): boolean => tools.includes(name);
|
|
667
|
+
const capabilities = {
|
|
668
|
+
background: { spawn: has("bg_task_spawn"), watch: has("bg_task_watch"), status: has("bg_task_status"), log: has("bg_task_log") },
|
|
669
|
+
wait: has(WAIT_OPERATIONS_TOOL), acknowledge: has("acknowledge_operation_result"), parking: has(WAIT_OPERATIONS_TOOL),
|
|
670
|
+
};
|
|
671
|
+
assertWaitToolDependencies(capabilities, tools);
|
|
655
672
|
return {
|
|
656
673
|
tools,
|
|
657
674
|
withheld,
|
|
658
|
-
capabilities
|
|
659
|
-
background: {
|
|
660
|
-
spawn: has("bg_task_spawn"),
|
|
661
|
-
watch: has("bg_task_watch"),
|
|
662
|
-
status: has("bg_task_status"),
|
|
663
|
-
log: has("bg_task_log"),
|
|
664
|
-
},
|
|
665
|
-
wait: has(WAIT_OPERATIONS_TOOL),
|
|
666
|
-
acknowledge: has("acknowledge_operation_result"),
|
|
667
|
-
// The bridge derives `wait_for_operations` from `wait && parking`.
|
|
668
|
-
parking: has(WAIT_OPERATIONS_TOOL),
|
|
669
|
-
},
|
|
675
|
+
capabilities,
|
|
670
676
|
};
|
|
671
677
|
}
|
|
672
678
|
|
|
@@ -860,6 +866,8 @@ export interface WorkerOperationsHost {
|
|
|
860
866
|
|
|
861
867
|
function scopeOf(registration: {
|
|
862
868
|
runId: string;
|
|
869
|
+
attemptId?: string;
|
|
870
|
+
assignment?: AssignmentBinding;
|
|
863
871
|
conversationId: string;
|
|
864
872
|
workspace: string;
|
|
865
873
|
authorityReference: string;
|
|
@@ -869,6 +877,7 @@ function scopeOf(registration: {
|
|
|
869
877
|
return {
|
|
870
878
|
runId: registration.runId,
|
|
871
879
|
conversationId: registration.conversationId,
|
|
880
|
+
...(registration.assignment && registration.attemptId ? { assignmentAttemptId: registration.attemptId } : {}),
|
|
872
881
|
workspace: registration.workspace,
|
|
873
882
|
authorityReference: registration.authorityReference,
|
|
874
883
|
branchId: registration.branchId ?? null,
|
|
@@ -937,6 +946,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
937
946
|
};
|
|
938
947
|
|
|
939
948
|
const register = async (registration: WorkerOperationRegistration): Promise<WorkerOperationHandle> => {
|
|
949
|
+
assertWaitToolDependencies(registration.capabilities, registration.tools);
|
|
940
950
|
const supervised = registration.tools.some((name) => name !== "report_assignment_result");
|
|
941
951
|
if (supervised && !capability.available) {
|
|
942
952
|
const ready = await start();
|
|
@@ -966,6 +976,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
966
976
|
tools: [...registration.tools],
|
|
967
977
|
capabilities: registration.capabilities as unknown as JsonRecord,
|
|
968
978
|
assignmentOutcomesVersion: 1,
|
|
979
|
+
assignmentTaskOwnership: registration.assignment !== undefined,
|
|
969
980
|
owner,
|
|
970
981
|
...(registration.writerLeaseId ? { writerLeaseId: registration.writerLeaseId } : {}),
|
|
971
982
|
}) : { assignmentOutcomesVersion: 1 };
|
|
@@ -988,8 +999,9 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
988
999
|
}
|
|
989
1000
|
};
|
|
990
1001
|
const handlers: OperationRunHandlers = {};
|
|
1002
|
+
let onToolRejected: OperationRunRegistration["onToolRejected"];
|
|
991
1003
|
if (registration.capabilities.reportAssignment && registration.assignment) {
|
|
992
|
-
|
|
1004
|
+
const assertReportAuthority = (context: OperationRequestContext): RunMeta => {
|
|
993
1005
|
const live = host.getRun(registration.runId);
|
|
994
1006
|
const meta = readMeta(registration.runId);
|
|
995
1007
|
if (!live || live.revoked || live.tokenGeneration !== context.tokenGeneration || context.signal.aborted
|
|
@@ -1013,7 +1025,20 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
1013
1025
|
} finally { store.close(); }
|
|
1014
1026
|
}
|
|
1015
1027
|
return meta;
|
|
1016
|
-
}
|
|
1028
|
+
};
|
|
1029
|
+
handlers.report_assignment_result = async (params, context) => {
|
|
1030
|
+
let permissions: ReturnType<typeof currentSandboxPermissions>;
|
|
1031
|
+
try { permissions = currentSandboxPermissions(options.pi as never); }
|
|
1032
|
+
catch (error) {
|
|
1033
|
+
recordAssignmentReportRejection(reasonOf(error), () => assertReportAuthority(context));
|
|
1034
|
+
throw error;
|
|
1035
|
+
}
|
|
1036
|
+
return recordAssignmentReport(registration.runId, params,
|
|
1037
|
+
() => assertReportAuthority(context), permissions) as unknown as JsonRecord;
|
|
1038
|
+
};
|
|
1039
|
+
onToolRejected = (error, context) => {
|
|
1040
|
+
if (context.tool === "report_assignment_result") recordAssignmentReportRejection(error.message, () => assertReportAuthority(context));
|
|
1041
|
+
};
|
|
1017
1042
|
}
|
|
1018
1043
|
const execute = (tool: string, params: JsonRecord): Promise<JsonRecord> => rpc.call("execute-tool", {
|
|
1019
1044
|
runId: registration.runId,
|
|
@@ -1082,7 +1107,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
1082
1107
|
note: typeof params.note === "string" ? params.note : "",
|
|
1083
1108
|
owner,
|
|
1084
1109
|
}) as unknown as WorkerAcknowledgeView;
|
|
1085
|
-
const parked = parkedWaitByGeneration(waitId, generation);
|
|
1110
|
+
const parked = await parkedWaitByGeneration(waitId, generation);
|
|
1086
1111
|
if (parked) updateParkRecord(parked.runId, { phase: "consumed" });
|
|
1087
1112
|
return view;
|
|
1088
1113
|
};
|
|
@@ -1192,6 +1217,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
1192
1217
|
tools: normalizeToolDescriptors(registration.schemas, registration.capabilities),
|
|
1193
1218
|
ownership: (taskId) => ownsTask(taskId),
|
|
1194
1219
|
handlers,
|
|
1220
|
+
onToolRejected,
|
|
1195
1221
|
});
|
|
1196
1222
|
durable?.save(registration, handle.token);
|
|
1197
1223
|
return {
|
|
@@ -1247,7 +1273,7 @@ export function createWorkerOperationsHost(options: WorkerOperationsHostOptions)
|
|
|
1247
1273
|
export function childEnvironment(
|
|
1248
1274
|
token: string,
|
|
1249
1275
|
endpoint: string,
|
|
1250
|
-
registration: { runId: string; conversationId: string; attemptId: string },
|
|
1276
|
+
registration: { runId: string; conversationId: string; attemptId: string; policy?: { deadlineAt: number | null } },
|
|
1251
1277
|
): Record<string, string> {
|
|
1252
1278
|
return {
|
|
1253
1279
|
[OPERATIONS_ENABLED_ENV]: "1",
|
|
@@ -1257,6 +1283,7 @@ export function childEnvironment(
|
|
|
1257
1283
|
[OPERATIONS_CONVERSATION_ID_ENV]: registration.conversationId,
|
|
1258
1284
|
[OPERATIONS_ATTEMPT_ID_ENV]: registration.attemptId,
|
|
1259
1285
|
[OPERATIONS_CHILD_ID_ENV]: `${registration.runId}:${randomUUID()}`,
|
|
1286
|
+
...(registration.policy ? { [OPERATIONS_DEADLINE_AT_ENV]: String(registration.policy.deadlineAt ?? 0) } : {}),
|
|
1260
1287
|
};
|
|
1261
1288
|
}
|
|
1262
1289
|
|
|
@@ -1538,6 +1565,7 @@ export function ownerBindingFromContext(ctx: ExtensionContext): WaitOwnerBinding
|
|
|
1538
1565
|
export interface ResumeAdmissionRequest {
|
|
1539
1566
|
version: 1;
|
|
1540
1567
|
owner: { sessionId: string; workspace: string; branchId?: string | null; goalId?: string | null };
|
|
1568
|
+
pending?(): void;
|
|
1541
1569
|
reply(gate: { allowed: boolean; reason?: string; revision: number; isCurrent?: () => boolean }): void;
|
|
1542
1570
|
}
|
|
1543
1571
|
|
|
@@ -1552,7 +1580,7 @@ export type ResumeAdmission =
|
|
|
1552
1580
|
export async function requestResumeAdmission(
|
|
1553
1581
|
pi: unknown,
|
|
1554
1582
|
owner: WaitOwnerBinding,
|
|
1555
|
-
options: { timeoutMs?: number } = {},
|
|
1583
|
+
options: { timeoutMs?: number; pendingTimeoutMs?: number } = {},
|
|
1556
1584
|
): Promise<ResumeAdmission> {
|
|
1557
1585
|
const bus = serviceBusOf(pi);
|
|
1558
1586
|
if (!bus) {
|
|
@@ -1567,8 +1595,9 @@ export async function requestResumeAdmission(
|
|
|
1567
1595
|
clearTimeout(timer);
|
|
1568
1596
|
resolve(value);
|
|
1569
1597
|
};
|
|
1570
|
-
|
|
1598
|
+
let timer = setTimeout(() => finish(null), timeoutMs);
|
|
1571
1599
|
timer.unref?.();
|
|
1600
|
+
let pending = false;
|
|
1572
1601
|
const request: ResumeAdmissionRequest = {
|
|
1573
1602
|
version: 1,
|
|
1574
1603
|
owner: {
|
|
@@ -1577,6 +1606,14 @@ export async function requestResumeAdmission(
|
|
|
1577
1606
|
branchId: owner.branchId,
|
|
1578
1607
|
goalId: owner.goalId,
|
|
1579
1608
|
},
|
|
1609
|
+
pending: () => {
|
|
1610
|
+
if (pending || settled || options.pendingTimeoutMs === undefined) return;
|
|
1611
|
+
pending = true;
|
|
1612
|
+
clearTimeout(timer);
|
|
1613
|
+
const budget = Math.max(timeoutMs, Math.min(60_000, options.pendingTimeoutMs));
|
|
1614
|
+
timer = setTimeout(() => finish({ allowed: false, reason: `Workflow admission did not answer within ${budget} ms`, revision: 0 }), budget);
|
|
1615
|
+
timer.unref?.();
|
|
1616
|
+
},
|
|
1580
1617
|
reply: (gate) => {
|
|
1581
1618
|
if (!gate || typeof gate.allowed !== "boolean") {
|
|
1582
1619
|
finish({ allowed: false, reason: "Goal returned a malformed resume admission", revision: -1 });
|
|
@@ -1643,14 +1680,15 @@ export function parkedWaits(): ParkedWait[] {
|
|
|
1643
1680
|
}
|
|
1644
1681
|
|
|
1645
1682
|
export function parkedWaitForRun(runId: string): ParkedWait | null {
|
|
1646
|
-
|
|
1683
|
+
const meta = readMeta(runId);
|
|
1684
|
+
const record = meta && readParkRecord(runId);
|
|
1685
|
+
return meta && record && isPendingPark(record) ? parkedEntry(meta, record) : null;
|
|
1647
1686
|
}
|
|
1648
1687
|
|
|
1649
1688
|
/** A parked attempt's record for one wait generation, in any phase. */
|
|
1650
|
-
export function parkedWaitByGeneration(waitId: string, generation: number): ParkedWait | null {
|
|
1651
|
-
for (const meta of
|
|
1652
|
-
|
|
1653
|
-
if (!record || record.waitId !== waitId || record.generation !== generation) continue;
|
|
1689
|
+
export async function parkedWaitByGeneration(waitId: string, generation: number): Promise<ParkedWait | null> {
|
|
1690
|
+
for await (const { meta, record } of scanParkRecords()) {
|
|
1691
|
+
if (record.waitId !== waitId || record.generation !== generation) continue;
|
|
1654
1692
|
return parkedEntry(meta, record);
|
|
1655
1693
|
}
|
|
1656
1694
|
return null;
|
|
@@ -2130,20 +2168,29 @@ export function createResumeOrchestration(options: ResumeOrchestrationOptions):
|
|
|
2130
2168
|
};
|
|
2131
2169
|
|
|
2132
2170
|
const resume = (park: ParkedWait) => options.dispatch
|
|
2133
|
-
? options.dispatch(park, () => resumeInScope(park))
|
|
2171
|
+
? options.dispatch(park, () => resumeInScope(park)).catch(error => hold(park, reasonOf(error)))
|
|
2134
2172
|
: resumeInScope(park);
|
|
2135
2173
|
|
|
2136
2174
|
const adapter: WorkerContinuationAdapter = {
|
|
2137
2175
|
version: 1,
|
|
2138
2176
|
id: `subagents-continuation:${randomUUID()}`,
|
|
2139
2177
|
async onWaitReady(event) {
|
|
2140
|
-
|
|
2178
|
+
let park: ParkedWait | null;
|
|
2179
|
+
if (event.parkedAttemptId !== undefined) {
|
|
2180
|
+
const meta = readMeta(event.parkedAttemptId);
|
|
2181
|
+
const record = meta && readParkRecord(meta.id);
|
|
2182
|
+
if (!meta || meta.sessionId !== event.owner.sessionId || !record
|
|
2183
|
+
|| record.waitId !== event.waitId || record.generation !== event.generation) return "deferred";
|
|
2184
|
+
park = parkedEntry(meta, record);
|
|
2185
|
+
} else {
|
|
2186
|
+
park = await parkedWaitByGeneration(event.waitId, event.generation);
|
|
2187
|
+
}
|
|
2141
2188
|
if (!park) return "delivered";
|
|
2142
2189
|
const outcome = await resume(park);
|
|
2143
2190
|
return outcome === "skipped" ? "deferred" : "delivered";
|
|
2144
2191
|
},
|
|
2145
2192
|
async onWaitCancelled(event) {
|
|
2146
|
-
const park = parkedWaitByGeneration(event.waitId, event.generation);
|
|
2193
|
+
const park = await parkedWaitByGeneration(event.waitId, event.generation);
|
|
2147
2194
|
if (!park || park.record.phase === "cancelled") return;
|
|
2148
2195
|
const cancellation = await stopPublishedAttempt(park, event.reason, options.stopAttempt, options.now);
|
|
2149
2196
|
updateParkRecord(park.runId, {
|
|
@@ -2365,6 +2412,7 @@ export function isTerminalAttempt(meta: RunMeta): boolean {
|
|
|
2365
2412
|
export interface ResumedAttemptExitInput {
|
|
2366
2413
|
/** The attempt id published by the resume claim (NOT the parked attempt). */
|
|
2367
2414
|
attemptId: string;
|
|
2415
|
+
priorPark?: { runId: string; waitId: string; generation: number };
|
|
2368
2416
|
service: WorkerOperationService | undefined;
|
|
2369
2417
|
/** Recorded status for the reason text. */
|
|
2370
2418
|
status?: string;
|
|
@@ -2413,7 +2461,20 @@ export function conversationWriterLeaseLive(
|
|
|
2413
2461
|
* remain unchanged, even if writer exit cannot yet be proved.
|
|
2414
2462
|
*/
|
|
2415
2463
|
export async function settleResumedAttemptExit(input: ResumedAttemptExitInput): Promise<ResumedAttemptExitResult> {
|
|
2416
|
-
|
|
2464
|
+
if (input.priorPark) {
|
|
2465
|
+
const { runId, waitId, generation } = input.priorPark;
|
|
2466
|
+
const meta = readMeta(runId);
|
|
2467
|
+
const record = meta && readParkRecord(runId);
|
|
2468
|
+
if (!meta || !record || record.waitId !== waitId || record.generation !== generation || record.resumedBy !== input.attemptId) {
|
|
2469
|
+
return { outcome: "ignored" };
|
|
2470
|
+
}
|
|
2471
|
+
return settleResumedAttemptExitForParks(input, [parkedEntry(meta, record)]);
|
|
2472
|
+
}
|
|
2473
|
+
const candidates: ParkedWait[] = [];
|
|
2474
|
+
for await (const { meta, record } of scanParkRecords()) {
|
|
2475
|
+
if (record.resumedBy === input.attemptId) candidates.push(parkedEntry(meta, record));
|
|
2476
|
+
}
|
|
2477
|
+
return settleResumedAttemptExitForParks(input, candidates);
|
|
2417
2478
|
}
|
|
2418
2479
|
|
|
2419
2480
|
async function settleResumedAttemptExitForParks(input: ResumedAttemptExitInput, candidates: readonly ParkedWait[]): Promise<ResumedAttemptExitResult> {
|
|
@@ -2658,12 +2719,10 @@ export async function reconcileParkedWaits(
|
|
|
2658
2719
|
// Consumed waits cannot resume, but a missed exit observer may have left
|
|
2659
2720
|
// their published writer claim behind. Reconcile that exact claim once.
|
|
2660
2721
|
const candidates: ParkedWait[] = [];
|
|
2661
|
-
for (const meta of
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
const record = readParkRecord(meta.id);
|
|
2666
|
-
if (record) candidates.push(parkedEntry(meta, record));
|
|
2722
|
+
for await (const { meta, record } of scanParkRecords()) {
|
|
2723
|
+
if (!isPendingPark(record) && !(record.phase === "consumed" && record.resumedBy
|
|
2724
|
+
&& record.resumeClaimId && record.resumeExitReconciledClaimId !== record.resumeClaimId)) continue;
|
|
2725
|
+
candidates.push(parkedEntry(meta, record));
|
|
2667
2726
|
}
|
|
2668
2727
|
// Release earlier writers before admitting later waits in the conversation.
|
|
2669
2728
|
candidates.sort((a, b) => a.record.parkedAt - b.record.parkedAt);
|
|
@@ -1,27 +1,43 @@
|
|
|
1
1
|
import { readFileSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
+
import { healthThresholdsForConfig } from "./domain/health-observation.mjs";
|
|
4
5
|
|
|
5
|
-
const caches = new Map<string, { revision: string; config: any }>();
|
|
6
|
+
const caches = new Map<string, { signature: string; revision: string; config: any; reason?: string }>();
|
|
7
|
+
|
|
8
|
+
async function readNamespacedConfig(agentDir: string): Promise<unknown> {
|
|
9
|
+
const { readHarnessSetting } = await import("./domain/shared-harness-settings.mjs");
|
|
10
|
+
return readHarnessSetting("subagents", { agentDir: () => agentDir });
|
|
11
|
+
}
|
|
6
12
|
|
|
7
13
|
/** Observe user preferences without invoking the legacy settings migration. */
|
|
8
|
-
export async function readHealthConfig(agentDir: string, needed = true) {
|
|
14
|
+
export async function readHealthConfig(agentDir: string, needed = true, readNamespaced = readNamespacedConfig) {
|
|
9
15
|
const legacy = join(agentDir, "extensions/pi-better-subagents-config.json");
|
|
10
|
-
const
|
|
16
|
+
const sources = [join(agentDir, "settings.json"), legacy].map(path => {
|
|
11
17
|
try { const info = statSync(path, { bigint: true }); return [info.ino, info.size, info.mtimeNs, info.ctimeNs].map(String); }
|
|
12
18
|
catch (error) { return (error as NodeJS.ErrnoException).code; }
|
|
13
|
-
})
|
|
19
|
+
});
|
|
20
|
+
const signature = createHash("sha256").update(JSON.stringify(sources)).digest("hex");
|
|
14
21
|
// Empty inventories have no health projections; do not initialize the SDK for them.
|
|
15
|
-
if (!needed) return { revision, config: {} };
|
|
16
|
-
|
|
22
|
+
if (!needed) return { revision: "", config: {}, reason: undefined };
|
|
23
|
+
const cached = caches.get(agentDir);
|
|
24
|
+
if (cached?.signature === signature && !cached.reason) return cached;
|
|
17
25
|
let config: any = {};
|
|
26
|
+
let reason: string | undefined;
|
|
18
27
|
try {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
// No source exists to read or lock; avoid cold SDK loading for defaults.
|
|
29
|
+
if (!sources.every(value => value === "ENOENT")) {
|
|
30
|
+
config = await readNamespaced(agentDir);
|
|
31
|
+
if (config === undefined) {
|
|
32
|
+
try { config = JSON.parse(readFileSync(legacy, "utf8")); }
|
|
33
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
22
36
|
if (!config || typeof config !== "object" || Array.isArray(config)) config = {};
|
|
23
|
-
} catch { config = {}; }
|
|
24
|
-
|
|
37
|
+
} catch { config = {}; reason = "Health configuration unavailable; using domain default thresholds."; }
|
|
38
|
+
// File identity discovers edits; only effective health content invalidates tasks.
|
|
39
|
+
const revision = createHash("sha256").update(JSON.stringify(healthThresholdsForConfig(config))).digest("hex");
|
|
40
|
+
const observation = { signature, revision, config, reason }; caches.set(agentDir, observation);
|
|
25
41
|
if (caches.size > 8) caches.delete(caches.keys().next().value!);
|
|
26
42
|
return observation;
|
|
27
43
|
}
|