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,6 +1,6 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/managed-launch-host.ts. Do not edit directly.
|
|
2
2
|
import { createHash, timingSafeEqual } from "node:crypto";
|
|
3
|
-
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { lstatSync, mkdirSync, readFileSync, realpathSync, statSync, watch } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { createAgentSession, DefaultResourceLoader, SessionManager, SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
@@ -10,7 +10,7 @@ import extension from "./index.domain.mjs";
|
|
|
10
10
|
import { bindRuntimeOutcomeStore } from "./assignment-outcomes.domain.mjs";
|
|
11
11
|
import { catalogSnapshotFromWire } from "./catalog-store.domain.mjs";
|
|
12
12
|
import { openLaunchJournal, launchDigest } from "./managed-launch-journal.mjs";
|
|
13
|
-
import { nextRunId, processStartToken, listMetas, writeMeta, listActiveMetasForParent, effectiveStatus, readMeta, readParkRecord, updateParkRecord } from "./registry.domain.mjs";
|
|
13
|
+
import { baseDir, nextRunId, processStartToken, listMetas, writeMeta, listActiveMetasForParent, effectiveStatus, readMeta, readParkRecord, updateParkRecord } from "./registry.domain.mjs";
|
|
14
14
|
import { recoverLaunchMetadata } from "./managed-launch-recovery.domain.mjs";
|
|
15
15
|
import { assertSubagentHandoff } from "./managed-launch-ownership.domain.mjs";
|
|
16
16
|
import { createOwnerCapacityGates } from "./capacity.mjs";
|
|
@@ -27,6 +27,8 @@ export class ManagedSubagentHost {
|
|
|
27
27
|
catalog;
|
|
28
28
|
createWorkerHost;
|
|
29
29
|
readPermissions;
|
|
30
|
+
verificationMs;
|
|
31
|
+
enterControl;
|
|
30
32
|
foldRevocation = new Int32Array(new SharedArrayBuffer(4));
|
|
31
33
|
failureWorker;
|
|
32
34
|
failureWorkerError;
|
|
@@ -40,23 +42,174 @@ export class ManagedSubagentHost {
|
|
|
40
42
|
closeJournal;
|
|
41
43
|
epoch;
|
|
42
44
|
pending = 0;
|
|
45
|
+
requestSequence = 0;
|
|
46
|
+
requestRecords = new Map();
|
|
47
|
+
foldRecord;
|
|
48
|
+
acceptedRequestLive = false;
|
|
43
49
|
continuationWindow = { started: 0, admitted: 0 };
|
|
44
50
|
continuationFailures = new Map();
|
|
45
51
|
workerHost;
|
|
46
52
|
path;
|
|
53
|
+
known = new Map();
|
|
54
|
+
healthClose;
|
|
55
|
+
healthChanged;
|
|
56
|
+
lifecycleMetrics = { passes: 0, entities: 0, deadlineLatenessMs: 0 };
|
|
57
|
+
healthDue = new Map();
|
|
58
|
+
writerProofs = new Map();
|
|
59
|
+
lifecycleReasons() {
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
const writers = [...this.known.values()].filter(meta => ["running", "orphaned"].includes(meta.status)).flatMap(meta => {
|
|
62
|
+
const proof = this.writerProofs.get(meta.id);
|
|
63
|
+
if (!proof || !proof.verified && now >= proof.unknownSince + this.verificationMs)
|
|
64
|
+
return [];
|
|
65
|
+
return [{
|
|
66
|
+
kind: proof.verified ? "worker" : "verification", id: meta.id, owner: meta.callbackOrigin, writer: { pid: meta.pid, start: meta.pidStartTime },
|
|
67
|
+
management: meta.management, lastProgressAt: meta.timing?.lastProgressAt ?? meta.startedAt,
|
|
68
|
+
nextDeadline: proof.verified ? this.healthDue.get(meta.id) ?? null : proof.unknownSince + this.verificationMs,
|
|
69
|
+
recovery: proof.verified ? "current-managed-writer-supervision" : "writer-unverified-no-takeover",
|
|
70
|
+
}];
|
|
71
|
+
});
|
|
72
|
+
return [...this.requestRecords.values(), ...(this.foldRecord ? [{ ...this.foldRecord }] : []),
|
|
73
|
+
...(this.acceptedRequestLive ? this.journal.lifecycleReasons(this.current.ownerKey, this.current.key) : []).map(reason => ({ ...reason,
|
|
74
|
+
management: { ...reason.management, instance: this.instance }, writerFence: 'current-managed-launch-epoch' })),
|
|
75
|
+
...writers, ...(this.workerHost?.advancingWaits?.() ?? [])];
|
|
76
|
+
}
|
|
77
|
+
observeHealth(reconcile) {
|
|
78
|
+
this.healthClose?.();
|
|
79
|
+
let closed = false, scheduled = false;
|
|
80
|
+
let timer;
|
|
81
|
+
const watchers = [], dirty = new Set(this.known.keys()), signatures = new Map();
|
|
82
|
+
const signature = (meta) => {
|
|
83
|
+
let log = "missing";
|
|
84
|
+
try {
|
|
85
|
+
const info = statSync(meta.logPath, { bigint: true });
|
|
86
|
+
log = `${info.ino}:${info.size}:${info.mtimeNs}`;
|
|
87
|
+
}
|
|
88
|
+
catch { /* No log yet. */ }
|
|
89
|
+
return JSON.stringify(meta) + log;
|
|
90
|
+
};
|
|
91
|
+
const schedule = () => {
|
|
92
|
+
if (closed || scheduled)
|
|
93
|
+
return;
|
|
94
|
+
scheduled = true;
|
|
95
|
+
setImmediate(() => { scheduled = false; if (!closed)
|
|
96
|
+
pass(); });
|
|
97
|
+
};
|
|
98
|
+
const hint = (id) => {
|
|
99
|
+
const meta = readMeta(id);
|
|
100
|
+
if (meta?.management?.root === this.root && meta.management.instance === this.instance && meta.management.epoch === this.epoch) {
|
|
101
|
+
if (signatures.get(id) === signature(meta))
|
|
102
|
+
return;
|
|
103
|
+
if (!this.writerProofs.has(id))
|
|
104
|
+
this.writerProofs.set(id, { verified: false, checkedAt: Date.now(), unknownSince: Date.now() });
|
|
105
|
+
this.known.set(id, meta);
|
|
106
|
+
dirty.add(id);
|
|
107
|
+
schedule();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
this.healthChanged = hint;
|
|
111
|
+
const pass = () => {
|
|
112
|
+
const now = Date.now();
|
|
113
|
+
for (const [id, due] of this.healthDue)
|
|
114
|
+
if (due <= now)
|
|
115
|
+
dirty.add(id);
|
|
116
|
+
const ids = [...dirty].slice(0, 32);
|
|
117
|
+
ids.forEach(id => dirty.delete(id));
|
|
118
|
+
if (ids.length) {
|
|
119
|
+
const release = this.enterControl?.();
|
|
120
|
+
if (this.enterControl && !release) {
|
|
121
|
+
ids.forEach(id => dirty.add(id));
|
|
122
|
+
timer = setTimeout(schedule, 1000);
|
|
123
|
+
timer.unref();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
this.lifecycleMetrics.passes++;
|
|
127
|
+
this.lifecycleMetrics.entities += ids.length;
|
|
128
|
+
for (const id of ids)
|
|
129
|
+
this.lifecycleMetrics.deadlineLatenessMs = Math.max(this.lifecycleMetrics.deadlineLatenessMs, now - (this.healthDue.get(id) ?? now));
|
|
130
|
+
try {
|
|
131
|
+
reconcile(ids);
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
release?.();
|
|
135
|
+
}
|
|
136
|
+
for (const id of ids) {
|
|
137
|
+
const meta = readMeta(id);
|
|
138
|
+
if (meta)
|
|
139
|
+
this.known.set(id, meta);
|
|
140
|
+
else
|
|
141
|
+
this.known.delete(id);
|
|
142
|
+
if (meta)
|
|
143
|
+
signatures.set(id, signature(meta));
|
|
144
|
+
this.healthDue.delete(id);
|
|
145
|
+
if (!meta || !["running", "orphaned"].includes(meta.status)) {
|
|
146
|
+
this.writerProofs.delete(id);
|
|
147
|
+
if (meta?.completionCallbackPendingAt && !meta.completionCallbackSentAt && !meta.completionCallbackSuppressedAt)
|
|
148
|
+
this.healthDue.set(id, now + 15000);
|
|
149
|
+
else {
|
|
150
|
+
this.known.delete(id);
|
|
151
|
+
signatures.delete(id);
|
|
152
|
+
}
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const verified = Boolean(meta.pidStartTime && processStartToken(meta.pid) === meta.pidStartTime && processExists(meta.pid));
|
|
156
|
+
const prior = this.writerProofs.get(id);
|
|
157
|
+
this.writerProofs.set(id, { verified, checkedAt: now, unknownSince: verified ? now : prior?.unknownSince ?? now });
|
|
158
|
+
const timing = meta.timing;
|
|
159
|
+
const deadlines = [now + 15000, timing?.ceilingAt,
|
|
160
|
+
!timing?.deadlineWakeSentAt ? timing?.deadlineAt : undefined,
|
|
161
|
+
timing?.steerDeliveredAt ? timing.steerDeliveredAt + timing.graceMs : undefined]
|
|
162
|
+
.filter((value) => typeof value === "number" && value > now);
|
|
163
|
+
this.healthDue.set(id, Math.min(...deadlines));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (dirty.size)
|
|
167
|
+
schedule();
|
|
168
|
+
if (timer)
|
|
169
|
+
clearTimeout(timer);
|
|
170
|
+
if (this.healthDue.size) {
|
|
171
|
+
const next = [...this.healthDue.values()].reduce((a, b) => Math.min(a, b), Infinity);
|
|
172
|
+
timer = setTimeout(schedule, Math.max(1, next - Date.now()));
|
|
173
|
+
timer.unref();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
try {
|
|
177
|
+
mkdirSync(join(baseDir(), "runs"), { recursive: true });
|
|
178
|
+
const watcher = watch(join(baseDir(), "runs"), { recursive: true }, (_event, file) => {
|
|
179
|
+
const id = file && String(file).split(/[/\\]/)[0];
|
|
180
|
+
if (id && /^[A-Za-z0-9_-]+$/.test(id))
|
|
181
|
+
hint(id);
|
|
182
|
+
});
|
|
183
|
+
watcher.on("error", () => watcher.close());
|
|
184
|
+
watchers.push(watcher);
|
|
185
|
+
}
|
|
186
|
+
catch { /* Known active writers still have independent liveness deadlines. */ }
|
|
187
|
+
schedule();
|
|
188
|
+
return this.healthClose = () => {
|
|
189
|
+
closed = true;
|
|
190
|
+
if (timer)
|
|
191
|
+
clearTimeout(timer);
|
|
192
|
+
watchers.forEach(watcher => watcher.close());
|
|
193
|
+
this.healthChanged = undefined;
|
|
194
|
+
this.healthDue.clear();
|
|
195
|
+
};
|
|
196
|
+
}
|
|
47
197
|
capacityFor = createOwnerCapacityGates(({ pid, start }) => listActiveMetasForParent(pid).filter(meta => meta.spawnPidStartTime === start && effectiveStatus(meta) === "running").length
|
|
48
198
|
+ this.journal.unresolvedAttempts().filter((attempt) => attempt.capacityOwner?.pid === pid && attempt.capacityOwner?.start === start && !readMeta(attempt.id)).length);
|
|
49
199
|
get busy() { return this.pending > 0 || Boolean(this.failureResponse); }
|
|
50
200
|
status() {
|
|
51
201
|
return { owner: "server", instanceId: this.instance, runtimeEpoch: this.epoch,
|
|
202
|
+
lifecycle: { ...this.lifecycleMetrics, activeDeadlines: this.healthDue.size },
|
|
52
203
|
inFlight: this.pending, failureFold: { worker: Boolean(this.failureWorker), inFlight: Boolean(this.failureResponse) }, continuationReady: this.workerHost?.service.continuationReady ?? false, continuationUnavailable: [...this.continuationFailures].map(([key, value]) => ({ key, ...value })), unresolvedAttempts: this.journal.unresolvedAttempts().filter((attempt) => !readMeta(attempt.id)).length };
|
|
53
204
|
}
|
|
54
|
-
constructor(root, instance, catalog, sharedStore, createWorkerHost, readPermissions) {
|
|
205
|
+
constructor(root, instance, catalog, sharedStore, createWorkerHost, readPermissions, verificationMs = 30000, enterControl) {
|
|
55
206
|
this.root = root;
|
|
56
207
|
this.instance = instance;
|
|
57
208
|
this.catalog = catalog;
|
|
58
209
|
this.createWorkerHost = createWorkerHost;
|
|
59
210
|
this.readPermissions = readPermissions;
|
|
211
|
+
this.verificationMs = verificationMs;
|
|
212
|
+
this.enterControl = enterControl;
|
|
60
213
|
this.current = { pid: process.pid, start: processStartToken(process.pid), owner: { workspace: root, sessionId: "runtime-recovery" } };
|
|
61
214
|
this.path = join(root, "operation-coordinator.sqlite");
|
|
62
215
|
const active = listMetas({ includeArchived: false });
|
|
@@ -150,6 +303,11 @@ export class ManagedSubagentHost {
|
|
|
150
303
|
}
|
|
151
304
|
}
|
|
152
305
|
async recover() {
|
|
306
|
+
for (const meta of listMetas({ includeArchived: false }))
|
|
307
|
+
if (meta.management?.root === this.root) {
|
|
308
|
+
this.known.set(meta.id, meta);
|
|
309
|
+
this.writerProofs.set(meta.id, { verified: false, checkedAt: Date.now(), unknownSince: Date.now() });
|
|
310
|
+
}
|
|
153
311
|
if (listMetas({ includeArchived: false }).some(meta => meta.management?.root === this.root))
|
|
154
312
|
await this.initialize();
|
|
155
313
|
}
|
|
@@ -185,12 +343,14 @@ export class ManagedSubagentHost {
|
|
|
185
343
|
return this.initializing ??= (async () => {
|
|
186
344
|
const host = this;
|
|
187
345
|
const port = {
|
|
346
|
+
observeHealth: reconcile => host.observeHealth(reconcile),
|
|
347
|
+
activeProviders: () => host.current.activeProviders ?? {},
|
|
188
348
|
backgroundTools: () => host.current.background?.available === true ? host.current.background.tools : [],
|
|
189
349
|
get owner() { return { pid: host.current.pid, start: host.current.start }; },
|
|
190
350
|
get identity() { return { root: host.root, instance: host.instance, epoch: host.epoch }; },
|
|
191
351
|
continuationContext: () => host.executionContext(host.current),
|
|
192
352
|
dispatchContinuation: (park, run) => host.dispatchContinuation(park, run),
|
|
193
|
-
supervised: () =>
|
|
353
|
+
supervised: () => [...host.known.values()].filter(meta => port.owns(meta)),
|
|
194
354
|
owns: meta => meta.management?.root === host.root && meta.management?.instance === host.instance && meta.management?.epoch === host.epoch,
|
|
195
355
|
assertCurrent: () => host.journal.current(host.epoch),
|
|
196
356
|
capacity: () => host.capacityFor(host.current),
|
|
@@ -200,7 +360,7 @@ export class ManagedSubagentHost {
|
|
|
200
360
|
const command = host.catalog.connection();
|
|
201
361
|
command({ type: "runtime_register_catalog", cwd: host.current.owner.workspace,
|
|
202
362
|
sessionId: host.current.owner.sessionId, authority: host.current.catalogAuthority });
|
|
203
|
-
return catalogSnapshotFromWire(command({ type: "runtime_get_catalog", overlay: configuration.getSessionSettings?.() ?? configuration.sessionSettings }));
|
|
363
|
+
return catalogSnapshotFromWire(command({ type: "runtime_get_catalog", fresh: true, overlay: configuration.getSessionSettings?.() ?? configuration.sessionSettings }));
|
|
204
364
|
},
|
|
205
365
|
beforeSpawn: input => {
|
|
206
366
|
assertSubagentHandoff(listMetas({ includeArchived: false }), host.root);
|
|
@@ -221,11 +381,11 @@ export class ManagedSubagentHost {
|
|
|
221
381
|
const policyDigest = input.policyPath ? launchDigest(JSON.parse(readFileSync(input.policyPath, "utf8"))) : undefined;
|
|
222
382
|
const attempt = host.journal.prepare(host.current.ownerKey, host.current.key, host.epoch, { ...input, preflightDigest, policyDigest,
|
|
223
383
|
capacityOwner: { pid: host.current.pid, start: host.current.start },
|
|
224
|
-
launchAuthority: host.current.launchAuthority ?? { owner: host.current.owner, pid: host.current.pid, start: host.current.start, settings: host.current.settings, model: host.current.model, projectTrusted: host.current.projectTrusted, background: host.current.background, permissions: host.current.permissions } });
|
|
384
|
+
launchAuthority: host.current.launchAuthority ?? { owner: host.current.owner, pid: host.current.pid, start: host.current.start, settings: host.current.settings, model: host.current.model, projectTrusted: host.current.projectTrusted, background: host.current.background, activeProviders: host.current.activeProviders, permissions: host.current.permissions } });
|
|
225
385
|
return { PI_MANAGED_SUBAGENT: JSON.stringify({ path: host.path, owner: host.current.ownerKey,
|
|
226
386
|
key: host.current.key, epoch: host.epoch, id: input.id, token: attempt.token }) };
|
|
227
387
|
},
|
|
228
|
-
spawned: (id, pid) => host.journal.spawned(host.current.ownerKey, host.current.key, host.epoch, id, pid, processStartToken(pid)),
|
|
388
|
+
spawned: (id, pid) => { host.journal.spawned(host.current.ownerKey, host.current.key, host.epoch, id, pid, processStartToken(pid)); setImmediate(() => host.healthChanged?.(id)); },
|
|
229
389
|
};
|
|
230
390
|
const cwd = this.root;
|
|
231
391
|
const settingsManager = SettingsManager.inMemory({});
|
|
@@ -276,6 +436,11 @@ export class ManagedSubagentHost {
|
|
|
276
436
|
return Promise.resolve("skipped");
|
|
277
437
|
this.continuationWindow.admitted++;
|
|
278
438
|
this.pending++;
|
|
439
|
+
const requestId = ++this.requestSequence;
|
|
440
|
+
this.requestRecords.set(requestId, { kind: 'continuation-request', id: requestId, waitId: park.waitId, runId: park.runId,
|
|
441
|
+
generation: park.generation, lastProgressAt: now, executionDeadline: null, nextDeadline: null,
|
|
442
|
+
recovery: 'captured-continuation-serialized-by-current-launch-journal-owner' });
|
|
443
|
+
let dispatched = false;
|
|
279
444
|
const result = this.tail.catch(() => undefined).then(async () => {
|
|
280
445
|
const saved = this.journal.attempt(park.runId)?.launchAuthority;
|
|
281
446
|
if (!saved)
|
|
@@ -286,7 +451,9 @@ export class ManagedSubagentHost {
|
|
|
286
451
|
capturedPermissions: saved.permissions, permissions,
|
|
287
452
|
ownerKey: JSON.stringify([saved.owner.workspace, saved.owner.sessionId]),
|
|
288
453
|
digest: launchDigest({ key, runId: park.runId }) };
|
|
454
|
+
this.acceptedRequestLive = true;
|
|
289
455
|
this.api.events.emit("pi-better-sandbox:policy", { state: "enabled", ...permissions });
|
|
456
|
+
dispatched = true;
|
|
290
457
|
const outcome = await run();
|
|
291
458
|
if (outcome === "resumed")
|
|
292
459
|
this.journal.finish(this.current.ownerKey, this.current.key, this.epoch, { status: outcome });
|
|
@@ -297,8 +464,12 @@ export class ManagedSubagentHost {
|
|
|
297
464
|
if (this.continuationFailures.size >= 128 && !this.continuationFailures.has(retryKey))
|
|
298
465
|
this.continuationFailures.delete(this.continuationFailures.keys().next().value);
|
|
299
466
|
this.continuationFailures.set(retryKey, { failures, retryAt: Date.now() + Math.min(30000, 1000 * 2 ** (failures - 1)), reason: String(error).slice(0, 500) });
|
|
467
|
+
// Let orchestration persist its existing pre-spawn hold. A skipped
|
|
468
|
+
// result would leave this exact generation ready despite refusal.
|
|
469
|
+
if (!dispatched)
|
|
470
|
+
throw error;
|
|
300
471
|
return "skipped";
|
|
301
|
-
}).finally(() => { this.pending--; });
|
|
472
|
+
}).finally(() => { this.requestRecords.delete(requestId); this.acceptedRequestLive = false; this.pending--; });
|
|
302
473
|
this.tail = result;
|
|
303
474
|
return result;
|
|
304
475
|
}
|
|
@@ -310,16 +481,23 @@ export class ManagedSubagentHost {
|
|
|
310
481
|
runId: meta.id, sessionId: meta.sessionId, status: meta.status,
|
|
311
482
|
})) }, content: [{ type: "text", text: `Original launch ${status}; no replacement attempt was dispatched.` }] };
|
|
312
483
|
}
|
|
313
|
-
handle(command) {
|
|
484
|
+
handle(command, onAccepted) {
|
|
314
485
|
if (Object.keys(command).some(key => !["id", "type", "authority"].includes(key)))
|
|
315
486
|
return Promise.reject(new Error("unsupported launch field"));
|
|
316
487
|
this.pending++;
|
|
488
|
+
const requestId = ++this.requestSequence;
|
|
489
|
+
this.requestRecords.set(requestId, { kind: 'launch-request', id: requestId, phase: 'queued-unaccepted',
|
|
490
|
+
lastProgressAt: Date.now(), executionDeadline: null, nextDeadline: null,
|
|
491
|
+
recovery: 'validate-captured-native-authority-before-admission-no-detached-execution-lease' });
|
|
317
492
|
const result = this.tail.catch(() => undefined).then(async () => {
|
|
318
493
|
const record = this.grant(command.authority);
|
|
319
494
|
// A retried tool call keeps its accepted recipient even after Goal/branch edits.
|
|
320
495
|
const ownerKey = JSON.stringify([record.owner.workspace, record.owner.sessionId]);
|
|
321
496
|
const digest = launchDigest({ tool: record.tool, params: record.params });
|
|
322
497
|
const intent = this.journal.accept(ownerKey, record.key, digest, this.epoch);
|
|
498
|
+
onAccepted?.(`launch-progress:${launchDigest([ownerKey, record.key])}`);
|
|
499
|
+
this.requestRecords.set(requestId, { ...this.requestRecords.get(requestId), phase: 'accepted',
|
|
500
|
+
operation: `launch-progress:${launchDigest([ownerKey, record.key])}`, lastProgressAt: Date.now() });
|
|
323
501
|
if (intent.prior) {
|
|
324
502
|
if (intent.result)
|
|
325
503
|
return JSON.parse(intent.result);
|
|
@@ -327,6 +505,7 @@ export class ManagedSubagentHost {
|
|
|
327
505
|
}
|
|
328
506
|
try {
|
|
329
507
|
this.current = { ...record, authority: command.authority, ownerKey, grantDigest: launchDigest(record) };
|
|
508
|
+
this.acceptedRequestLive = true;
|
|
330
509
|
await this.initialize();
|
|
331
510
|
this.api.events.emit("pi-better-sandbox:policy", { state: "enabled", ...record.permissions });
|
|
332
511
|
const context = this.executionContext(record);
|
|
@@ -344,13 +523,18 @@ export class ManagedSubagentHost {
|
|
|
344
523
|
}
|
|
345
524
|
throw error;
|
|
346
525
|
}
|
|
347
|
-
}).finally(() => { this.pending--; });
|
|
526
|
+
}).finally(() => { this.requestRecords.delete(requestId); this.acceptedRequestLive = false; this.pending--; });
|
|
348
527
|
this.tail = result;
|
|
349
528
|
return result;
|
|
350
529
|
}
|
|
351
530
|
/** One root mechanical worker; no coordinator connection or query mutations. */
|
|
352
531
|
foldTerminalFailures(ids) {
|
|
532
|
+
let release;
|
|
533
|
+
let physicalExit;
|
|
353
534
|
const result = this.tail.catch(() => undefined).then(async () => {
|
|
535
|
+
release = this.enterControl?.();
|
|
536
|
+
if (this.enterControl && !release)
|
|
537
|
+
throw new Error("runtime-overloaded: failure fold source capacity");
|
|
354
538
|
this.journal.current(this.epoch);
|
|
355
539
|
if (Atomics.load(this.foldRevocation, 0))
|
|
356
540
|
throw new Error("failure-fold-owner-revoked");
|
|
@@ -379,15 +563,39 @@ export class ManagedSubagentHost {
|
|
|
379
563
|
worker.on("exit", code => fail(new Error(`failure-fold-worker-exited: ${code}`)));
|
|
380
564
|
worker.unref();
|
|
381
565
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
566
|
+
let timer;
|
|
567
|
+
try {
|
|
568
|
+
await new Promise((resolve, reject) => {
|
|
569
|
+
this.failureResponse = { resolve, reject };
|
|
570
|
+
this.foldRecord = { kind: 'failure-fold', ids: [...ids], lastProgressAt: Date.now(), nextDeadline: Date.now() + this.verificationMs,
|
|
571
|
+
recovery: 'revoke-unacknowledged-fold-generation-at-existing-verification-deadline' };
|
|
572
|
+
timer = setTimeout(() => {
|
|
573
|
+
const error = new Error("failure-fold-verification-deadline: source worker did not acknowledge");
|
|
574
|
+
Atomics.store(this.foldRevocation, 0, 1);
|
|
575
|
+
this.failureWorkerError = error;
|
|
576
|
+
this.failureResponse = undefined;
|
|
577
|
+
physicalExit = this.failureWorker?.terminate();
|
|
578
|
+
reject(error);
|
|
579
|
+
}, this.verificationMs);
|
|
580
|
+
this.failureWorker.postMessage({ ids });
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
finally {
|
|
584
|
+
this.foldRecord = undefined;
|
|
585
|
+
if (timer)
|
|
586
|
+
clearTimeout(timer);
|
|
587
|
+
}
|
|
588
|
+
}).finally(() => {
|
|
589
|
+
if (physicalExit)
|
|
590
|
+
void physicalExit.then(() => release?.(), () => undefined);
|
|
591
|
+
else
|
|
592
|
+
release?.();
|
|
386
593
|
});
|
|
387
594
|
this.tail = result;
|
|
388
595
|
return result;
|
|
389
596
|
}
|
|
390
597
|
async close() {
|
|
598
|
+
this.healthClose?.();
|
|
391
599
|
Atomics.store(this.foldRevocation, 0, 1);
|
|
392
600
|
await this.tail.catch(() => undefined);
|
|
393
601
|
await this.failureWorker?.terminate();
|