pi-better-server 0.5.0 → 0.7.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 +7 -3
- 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/frontend.ts +10 -2
- 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-full-runtime.mjs +2 -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 +181 -27
- package/src/runtime/background.ts +365 -70
- 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 +52 -14
- package/src/runtime/domain/background/registry.mjs +61 -3
- package/src/runtime/domain/background/supervisor/store.mjs +3 -3
- package/src/runtime/domain/background/supervisor/supervisor.mjs +9 -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 +25 -9
- package/src/runtime/domain/background-service/index.ts +25 -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 +159 -19
- package/src/runtime/domain/background-service/managed-frontend.ts +135 -19
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +21 -5
- package/src/runtime/domain/background-service/navigator-provider.ts +19 -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 +372 -57
- package/src/runtime/domain/background-service/observed-waits.ts +321 -53
- 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 +52 -14
- package/src/runtime/domain/background-service/process.ts +48 -14
- 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/review-settings.domain.mjs +16 -0
- package/src/runtime/domain/background-service/review-settings.ts +18 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +40 -86
- package/src/runtime/domain/background-service/runtime.ts +27 -82
- 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 +273 -41
- package/src/runtime/domain/background-service/shared-navigator.ts +244 -40
- 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/outbox.domain.mjs +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +9 -0
- 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 +26 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +40 -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/stall.domain.mjs +5 -3
- package/src/runtime/domain/background-service/stall.ts +7 -4
- package/src/runtime/domain/background-service/supervised-progress.domain.mjs +42 -0
- package/src/runtime/domain/background-service/supervised-progress.ts +43 -0
- package/src/runtime/domain/background-service/supervisor/README.md +1 -4
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +52 -14
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/generated/watch-fingerprint.mjs +69 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/runner.ts +38 -3
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/store.ts +3 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +9 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +6 -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 +53 -40
- package/src/runtime/domain/background-service/tools.ts +67 -54
- package/src/runtime/domain/background-service/types.domain.mjs +1 -0
- package/src/runtime/domain/background-service/types.ts +7 -3
- package/src/runtime/domain/background-service/watch-fingerprint.domain.mjs +67 -0
- package/src/runtime/domain/background-service/watch-fingerprint.ts +70 -0
- 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/outbox.mjs +7 -0
- 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 +26 -4
- 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/log-paths.mjs +8 -1
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +58 -9
- package/src/runtime/domain/sandbox-policy/README.md +63 -65
- 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/session-store.mjs +7 -0
- package/src/runtime/domain/subagents/README.md +13 -11
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +10 -7
- package/src/runtime/domain/subagents/assignment-outcomes.ts +9 -6
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +109 -24
- package/src/runtime/domain/subagents/assignment-report.ts +103 -19
- package/src/runtime/domain/subagents/batch.mjs +13 -5
- 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/cleanup.domain.mjs +11 -2
- package/src/runtime/domain/subagents/cleanup.ts +10 -2
- package/src/runtime/domain/subagents/config.domain.mjs +54 -2
- package/src/runtime/domain/subagents/config.ts +53 -3
- 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/continuation.domain.mjs +4 -2
- package/src/runtime/domain/subagents/continuation.ts +4 -2
- package/src/runtime/domain/subagents/extensions.mjs +11 -13
- package/src/runtime/domain/subagents/failures.domain.mjs +11 -2
- package/src/runtime/domain/subagents/failures.ts +10 -2
- package/src/runtime/domain/subagents/finalization.domain.mjs +16 -1
- package/src/runtime/domain/subagents/finalization.ts +21 -1
- 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 +457 -182
- package/src/runtime/domain/subagents/index.ts +417 -155
- package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +515 -0
- package/src/runtime/domain/subagents/isolated-workspace.ts +557 -0
- 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/list.mjs +2 -2
- 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 +27 -7
- package/src/runtime/domain/subagents/managed-launch-client.ts +28 -8
- 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/output-payload.domain.mjs +24 -9
- package/src/runtime/domain/subagents/output-payload.ts +26 -12
- 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 +4 -2
- package/src/runtime/domain/subagents/parse.domain.mjs +58 -9
- package/src/runtime/domain/subagents/parse.ts +57 -10
- 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 +71 -51
- package/src/runtime/domain/subagents/registry.ts +77 -38
- package/src/runtime/domain/subagents/retained-result.domain.mjs +56 -0
- package/src/runtime/domain/subagents/retained-result.ts +65 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +3 -1
- package/src/runtime/domain/subagents/session-selection.ts +2 -1
- package/src/runtime/domain/subagents/session-store.domain.mjs +7 -0
- package/src/runtime/domain/subagents/session-store.ts +9 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +151 -107
- package/src/runtime/domain/subagents/settings-page.ts +147 -108
- 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 +28 -29
- package/src/runtime/domain/subagents/shared-catalog.ts +29 -21
- 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 +273 -41
- package/src/runtime/domain/subagents/shared-navigator.ts +244 -40
- 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/outbox.domain.mjs +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +9 -0
- 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 +26 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +40 -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-guard.domain.mjs +14 -1
- package/src/runtime/domain/subagents/task-guard.ts +13 -1
- package/src/runtime/domain/subagents/task-policy.domain.mjs +3 -2
- package/src/runtime/domain/subagents/task-policy.ts +8 -2
- package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
- package/src/runtime/domain/subagents/timing.ts +10 -1
- package/src/runtime/domain/subagents/tools.domain.mjs +4 -8
- package/src/runtime/domain/subagents/tools.ts +4 -7
- package/src/runtime/domain/subagents/work-observation.domain.mjs +102 -17
- package/src/runtime/domain/subagents/work-observation.ts +91 -17
- 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/domain/subagents/workspace-files.domain.mjs +103 -0
- package/src/runtime/domain/subagents/workspace-files.ts +114 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.d.mts +38 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +5 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +6 -0
- package/src/runtime/domain/subagents/worktree-feedback.domain.mjs +55 -0
- package/src/runtime/domain/subagents/worktree-feedback.ts +77 -0
- 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 +849 -121
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/root.ts +5 -2
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdirSync, readFileSync, realpathSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { WorkClient } from "./shared-work-client.mjs";
|
|
4
|
+
import { WorkClient, connectWorkClient } from "./shared-work-client.mjs";
|
|
5
5
|
export const TERMINAL_NAVIGATOR_RETENTION_MS = 30_000;
|
|
6
6
|
|
|
7
7
|
let client: WorkClient | undefined;
|
|
@@ -10,16 +10,26 @@ let context: { agentDir: string; origin: { cwd: string; sessionId?: string } } |
|
|
|
10
10
|
let connecting: Promise<void> | undefined;
|
|
11
11
|
let collecting: Promise<void> | undefined;
|
|
12
12
|
let collectingClient: WorkClient | undefined;
|
|
13
|
+
let collectionRetry: ReturnType<typeof setTimeout> | undefined;
|
|
14
|
+
let collectionFailures = 0;
|
|
13
15
|
let dirty = false;
|
|
14
16
|
let retry: ReturnType<typeof setTimeout> | undefined;
|
|
15
17
|
let backoff = 100;
|
|
16
18
|
let failure = "Shared runtime observation is connecting.";
|
|
17
19
|
let generation = 0;
|
|
20
|
+
let connectionAbort = new AbortController();
|
|
18
21
|
const details = new Map<string, any>();
|
|
19
22
|
const pendingDetails = new Set<string>();
|
|
20
23
|
let refresh = () => {};
|
|
24
|
+
const observationListeners = new Set<() => void>();
|
|
25
|
+
export function onWorkObservation(notify: () => void) {
|
|
26
|
+
observationListeners.add(notify);
|
|
27
|
+
return () => { observationListeners.delete(notify); };
|
|
28
|
+
}
|
|
21
29
|
|
|
22
30
|
export function workObservation() { return snapshot; }
|
|
31
|
+
export function hasWorkObservationContext() { return context !== undefined; }
|
|
32
|
+
export function workObservationStarted() { return Boolean(connecting || client || retry || snapshot); }
|
|
23
33
|
export function workObservationFailure() { return snapshot?.reason ?? failure; }
|
|
24
34
|
|
|
25
35
|
function degraded(error: unknown) {
|
|
@@ -38,8 +48,9 @@ function reconnectLater(current: number) {
|
|
|
38
48
|
backoff = Math.min(2000, backoff * 2);
|
|
39
49
|
}
|
|
40
50
|
|
|
41
|
-
// Every page is bounded;
|
|
51
|
+
// Every page is bounded; a conversation anchor fences collection across filtered queries.
|
|
42
52
|
async function collect(candidate: WorkClient, current: number) {
|
|
53
|
+
if (collectionRetry) clearTimeout(collectionRetry); collectionRetry = undefined;
|
|
43
54
|
dirty = true;
|
|
44
55
|
if (collecting && collectingClient === candidate) return collecting;
|
|
45
56
|
collectingClient = candidate;
|
|
@@ -50,38 +61,71 @@ async function collect(candidate: WorkClient, current: number) {
|
|
|
50
61
|
let completed = false;
|
|
51
62
|
for (let attempt = 0; attempt < 2 && !completed; attempt++) {
|
|
52
63
|
try {
|
|
64
|
+
const anchorScope = { ...context!.origin, limit: 1 };
|
|
65
|
+
const anchor = await candidate.get(anchorScope);
|
|
53
66
|
const first = await candidate.get(scope);
|
|
54
67
|
if (current !== generation || candidate !== client) return;
|
|
55
68
|
if (first.status === "rebuilding") {
|
|
56
|
-
snapshot = { ...first, rows: snapshot?.rows ?? [] }; refresh();
|
|
69
|
+
snapshot = { ...first, rows: snapshot?.rows ?? [] }; refresh();
|
|
70
|
+
// A newer publication may already be owed while this page
|
|
71
|
+
// was in flight. Drain that demand, but never poll for it.
|
|
72
|
+
break;
|
|
57
73
|
}
|
|
58
74
|
const rows = [...first.rows];
|
|
59
75
|
let cursor = first.nextCursor;
|
|
60
76
|
while (cursor) {
|
|
61
77
|
const page = await candidate.get({ ...scope, cursor });
|
|
62
|
-
if (page.
|
|
78
|
+
if (page.scopeRevision !== first.scopeRevision || page.instanceId !== first.instanceId) throw new Error("resync_required: active pages changed");
|
|
63
79
|
rows.push(...page.rows); cursor = page.nextCursor;
|
|
64
80
|
}
|
|
65
|
-
|
|
66
|
-
|
|
81
|
+
// Cover the disconnect interval, not merely the last 30 s of
|
|
82
|
+
// worker time. The navigator starts its own visibility clock.
|
|
83
|
+
const endedAfter = Math.min(Date.now() - TERMINAL_NAVIGATOR_RETENTION_MS, snapshot?.observedAtLocal ?? Date.now());
|
|
84
|
+
const history = await candidate.get({ ...context!.origin, active: false, endedAfter, limit: 200 });
|
|
85
|
+
if (history.instanceId !== first.instanceId) throw new Error("resync_required: history changed");
|
|
67
86
|
if (current !== generation || candidate !== client) return;
|
|
68
87
|
const owed = [];
|
|
69
88
|
let owedCursor: string | undefined;
|
|
70
89
|
do {
|
|
71
90
|
const page = await candidate.get({ ...context!.origin, pendingRecipient: true, limit: 200, ...(owedCursor ? { cursor: owedCursor } : {}) });
|
|
72
|
-
if (page.
|
|
91
|
+
if (page.instanceId !== first.instanceId) throw new Error("resync_required: recipient page changed");
|
|
73
92
|
owed.push(...page.rows); owedCursor = page.nextCursor;
|
|
74
93
|
} while (owedCursor);
|
|
75
94
|
if (current !== generation || candidate !== client) return;
|
|
76
|
-
const
|
|
77
|
-
|
|
95
|
+
const historyRows = [...history.rows];
|
|
96
|
+
let historyCursor = history.nextCursor;
|
|
97
|
+
while (historyCursor) {
|
|
98
|
+
const page = await candidate.get({ ...context!.origin, active: false, endedAfter, limit: 200, cursor: historyCursor });
|
|
99
|
+
if (page.scopeRevision !== history.scopeRevision || page.instanceId !== first.instanceId) throw new Error("resync_required: history pages changed");
|
|
100
|
+
historyRows.push(...page.rows); historyCursor = page.nextCursor;
|
|
101
|
+
}
|
|
102
|
+
if (current !== generation || candidate !== client) return;
|
|
103
|
+
const confirmed = await candidate.get(anchorScope);
|
|
104
|
+
if (current !== generation || candidate !== client) return;
|
|
105
|
+
if (confirmed.instanceId !== anchor.instanceId || confirmed.scopeRevision !== anchor.scopeRevision) throw new Error("resync_required: conversation changed during collection");
|
|
106
|
+
const allRows = [...new Map([...rows, ...historyRows, ...owed].map(row => [row.meta.id, row])).values()];
|
|
107
|
+
snapshot = { ...first, seq: anchor.seq, observedRevisionVector: anchor.observedRevisionVector, rows: allRows, nextCursor: undefined,
|
|
108
|
+
observedAtLocal: Date.now(),
|
|
78
109
|
totalMatching: first.totalMatching + history.totalMatching, activity: { active: rows.length } };
|
|
110
|
+
collectionFailures = 0;
|
|
79
111
|
completed = true; refresh();
|
|
80
112
|
} catch (error) {
|
|
81
113
|
if (current !== generation || candidate !== client) return;
|
|
82
114
|
if (attempt === 1 || candidate.closed) {
|
|
83
115
|
degraded(error);
|
|
84
|
-
if (candidate.closed) return;
|
|
116
|
+
if (current !== generation || candidate !== client || candidate.closed) return;
|
|
117
|
+
// Retry the outstanding notification after transient transport or
|
|
118
|
+
// consistency failures, even when the terminal source sends no more events.
|
|
119
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
120
|
+
if (!dirty && /^(?:runtime-(?:timeout|overloaded|unhealthy)|resync_required):/.test(message) && collectionFailures < 3) {
|
|
121
|
+
const wait = 100 * 2 ** collectionFailures++;
|
|
122
|
+
collectionRetry = setTimeout(() => {
|
|
123
|
+
collectionRetry = undefined;
|
|
124
|
+
if (current === generation && candidate === client && !candidate.closed)
|
|
125
|
+
void collect(candidate, current).catch(error => { if (current === generation && candidate === client) degraded(error); });
|
|
126
|
+
}, wait);
|
|
127
|
+
collectionRetry.unref?.();
|
|
128
|
+
}
|
|
85
129
|
// A notification received during these page reads is
|
|
86
130
|
// still owed a coherent collection. Drain only that
|
|
87
131
|
// demand through the outer loop; do not start a poller.
|
|
@@ -96,6 +140,7 @@ async function collect(candidate: WorkClient, current: number) {
|
|
|
96
140
|
|
|
97
141
|
async function connectObservation(current: number) {
|
|
98
142
|
const saved = context!;
|
|
143
|
+
const signal = connectionAbort.signal;
|
|
99
144
|
mkdirSync(saved.agentDir, { recursive: true, mode: 0o700 });
|
|
100
145
|
saved.agentDir = realpathSync(saved.agentDir);
|
|
101
146
|
let registration;
|
|
@@ -104,23 +149,32 @@ async function connectObservation(current: number) {
|
|
|
104
149
|
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
105
150
|
const path = "./runtime-client/src/runtime/client.mjs";
|
|
106
151
|
const { ensureRuntime } = await import(path);
|
|
107
|
-
await ensureRuntime({ agentDir: saved.agentDir });
|
|
152
|
+
await ensureRuntime({ agentDir: saved.agentDir, signal });
|
|
108
153
|
registration = JSON.parse(readFileSync(join(saved.agentDir, "server-registration-v1.json"), "utf8"));
|
|
109
154
|
}
|
|
110
155
|
if (current !== generation) return;
|
|
111
156
|
if (registration.version !== 1 || registration.agentDir !== saved.agentDir) throw new Error("Invalid canonical runtime registration");
|
|
112
157
|
client?.close();
|
|
113
|
-
const candidate =
|
|
158
|
+
const candidate = await connectWorkClient(join(registration.serverDir, "pi-server.sock"), saved.agentDir, [], {
|
|
159
|
+
signal,
|
|
160
|
+
recover: async ({ timeoutMs, signal }) => {
|
|
161
|
+
const path = "./runtime-client/src/runtime/client.mjs";
|
|
162
|
+
const { ensureRuntime } = await import(path);
|
|
163
|
+
await ensureRuntime({ agentDir: saved.agentDir, serverDir: registration.serverDir, timeoutMs, signal });
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
if (current !== generation) { candidate.close(); return; }
|
|
114
167
|
client = candidate;
|
|
115
168
|
candidate.onChange(() => {
|
|
116
169
|
if (current !== generation || candidate !== client) return;
|
|
170
|
+
collectionFailures = 0;
|
|
117
171
|
if (candidate.closed) {
|
|
118
172
|
details.clear(); pendingDetails.clear();
|
|
119
173
|
degraded(candidate.snapshot?.reason ?? "runtime-unavailable: disconnected; resync required");
|
|
120
174
|
reconnectLater(current);
|
|
121
175
|
} else void collect(candidate, current).catch(error => { if (current === generation) degraded(error); });
|
|
122
176
|
});
|
|
123
|
-
await candidate.subscribe({ ...saved.origin,
|
|
177
|
+
await candidate.subscribe({ ...saved.origin, limit: 200 });
|
|
124
178
|
if (candidate.snapshot?.status === "rebuilding") await new Promise<void>((resolve, reject) => {
|
|
125
179
|
const timer = setTimeout(() => { stop(); reject(new Error("Runtime scope is still rebuilding; retry the observation.")); }, 5000);
|
|
126
180
|
const stop = candidate.onChange(value => {
|
|
@@ -132,14 +186,26 @@ async function connectObservation(current: number) {
|
|
|
132
186
|
if (current === generation) { backoff = 100; if (retry) clearTimeout(retry); retry = undefined; }
|
|
133
187
|
}
|
|
134
188
|
|
|
135
|
-
export
|
|
189
|
+
export function configureWorkObservation(agentDir: string, origin: { cwd: string; sessionId?: string }, changed: () => void) {
|
|
136
190
|
stopWorkObservation();
|
|
191
|
+
context = { agentDir, origin }; refresh = () => {
|
|
192
|
+
changed();
|
|
193
|
+
for (const notify of observationListeners) notify();
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export async function activateWorkObservation() {
|
|
198
|
+
if (!context) return;
|
|
137
199
|
const current = generation;
|
|
138
|
-
context = { agentDir, origin }; refresh = changed;
|
|
139
200
|
try { await ensureObservation(); }
|
|
140
201
|
catch (error) { if (current === generation) { degraded(error); reconnectLater(current); } }
|
|
141
202
|
}
|
|
142
203
|
|
|
204
|
+
export async function startWorkObservation(agentDir: string, origin: { cwd: string; sessionId?: string }, changed: () => void) {
|
|
205
|
+
configureWorkObservation(agentDir, origin, changed);
|
|
206
|
+
await activateWorkObservation();
|
|
207
|
+
}
|
|
208
|
+
|
|
143
209
|
async function ensureObservation() {
|
|
144
210
|
if (connecting) return connecting;
|
|
145
211
|
if (client && !client.closed) return;
|
|
@@ -150,9 +216,14 @@ async function ensureObservation() {
|
|
|
150
216
|
}
|
|
151
217
|
|
|
152
218
|
async function query(scope: object) {
|
|
219
|
+
const current = generation;
|
|
153
220
|
for (let attempt = 0; ; attempt++) {
|
|
154
|
-
try {
|
|
155
|
-
|
|
221
|
+
try {
|
|
222
|
+
await ensureObservation();
|
|
223
|
+
if (current !== generation) throw new Error("runtime-unavailable: observation closed");
|
|
224
|
+
return await client!.get(scope);
|
|
225
|
+
}
|
|
226
|
+
catch (error) { if (current !== generation || (client && !client.closed) || attempt === 1) throw error; }
|
|
156
227
|
}
|
|
157
228
|
}
|
|
158
229
|
|
|
@@ -167,6 +238,9 @@ export async function observedList(scope: object) { return query(scope); }
|
|
|
167
238
|
|
|
168
239
|
export function stopWorkObservation() {
|
|
169
240
|
generation++; context = undefined;
|
|
241
|
+
if (collectionRetry) clearTimeout(collectionRetry); collectionRetry = undefined;
|
|
242
|
+
collectionFailures = 0;
|
|
243
|
+
connectionAbort.abort(); connectionAbort = new AbortController();
|
|
170
244
|
if (retry) clearTimeout(retry); retry = undefined;
|
|
171
245
|
client?.close(); client = undefined; snapshot = undefined;
|
|
172
246
|
connecting = undefined; collecting = undefined; collectingClient = undefined; dirty = false;
|
|
@@ -169,6 +169,7 @@ export async function createOperationBridgeHost(options = {}) {
|
|
|
169
169
|
? { checkpointEvidenceValidator: registration.checkpointEvidenceValidator }
|
|
170
170
|
: {}),
|
|
171
171
|
handlers: Object.freeze({ ...registration.handlers }),
|
|
172
|
+
onToolRejected: registration.onToolRejected,
|
|
172
173
|
descriptor,
|
|
173
174
|
});
|
|
174
175
|
runs.set(registration.runId, {
|
|
@@ -469,13 +470,17 @@ export async function createOperationBridgeHost(options = {}) {
|
|
|
469
470
|
return;
|
|
470
471
|
}
|
|
471
472
|
const params = (envelope.params ?? {});
|
|
473
|
+
const reject = (error) => {
|
|
474
|
+
run.registration.onToolRejected?.(error, makeContext(run, envelope, new AbortController().signal));
|
|
475
|
+
sendError(socket, envelope.id, error);
|
|
476
|
+
};
|
|
472
477
|
if (findSecretField(params)) {
|
|
473
|
-
|
|
478
|
+
reject({ code: "authority-field", message: "request contains a credential-shaped field" });
|
|
474
479
|
return;
|
|
475
480
|
}
|
|
476
481
|
const bridgeEnvironmentField = findBridgeEnvironmentKey(params);
|
|
477
482
|
if (bridgeEnvironmentField) {
|
|
478
|
-
|
|
483
|
+
reject({
|
|
479
484
|
code: "bridge-env-leak",
|
|
480
485
|
message: `${bridgeEnvironmentField} is a parent bridge credential and cannot be passed to a launched task`,
|
|
481
486
|
});
|
|
@@ -484,7 +489,7 @@ export async function createOperationBridgeHost(options = {}) {
|
|
|
484
489
|
}
|
|
485
490
|
const authorityField = findAuthorityField(params);
|
|
486
491
|
if (authorityField) {
|
|
487
|
-
|
|
492
|
+
reject({
|
|
488
493
|
code: "authority-field",
|
|
489
494
|
message: `caller field ${authorityField} would override parent authority`,
|
|
490
495
|
});
|
|
@@ -493,7 +498,7 @@ export async function createOperationBridgeHost(options = {}) {
|
|
|
493
498
|
}
|
|
494
499
|
const schema = validateJsonSchema(descriptor.parameters, params);
|
|
495
500
|
if (!schema.ok) {
|
|
496
|
-
|
|
501
|
+
reject({
|
|
497
502
|
code: "schema-invalid",
|
|
498
503
|
message: `${schema.path}: ${schema.message}`,
|
|
499
504
|
});
|
|
@@ -139,6 +139,8 @@ export interface OperationRunRegistration {
|
|
|
139
139
|
* against the parent's own records before the checkpoint handler runs.
|
|
140
140
|
*/
|
|
141
141
|
checkpointEvidenceValidator?: OperationCheckpointEvidenceCheck;
|
|
142
|
+
/** Synchronous parent diagnostic hook after authentication, before handler dispatch. */
|
|
143
|
+
onToolRejected?: (error: OperationBridgeErrorBody, context: OperationRequestContext) => void;
|
|
142
144
|
handlers: OperationRunHandlers;
|
|
143
145
|
/** Test-only or pre-provisioned token. Production should omit this and use the generated value. */
|
|
144
146
|
token?: string;
|
|
@@ -209,6 +211,7 @@ interface FrozenRegistration {
|
|
|
209
211
|
tools: readonly OperationToolDescriptor[];
|
|
210
212
|
ownership: OperationOwnershipCheck;
|
|
211
213
|
checkpointEvidenceValidator?: OperationCheckpointEvidenceCheck;
|
|
214
|
+
onToolRejected?: OperationRunRegistration["onToolRejected"];
|
|
212
215
|
handlers: OperationRunHandlers;
|
|
213
216
|
descriptor: OperationBridgeDescriptor;
|
|
214
217
|
}
|
|
@@ -401,6 +404,7 @@ export async function createOperationBridgeHost(
|
|
|
401
404
|
? { checkpointEvidenceValidator: registration.checkpointEvidenceValidator }
|
|
402
405
|
: {}),
|
|
403
406
|
handlers: Object.freeze({ ...registration.handlers }),
|
|
407
|
+
onToolRejected: registration.onToolRejected,
|
|
404
408
|
descriptor,
|
|
405
409
|
});
|
|
406
410
|
runs.set(registration.runId, {
|
|
@@ -698,13 +702,17 @@ export async function createOperationBridgeHost(
|
|
|
698
702
|
return;
|
|
699
703
|
}
|
|
700
704
|
const params = (envelope.params ?? {}) as JsonRecord;
|
|
705
|
+
const reject = (error: OperationBridgeErrorBody): void => {
|
|
706
|
+
run.registration.onToolRejected?.(error, makeContext(run, envelope, new AbortController().signal));
|
|
707
|
+
sendError(socket, envelope.id, error);
|
|
708
|
+
};
|
|
701
709
|
if (findSecretField(params)) {
|
|
702
|
-
|
|
710
|
+
reject({ code: "authority-field", message: "request contains a credential-shaped field" });
|
|
703
711
|
return;
|
|
704
712
|
}
|
|
705
713
|
const bridgeEnvironmentField = findBridgeEnvironmentKey(params);
|
|
706
714
|
if (bridgeEnvironmentField) {
|
|
707
|
-
|
|
715
|
+
reject({
|
|
708
716
|
code: "bridge-env-leak",
|
|
709
717
|
message: `${bridgeEnvironmentField} is a parent bridge credential and cannot be passed to a launched task`,
|
|
710
718
|
});
|
|
@@ -713,7 +721,7 @@ export async function createOperationBridgeHost(
|
|
|
713
721
|
}
|
|
714
722
|
const authorityField = findAuthorityField(params);
|
|
715
723
|
if (authorityField) {
|
|
716
|
-
|
|
724
|
+
reject({
|
|
717
725
|
code: "authority-field",
|
|
718
726
|
message: `caller field ${authorityField} would override parent authority`,
|
|
719
727
|
});
|
|
@@ -722,7 +730,7 @@ export async function createOperationBridgeHost(
|
|
|
722
730
|
}
|
|
723
731
|
const schema = validateJsonSchema(descriptor.parameters, params);
|
|
724
732
|
if (!schema.ok) {
|
|
725
|
-
|
|
733
|
+
reject({
|
|
726
734
|
code: "schema-invalid",
|
|
727
735
|
message: `${schema.path}: ${schema.message}`,
|
|
728
736
|
});
|
|
@@ -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);
|