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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/shared-operation-coordinator/assignment-inbox.mjs. Do not edit directly.
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
/** Rebuildable observation state, never an execution or delivery credential. */
|
|
4
|
+
export class AssignmentInbox {
|
|
5
|
+
constructor(path, connectionOrOptions, options = {}) {
|
|
6
|
+
const connection = typeof connectionOrOptions?.prepare === "function" ? connectionOrOptions : undefined;
|
|
7
|
+
if (!connection)
|
|
8
|
+
options = connectionOrOptions ?? options;
|
|
9
|
+
this.entityPrefix = options.entityPrefix;
|
|
10
|
+
const { DatabaseSync } = createRequire(import.meta.url)("node:sqlite");
|
|
11
|
+
this.shared = Boolean(connection);
|
|
12
|
+
this.db = connection ?? new DatabaseSync(path);
|
|
13
|
+
this.alias = this.entityPrefix === "background:" ? "background_inbox" : "assignment_inbox";
|
|
14
|
+
this.prefix = connection ? `${this.alias}.` : "";
|
|
15
|
+
let attached = false;
|
|
16
|
+
try {
|
|
17
|
+
// Share the query owner's handle; only the attached derived file is durable.
|
|
18
|
+
if (connection) {
|
|
19
|
+
connection.prepare(`ATTACH DATABASE ? AS ${this.alias}`).run(path);
|
|
20
|
+
attached = true;
|
|
21
|
+
}
|
|
22
|
+
// A second observer may open while the first holds a derived write
|
|
23
|
+
// transaction. Existing schema/diagnostics require no write reservation.
|
|
24
|
+
const tables = this.db.prepare(`SELECT count(*) AS n FROM ${this.prefix}sqlite_master
|
|
25
|
+
WHERE type='table' AND name IN ('position','pending','applied_scopes','diagnostics')`).get().n;
|
|
26
|
+
if (tables === 4 && this.db.prepare(`SELECT 1 FROM ${this.prefix}diagnostics LIMIT 1`).get())
|
|
27
|
+
return;
|
|
28
|
+
this.db.exec(`CREATE TABLE IF NOT EXISTS ${this.prefix}position (
|
|
29
|
+
singleton INTEGER PRIMARY KEY CHECK(singleton=1), generation TEXT NOT NULL,
|
|
30
|
+
received INTEGER NOT NULL, applied INTEGER NOT NULL);
|
|
31
|
+
CREATE TABLE IF NOT EXISTS ${this.prefix}pending (
|
|
32
|
+
scope TEXT PRIMARY KEY, seq INTEGER NOT NULL, first_seq INTEGER NOT NULL, since INTEGER NOT NULL);
|
|
33
|
+
CREATE TABLE IF NOT EXISTS ${this.prefix}applied_scopes (scope TEXT PRIMARY KEY, seq INTEGER NOT NULL);
|
|
34
|
+
CREATE TABLE IF NOT EXISTS ${this.prefix}diagnostics (repairs INTEGER NOT NULL);`);
|
|
35
|
+
// Reopening an initialized inbox must not reserve every attached file
|
|
36
|
+
// merely to execute an INSERT whose SELECT would produce no rows.
|
|
37
|
+
if (!this.db.prepare(`SELECT 1 FROM ${this.prefix}diagnostics LIMIT 1`).get()) {
|
|
38
|
+
this.db.exec(`INSERT INTO ${this.prefix}diagnostics SELECT 0 WHERE NOT EXISTS (SELECT 1 FROM ${this.prefix}diagnostics)`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
// A failed constructor cannot transfer its alias to a caller.
|
|
43
|
+
// Never detach an earlier participant or close a borrowed owner.
|
|
44
|
+
try {
|
|
45
|
+
if (attached)
|
|
46
|
+
this.db.exec(`DETACH DATABASE ${this.alias}`);
|
|
47
|
+
else if (!connection)
|
|
48
|
+
this.db.close();
|
|
49
|
+
}
|
|
50
|
+
catch (cleanup) {
|
|
51
|
+
throw new AggregateError([error, cleanup], "Assignment inbox initialization and owned cleanup failed");
|
|
52
|
+
}
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
receive(source, identity) {
|
|
57
|
+
const version = source.prepare("SELECT value FROM schema_meta WHERE key='schema_version'").get()?.value;
|
|
58
|
+
if (!["1", "2", "3", "4"].includes(version))
|
|
59
|
+
throw new Error("Unsupported assignment source schema");
|
|
60
|
+
const token = source.prepare("SELECT generation FROM assignment_change_source WHERE singleton=1").get()?.generation;
|
|
61
|
+
if (!token)
|
|
62
|
+
throw new Error("Assignment change journal unavailable");
|
|
63
|
+
const generation = `${identity}:${version}:${token}`;
|
|
64
|
+
const bounds = source.prepare("SELECT min(seq) AS first, max(seq) AS last FROM assignment_changes").get();
|
|
65
|
+
const last = Number(bounds.last ?? 0);
|
|
66
|
+
const position = this.db.prepare(`SELECT * FROM ${this.prefix}position WHERE singleton=1`).get();
|
|
67
|
+
const reset = !position || position.generation !== generation || position.received > last
|
|
68
|
+
|| (bounds.first !== null && position.received < Number(bounds.first) - 1);
|
|
69
|
+
const after = reset ? last : position.received;
|
|
70
|
+
const changes = reset ? [] : source.prepare("SELECT * FROM assignment_changes WHERE seq>? ORDER BY seq LIMIT 128").all(after);
|
|
71
|
+
this.more = !reset && Number(changes.at(-1)?.seq ?? after) < last;
|
|
72
|
+
if (!reset && !changes.length)
|
|
73
|
+
return this.batch(generation);
|
|
74
|
+
this.db.exec(this.shared ? `SAVEPOINT ${this.alias}_receive` : "BEGIN IMMEDIATE");
|
|
75
|
+
try {
|
|
76
|
+
if (reset) {
|
|
77
|
+
this.db.exec(`DELETE FROM ${this.prefix}pending; DELETE FROM ${this.prefix}applied_scopes; UPDATE ${this.prefix}diagnostics SET repairs=repairs+1`);
|
|
78
|
+
this.db.prepare(`INSERT INTO ${this.prefix}pending VALUES('*', ?, 0, ?)`).run(last, Date.now());
|
|
79
|
+
this.db.prepare(`INSERT OR REPLACE INTO ${this.prefix}position VALUES(1, ?, ?, 0)`).run(generation, last);
|
|
80
|
+
}
|
|
81
|
+
const insert = this.db.prepare(`INSERT INTO ${this.prefix}pending VALUES(?, ?, ?, ?)
|
|
82
|
+
ON CONFLICT(scope) DO UPDATE SET seq=excluded.seq`);
|
|
83
|
+
for (const change of changes) {
|
|
84
|
+
const background = change.entity.startsWith('background:');
|
|
85
|
+
if (this.entityPrefix ? !change.entity.startsWith(this.entityPrefix) : background)
|
|
86
|
+
continue;
|
|
87
|
+
insert.run(JSON.stringify([change.session_id, change.workspace, change.assignment_id]), change.seq, change.seq, Date.now());
|
|
88
|
+
}
|
|
89
|
+
// The obligations above and received position commit together.
|
|
90
|
+
if (changes.length)
|
|
91
|
+
this.db.prepare(`UPDATE ${this.prefix}position SET received=? WHERE singleton=1`).run(changes.at(-1).seq);
|
|
92
|
+
this.db.exec(this.shared ? `RELEASE ${this.alias}_receive` : "COMMIT");
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
this.db.exec(this.shared ? `ROLLBACK TO ${this.alias}_receive; RELEASE ${this.alias}_receive` : "ROLLBACK");
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
return this.batch(generation);
|
|
99
|
+
}
|
|
100
|
+
batch(generation) {
|
|
101
|
+
const batch = new Map(this.db.prepare(`SELECT scope, seq FROM ${this.prefix}pending ORDER BY first_seq, scope LIMIT 128`).all().map(row => [row.scope, String(row.seq)]));
|
|
102
|
+
Object.defineProperty(batch, "generation", { value: generation });
|
|
103
|
+
return batch;
|
|
104
|
+
}
|
|
105
|
+
acknowledge(batch, baselineComplete) {
|
|
106
|
+
const position = this.db.prepare(`SELECT * FROM ${this.prefix}position WHERE singleton=1`).get();
|
|
107
|
+
if (batch.generation && batch.generation !== position?.generation)
|
|
108
|
+
return;
|
|
109
|
+
if (batch.size && ![...batch.keys()].some(scope => scope !== "*" || baselineComplete))
|
|
110
|
+
return;
|
|
111
|
+
if (!batch.size && (!position || position.applied === position.received))
|
|
112
|
+
return;
|
|
113
|
+
this.db.exec(this.shared ? `SAVEPOINT ${this.alias}_ack` : "BEGIN IMMEDIATE");
|
|
114
|
+
try {
|
|
115
|
+
const remove = this.db.prepare(`DELETE FROM ${this.prefix}pending WHERE scope=? AND seq=?`);
|
|
116
|
+
const applied = this.db.prepare(`INSERT INTO ${this.prefix}applied_scopes VALUES(?,?) ON CONFLICT(scope) DO UPDATE SET seq=max(seq,excluded.seq)`);
|
|
117
|
+
for (const [scope, seq] of batch)
|
|
118
|
+
if (scope !== "*" || baselineComplete) {
|
|
119
|
+
if (remove.run(scope, Number(seq)).changes)
|
|
120
|
+
applied.run(scope, Number(seq));
|
|
121
|
+
}
|
|
122
|
+
// A later entity completing cannot advance past any earlier obligation.
|
|
123
|
+
this.db.exec(`UPDATE ${this.prefix}position SET applied=max(0,min(received,
|
|
124
|
+
COALESCE((SELECT min(first_seq)-1 FROM ${this.prefix}pending), received))) WHERE singleton=1`);
|
|
125
|
+
this.db.exec(this.shared ? `RELEASE ${this.alias}_ack` : "COMMIT");
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
this.db.exec(this.shared ? `ROLLBACK TO ${this.alias}_ack; RELEASE ${this.alias}_ack` : "ROLLBACK");
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
get metrics() {
|
|
133
|
+
const pending = this.db.prepare(`SELECT count(*) AS pending, min(since) AS oldestPendingAt FROM ${this.prefix}pending`).get();
|
|
134
|
+
return { ...this.db.prepare(`SELECT * FROM ${this.prefix}position`).get(),
|
|
135
|
+
more: Boolean(this.more),
|
|
136
|
+
affected: this.db.prepare(`SELECT scope, seq, first_seq, since FROM ${this.prefix}pending ORDER BY first_seq, scope LIMIT 128`).all(),
|
|
137
|
+
...pending, oldestPendingAgeMs: pending.oldestPendingAt === null ? 0 : Math.max(0, Date.now() - Number(pending.oldestPendingAt)),
|
|
138
|
+
...this.db.prepare(`SELECT repairs FROM ${this.prefix}diagnostics`).get() };
|
|
139
|
+
}
|
|
140
|
+
close() { if (this.shared)
|
|
141
|
+
this.db.exec(`DETACH DATABASE ${this.alias}`);
|
|
142
|
+
else
|
|
143
|
+
this.db.close(); }
|
|
144
|
+
}
|
package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/shared-operation-coordinator/assignment-observation.mjs. Do not edit directly.
|
|
2
2
|
// Generated from packages/operation-coordinator/assignment-observation.mjs. Do not edit directly.
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
-
import {
|
|
4
|
+
import { AssignmentInbox } from "./assignment-inbox.mjs";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
// Only first-party source SQL passes this facade; quoted values stay untouched.
|
|
7
|
+
const sourceTables = new Set(["schema_meta", "sqlite_master", "sqlite_schema", "assignment_change_source", "assignment_changes",
|
|
8
|
+
"waits", "wait_dependencies", "resume_claims", "operations", "coordinator_state", "assignment_outcomes",
|
|
9
|
+
"subagent_launch_intents", "background_input_versions", "background_parent_callbacks", "assignments", "assignment_bindings", "assignment_attempts"]);
|
|
10
|
+
function sourceSQL(sql) {
|
|
11
|
+
if (/^PRAGMA\s+data_version\s*$/i.test(sql))
|
|
12
|
+
return "PRAGMA coordinator_source.data_version";
|
|
13
|
+
return sql.replace(/'(?:''|[^'])*'|\b[A-Za-z_][A-Za-z_0-9]*\b/g, token => sourceTables.has(token) ? `coordinator_source.${token}` : token);
|
|
14
|
+
}
|
|
5
15
|
/** Read-only, bounded projection input. Never creates/migrates a database. */
|
|
6
16
|
export function readAssignmentWaits(path, owner, connection) {
|
|
7
17
|
let db;
|
|
@@ -46,12 +56,25 @@ export function readAssignmentWaits(path, owner, connection) {
|
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
58
|
/** A root read model owns this connection; ordinary observers remain one-shot. */
|
|
49
|
-
export function createAssignmentReader(path) {
|
|
59
|
+
export function createAssignmentReader(path, inboxPath = ":memory:", derivedConnection, options = {}) {
|
|
60
|
+
const inbox = new AssignmentInbox(inboxPath, derivedConnection);
|
|
50
61
|
let db;
|
|
51
62
|
let identity;
|
|
52
63
|
let snapshot = false;
|
|
64
|
+
const composed = options.composed === true;
|
|
65
|
+
const owner = derivedConnection;
|
|
66
|
+
const dropSource = () => {
|
|
67
|
+
if (composed) {
|
|
68
|
+
if (db)
|
|
69
|
+
owner.exec("DETACH DATABASE coordinator_source");
|
|
70
|
+
}
|
|
71
|
+
else
|
|
72
|
+
db?.close();
|
|
73
|
+
db = undefined;
|
|
74
|
+
statements.clear();
|
|
75
|
+
};
|
|
53
76
|
const statements = new Map();
|
|
54
|
-
|
|
77
|
+
const reader = {
|
|
55
78
|
revision() {
|
|
56
79
|
const { statSync } = createRequire(import.meta.url)("node:fs");
|
|
57
80
|
const stat = statSync(path, { bigint: true });
|
|
@@ -59,28 +82,40 @@ export function createAssignmentReader(path) {
|
|
|
59
82
|
if (identity !== next) {
|
|
60
83
|
if (snapshot)
|
|
61
84
|
throw new Error("Coordinator identity changed during observation");
|
|
62
|
-
|
|
63
|
-
db = undefined;
|
|
64
|
-
statements.clear();
|
|
85
|
+
dropSource();
|
|
65
86
|
identity = next;
|
|
66
87
|
}
|
|
67
88
|
const { DatabaseSync } = createRequire(import.meta.url)("node:sqlite");
|
|
68
|
-
|
|
89
|
+
if (!db) {
|
|
90
|
+
if (composed) {
|
|
91
|
+
const uri = pathToFileURL(path);
|
|
92
|
+
uri.searchParams.set("mode", "ro");
|
|
93
|
+
owner.prepare("ATTACH DATABASE ? AS coordinator_source").run(uri.href);
|
|
94
|
+
db = { prepare: sql => owner.prepare(sourceSQL(sql)), get observationActive() { return snapshot; }, beginSnapshot: () => reader.beginSnapshot() };
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
db = new DatabaseSync(path, { readOnly: true });
|
|
98
|
+
}
|
|
69
99
|
return `${identity}:${db.prepare("PRAGMA data_version").get().data_version}`;
|
|
70
100
|
},
|
|
71
101
|
connection(refresh = true) { if (refresh)
|
|
72
102
|
this.revision(); return db; },
|
|
103
|
+
changes() { this.revision(); return inbox.receive(db, identity); },
|
|
104
|
+
acknowledgeChanges(batch, complete) { inbox.acknowledge(batch, complete); },
|
|
105
|
+
get changeMetrics() { return inbox.metrics; },
|
|
106
|
+
get snapshotActive() { return snapshot; },
|
|
73
107
|
beginSnapshot() {
|
|
74
108
|
this.revision();
|
|
75
109
|
if (snapshot)
|
|
76
110
|
throw new Error("Coordinator snapshot already open");
|
|
77
|
-
db
|
|
111
|
+
const transaction = composed ? owner : db;
|
|
112
|
+
transaction.exec("BEGIN");
|
|
78
113
|
snapshot = true;
|
|
79
114
|
const release = () => {
|
|
80
115
|
if (!snapshot)
|
|
81
116
|
return;
|
|
82
117
|
try {
|
|
83
|
-
|
|
118
|
+
transaction.exec("ROLLBACK");
|
|
84
119
|
}
|
|
85
120
|
finally {
|
|
86
121
|
snapshot = false;
|
|
@@ -89,7 +124,12 @@ export function createAssignmentReader(path) {
|
|
|
89
124
|
try {
|
|
90
125
|
// Pin the WAL read view before recording its revision; other writers keep advancing.
|
|
91
126
|
db.prepare("SELECT count(*) FROM sqlite_schema").get();
|
|
92
|
-
return { revision: this.revision(), release
|
|
127
|
+
return { revision: this.revision(), release, commit: () => {
|
|
128
|
+
if (!snapshot)
|
|
129
|
+
return;
|
|
130
|
+
transaction.exec("COMMIT");
|
|
131
|
+
snapshot = false;
|
|
132
|
+
} };
|
|
93
133
|
}
|
|
94
134
|
catch (error) {
|
|
95
135
|
release();
|
|
@@ -109,35 +149,6 @@ export function createAssignmentReader(path) {
|
|
|
109
149
|
return { verified: false, waits: [], reason: "Coordinator state is unverified; compatible supervision is unavailable." };
|
|
110
150
|
}
|
|
111
151
|
},
|
|
112
|
-
conversationRevisions() {
|
|
113
|
-
try {
|
|
114
|
-
this.revision();
|
|
115
|
-
if (!["1", "2", "3", "4"].includes(db.prepare("SELECT value FROM schema_meta WHERE key = 'schema_version'").get()?.value))
|
|
116
|
-
return undefined;
|
|
117
|
-
const hashes = new Map();
|
|
118
|
-
const add = (sessionId, workspace, value) => {
|
|
119
|
-
const key = JSON.stringify([sessionId, workspace]);
|
|
120
|
-
if (!hashes.has(key))
|
|
121
|
-
hashes.set(key, createHash("sha256"));
|
|
122
|
-
hashes.get(key).update(JSON.stringify(value));
|
|
123
|
-
};
|
|
124
|
-
// One source pass per changed database revision, instead of one
|
|
125
|
-
// projection/query/log parse for every historical attempt.
|
|
126
|
-
for (const row of db.prepare(`SELECT w.*, (SELECT json_group_array(attempt_id)
|
|
127
|
-
FROM resume_claims c WHERE c.wait_id = w.wait_id AND c.generation = w.generation) AS claimed_attempts
|
|
128
|
-
FROM waits w WHERE owner_kind = 'worker-conversation' ORDER BY wait_id, generation`).all()) {
|
|
129
|
-
add(row.owner_session_id, row.owner_workspace, row);
|
|
130
|
-
}
|
|
131
|
-
for (const row of db.prepare("SELECT record_json FROM assignment_outcomes ORDER BY assignment_id").all()) {
|
|
132
|
-
const record = JSON.parse(row.record_json);
|
|
133
|
-
add(record.owner.sessionId, record.owner.workspace, record);
|
|
134
|
-
}
|
|
135
|
-
return new Map([...hashes].map(([key, hash]) => [key, hash.digest("hex")]));
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
return undefined;
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
152
|
upgradeObligations() {
|
|
142
153
|
try {
|
|
143
154
|
this.revision();
|
|
@@ -170,8 +181,9 @@ export function createAssignmentReader(path) {
|
|
|
170
181
|
return [...obligations, ...reasons];
|
|
171
182
|
},
|
|
172
183
|
close() { if (snapshot) {
|
|
173
|
-
db.exec("ROLLBACK");
|
|
184
|
+
(composed ? owner : db).exec("ROLLBACK");
|
|
174
185
|
snapshot = false;
|
|
175
|
-
}
|
|
186
|
+
} dropSource(); identity = undefined; inbox.close(); },
|
|
176
187
|
};
|
|
188
|
+
return reader;
|
|
177
189
|
}
|
package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/shared-operation-coordinator/src/assignment-changes.ts. Do not edit directly.
|
|
2
|
+
/** Additive observation journal. Triggers also cover already-running old writers. */
|
|
3
|
+
export function ensureAssignmentChanges(ctx) {
|
|
4
|
+
ctx.transaction(() => {
|
|
5
|
+
ctx.db.exec(`CREATE TABLE IF NOT EXISTS assignment_change_source (
|
|
6
|
+
singleton INTEGER PRIMARY KEY CHECK(singleton=1), generation TEXT NOT NULL);
|
|
7
|
+
INSERT OR IGNORE INTO assignment_change_source VALUES(1, lower(hex(randomblob(16))));
|
|
8
|
+
CREATE TABLE IF NOT EXISTS assignment_changes (
|
|
9
|
+
seq INTEGER PRIMARY KEY AUTOINCREMENT, entity TEXT NOT NULL, entity_id TEXT NOT NULL DEFAULT '',
|
|
10
|
+
assignment_id TEXT, session_id TEXT NOT NULL, workspace TEXT NOT NULL,
|
|
11
|
+
changed_at INTEGER NOT NULL DEFAULT (unixepoch()*1000));
|
|
12
|
+
CREATE INDEX IF NOT EXISTS waits_assignment_observation ON waits
|
|
13
|
+
(owner_kind,owner_session_id,owner_workspace,json_extract(origin_json,'$.assignmentRef'),created_at DESC,generation DESC);
|
|
14
|
+
CREATE INDEX IF NOT EXISTS resume_claims_wait_observation ON resume_claims(wait_id,generation,attempt_id);
|
|
15
|
+
CREATE TABLE IF NOT EXISTS background_input_versions (
|
|
16
|
+
operation_id TEXT PRIMARY KEY, revision INTEGER NOT NULL);
|
|
17
|
+
CREATE TRIGGER IF NOT EXISTS assignment_changes_retention AFTER INSERT ON assignment_changes
|
|
18
|
+
BEGIN DELETE FROM assignment_changes WHERE seq <= NEW.seq - 4096; END;`);
|
|
19
|
+
// Repair is an operation-ID keyset, not an observer equality lookup.
|
|
20
|
+
// A leading observer column competes with the ordered recent-terminal index.
|
|
21
|
+
if (ctx.db.prepare("PRAGMA index_info(background_operation_repair)").all().length > 1)
|
|
22
|
+
ctx.db.exec("DROP INDEX background_operation_repair");
|
|
23
|
+
ctx.db.exec("CREATE INDEX IF NOT EXISTS background_operation_repair ON operations(operation_id) WHERE observer_kind='local-supervisor'");
|
|
24
|
+
const sources = [
|
|
25
|
+
{ table: "waits", select: (r) => `SELECT 'wait', ${r}.wait_id || ':' || ${r}.generation, json_extract(${r}.origin_json,'$.assignmentRef'), ${r}.owner_session_id, ${r}.owner_workspace WHERE ${r}.owner_kind='worker-conversation'` },
|
|
26
|
+
{ table: "resume_claims", select: (r) => `SELECT 'claim', ${r}.claim_id, json_extract(w.origin_json,'$.assignmentRef'), w.owner_session_id, w.owner_workspace FROM waits w WHERE w.wait_id=${r}.wait_id AND w.generation=${r}.generation AND w.owner_kind='worker-conversation'` },
|
|
27
|
+
{ table: "assignment_bindings", select: (r) => `SELECT 'binding', ${r}.assignment_id, ${r}.assignment_id, json_extract(${r}.owner_json,'$.sessionId'), json_extract(${r}.owner_json,'$.workspace')` },
|
|
28
|
+
{ table: "assignment_attempts", select: (r) => `SELECT 'attempt', ${r}.attempt_id, b.assignment_id, json_extract(b.owner_json,'$.sessionId'), json_extract(b.owner_json,'$.workspace') FROM assignment_bindings b WHERE b.assignment_id=${r}.assignment_id` },
|
|
29
|
+
{ table: "assignment_outcomes", select: (r) => `SELECT 'outcome', ${r}.assignment_id, ${r}.assignment_id, json_extract(${r}.record_json,'$.owner.sessionId'), json_extract(${r}.record_json,'$.owner.workspace')` },
|
|
30
|
+
{ table: "outbox_events", select: (r) => `SELECT 'receipt', ${r}.event_id, b.assignment_id, json_extract(b.owner_json,'$.sessionId'), json_extract(b.owner_json,'$.workspace') FROM assignment_bindings b WHERE b.assignment_id=${r}.operation_id UNION ALL SELECT 'receipt', ${r}.event_id, json_extract(w.origin_json,'$.assignmentRef'), w.owner_session_id, w.owner_workspace FROM waits w WHERE w.wait_id=${r}.wait_id AND w.generation=${r}.generation AND w.owner_kind='worker-conversation'` },
|
|
31
|
+
];
|
|
32
|
+
for (const { table, select } of sources)
|
|
33
|
+
for (const action of ["INSERT", "UPDATE", "DELETE"]) {
|
|
34
|
+
const records = action === "UPDATE" ? ["OLD", "NEW"] : [action === "DELETE" ? "OLD" : "NEW"];
|
|
35
|
+
ctx.db.exec(`CREATE TRIGGER IF NOT EXISTS assignment_change_${table}_${action.toLowerCase()} AFTER ${action} ON ${table} BEGIN ${records.map(r => `INSERT INTO assignment_changes(entity,entity_id,assignment_id,session_id,workspace) ${select(r)};`).join(" ")} END;`);
|
|
36
|
+
}
|
|
37
|
+
// These are observation inputs, not execution or delivery authority. Old
|
|
38
|
+
// cooperative SQL writers inherit the same atomic invalidation triggers.
|
|
39
|
+
const backgroundSources = [
|
|
40
|
+
{ table: "operations", select: (r) => `SELECT ${r}.operation_id, 1 WHERE ${r}.observer_kind='local-supervisor'` },
|
|
41
|
+
{ table: "waits", select: (r) => `SELECT d.operation_id, 1 FROM wait_dependencies d JOIN operations o ON o.operation_id=d.operation_id WHERE d.wait_id=${r}.wait_id AND d.generation=${r}.generation AND o.observer_kind='local-supervisor'` },
|
|
42
|
+
{ table: "wait_dependencies", select: (r) => `SELECT ${r}.operation_id, 1 WHERE EXISTS(SELECT 1 FROM operations o WHERE o.operation_id=${r}.operation_id AND o.observer_kind='local-supervisor')` },
|
|
43
|
+
{ table: "background_parent_callbacks", select: (r) => `SELECT ${r}.operation_id, 1 WHERE 1` },
|
|
44
|
+
{ table: "coordinator_state", select: (r) => `SELECT o.operation_id, 1 FROM operations o WHERE ${r}.key LIKE 'result-supervision-v1:%' AND o.operation_id=substr(${r}.key,length('result-supervision-v1:')+1) AND o.observer_kind='local-supervisor'` },
|
|
45
|
+
];
|
|
46
|
+
// Version 1 installed one-column SELECTs into a two-column INSERT. Replace
|
|
47
|
+
// only these owned triggers, atomically, without resetting source positions.
|
|
48
|
+
const replaceBackgroundTriggers = ctx.db.prepare("SELECT value FROM schema_meta WHERE key='background_input_triggers_version'").get()?.value !== "2";
|
|
49
|
+
for (const { table, select } of backgroundSources)
|
|
50
|
+
for (const action of ["INSERT", "UPDATE", "DELETE"]) {
|
|
51
|
+
if (replaceBackgroundTriggers)
|
|
52
|
+
ctx.db.exec(`DROP TRIGGER IF EXISTS background_input_${table}_${action.toLowerCase()}`);
|
|
53
|
+
const records = action === "UPDATE" ? ["OLD", "NEW"] : [action === "DELETE" ? "OLD" : "NEW"];
|
|
54
|
+
ctx.db.exec(`CREATE TRIGGER IF NOT EXISTS background_input_${table}_${action.toLowerCase()}
|
|
55
|
+
${action === "DELETE" ? "BEFORE" : "AFTER"} ${action} ON ${table} BEGIN
|
|
56
|
+
${records.map(r => `INSERT INTO background_input_versions(operation_id,revision) ${select(r)}
|
|
57
|
+
ON CONFLICT(operation_id) DO UPDATE SET revision=revision+1;`).join(" ")}
|
|
58
|
+
END;`);
|
|
59
|
+
}
|
|
60
|
+
if (replaceBackgroundTriggers)
|
|
61
|
+
ctx.db.prepare("INSERT OR REPLACE INTO schema_meta(key,value) VALUES('background_input_triggers_version','2')").run();
|
|
62
|
+
ctx.db.exec(`CREATE TRIGGER IF NOT EXISTS background_journal_insert AFTER INSERT ON background_input_versions BEGIN
|
|
63
|
+
INSERT INTO assignment_changes(entity,entity_id,assignment_id,session_id,workspace)
|
|
64
|
+
SELECT 'background:operation', NEW.operation_id, NEW.operation_id, owner_session_id, owner_workspace FROM operations WHERE operation_id=NEW.operation_id;
|
|
65
|
+
END;
|
|
66
|
+
CREATE TRIGGER IF NOT EXISTS background_journal_update AFTER UPDATE ON background_input_versions BEGIN
|
|
67
|
+
INSERT INTO assignment_changes(entity,entity_id,assignment_id,session_id,workspace)
|
|
68
|
+
SELECT 'background:operation', NEW.operation_id, NEW.operation_id, owner_session_id, owner_workspace FROM operations WHERE operation_id=NEW.operation_id;
|
|
69
|
+
END;
|
|
70
|
+
CREATE TRIGGER IF NOT EXISTS background_journal_previous_scope AFTER UPDATE ON operations
|
|
71
|
+
WHEN OLD.observer_kind='local-supervisor' AND (OLD.owner_session_id<>NEW.owner_session_id OR OLD.owner_workspace<>NEW.owner_workspace OR OLD.owner_kind<>NEW.owner_kind)
|
|
72
|
+
BEGIN INSERT INTO assignment_changes(entity,entity_id,assignment_id,session_id,workspace)
|
|
73
|
+
VALUES('background:operation',OLD.operation_id,OLD.operation_id,OLD.owner_session_id,OLD.owner_workspace); END;`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Generated from packages/operation-coordinator/src/assignment-changes.ts. Do not edit directly.
|
|
2
|
+
import type { StoreContext } from "./sqlite.ts";
|
|
3
|
+
|
|
4
|
+
/** Additive observation journal. Triggers also cover already-running old writers. */
|
|
5
|
+
export function ensureAssignmentChanges(ctx: StoreContext): void {
|
|
6
|
+
ctx.transaction(() => {
|
|
7
|
+
ctx.db.exec(`CREATE TABLE IF NOT EXISTS assignment_change_source (
|
|
8
|
+
singleton INTEGER PRIMARY KEY CHECK(singleton=1), generation TEXT NOT NULL);
|
|
9
|
+
INSERT OR IGNORE INTO assignment_change_source VALUES(1, lower(hex(randomblob(16))));
|
|
10
|
+
CREATE TABLE IF NOT EXISTS assignment_changes (
|
|
11
|
+
seq INTEGER PRIMARY KEY AUTOINCREMENT, entity TEXT NOT NULL, entity_id TEXT NOT NULL DEFAULT '',
|
|
12
|
+
assignment_id TEXT, session_id TEXT NOT NULL, workspace TEXT NOT NULL,
|
|
13
|
+
changed_at INTEGER NOT NULL DEFAULT (unixepoch()*1000));
|
|
14
|
+
CREATE INDEX IF NOT EXISTS waits_assignment_observation ON waits
|
|
15
|
+
(owner_kind,owner_session_id,owner_workspace,json_extract(origin_json,'$.assignmentRef'),created_at DESC,generation DESC);
|
|
16
|
+
CREATE INDEX IF NOT EXISTS resume_claims_wait_observation ON resume_claims(wait_id,generation,attempt_id);
|
|
17
|
+
CREATE TABLE IF NOT EXISTS background_input_versions (
|
|
18
|
+
operation_id TEXT PRIMARY KEY, revision INTEGER NOT NULL);
|
|
19
|
+
CREATE TRIGGER IF NOT EXISTS assignment_changes_retention AFTER INSERT ON assignment_changes
|
|
20
|
+
BEGIN DELETE FROM assignment_changes WHERE seq <= NEW.seq - 4096; END;`);
|
|
21
|
+
// Repair is an operation-ID keyset, not an observer equality lookup.
|
|
22
|
+
// A leading observer column competes with the ordered recent-terminal index.
|
|
23
|
+
if (ctx.db.prepare("PRAGMA index_info(background_operation_repair)").all().length > 1)
|
|
24
|
+
ctx.db.exec("DROP INDEX background_operation_repair");
|
|
25
|
+
ctx.db.exec("CREATE INDEX IF NOT EXISTS background_operation_repair ON operations(operation_id) WHERE observer_kind='local-supervisor'");
|
|
26
|
+
const sources = [
|
|
27
|
+
{ table: "waits", select: (r: string) => `SELECT 'wait', ${r}.wait_id || ':' || ${r}.generation, json_extract(${r}.origin_json,'$.assignmentRef'), ${r}.owner_session_id, ${r}.owner_workspace WHERE ${r}.owner_kind='worker-conversation'` },
|
|
28
|
+
{ table: "resume_claims", select: (r: string) => `SELECT 'claim', ${r}.claim_id, json_extract(w.origin_json,'$.assignmentRef'), w.owner_session_id, w.owner_workspace FROM waits w WHERE w.wait_id=${r}.wait_id AND w.generation=${r}.generation AND w.owner_kind='worker-conversation'` },
|
|
29
|
+
{ table: "assignment_bindings", select: (r: string) => `SELECT 'binding', ${r}.assignment_id, ${r}.assignment_id, json_extract(${r}.owner_json,'$.sessionId'), json_extract(${r}.owner_json,'$.workspace')` },
|
|
30
|
+
{ table: "assignment_attempts", select: (r: string) => `SELECT 'attempt', ${r}.attempt_id, b.assignment_id, json_extract(b.owner_json,'$.sessionId'), json_extract(b.owner_json,'$.workspace') FROM assignment_bindings b WHERE b.assignment_id=${r}.assignment_id` },
|
|
31
|
+
{ table: "assignment_outcomes", select: (r: string) => `SELECT 'outcome', ${r}.assignment_id, ${r}.assignment_id, json_extract(${r}.record_json,'$.owner.sessionId'), json_extract(${r}.record_json,'$.owner.workspace')` },
|
|
32
|
+
{ table: "outbox_events", select: (r: string) => `SELECT 'receipt', ${r}.event_id, b.assignment_id, json_extract(b.owner_json,'$.sessionId'), json_extract(b.owner_json,'$.workspace') FROM assignment_bindings b WHERE b.assignment_id=${r}.operation_id UNION ALL SELECT 'receipt', ${r}.event_id, json_extract(w.origin_json,'$.assignmentRef'), w.owner_session_id, w.owner_workspace FROM waits w WHERE w.wait_id=${r}.wait_id AND w.generation=${r}.generation AND w.owner_kind='worker-conversation'` },
|
|
33
|
+
];
|
|
34
|
+
for (const { table, select } of sources) for (const action of ["INSERT", "UPDATE", "DELETE"]) {
|
|
35
|
+
const records = action === "UPDATE" ? ["OLD", "NEW"] : [action === "DELETE" ? "OLD" : "NEW"];
|
|
36
|
+
ctx.db.exec(`CREATE TRIGGER IF NOT EXISTS assignment_change_${table}_${action.toLowerCase()} AFTER ${action} ON ${table} BEGIN ${records.map(r => `INSERT INTO assignment_changes(entity,entity_id,assignment_id,session_id,workspace) ${select(r)};`).join(" ")} END;`);
|
|
37
|
+
}
|
|
38
|
+
// These are observation inputs, not execution or delivery authority. Old
|
|
39
|
+
// cooperative SQL writers inherit the same atomic invalidation triggers.
|
|
40
|
+
const backgroundSources = [
|
|
41
|
+
{ table: "operations", select: (r: string) => `SELECT ${r}.operation_id, 1 WHERE ${r}.observer_kind='local-supervisor'` },
|
|
42
|
+
{ table: "waits", select: (r: string) => `SELECT d.operation_id, 1 FROM wait_dependencies d JOIN operations o ON o.operation_id=d.operation_id WHERE d.wait_id=${r}.wait_id AND d.generation=${r}.generation AND o.observer_kind='local-supervisor'` },
|
|
43
|
+
{ table: "wait_dependencies", select: (r: string) => `SELECT ${r}.operation_id, 1 WHERE EXISTS(SELECT 1 FROM operations o WHERE o.operation_id=${r}.operation_id AND o.observer_kind='local-supervisor')` },
|
|
44
|
+
{ table: "background_parent_callbacks", select: (r: string) => `SELECT ${r}.operation_id, 1 WHERE 1` },
|
|
45
|
+
{ table: "coordinator_state", select: (r: string) => `SELECT o.operation_id, 1 FROM operations o WHERE ${r}.key LIKE 'result-supervision-v1:%' AND o.operation_id=substr(${r}.key,length('result-supervision-v1:')+1) AND o.observer_kind='local-supervisor'` },
|
|
46
|
+
];
|
|
47
|
+
// Version 1 installed one-column SELECTs into a two-column INSERT. Replace
|
|
48
|
+
// only these owned triggers, atomically, without resetting source positions.
|
|
49
|
+
const replaceBackgroundTriggers = ctx.db.prepare("SELECT value FROM schema_meta WHERE key='background_input_triggers_version'").get()?.value !== "2";
|
|
50
|
+
for (const { table, select } of backgroundSources) for (const action of ["INSERT", "UPDATE", "DELETE"]) {
|
|
51
|
+
if (replaceBackgroundTriggers) ctx.db.exec(`DROP TRIGGER IF EXISTS background_input_${table}_${action.toLowerCase()}`);
|
|
52
|
+
const records = action === "UPDATE" ? ["OLD", "NEW"] : [action === "DELETE" ? "OLD" : "NEW"];
|
|
53
|
+
ctx.db.exec(`CREATE TRIGGER IF NOT EXISTS background_input_${table}_${action.toLowerCase()}
|
|
54
|
+
${action === "DELETE" ? "BEFORE" : "AFTER"} ${action} ON ${table} BEGIN
|
|
55
|
+
${records.map(r => `INSERT INTO background_input_versions(operation_id,revision) ${select(r)}
|
|
56
|
+
ON CONFLICT(operation_id) DO UPDATE SET revision=revision+1;`).join(" ")}
|
|
57
|
+
END;`);
|
|
58
|
+
}
|
|
59
|
+
if (replaceBackgroundTriggers) ctx.db.prepare("INSERT OR REPLACE INTO schema_meta(key,value) VALUES('background_input_triggers_version','2')").run();
|
|
60
|
+
ctx.db.exec(`CREATE TRIGGER IF NOT EXISTS background_journal_insert AFTER INSERT ON background_input_versions BEGIN
|
|
61
|
+
INSERT INTO assignment_changes(entity,entity_id,assignment_id,session_id,workspace)
|
|
62
|
+
SELECT 'background:operation', NEW.operation_id, NEW.operation_id, owner_session_id, owner_workspace FROM operations WHERE operation_id=NEW.operation_id;
|
|
63
|
+
END;
|
|
64
|
+
CREATE TRIGGER IF NOT EXISTS background_journal_update AFTER UPDATE ON background_input_versions BEGIN
|
|
65
|
+
INSERT INTO assignment_changes(entity,entity_id,assignment_id,session_id,workspace)
|
|
66
|
+
SELECT 'background:operation', NEW.operation_id, NEW.operation_id, owner_session_id, owner_workspace FROM operations WHERE operation_id=NEW.operation_id;
|
|
67
|
+
END;
|
|
68
|
+
CREATE TRIGGER IF NOT EXISTS background_journal_previous_scope AFTER UPDATE ON operations
|
|
69
|
+
WHEN OLD.observer_kind='local-supervisor' AND (OLD.owner_session_id<>NEW.owner_session_id OR OLD.owner_workspace<>NEW.owner_workspace OR OLD.owner_kind<>NEW.owner_kind)
|
|
70
|
+
BEGIN INSERT INTO assignment_changes(entity,entity_id,assignment_id,session_id,workspace)
|
|
71
|
+
VALUES('background:operation',OLD.operation_id,OLD.operation_id,OLD.owner_session_id,OLD.owner_workspace); END;`);
|
|
72
|
+
});
|
|
73
|
+
}
|
package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/shared-operation-coordinator/src/assignment-outcomes.ts. Do not edit directly.
|
|
2
2
|
// Generated from packages/operation-coordinator/src/assignment-outcomes.ts. Do not edit directly.
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import { bumpChangeRevision } from "./discovery.domain.mjs";
|
|
4
5
|
import { StoreError } from "./errors.domain.mjs";
|
|
5
6
|
import { columnText, getRow, getRows, run } from "./sqlite.domain.mjs";
|
|
6
7
|
import { requireWait, readPins } from "./rows.domain.mjs";
|
|
@@ -108,6 +109,7 @@ export function recordAssignmentOutcome(ctx, input) {
|
|
|
108
109
|
for (const e of retained)
|
|
109
110
|
run(ctx, `INSERT OR IGNORE INTO evidence_pins (pin_id, wait_id, generation, operation_id, terminal_revision, kind, ref, summary, detail_lost, bytes, pinned_at) VALUES (?, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?)`, `pin_${randomUUID()}`, eventId, e.operationId, e.terminalRevision, e.kind, e.ref, e.summary ?? null, e.detailLost ? 1 : 0, e.bytes ?? null, at);
|
|
110
111
|
run(ctx, `INSERT INTO outbox_events (event_id, event_type, operation_id, terminal_revision, wait_id, generation, recipient_kind, recipient_session_id, recipient_workspace, recipient_branch_id, recipient_goal_id, state, created_at) VALUES (?, 'assignment-outcome', ?, ?, ?, 1, ?, ?, ?, ?, ?, 'pending', ?)`, eventId, assignmentId, revision, eventId, recipient.kind, recipient.sessionId, recipient.workspace, recipient.branchId ?? null, recipient.goalId ?? null, at);
|
|
112
|
+
bumpChangeRevision(ctx);
|
|
111
113
|
return record;
|
|
112
114
|
});
|
|
113
115
|
}
|
package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Generated from packages/operation-coordinator/src/assignment-outcomes.ts. Do not edit directly.
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { bumpChangeRevision } from "./discovery.ts";
|
|
3
4
|
import { StoreError } from "./errors.ts";
|
|
4
5
|
import { columnText, getRow, getRows, run, type StoreContext } from "./sqlite.ts";
|
|
5
6
|
import { requireWait, readPins } from "./rows.ts";
|
|
@@ -120,6 +121,7 @@ export function recordAssignmentOutcome(ctx: StoreContext, input: AssignmentOutc
|
|
|
120
121
|
}
|
|
121
122
|
for (const e of retained) run(ctx, `INSERT OR IGNORE INTO evidence_pins (pin_id, wait_id, generation, operation_id, terminal_revision, kind, ref, summary, detail_lost, bytes, pinned_at) VALUES (?, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?)`, `pin_${randomUUID()}`, eventId, e.operationId, e.terminalRevision, e.kind, e.ref, e.summary ?? null, e.detailLost ? 1 : 0, e.bytes ?? null, at);
|
|
122
123
|
run(ctx, `INSERT INTO outbox_events (event_id, event_type, operation_id, terminal_revision, wait_id, generation, recipient_kind, recipient_session_id, recipient_workspace, recipient_branch_id, recipient_goal_id, state, created_at) VALUES (?, 'assignment-outcome', ?, ?, ?, 1, ?, ?, ?, ?, ?, 'pending', ?)`, eventId, assignmentId, revision, eventId, recipient.kind, recipient.sessionId, recipient.workspace, recipient.branchId ?? null, recipient.goalId ?? null, at);
|
|
124
|
+
bumpChangeRevision(ctx);
|
|
123
125
|
return record;
|
|
124
126
|
});
|
|
125
127
|
}
|
package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs
CHANGED
|
@@ -24,7 +24,7 @@ export class BackgroundRequests {
|
|
|
24
24
|
write(value) {
|
|
25
25
|
this.context.db.prepare('INSERT OR REPLACE INTO coordinator_state (key,value) VALUES (?,?)').run(storageKey(value.owner, value.key), JSON.stringify(value));
|
|
26
26
|
}
|
|
27
|
-
accept(owner, key, digest) {
|
|
27
|
+
accept(owner, key, digest, writerFence) {
|
|
28
28
|
this.alive();
|
|
29
29
|
return this.context.transaction(() => {
|
|
30
30
|
const prior = this.read(owner, key);
|
|
@@ -33,7 +33,7 @@ export class BackgroundRequests {
|
|
|
33
33
|
throw new Error('request-conflict: Background request key changed content');
|
|
34
34
|
return { prior: true, record: prior };
|
|
35
35
|
}
|
|
36
|
-
const record = { owner, key, digest, state: 'accepted', operations: [] };
|
|
36
|
+
const record = { owner, key, digest, state: 'accepted', operations: [], acceptedAt: Date.now(), lastProgressAt: Date.now(), writerFence };
|
|
37
37
|
this.write(record);
|
|
38
38
|
return { prior: false, record };
|
|
39
39
|
});
|
|
@@ -62,9 +62,18 @@ export class BackgroundRequests {
|
|
|
62
62
|
if (!value)
|
|
63
63
|
throw new Error('Background request not admitted');
|
|
64
64
|
change(value);
|
|
65
|
+
value.lastProgressAt = Date.now();
|
|
65
66
|
this.write(value);
|
|
66
67
|
});
|
|
67
68
|
}
|
|
69
|
+
lifecycleReasons() {
|
|
70
|
+
return this.pending().map(record => ({ kind: 'task', id: storageKey(record.owner, record.key),
|
|
71
|
+
owner: record.owner, state: record.state, acceptedAt: record.acceptedAt ?? null,
|
|
72
|
+
writerFence: record.writerFence ?? null,
|
|
73
|
+
lastProgressAt: record.lastProgressAt ?? null, executionDeadline: null, nextDeadline: null,
|
|
74
|
+
operations: record.operations.map(({ operationId, taskId }) => ({ operationId, taskId })),
|
|
75
|
+
recovery: 'drain-accepted-background-request-until-journal-return-or-authoritative-handoff' }));
|
|
76
|
+
}
|
|
68
77
|
hasPending() {
|
|
69
78
|
this.alive();
|
|
70
79
|
return Boolean(this.context.db.prepare(`SELECT 1 FROM coordinator_state INDEXED BY background_requests_pending WHERE ${pendingPredicate} LIMIT 1`).get());
|
package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts
CHANGED
|
@@ -12,6 +12,9 @@ export interface BackgroundRequest {
|
|
|
12
12
|
token: string;
|
|
13
13
|
}>;
|
|
14
14
|
result?: unknown;
|
|
15
|
+
acceptedAt?: number;
|
|
16
|
+
lastProgressAt?: number;
|
|
17
|
+
writerFence?: { instance: string; pid: number; start: string };
|
|
15
18
|
}
|
|
16
19
|
const prefix = 'background-request-v1:';
|
|
17
20
|
// A partial index excludes returned history. CASE protects other coordinator
|
|
@@ -36,7 +39,7 @@ export class BackgroundRequests {
|
|
|
36
39
|
private write(value: BackgroundRequest) {
|
|
37
40
|
this.context.db.prepare('INSERT OR REPLACE INTO coordinator_state (key,value) VALUES (?,?)').run(storageKey(value.owner, value.key), JSON.stringify(value));
|
|
38
41
|
}
|
|
39
|
-
accept(owner: string, key: string, digest: string) {
|
|
42
|
+
accept(owner: string, key: string, digest: string, writerFence?: BackgroundRequest['writerFence']) {
|
|
40
43
|
this.alive();
|
|
41
44
|
return this.context.transaction(() => {
|
|
42
45
|
const prior = this.read(owner, key);
|
|
@@ -45,7 +48,7 @@ export class BackgroundRequests {
|
|
|
45
48
|
throw new Error('request-conflict: Background request key changed content');
|
|
46
49
|
return { prior: true, record: prior };
|
|
47
50
|
}
|
|
48
|
-
const record: BackgroundRequest = { owner, key, digest, state: 'accepted', operations: [] };
|
|
51
|
+
const record: BackgroundRequest = { owner, key, digest, state: 'accepted', operations: [], acceptedAt: Date.now(), lastProgressAt: Date.now(), writerFence };
|
|
49
52
|
this.write(record);
|
|
50
53
|
return { prior: false, record };
|
|
51
54
|
});
|
|
@@ -65,7 +68,15 @@ export class BackgroundRequests {
|
|
|
65
68
|
private update(owner: string, key: string, change: (value: BackgroundRequest) => void) {
|
|
66
69
|
this.alive();
|
|
67
70
|
this.context.transaction(() => { const value = this.read(owner, key); if (!value)
|
|
68
|
-
throw new Error('Background request not admitted'); change(value); this.write(value); });
|
|
71
|
+
throw new Error('Background request not admitted'); change(value); value.lastProgressAt = Date.now(); this.write(value); });
|
|
72
|
+
}
|
|
73
|
+
lifecycleReasons() {
|
|
74
|
+
return this.pending().map(record => ({ kind: 'task', id: storageKey(record.owner, record.key),
|
|
75
|
+
owner: record.owner, state: record.state, acceptedAt: record.acceptedAt ?? null,
|
|
76
|
+
writerFence: record.writerFence ?? null,
|
|
77
|
+
lastProgressAt: record.lastProgressAt ?? null, executionDeadline: null, nextDeadline: null,
|
|
78
|
+
operations: record.operations.map(({ operationId, taskId }) => ({ operationId, taskId })),
|
|
79
|
+
recovery: 'drain-accepted-background-request-until-journal-return-or-authoritative-handoff' }));
|
|
69
80
|
}
|
|
70
81
|
hasPending(): boolean {
|
|
71
82
|
this.alive();
|
|
@@ -36,9 +36,11 @@ export function readDiscoveryClaim(ctx, scope) {
|
|
|
36
36
|
/** Read scope transfer and its discovery claim from one SQLite snapshot. */
|
|
37
37
|
export function readDiscoveryState(ctx, scope) {
|
|
38
38
|
scope = requireId("scope", scope);
|
|
39
|
-
const row = getRow(ctx, `SELECT d.*, EXISTS(SELECT 1 FROM coordinator_state WHERE key = ?) AS managed
|
|
39
|
+
const row = getRow(ctx, `SELECT d.*, EXISTS(SELECT 1 FROM coordinator_state WHERE key = ?) AS managed,
|
|
40
|
+
EXISTS(SELECT 1 FROM operations INDEXED BY operations_assignment_cleanup
|
|
41
|
+
WHERE assignment_attempt_id IS NOT NULL) AS has_assignment_tasks
|
|
40
42
|
FROM (SELECT 1) LEFT JOIN discovery_claims d ON d.scope = ?`, "result-scope-v1:" + scope, scope);
|
|
41
|
-
return { managed: Number(row.managed) === 1, claim: row.scope == null ? null : mapClaim(row) };
|
|
43
|
+
return { managed: Number(row.managed) === 1, claim: row.scope == null ? null : mapClaim(row), hasAssignmentTasks: Number(row.has_assignment_tasks) === 1 };
|
|
42
44
|
}
|
|
43
45
|
export function tryClaimDiscovery(ctx, input) {
|
|
44
46
|
const scope = requireId("scope", input.scope);
|
|
@@ -49,11 +49,13 @@ export function readDiscoveryClaim(ctx: StoreContext, scope: unknown): Discovery
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/** Read scope transfer and its discovery claim from one SQLite snapshot. */
|
|
52
|
-
export function readDiscoveryState(ctx: StoreContext, scope: string): { managed: boolean; claim: DiscoveryClaimRecord | null } {
|
|
52
|
+
export function readDiscoveryState(ctx: StoreContext, scope: string): { managed: boolean; claim: DiscoveryClaimRecord | null; hasAssignmentTasks: boolean } {
|
|
53
53
|
scope = requireId("scope", scope);
|
|
54
|
-
const row = getRow(ctx, `SELECT d.*, EXISTS(SELECT 1 FROM coordinator_state WHERE key = ?) AS managed
|
|
54
|
+
const row = getRow(ctx, `SELECT d.*, EXISTS(SELECT 1 FROM coordinator_state WHERE key = ?) AS managed,
|
|
55
|
+
EXISTS(SELECT 1 FROM operations INDEXED BY operations_assignment_cleanup
|
|
56
|
+
WHERE assignment_attempt_id IS NOT NULL) AS has_assignment_tasks
|
|
55
57
|
FROM (SELECT 1) LEFT JOIN discovery_claims d ON d.scope = ?`, "result-scope-v1:" + scope, scope)!;
|
|
56
|
-
return { managed: Number(row.managed) === 1, claim: row.scope == null ? null : mapClaim(row) };
|
|
58
|
+
return { managed: Number(row.managed) === 1, claim: row.scope == null ? null : mapClaim(row), hasAssignmentTasks: Number(row.has_assignment_tasks) === 1 };
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
export function tryClaimDiscovery(
|