pi-better-server 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -1
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +87 -0
- package/scripts/event-publication/writer.mjs +6 -0
- package/scripts/measure-full-runtime/frontend.ts +24 -0
- package/scripts/measure-full-runtime/hosted-extension.ts +28 -0
- package/scripts/measure-full-runtime/probe.mjs +29 -0
- 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 +146 -0
- package/scripts/measure-shared-reads/probe.mjs +26 -2
- package/scripts/measure-shared-reads.mjs +44 -9
- package/scripts/private-runtime/package-lock.json +66 -4
- package/scripts/private-runtime/package.json +10 -2
- package/scripts/source-provenance.mjs +31 -0
- package/scripts/test-on-pi.sh +3 -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 +27 -0
- package/src/runtime/background-tools.ts +389 -0
- package/src/runtime/background.ts +410 -48
- 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 +71 -33
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +3 -3
- package/src/runtime/domain/background/registry.mjs +89 -4
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +83 -0
- package/src/runtime/domain/background-service/adapter-contract.ts +70 -0
- package/src/runtime/domain/background-service/batch.domain.mjs +91 -0
- package/src/runtime/domain/background-service/batch.ts +111 -0
- package/src/runtime/domain/background-service/conditions.domain.mjs +94 -0
- package/src/runtime/domain/background-service/conditions.ts +99 -0
- package/src/runtime/domain/background-service/delivery-observer.domain.mjs +37 -0
- package/src/runtime/domain/background-service/delivery-observer.ts +42 -0
- package/src/runtime/domain/background-service/failures.domain.mjs +209 -0
- package/src/runtime/domain/background-service/failures.ts +212 -0
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +193 -0
- package/src/runtime/domain/background-service/goal-provider.ts +209 -0
- package/src/runtime/domain/background-service/index.domain.mjs +54 -0
- package/src/runtime/domain/background-service/index.ts +55 -0
- package/src/runtime/domain/background-service/logs.domain.mjs +129 -0
- package/src/runtime/domain/background-service/logs.ts +134 -0
- package/src/runtime/domain/background-service/maintenance.domain.mjs +95 -0
- package/src/runtime/domain/background-service/maintenance.ts +98 -0
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +32 -0
- package/src/runtime/domain/background-service/managed-authority.ts +30 -0
- package/src/runtime/domain/background-service/managed-client.domain.mjs +79 -0
- package/src/runtime/domain/background-service/managed-client.ts +73 -0
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +225 -0
- package/src/runtime/domain/background-service/managed-frontend.ts +176 -0
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +492 -0
- package/src/runtime/domain/background-service/navigator-provider.ts +485 -0
- 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 +4080 -0
- package/src/runtime/domain/background-service/observed-waits.ts +4513 -0
- package/src/runtime/domain/background-service/output.domain.mjs +867 -0
- package/src/runtime/domain/background-service/output.ts +952 -0
- package/src/runtime/domain/background-service/process-identity.domain.mjs +129 -0
- package/src/runtime/domain/background-service/process-identity.ts +134 -0
- package/src/runtime/domain/background-service/process.domain.mjs +512 -0
- package/src/runtime/domain/background-service/process.ts +532 -0
- package/src/runtime/domain/background-service/prompt.domain.mjs +58 -0
- package/src/runtime/domain/background-service/prompt.ts +72 -0
- package/src/runtime/domain/background-service/registry.domain.mjs +460 -0
- package/src/runtime/domain/background-service/registry.ts +450 -0
- package/src/runtime/domain/background-service/remote-task-preset.domain.mjs +67 -0
- package/src/runtime/domain/background-service/remote-task-preset.ts +127 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +1511 -0
- package/src/runtime/domain/background-service/runtime.ts +1636 -0
- package/src/runtime/domain/background-service/sandbox.domain.mjs +735 -0
- package/src/runtime/domain/background-service/sandbox.ts +913 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/background-service/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/background-service/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/background-service/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/background-service/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/background-service/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/background-service/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/background-service/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/background-service/shared-navigator.ts +1962 -0
- 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 +189 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/index.ts +122 -0
- 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 +163 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/background-service/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/background-service/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +698 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.ts +979 -0
- package/src/runtime/domain/background-service/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/background-service/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/background-service/shared-work-client.mjs +303 -0
- package/src/runtime/domain/background-service/stall-attention.domain.mjs +29 -0
- package/src/runtime/domain/background-service/stall-attention.ts +31 -0
- package/src/runtime/domain/background-service/stall.domain.mjs +57 -0
- package/src/runtime/domain/background-service/stall.ts +57 -0
- package/src/runtime/domain/background-service/supervisor/README.md +111 -0
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +90 -0
- package/src/runtime/domain/background-service/supervisor/generated/conditions.mjs +96 -0
- package/src/runtime/domain/background-service/supervisor/generated/identity.mjs +95 -0
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +131 -0
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +514 -0
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +872 -0
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +609 -0
- package/src/runtime/domain/background-service/supervisor/generated/types.mjs +50 -0
- package/src/runtime/domain/background-service/supervisor/identity.domain.mjs +93 -0
- package/src/runtime/domain/background-service/supervisor/identity.ts +99 -0
- package/src/runtime/domain/background-service/supervisor/index.domain.mjs +22 -0
- package/src/runtime/domain/background-service/supervisor/index.ts +37 -0
- package/src/runtime/domain/background-service/supervisor/invocation.domain.mjs +30 -0
- package/src/runtime/domain/background-service/supervisor/invocation.ts +44 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +870 -0
- package/src/runtime/domain/background-service/supervisor/runner.ts +982 -0
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +605 -0
- package/src/runtime/domain/background-service/supervisor/store.ts +651 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +721 -0
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +804 -0
- package/src/runtime/domain/background-service/supervisor/types.domain.mjs +48 -0
- package/src/runtime/domain/background-service/supervisor/types.ts +394 -0
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +60 -0
- package/src/runtime/domain/background-service/task-diagnostics.ts +71 -0
- package/src/runtime/domain/background-service/tools.domain.mjs +1050 -0
- package/src/runtime/domain/background-service/tools.ts +1142 -0
- package/src/runtime/domain/background-service/types.domain.mjs +5 -0
- package/src/runtime/domain/background-service/types.ts +236 -0
- package/src/runtime/domain/background-service/work-observation.domain.mjs +176 -0
- package/src/runtime/domain/background-service/work-observation.ts +144 -0
- 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-parent-callbacks.mjs +65 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +86 -0
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +73 -21
- package/src/runtime/domain/coordinator/src/store.mjs +32 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +119 -0
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/coordinator/src/upgrade.mjs +22 -0
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +50 -5
- package/src/runtime/domain/sandbox-policy/README.md +633 -0
- package/src/runtime/domain/sandbox-policy/background-admission.domain.mjs +83 -0
- package/src/runtime/domain/sandbox-policy/background-admission.ts +75 -0
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +245 -0
- package/src/runtime/domain/sandbox-policy/commands.ts +336 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.domain.mjs +440 -0
- package/src/runtime/domain/sandbox-policy/deny-rules.ts +620 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.domain.mjs +30 -0
- package/src/runtime/domain/sandbox-policy/diagnostics-command.ts +27 -0
- package/src/runtime/domain/sandbox-policy/events.domain.mjs +49 -0
- package/src/runtime/domain/sandbox-policy/events.ts +85 -0
- package/src/runtime/domain/sandbox-policy/files.domain.mjs +153 -0
- package/src/runtime/domain/sandbox-policy/files.ts +224 -0
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +289 -0
- package/src/runtime/domain/sandbox-policy/index.ts +386 -0
- package/src/runtime/domain/sandbox-policy/package.json +66 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +36 -0
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +46 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +309 -0
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +295 -0
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +98 -0
- package/src/runtime/domain/sandbox-policy/permissions.ts +125 -0
- package/src/runtime/domain/sandbox-policy/policy.domain.mjs +80 -0
- package/src/runtime/domain/sandbox-policy/policy.ts +102 -0
- package/src/runtime/domain/sandbox-policy/preferences.domain.mjs +55 -0
- package/src/runtime/domain/sandbox-policy/preferences.ts +82 -0
- package/src/runtime/domain/sandbox-policy/rules-page.domain.mjs +138 -0
- package/src/runtime/domain/sandbox-policy/rules-page.ts +176 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.domain.mjs +22 -0
- package/src/runtime/domain/sandbox-policy/session-permissions.ts +24 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/sandbox-policy/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-application.ts +185 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/sandbox-policy/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +335 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/sandbox-policy/shared-task-files.ts +342 -0
- 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 +220 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +123 -0
- package/src/runtime/domain/sandbox-policy/shell.domain.mjs +93 -0
- package/src/runtime/domain/sandbox-policy/shell.ts +129 -0
- package/src/runtime/domain/sandbox-policy/state.domain.mjs +307 -0
- package/src/runtime/domain/sandbox-policy/state.ts +408 -0
- package/src/runtime/domain/sandbox-policy/status.domain.mjs +64 -0
- package/src/runtime/domain/sandbox-policy/status.ts +76 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.domain.mjs +69 -0
- package/src/runtime/domain/sandbox-policy/subagent-admission.ts +60 -0
- package/src/runtime/domain/subagents/CONTEXT.md +202 -0
- package/src/runtime/domain/subagents/PRODUCT.md +49 -0
- package/src/runtime/domain/subagents/README.md +201 -0
- package/src/runtime/domain/subagents/agent-catalog.mjs +64 -0
- package/src/runtime/domain/subagents/agent-commands.domain.mjs +822 -0
- package/src/runtime/domain/subagents/agent-commands.ts +905 -0
- package/src/runtime/domain/subagents/agent-inspection.domain.mjs +398 -0
- package/src/runtime/domain/subagents/agent-inspection.ts +574 -0
- package/src/runtime/domain/subagents/agent-operations.domain.mjs +40 -0
- package/src/runtime/domain/subagents/agent-operations.ts +61 -0
- package/src/runtime/domain/subagents/agent-session-settings.domain.mjs +112 -0
- package/src/runtime/domain/subagents/agent-session-settings.ts +118 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.domain.mjs +84 -0
- package/src/runtime/domain/subagents/agents-catalog-tool.ts +118 -0
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +276 -0
- package/src/runtime/domain/subagents/assignment-outcomes.ts +212 -0
- package/src/runtime/domain/subagents/assignment-projection.mjs +261 -0
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +174 -0
- package/src/runtime/domain/subagents/assignment-report.ts +156 -0
- package/src/runtime/domain/subagents/batch.mjs +275 -0
- package/src/runtime/domain/subagents/callback-fields.domain.mjs +72 -0
- package/src/runtime/domain/subagents/callback-fields.ts +95 -0
- package/src/runtime/domain/subagents/capacity.mjs +108 -0
- package/src/runtime/domain/subagents/catalog-editor.domain.mjs +98 -0
- package/src/runtime/domain/subagents/catalog-editor.ts +125 -0
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +104 -0
- package/src/runtime/domain/subagents/catalog-host-admission.ts +85 -0
- package/src/runtime/domain/subagents/catalog-identity.domain.mjs +222 -0
- package/src/runtime/domain/subagents/catalog-identity.ts +258 -0
- package/src/runtime/domain/subagents/catalog-overlay.domain.mjs +9 -0
- package/src/runtime/domain/subagents/catalog-overlay.ts +10 -0
- package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +164 -0
- package/src/runtime/domain/subagents/catalog-preferences.ts +139 -0
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +366 -0
- package/src/runtime/domain/subagents/catalog-resolver.ts +540 -0
- package/src/runtime/domain/subagents/catalog-runtime.domain.mjs +570 -0
- package/src/runtime/domain/subagents/catalog-runtime.ts +680 -0
- package/src/runtime/domain/subagents/catalog-schema.domain.mjs +1331 -0
- package/src/runtime/domain/subagents/catalog-schema.ts +1563 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.domain.mjs +95 -0
- package/src/runtime/domain/subagents/catalog-skill-edits.ts +116 -0
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +808 -0
- package/src/runtime/domain/subagents/catalog-store.ts +1006 -0
- package/src/runtime/domain/subagents/catalog-ui.domain.mjs +651 -0
- package/src/runtime/domain/subagents/catalog-ui.ts +611 -0
- 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-codemode.domain.mjs +16 -0
- package/src/runtime/domain/subagents/child-codemode.ts +17 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +193 -0
- package/src/runtime/domain/subagents/child-incidents.domain.mjs +170 -0
- package/src/runtime/domain/subagents/child-incidents.ts +169 -0
- package/src/runtime/domain/subagents/child-operations.domain.mjs +986 -0
- package/src/runtime/domain/subagents/child-operations.ts +1191 -0
- package/src/runtime/domain/subagents/child-ownership.domain.mjs +205 -0
- package/src/runtime/domain/subagents/child-ownership.ts +160 -0
- package/src/runtime/domain/subagents/child-preflight.mjs +38 -0
- 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/child-runtime.mjs +67 -0
- package/src/runtime/domain/subagents/child-steer.domain.mjs +109 -0
- package/src/runtime/domain/subagents/child-steer.ts +102 -0
- package/src/runtime/domain/subagents/cleanup.domain.mjs +818 -0
- package/src/runtime/domain/subagents/cleanup.ts +1017 -0
- package/src/runtime/domain/subagents/codex-import.domain.mjs +575 -0
- package/src/runtime/domain/subagents/codex-import.ts +717 -0
- package/src/runtime/domain/subagents/completion.domain.mjs +6 -0
- package/src/runtime/domain/subagents/completion.mjs +152 -0
- package/src/runtime/domain/subagents/completion.ts +11 -0
- package/src/runtime/domain/subagents/config.domain.mjs +248 -0
- package/src/runtime/domain/subagents/config.json +15 -0
- package/src/runtime/domain/subagents/config.ts +328 -0
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +38 -0
- package/src/runtime/domain/subagents/continuation-authority.ts +31 -0
- 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 +942 -0
- package/src/runtime/domain/subagents/continuation.ts +1051 -0
- package/src/runtime/domain/subagents/delegation.domain.mjs +19 -0
- package/src/runtime/domain/subagents/delegation.ts +24 -0
- package/src/runtime/domain/subagents/effective-settings.domain.mjs +130 -0
- package/src/runtime/domain/subagents/effective-settings.ts +184 -0
- package/src/runtime/domain/subagents/extensions.domain.mjs +6 -0
- package/src/runtime/domain/subagents/extensions.mjs +164 -0
- package/src/runtime/domain/subagents/extensions.ts +19 -0
- package/src/runtime/domain/subagents/failures.domain.mjs +362 -0
- package/src/runtime/domain/subagents/failures.ts +319 -0
- package/src/runtime/domain/subagents/finalization.domain.mjs +168 -0
- package/src/runtime/domain/subagents/finalization.ts +218 -0
- package/src/runtime/domain/subagents/git-remotes.domain.mjs +351 -0
- package/src/runtime/domain/subagents/git-remotes.ts +413 -0
- package/src/runtime/domain/subagents/git-workspace.domain.mjs +337 -0
- package/src/runtime/domain/subagents/git-workspace.ts +430 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +125 -0
- package/src/runtime/domain/subagents/goal-provider.ts +132 -0
- package/src/runtime/domain/subagents/health-observation.domain.mjs +617 -0
- package/src/runtime/domain/subagents/health-observation.ts +818 -0
- package/src/runtime/domain/subagents/health-surface.mjs +284 -0
- package/src/runtime/domain/subagents/health.domain.mjs +261 -0
- package/src/runtime/domain/subagents/health.ts +343 -0
- package/src/runtime/domain/subagents/historical-attention.domain.mjs +37 -0
- package/src/runtime/domain/subagents/historical-attention.ts +35 -0
- package/src/runtime/domain/subagents/incident-model.domain.mjs +322 -0
- package/src/runtime/domain/subagents/incident-model.ts +358 -0
- package/src/runtime/domain/subagents/index.domain.mjs +4731 -0
- package/src/runtime/domain/subagents/index.ts +4781 -0
- package/src/runtime/domain/subagents/launch-abort.domain.mjs +13 -0
- package/src/runtime/domain/subagents/launch-abort.ts +21 -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/lifecycle.domain.mjs +265 -0
- package/src/runtime/domain/subagents/lifecycle.ts +360 -0
- package/src/runtime/domain/subagents/list.domain.mjs +2 -0
- package/src/runtime/domain/subagents/list.mjs +152 -0
- package/src/runtime/domain/subagents/list.ts +19 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +217 -0
- package/src/runtime/domain/subagents/log-cursor.ts +268 -0
- package/src/runtime/domain/subagents/managed-background-capability.domain.mjs +10 -0
- package/src/runtime/domain/subagents/managed-background-capability.ts +9 -0
- package/src/runtime/domain/subagents/managed-failure-worker.mjs +36 -0
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +48 -0
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +75 -0
- package/src/runtime/domain/subagents/managed-launch-client.ts +59 -0
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +627 -0
- package/src/runtime/domain/subagents/managed-launch-host.ts +504 -0
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +17 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-ownership.ts +22 -0
- package/src/runtime/domain/subagents/managed-launch-port.domain.mjs +2 -0
- package/src/runtime/domain/subagents/managed-launch-port.ts +25 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.domain.mjs +29 -0
- package/src/runtime/domain/subagents/managed-launch-recovery.ts +45 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.domain.mjs +63 -0
- package/src/runtime/domain/subagents/managed-worker-bridge.ts +48 -0
- package/src/runtime/domain/subagents/managed-worker.mjs +13 -0
- package/src/runtime/domain/subagents/model-resolution-core.domain.mjs +822 -0
- package/src/runtime/domain/subagents/model-resolution-core.ts +1074 -0
- package/src/runtime/domain/subagents/model-resolution.domain.mjs +22 -0
- package/src/runtime/domain/subagents/model-resolution.ts +32 -0
- package/src/runtime/domain/subagents/navigator.domain.mjs +6 -0
- package/src/runtime/domain/subagents/navigator.mjs +1233 -0
- package/src/runtime/domain/subagents/navigator.ts +39 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +1012 -0
- package/src/runtime/domain/subagents/operation-bridge-types.ts +1156 -0
- package/src/runtime/domain/subagents/outage-observations.domain.mjs +84 -0
- package/src/runtime/domain/subagents/outage-observations.ts +73 -0
- package/src/runtime/domain/subagents/output-payload.domain.mjs +767 -0
- package/src/runtime/domain/subagents/output-payload.ts +987 -0
- 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 +86 -0
- package/src/runtime/domain/subagents/park-checkpoint.domain.mjs +55 -0
- package/src/runtime/domain/subagents/park-checkpoint.ts +61 -0
- package/src/runtime/domain/subagents/parse.domain.mjs +1218 -0
- package/src/runtime/domain/subagents/parse.ts +1451 -0
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +232 -0
- package/src/runtime/domain/subagents/permission-policy.ts +291 -0
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +1584 -0
- package/src/runtime/domain/subagents/registry.ts +1904 -0
- package/src/runtime/domain/subagents/role-assignment.domain.mjs +104 -0
- package/src/runtime/domain/subagents/role-assignment.ts +141 -0
- package/src/runtime/domain/subagents/roles/role.architect.md +13 -0
- package/src/runtime/domain/subagents/roles/role.developer.md +16 -0
- package/src/runtime/domain/subagents/roles/role.explorer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.product-manager.md +13 -0
- package/src/runtime/domain/subagents/roles/role.researcher.md +13 -0
- package/src/runtime/domain/subagents/roles/role.reviewer.md +13 -0
- package/src/runtime/domain/subagents/roles/role.writer.md +12 -0
- package/src/runtime/domain/subagents/sandbox.domain.mjs +64 -0
- package/src/runtime/domain/subagents/sandbox.ts +92 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +32 -0
- package/src/runtime/domain/subagents/session-selection.ts +35 -0
- package/src/runtime/domain/subagents/session-store.domain.mjs +489 -0
- package/src/runtime/domain/subagents/session-store.ts +468 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +313 -0
- package/src/runtime/domain/subagents/settings-page.ts +363 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +777 -0
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +956 -0
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +70 -0
- package/src/runtime/domain/subagents/shared-catalog.ts +61 -0
- package/src/runtime/domain/subagents/shared-execution-policy.domain.mjs +50 -0
- package/src/runtime/domain/subagents/shared-execution-policy.ts +61 -0
- package/src/runtime/domain/subagents/shared-failure-observations.domain.mjs +1078 -0
- package/src/runtime/domain/subagents/shared-failure-observations.ts +1166 -0
- package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +126 -0
- package/src/runtime/domain/subagents/shared-harness-settings.ts +116 -0
- package/src/runtime/domain/subagents/shared-log-utils.domain.mjs +1223 -0
- package/src/runtime/domain/subagents/shared-log-utils.ts +1492 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +289 -0
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +272 -0
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +1930 -0
- package/src/runtime/domain/subagents/shared-navigator.ts +1962 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +189 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.domain.mjs +51 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/index.ts +122 -0
- 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 +163 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +174 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.domain.mjs +66 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +87 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +90 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +97 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +139 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/errors.ts +79 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +342 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +513 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +283 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +458 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.domain.mjs +52 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/recovery.ts +55 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +114 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +140 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +280 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +442 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +420 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +441 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.domain.mjs +194 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/sqlite.ts +239 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +275 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +585 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +120 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +142 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.domain.mjs +188 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +25 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +707 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.domain.mjs +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.domain.mjs +234 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/validate.ts +241 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +851 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +1424 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.domain.mjs +40 -0
- package/src/runtime/domain/subagents/shared-permission-blocker.ts +48 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.domain.mjs +41 -0
- package/src/runtime/domain/subagents/shared-render-scheduler.ts +47 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.domain.mjs +1531 -0
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1757 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +591 -0
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +491 -0
- package/src/runtime/domain/subagents/shared-stall-detector.domain.mjs +37 -0
- package/src/runtime/domain/subagents/shared-stall-detector.ts +69 -0
- package/src/runtime/domain/subagents/shared-task-application.domain.mjs +185 -0
- package/src/runtime/domain/subagents/shared-task-application.ts +185 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.domain.mjs +416 -0
- package/src/runtime/domain/subagents/shared-task-apply-patch.ts +409 -0
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +325 -0
- package/src/runtime/domain/subagents/shared-task-exec.ts +335 -0
- package/src/runtime/domain/subagents/shared-task-files.domain.mjs +346 -0
- package/src/runtime/domain/subagents/shared-task-files.ts +342 -0
- 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 +220 -0
- package/src/runtime/domain/subagents/shared-task-process-list.ts +209 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +227 -0
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +224 -0
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +92 -0
- package/src/runtime/domain/subagents/shared-task-tools.ts +123 -0
- package/src/runtime/domain/subagents/shared-work-client.mjs +303 -0
- package/src/runtime/domain/subagents/shared-worktree-context.domain.mjs +142 -0
- package/src/runtime/domain/subagents/shared-worktree-context.ts +158 -0
- package/src/runtime/domain/subagents/skill-picker.domain.mjs +316 -0
- package/src/runtime/domain/subagents/skill-picker.ts +353 -0
- package/src/runtime/domain/subagents/skills.domain.mjs +138 -0
- package/src/runtime/domain/subagents/skills.ts +183 -0
- package/src/runtime/domain/subagents/spawn.domain.mjs +72 -0
- package/src/runtime/domain/subagents/spawn.ts +80 -0
- package/src/runtime/domain/subagents/stop.domain.mjs +184 -0
- package/src/runtime/domain/subagents/stop.ts +217 -0
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +101 -0
- package/src/runtime/domain/subagents/subagent-tools.ts +137 -0
- package/src/runtime/domain/subagents/task-guard.domain.mjs +163 -0
- package/src/runtime/domain/subagents/task-guard.ts +144 -0
- package/src/runtime/domain/subagents/task-policy.domain.mjs +201 -0
- package/src/runtime/domain/subagents/task-policy.ts +236 -0
- package/src/runtime/domain/subagents/task-runtime.mjs +53 -0
- package/src/runtime/domain/subagents/task-tool-owner.domain.mjs +18 -0
- package/src/runtime/domain/subagents/task-tool-owner.ts +21 -0
- package/src/runtime/domain/subagents/thinking.domain.mjs +22 -0
- package/src/runtime/domain/subagents/thinking.ts +28 -0
- package/src/runtime/domain/subagents/tier-policy.domain.mjs +75 -0
- package/src/runtime/domain/subagents/tier-policy.ts +126 -0
- package/src/runtime/domain/subagents/timing-notifications.domain.mjs +51 -0
- package/src/runtime/domain/subagents/timing-notifications.ts +37 -0
- package/src/runtime/domain/subagents/timing.domain.mjs +487 -0
- package/src/runtime/domain/subagents/timing.ts +634 -0
- package/src/runtime/domain/subagents/tools.domain.mjs +558 -0
- package/src/runtime/domain/subagents/tools.ts +629 -0
- package/src/runtime/domain/subagents/widget.domain.mjs +6 -0
- package/src/runtime/domain/subagents/widget.mjs +246 -0
- package/src/runtime/domain/subagents/widget.ts +30 -0
- package/src/runtime/domain/subagents/work-observation.domain.mjs +316 -0
- package/src/runtime/domain/subagents/work-observation.ts +248 -0
- package/src/runtime/domain/subagents/worker-catalog.domain.mjs +120 -0
- package/src/runtime/domain/subagents/worker-catalog.ts +162 -0
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +1009 -0
- package/src/runtime/domain/subagents/worker-operations-host.ts +1238 -0
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +2336 -0
- package/src/runtime/domain/subagents/worker-waits.ts +2878 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +52 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +50 -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 +27 -3
- package/src/runtime/query-executor.ts +178 -34
- package/src/runtime/query-worker.mjs +119 -22
- package/src/runtime/read-model.ts +939 -113
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +73 -0
- 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 +185 -22
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -4,25 +4,33 @@ import { resolve } from "node:path";
|
|
|
4
4
|
import type { Duplex } from "node:stream";
|
|
5
5
|
import type { WorkReadModel } from "./read-model.ts";
|
|
6
6
|
import { workScope } from "./queries.ts";
|
|
7
|
+
import { executionPhases, inventoryPhases } from "./read-watchdog-probe.ts";
|
|
8
|
+
import { notifyWorkBudget } from "./work-budget.ts";
|
|
9
|
+
import { HostSourceWatches } from "./source-watch.ts";
|
|
7
10
|
|
|
8
11
|
export interface EncodedRead { json: string }
|
|
9
|
-
interface Waiter { connection: number; resolve(value: EncodedRead): void; reject(error: Error): void }
|
|
12
|
+
interface Waiter { connection: number; expiresAt: number; deadline: ReturnType<typeof setTimeout>; resolve(value: EncodedRead): void; reject(error: Error): void }
|
|
10
13
|
interface Query {
|
|
11
14
|
id: number; key?: string; command: Record<string, unknown>; connection: number;
|
|
12
|
-
enqueued: number;
|
|
15
|
+
enqueued: number; started?: number; progressAt: number; waiters: Set<Waiter>;
|
|
13
16
|
}
|
|
14
17
|
export type ReadStream = Pick<Duplex, "destroyed" | "writableLength" | "write" | "on" | "once" | "off">;
|
|
15
18
|
interface Stream { socket: ReadStream; paused: boolean; generation: number; drain: () => void; close: () => void }
|
|
16
|
-
interface WorkerMetrics { inventories?: number; sqlite?: { opens: number; active: number; maximum: number }; [key: string]: unknown }
|
|
19
|
+
interface WorkerMetrics { sourceWatchers?: number; inventories?: number; coordinatorConnections?: number; indexConnections?: number; sqlite?: { opens: number; active: number; maximum: number }; [key: string]: unknown }
|
|
17
20
|
export interface QueryExecutorOptions {
|
|
18
|
-
|
|
21
|
+
queryCacheDiagnostics?: boolean;
|
|
22
|
+
capacity?: number; timeoutMs?: number; maxConnections?: number; watchdogMs?: number;
|
|
19
23
|
workerUrl?: URL;
|
|
24
|
+
logWatchdog?: (line: string) => void;
|
|
25
|
+
budgetBuffer?: SharedArrayBuffer;
|
|
26
|
+
onTerminalLogsChanged?: (ids: string[]) => Promise<void>;
|
|
20
27
|
modelOptions?: { supervisorDirectory?: string; baseDir?: string; durableDir?: string; intervalMs?: number };
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
/** One root, one read worker, one admitted operation at a time. No mutation RPC. */
|
|
24
31
|
export class WorkQueryExecutor {
|
|
25
32
|
private worker: Worker;
|
|
33
|
+
private sourceWatches = new HostSourceWatches();
|
|
26
34
|
private streams = new Map<number, Stream>();
|
|
27
35
|
private workerConnections = new Set<number>();
|
|
28
36
|
private queue: Query[] = [];
|
|
@@ -37,7 +45,13 @@ export class WorkQueryExecutor {
|
|
|
37
45
|
private closed = false;
|
|
38
46
|
private workerGeneration = 0;
|
|
39
47
|
private recoveryAttempts: number[] = [];
|
|
48
|
+
private internalRecoveryDemand = false;
|
|
40
49
|
private recoveryTimer?: ReturnType<typeof setTimeout>;
|
|
50
|
+
private watchdog?: ReturnType<typeof setInterval>;
|
|
51
|
+
private watchdogCheck?: ReturnType<typeof setImmediate>;
|
|
52
|
+
private lastResponse = performance.now();
|
|
53
|
+
private heartbeat!: BigInt64Array;
|
|
54
|
+
private probe?: Int32Array;
|
|
41
55
|
private workerMetrics: WorkerMetrics = {};
|
|
42
56
|
private lastObservation: Omit<ReturnType<WorkReadModel["observation"]>, "observedAt"> & { observedAt: number | null } = {
|
|
43
57
|
status: "rebuilding", reason: "Initial source inventory is rebuilding.", observedAt: null, reasons: [],
|
|
@@ -49,29 +63,100 @@ export class WorkQueryExecutor {
|
|
|
49
63
|
private rejected = 0;
|
|
50
64
|
private cancelled = 0;
|
|
51
65
|
private timeouts = 0;
|
|
66
|
+
private queueTimeouts = 0;
|
|
67
|
+
private callerTimeouts = 0;
|
|
52
68
|
private durations: number[] = [];
|
|
53
69
|
private options: QueryExecutorOptions;
|
|
54
70
|
private agentDir: string;
|
|
55
71
|
readonly instanceId: string;
|
|
72
|
+
requestReasons() {
|
|
73
|
+
return [...this.queue, ...(this.active ? [this.active] : [])].flatMap(query => [...query.waiters].map(waiter => ({
|
|
74
|
+
kind: 'read-request', id: query.id, connection: waiter.connection, generation: this.workerGeneration,
|
|
75
|
+
phase: query.started === undefined ? 'queued' : 'dispatched',
|
|
76
|
+
lastProgressAt: query.progressAt,
|
|
77
|
+
nextDeadline: waiter.expiresAt, executionDeadline: null,
|
|
78
|
+
recovery: 'caller-timeout-or-disconnect-removes-waiter-without-cancelling-physical-worker-work',
|
|
79
|
+
})));
|
|
80
|
+
}
|
|
56
81
|
|
|
57
82
|
constructor(agentDir: string, instanceId: string, options: QueryExecutorOptions = {}) {
|
|
58
83
|
this.options = options; this.instanceId = instanceId; this.agentDir = agentDir;
|
|
59
84
|
this.lag.enable();
|
|
60
85
|
this.worker = this.startWorker();
|
|
86
|
+
const watchdogMs = this.options.watchdogMs ?? 4000;
|
|
87
|
+
let previousCheck = performance.now();
|
|
88
|
+
let resumedAt = previousCheck;
|
|
89
|
+
this.watchdog = setInterval(() => {
|
|
90
|
+
const now = performance.now();
|
|
91
|
+
// After system sleep both threads can resume with an expired heartbeat.
|
|
92
|
+
if (now - previousCheck > watchdogMs) resumedAt = now;
|
|
93
|
+
previousCheck = now;
|
|
94
|
+
if (this.closed || this.failure || now - Math.max(this.lastResponse, resumedAt) <= watchdogMs) return;
|
|
95
|
+
// Drain queued worker responses before treating a delayed timer as worker silence.
|
|
96
|
+
this.watchdogCheck ??= setImmediate(() => {
|
|
97
|
+
this.watchdogCheck = undefined;
|
|
98
|
+
this.checkWatchdog();
|
|
99
|
+
});
|
|
100
|
+
this.watchdogCheck.unref();
|
|
101
|
+
}, Math.min(250, watchdogMs / 4));
|
|
102
|
+
this.watchdog.unref();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private checkWatchdog() {
|
|
106
|
+
const silenceMs = performance.now() - this.lastResponse;
|
|
107
|
+
if (!this.closed && !this.failure && silenceMs > (this.options.watchdogMs ?? 4000)) {
|
|
108
|
+
const tick = Atomics.load(this.heartbeat, 0);
|
|
109
|
+
const heartbeatAgeMs = tick === 0n ? null : Number(process.hrtime.bigint() - tick) / 1e6;
|
|
110
|
+
// A busy parent can run the overdue watchdog before draining queued messages.
|
|
111
|
+
if (heartbeatAgeMs !== null && heartbeatAgeMs <= (this.options.watchdogMs ?? 4000)) return;
|
|
112
|
+
if (this.probe) {
|
|
113
|
+
const evidence = { generation: this.workerGeneration, silenceMs: Math.round(silenceMs),
|
|
114
|
+
heartbeatAgeMs: heartbeatAgeMs === null ? null : Math.round(heartbeatAgeMs),
|
|
115
|
+
mainLoopMaxDelayMs: Math.round(this.lag.max / 1e6), active: !!this.active, queued: this.queue.length,
|
|
116
|
+
execution: executionPhases[Atomics.load(this.probe, 0)], inventory: inventoryPhases[Atomics.load(this.probe, 1)] };
|
|
117
|
+
try { this.options.logWatchdog?.(`Read worker watchdog: ${JSON.stringify(evidence)}`); } catch { /* preserve watchdog behavior */ }
|
|
118
|
+
}
|
|
119
|
+
this.fail(new Error("runtime-unhealthy: read worker unresponsive; watchdog deadline exceeded"));
|
|
120
|
+
}
|
|
61
121
|
}
|
|
62
122
|
|
|
63
123
|
private startWorker() {
|
|
124
|
+
if (this.options.budgetBuffer) {
|
|
125
|
+
// startWorker runs only initially or after the preceding thread exited.
|
|
126
|
+
// A dead generation cannot retain source credits in the shared budget.
|
|
127
|
+
const counts = new Int32Array(this.options.budgetBuffer);
|
|
128
|
+
Atomics.store(counts, 1, 0); Atomics.store(counts, 2, 0);
|
|
129
|
+
notifyWorkBudget(this.options.budgetBuffer);
|
|
130
|
+
}
|
|
131
|
+
const generation = this.workerGeneration;
|
|
64
132
|
const instanceId = this.workerGeneration ? `${this.instanceId}:reads:${this.workerGeneration}` : this.instanceId;
|
|
133
|
+
this.heartbeat = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT));
|
|
134
|
+
this.probe = this.options.logWatchdog ? new Int32Array(new SharedArrayBuffer(8)) : undefined;
|
|
65
135
|
const worker = new Worker(this.options.workerUrl ?? new URL("./query-worker.mjs", import.meta.url), {
|
|
66
|
-
execArgv: [], workerData: { agentDir: this.agentDir, instanceId, modelOptions: this.options.modelOptions },
|
|
136
|
+
execArgv: [], workerData: { agentDir: this.agentDir, instanceId, modelOptions: { ...this.options.modelOptions, budgetBuffer: this.options.budgetBuffer },
|
|
137
|
+
queryCacheDiagnostics: this.options.queryCacheDiagnostics === true, probe: this.probe, heartbeat: this.heartbeat },
|
|
138
|
+
});
|
|
139
|
+
worker.on("message", message => {
|
|
140
|
+
if (this.sourceWatches.handle(generation, message, value => {
|
|
141
|
+
if (worker === this.worker && !this.exited) worker.postMessage(value);
|
|
142
|
+
})) return;
|
|
143
|
+
if (worker === this.worker) this.receive(message);
|
|
144
|
+
});
|
|
145
|
+
worker.on("error", error => {
|
|
146
|
+
if (worker !== this.worker) return;
|
|
147
|
+
const original = String(error);
|
|
148
|
+
// Preserve the SQLite producer that the forwarded Error message omits.
|
|
149
|
+
const producer = /database (?:is locked|table is locked)/.test(original)
|
|
150
|
+
? `\n${String(error instanceof Error ? error.stack ?? error : error).split("\n").slice(0, 12).join("\n").slice(0, 4096)}` : "";
|
|
151
|
+
this.fail(new Error(`runtime-unhealthy: read worker failed: ${original}${producer}`, { cause: error }));
|
|
67
152
|
});
|
|
68
|
-
worker.on("message", message => { if (worker === this.worker) this.receive(message); });
|
|
69
|
-
worker.on("error", error => { if (worker === this.worker) this.fail(new Error(`runtime-unhealthy: read worker failed: ${String(error)}`)); });
|
|
70
153
|
worker.on("exit", code => {
|
|
71
154
|
if (worker !== this.worker) return;
|
|
72
155
|
this.exited = true;
|
|
156
|
+
void this.sourceWatches.revoke(generation).catch(() => {});
|
|
73
157
|
const sqlite = this.workerMetrics.sqlite;
|
|
74
|
-
|
|
158
|
+
this.workerMetrics = { ...this.workerMetrics, sourceWatchers: 0, coordinatorConnections: 0, indexConnections: 0,
|
|
159
|
+
...(sqlite ? { sqlite: { ...sqlite, active: 0 } } : {}) };
|
|
75
160
|
this.fail(new Error(`runtime-unhealthy: read worker exited (${code}); rebuilding reads after recovery`));
|
|
76
161
|
this.scheduleRecovery();
|
|
77
162
|
});
|
|
@@ -79,7 +164,7 @@ export class WorkQueryExecutor {
|
|
|
79
164
|
}
|
|
80
165
|
|
|
81
166
|
private scheduleRecovery() {
|
|
82
|
-
if (this.closed || !this.exited || this.recoveryTimer || !this.streams.size) return;
|
|
167
|
+
if (this.closed || !this.exited || this.recoveryTimer || (!this.streams.size && !this.internalRecoveryDemand)) return;
|
|
83
168
|
const now = Date.now();
|
|
84
169
|
this.recoveryAttempts = this.recoveryAttempts.filter(attempt => now - attempt < 60_000);
|
|
85
170
|
if (this.recoveryAttempts.length >= 2) {
|
|
@@ -90,11 +175,13 @@ export class WorkQueryExecutor {
|
|
|
90
175
|
}
|
|
91
176
|
this.recoveryTimer = setTimeout(() => {
|
|
92
177
|
this.recoveryTimer = undefined;
|
|
93
|
-
if (this.closed || !this.streams.size) return;
|
|
178
|
+
if (this.closed || (!this.streams.size && !this.internalRecoveryDemand)) return;
|
|
94
179
|
this.recoveryAttempts.push(Date.now());
|
|
95
180
|
this.workerGeneration++;
|
|
181
|
+
this.internalRecoveryDemand = false;
|
|
96
182
|
this.exited = false; this.failure = undefined; this.termination = undefined;
|
|
97
183
|
this.workerMetrics = {}; this.workerConnections.clear(); this.revision++;
|
|
184
|
+
this.lastResponse = performance.now();
|
|
98
185
|
this.lastObservation = { status: "rebuilding", reason: "Read worker is recovering its source inventory.", observedAt: null, reasons: [] };
|
|
99
186
|
this.lag.reset(); this.lag.enable();
|
|
100
187
|
try { this.worker = this.startWorker(); }
|
|
@@ -126,6 +213,11 @@ export class WorkQueryExecutor {
|
|
|
126
213
|
return { handle: (command: Record<string, unknown>) => this.request(connection, command), close };
|
|
127
214
|
}
|
|
128
215
|
|
|
216
|
+
async snapshot(scope: Record<string, unknown>): Promise<any> { return JSON.parse((await this.request(0, {type:"runtime_get_snapshot",scope})).json); }
|
|
217
|
+
|
|
218
|
+
async upgradeObligations(): Promise<any[]> {
|
|
219
|
+
return JSON.parse((await this.request(0, { type: "runtime_get_upgrade_obligations" })).json);
|
|
220
|
+
}
|
|
129
221
|
async livenessReasons(): Promise<any[]> {
|
|
130
222
|
const result = await this.request(0, { type: "runtime_get_liveness" });
|
|
131
223
|
return JSON.parse(result.json);
|
|
@@ -136,9 +228,9 @@ export class WorkQueryExecutor {
|
|
|
136
228
|
}
|
|
137
229
|
|
|
138
230
|
metrics() {
|
|
139
|
-
return { ...this.workerMetrics, executor: { active: this.active ? 1 : 0, queued: this.queue.length,
|
|
231
|
+
return { ...this.workerMetrics, sourceSubscriptions: this.sourceWatches.metrics(), executor: { active: this.active ? 1 : 0, queued: this.queue.length,
|
|
140
232
|
clients: this.streams.size, completed: this.completed, singleflightHits: this.coalesced, rejected: this.rejected,
|
|
141
|
-
cancelled: this.cancelled, timeouts: this.timeouts,
|
|
233
|
+
cancelled: this.cancelled, timeouts: this.timeouts, queueTimeouts: this.queueTimeouts, callerTimeouts: this.callerTimeouts,
|
|
142
234
|
capacity: this.options.capacity ?? 64, waitMs: [...this.waits], readMs: [...this.durations],
|
|
143
235
|
eventLoopLagMs: { p50: this.lag.percentile(50) / 1e6, p95: this.lag.percentile(95) / 1e6, p99: this.lag.percentile(99) / 1e6 },
|
|
144
236
|
worker: this.exited ? "stopped" : this.failure ? "stopping" : "running",
|
|
@@ -149,12 +241,27 @@ export class WorkQueryExecutor {
|
|
|
149
241
|
private request(connection: number, input: Record<string, unknown>): Promise<EncodedRead> {
|
|
150
242
|
if (connection !== 0 && !this.streams.has(connection)) return Promise.reject(new Error("runtime-unavailable: client disconnected"));
|
|
151
243
|
if (input.type === "runtime_get_metrics") return Promise.resolve({ json: JSON.stringify(this.metrics()) });
|
|
152
|
-
if (this.failure) {
|
|
153
|
-
|
|
244
|
+
if (this.failure) {
|
|
245
|
+
if (connection === 0) this.internalRecoveryDemand = true;
|
|
246
|
+
this.scheduleRecovery(); return Promise.reject(this.failure);
|
|
247
|
+
}
|
|
154
248
|
if (input.sinceSeq !== undefined && !Number.isSafeInteger(input.sinceSeq)) return Promise.reject(new Error("Invalid replay sequence"));
|
|
155
249
|
if (input.instanceId !== undefined && (typeof input.instanceId !== "string" || input.instanceId.length > 256)) return Promise.reject(new Error("Invalid runtime instance"));
|
|
250
|
+
if (input.type === "runtime_unsubscribe") {
|
|
251
|
+
for (const query of [...this.queue, ...(this.active ? [this.active] : [])]) {
|
|
252
|
+
if (query.command.type !== "runtime_subscribe" || query.connection !== connection) continue;
|
|
253
|
+
this.finish(query, new Error("runtime-unavailable: subscription cancelled"));
|
|
254
|
+
this.release(query);
|
|
255
|
+
}
|
|
256
|
+
const stream = this.streams.get(connection);
|
|
257
|
+
if (stream) stream.generation++;
|
|
258
|
+
this.worker.postMessage({ type: "detach", connection });
|
|
259
|
+
this.workerConnections.delete(connection);
|
|
260
|
+
return Promise.resolve({ json: '{"unsubscribed":true}' });
|
|
261
|
+
}
|
|
262
|
+
if (!["runtime_get_snapshot", "runtime_subscribe", "runtime_unsubscribe", "runtime_get_liveness", "runtime_get_upgrade_obligations"].includes(String(input.type))) return Promise.reject(new Error("Unsupported read operation"));
|
|
156
263
|
const command: Record<string, unknown> = { type: input.type, sinceSeq: input.sinceSeq, instanceId: input.instanceId };
|
|
157
|
-
if (command.type !== "runtime_unsubscribe" && command.type !== "runtime_get_liveness") {
|
|
264
|
+
if (command.type !== "runtime_unsubscribe" && command.type !== "runtime_get_liveness" && command.type !== "runtime_get_upgrade_obligations") {
|
|
158
265
|
const scope = workScope(input.scope);
|
|
159
266
|
if (scope.cwd) scope.cwd = resolve(scope.cwd);
|
|
160
267
|
scope.limit ??= scope.backgroundHistory ? 10 : 50;
|
|
@@ -171,13 +278,17 @@ export class WorkQueryExecutor {
|
|
|
171
278
|
return Promise.reject(new Error("runtime-overloaded: read queue is full; retry later"));
|
|
172
279
|
}
|
|
173
280
|
const id = ++this.counter;
|
|
174
|
-
query = { id, key, command, connection: key ? 0 : connection, enqueued: performance.now(),
|
|
175
|
-
deadline: setTimeout(() => this.expire(id), this.options.timeoutMs ?? 4000), waiters: new Set() };
|
|
281
|
+
query = { id, key, command, connection: key ? 0 : connection, enqueued: performance.now(), progressAt: Date.now(), waiters: new Set() };
|
|
176
282
|
this.queue.push(query);
|
|
177
283
|
if (key) this.flights.set(key, query);
|
|
178
284
|
}
|
|
179
285
|
const admitted = query;
|
|
180
|
-
const result = new Promise<EncodedRead>((resolve, reject) =>
|
|
286
|
+
const result = new Promise<EncodedRead>((resolve, reject) => {
|
|
287
|
+
const waiter: Waiter = { connection, resolve, reject,
|
|
288
|
+
expiresAt: Date.now() + (this.options.timeoutMs ?? 4000),
|
|
289
|
+
deadline: setTimeout(() => this.expire(admitted, waiter), this.options.timeoutMs ?? 4000) };
|
|
290
|
+
admitted.waiters.add(waiter);
|
|
291
|
+
});
|
|
181
292
|
this.pump();
|
|
182
293
|
return result;
|
|
183
294
|
}
|
|
@@ -185,6 +296,8 @@ export class WorkQueryExecutor {
|
|
|
185
296
|
private pump() {
|
|
186
297
|
if (this.failure || this.active || !this.queue.length) return;
|
|
187
298
|
const query = this.active = this.queue.shift()!;
|
|
299
|
+
query.started = performance.now();
|
|
300
|
+
query.progressAt = Date.now();
|
|
188
301
|
this.waits.push(performance.now() - query.enqueued);
|
|
189
302
|
if (this.waits.length > 128) this.waits.shift();
|
|
190
303
|
const stream = this.streams.get(query.connection);
|
|
@@ -195,8 +308,24 @@ export class WorkQueryExecutor {
|
|
|
195
308
|
|
|
196
309
|
private receive(message: any) {
|
|
197
310
|
if (this.failure) return;
|
|
311
|
+
this.lastResponse = performance.now();
|
|
312
|
+
if (message.type === "heartbeat") { this.worker.postMessage({ type: "heartbeat-consumed" }); return; }
|
|
313
|
+
// Replies to cancelled reads carry no fresh observation or metrics authority.
|
|
314
|
+
if (message.type === "reply" && (!this.active || message.id !== this.active.id || !this.active.waiters.size)) {
|
|
315
|
+
if (message.id === this.active?.id) { this.active = undefined; this.pump(); }
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
198
318
|
if (message.metrics) this.workerMetrics = message.metrics;
|
|
199
319
|
if (message.observation) this.lastObservation = message.observation;
|
|
320
|
+
if (message.type === "terminal-logs") {
|
|
321
|
+
const sourceWorker = this.worker;
|
|
322
|
+
const ids = Array.isArray(message.ids) ? message.ids.filter((id: unknown): id is string => typeof id === "string" && /^[A-Za-z0-9_-]+$/.test(id)).slice(0, 128) : [];
|
|
323
|
+
void Promise.resolve().then(() => this.options.onTerminalLogsChanged?.(ids)).then(
|
|
324
|
+
() => { if (!this.failure && this.worker === sourceWorker) sourceWorker.postMessage({ type: "terminal-logs-consumed" }); },
|
|
325
|
+
error => { if (!this.failure && this.worker === sourceWorker) this.fail(new Error(`runtime-unhealthy: terminal failure supervision failed: ${String(error)}`)); },
|
|
326
|
+
);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
200
329
|
if (message.type === "revision") { this.revision++; this.worker.postMessage({ type: "revision-consumed" }); return; }
|
|
201
330
|
if (message.type === "event") {
|
|
202
331
|
if (this.streams.get(message.connection)?.generation === message.generation) this.event(message.connection, message.line);
|
|
@@ -206,27 +335,40 @@ export class WorkQueryExecutor {
|
|
|
206
335
|
if (message.type !== "reply" || message.id !== this.active?.id) return;
|
|
207
336
|
const query = this.active!;
|
|
208
337
|
this.active = undefined; this.completed++;
|
|
209
|
-
this.durations.push(performance.now() - query.
|
|
338
|
+
this.durations.push(performance.now() - query.started!);
|
|
210
339
|
if (this.durations.length > 128) this.durations.shift();
|
|
211
340
|
this.finish(query, message.error ? new Error(message.error) : undefined, { json: message.json });
|
|
212
341
|
this.pump();
|
|
213
342
|
}
|
|
214
343
|
|
|
215
344
|
private finish(query: Query, error?: Error, value: EncodedRead = { json: "null" }) {
|
|
216
|
-
clearTimeout(query.deadline);
|
|
217
345
|
if (query.key && this.flights.get(query.key) === query) this.flights.delete(query.key);
|
|
218
|
-
for (const waiter of query.waiters) { if (error) waiter.reject(error); else waiter.resolve(value); }
|
|
346
|
+
for (const waiter of query.waiters) { clearTimeout(waiter.deadline); if (error) waiter.reject(error); else waiter.resolve(value); }
|
|
219
347
|
query.waiters.clear();
|
|
220
348
|
}
|
|
221
349
|
|
|
222
|
-
private expire(
|
|
350
|
+
private expire(query: Query, waiter: Waiter) {
|
|
351
|
+
if (!query.waiters.delete(waiter)) return;
|
|
223
352
|
this.timeouts++;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
this.
|
|
353
|
+
if (query === this.active) this.callerTimeouts++;
|
|
354
|
+
else this.queueTimeouts++;
|
|
355
|
+
waiter.reject(new Error(query === this.active
|
|
356
|
+
? "runtime-timeout: caller read deadline exceeded; source was not verified"
|
|
357
|
+
: "runtime-overloaded: queued read deadline exceeded; retry later"));
|
|
358
|
+
this.release(query);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
private release(query: Query) {
|
|
362
|
+
if (query.waiters.size) return;
|
|
363
|
+
this.finish(query);
|
|
364
|
+
if (query === this.active) {
|
|
365
|
+
// Keep the execution slot until cancellation is acknowledged. This bounds
|
|
366
|
+
// the worker mailbox even when native work cannot be interrupted.
|
|
367
|
+
this.worker.postMessage({ type: "cancel", id: query.id });
|
|
368
|
+
} else {
|
|
369
|
+
const index = this.queue.indexOf(query);
|
|
370
|
+
if (index >= 0) this.queue.splice(index, 1);
|
|
371
|
+
}
|
|
230
372
|
}
|
|
231
373
|
|
|
232
374
|
private event(connection: number, line: string) {
|
|
@@ -244,34 +386,36 @@ export class WorkQueryExecutor {
|
|
|
244
386
|
if (this.workerConnections.delete(connection) && !this.failure) this.worker.postMessage({ type: "detach", connection });
|
|
245
387
|
for (const query of [...this.queue, ...(this.active ? [this.active] : [])]) {
|
|
246
388
|
for (const waiter of query.waiters) if (waiter.connection === connection) {
|
|
247
|
-
query.waiters.delete(waiter); this.cancelled++; waiter.reject(new Error("runtime-unavailable: client disconnected"));
|
|
248
|
-
}
|
|
249
|
-
if (!query.waiters.size && query !== this.active) {
|
|
250
|
-
this.queue.splice(this.queue.indexOf(query), 1);
|
|
251
|
-
this.finish(query);
|
|
389
|
+
query.waiters.delete(waiter); clearTimeout(waiter.deadline); this.cancelled++; waiter.reject(new Error("runtime-unavailable: client disconnected"));
|
|
252
390
|
}
|
|
391
|
+
this.release(query);
|
|
253
392
|
}
|
|
254
393
|
}
|
|
255
394
|
|
|
256
395
|
private fail(error: Error) {
|
|
257
396
|
if (this.failure) return;
|
|
397
|
+
if ([...this.queue, ...(this.active ? [this.active] : [])].some(query =>
|
|
398
|
+
[...query.waiters].some(waiter => waiter.connection === 0))) this.internalRecoveryDemand = true;
|
|
258
399
|
this.failure = error; this.lag.disable();
|
|
259
400
|
for (const query of [...this.queue, ...(this.active ? [this.active] : [])]) this.finish(query, error);
|
|
260
401
|
this.queue = []; this.active = undefined;
|
|
261
402
|
for (const connection of this.streams.keys()) this.event(connection, JSON.stringify({ type: "event",
|
|
262
403
|
event: { type: "resync_required", reason: error.message, instanceId: this.instanceId } }) + "\n");
|
|
404
|
+
void this.sourceWatches.revoke(this.workerGeneration).catch(() => {});
|
|
263
405
|
this.termination = this.worker.terminate();
|
|
264
406
|
this.worker.unref();
|
|
265
407
|
}
|
|
266
408
|
|
|
267
409
|
async close() {
|
|
268
410
|
this.closed = true;
|
|
411
|
+
if (this.watchdog) clearInterval(this.watchdog);
|
|
412
|
+
if (this.watchdogCheck) clearImmediate(this.watchdogCheck);
|
|
269
413
|
if (this.recoveryTimer) { clearTimeout(this.recoveryTimer); this.recoveryTimer = undefined; }
|
|
270
414
|
this.fail(new Error("runtime-unavailable: query executor closed"));
|
|
271
415
|
for (const connection of this.streams.keys()) this.detach(connection);
|
|
272
416
|
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
273
417
|
// Bound graceful close even while native SQLite is still finishing a call.
|
|
274
|
-
await Promise.race([this.termination, new Promise<void>(resolve => { timeout = setTimeout(resolve, 1000); })]);
|
|
418
|
+
await Promise.race([Promise.all([this.termination, this.sourceWatches.close().catch(() => {})]), new Promise<void>(resolve => { timeout = setTimeout(resolve, 1000); })]);
|
|
275
419
|
if (timeout) clearTimeout(timeout);
|
|
276
420
|
}
|
|
277
421
|
}
|
|
@@ -3,6 +3,20 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { EventEmitter } from "node:events";
|
|
4
4
|
import { performance } from "node:perf_hooks";
|
|
5
5
|
|
|
6
|
+
// Publish liveness during async imports too. This clock measures the worker's
|
|
7
|
+
// own event loop, independently of parent delivery and source readiness.
|
|
8
|
+
let heartbeatPending = false;
|
|
9
|
+
let rpcInstalled = false;
|
|
10
|
+
const heartbeat = workerData.heartbeat;
|
|
11
|
+
const markHeartbeat = () => { if (heartbeat) Atomics.store(heartbeat, 0, process.hrtime.bigint()); };
|
|
12
|
+
markHeartbeat();
|
|
13
|
+
setInterval(() => {
|
|
14
|
+
markHeartbeat();
|
|
15
|
+
if (!rpcInstalled || heartbeatPending) return;
|
|
16
|
+
heartbeatPending = true;
|
|
17
|
+
parentPort.postMessage({ type: "heartbeat" });
|
|
18
|
+
}, 250).unref();
|
|
19
|
+
|
|
6
20
|
// The fixed Node 24 artifact strips types natively and does not depend on tsx.
|
|
7
21
|
// Development on Node 22 uses the workspace loader without inheriting test preloads.
|
|
8
22
|
if (Number(process.versions.node.split(".")[0]) < 24) {
|
|
@@ -25,25 +39,83 @@ sqlite.DatabaseSync = class extends OriginalDatabase {
|
|
|
25
39
|
}
|
|
26
40
|
};
|
|
27
41
|
const { WorkReadModel } = await import("./read-model.ts");
|
|
28
|
-
const {
|
|
29
|
-
const
|
|
42
|
+
const { createWorkBudget } = await import("./work-budget.ts");
|
|
43
|
+
const budget = createWorkBudget(workerData.modelOptions?.budgetBuffer);
|
|
44
|
+
const { workerSourceWatch } = await import("./source-watch.ts");
|
|
45
|
+
const { WorkQueries, workScope, queryEncodingMetrics, snapshotJSON } = await import("./queries.ts");
|
|
46
|
+
const { executionPhases, inventoryPhases } = await import("./read-watchdog-probe.ts");
|
|
47
|
+
const probe = workerData.probe;
|
|
48
|
+
const markExecution = phase => { if (probe) Atomics.store(probe, 0, executionPhases.indexOf(phase)); };
|
|
49
|
+
function observeExecution(phase, run) {
|
|
50
|
+
if (!probe) return run();
|
|
51
|
+
const previous = Atomics.exchange(probe, 0, executionPhases.indexOf(phase));
|
|
52
|
+
try { return run(); } finally { Atomics.store(probe, 0, previous); }
|
|
53
|
+
}
|
|
54
|
+
let model;
|
|
55
|
+
try {
|
|
56
|
+
model = new WorkReadModel(workerData.agentDir, workerData.instanceId, {
|
|
57
|
+
...workerData.modelOptions, watch: workerSourceWatch(parentPort),
|
|
58
|
+
inventoryPhase: probe ? phase => Atomics.store(probe, 1, inventoryPhases.indexOf(phase)) : undefined,
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
// Worker error forwarding retains only String(error). Keep the original
|
|
62
|
+
// statement's stack for this specific bootstrap failure, without source data.
|
|
63
|
+
if (/database is locked/.test(String(error))) {
|
|
64
|
+
console.error(`[runtime-read-bootstrap] WorkReadModel constructor\n${String(error?.stack ?? error).split("\n").slice(0, 12).join("\n").slice(0, 4096)}`);
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
markExecution("idle");
|
|
69
|
+
// One bounded in-flight batch. Remaining obligations stay in the reconstructable
|
|
70
|
+
// inventory index; an acknowledgement cannot erase a newer revision of an ID.
|
|
71
|
+
let terminalLogsPending;
|
|
72
|
+
const sendTerminalLogs = () => {
|
|
73
|
+
if (terminalLogsPending) return;
|
|
74
|
+
const batch = model.terminalLogChanges();
|
|
75
|
+
if (!batch.length) return;
|
|
76
|
+
terminalLogsPending = batch;
|
|
77
|
+
parentPort.postMessage({ type: "terminal-logs", ids: batch.map(entry => entry.id) });
|
|
78
|
+
};
|
|
79
|
+
model.onTerminalLogsChanged = sendTerminalLogs;
|
|
30
80
|
const sessions = new Map();
|
|
81
|
+
const requests = new Map();
|
|
31
82
|
const cache = new Map();
|
|
32
83
|
const encoded = new WeakMap();
|
|
33
|
-
let cacheBytes = 0, cacheHits = 0, queryCount = 0;
|
|
84
|
+
let cacheBytes = 0, cacheHits = 0, queryCount = 0, serializationCount = 0;
|
|
34
85
|
let revisionPending = false, revisionDirty = false;
|
|
35
86
|
const durations = [];
|
|
36
|
-
const
|
|
37
|
-
|
|
87
|
+
const cacheComparisons = workerData.queryCacheDiagnostics ? [] : undefined;
|
|
88
|
+
const metrics = () => ({ ...model.metrics, background: model.backgroundMetrics, sqlite: { ...connections }, cacheHits, queryCount, serializationCount, eventEncoding: { ...queryEncodingMetrics }, cacheBytes,
|
|
89
|
+
cacheEntries: cache.size, queryDurationMs: [...durations], ...(cacheComparisons ? { cacheComparisons: [...cacheComparisons] } : {}) });
|
|
38
90
|
const snapshot = model.snapshot.bind(model);
|
|
39
|
-
model.snapshot = scope => {
|
|
91
|
+
model.snapshot = scope => observeExecution("snapshot", () => {
|
|
92
|
+
scope = workScope(scope ?? {});
|
|
40
93
|
const key = JSON.stringify(scope ?? {});
|
|
94
|
+
const revision = model.contentRevision(scope);
|
|
41
95
|
const cacheable = !scope?.backgroundHistory;
|
|
42
96
|
const previous = cacheable ? cache.get(key) : undefined;
|
|
43
|
-
|
|
97
|
+
const comparedAt = Date.now();
|
|
98
|
+
const hit = previous?.revision === revision && (previous.value.nextDeadline === null || previous.value.nextDeadline > comparedAt);
|
|
99
|
+
// Only the original regression fixture opts in; no extra source reads.
|
|
100
|
+
let comparison;
|
|
101
|
+
if (cacheComparisons) {
|
|
102
|
+
comparison = { queryCount, scope, revision, priorRevision: previous?.revision ?? null,
|
|
103
|
+
priorScopeRevision: previous?.value.scopeRevision ?? null, priorSeq: previous?.value.seq ?? null,
|
|
104
|
+
priorObservedRevisionVector: previous?.value.observedRevisionVector ?? null, priorDeadline: previous?.value.nextDeadline ?? null,
|
|
105
|
+
comparedAt, hit: Boolean(hit) };
|
|
106
|
+
cacheComparisons.push(comparison);
|
|
107
|
+
if (cacheComparisons.length > 16) cacheComparisons.shift();
|
|
108
|
+
}
|
|
109
|
+
if (hit) {
|
|
110
|
+
cacheHits++; cache.delete(key); cache.set(key, previous); return previous.value;
|
|
111
|
+
}
|
|
112
|
+
if (previous) { cacheBytes -= previous.bytes; cache.delete(key); }
|
|
44
113
|
const started = performance.now();
|
|
45
114
|
const value = snapshot(scope);
|
|
46
|
-
|
|
115
|
+
if (comparison) Object.assign(comparison, { scopeRevision: value.scopeRevision,
|
|
116
|
+
nextDeadline: value.nextDeadline, seq: value.seq, observedRevisionVector: value.observedRevisionVector });
|
|
117
|
+
const json = snapshotJSON(value);
|
|
118
|
+
serializationCount++;
|
|
47
119
|
const bytes = Buffer.byteLength(json);
|
|
48
120
|
encoded.set(value, json);
|
|
49
121
|
queryCount++; durations.push(performance.now() - started);
|
|
@@ -53,16 +125,15 @@ model.snapshot = scope => {
|
|
|
53
125
|
const oldest = cache.keys().next().value;
|
|
54
126
|
cacheBytes -= cache.get(oldest).bytes; cache.delete(oldest);
|
|
55
127
|
}
|
|
56
|
-
cache.set(key, { value, bytes }); cacheBytes += bytes;
|
|
128
|
+
cache.set(key, { value, bytes, revision }); cacheBytes += bytes;
|
|
57
129
|
}
|
|
58
130
|
return value;
|
|
59
|
-
};
|
|
131
|
+
});
|
|
60
132
|
function revision() {
|
|
61
133
|
revisionPending = true;
|
|
62
|
-
parentPort.postMessage({ type: "revision", metrics: metrics(), observation: model.observation() });
|
|
134
|
+
observeExecution("publish", () => parentPort.postMessage({ type: "revision", metrics: metrics(), observation: model.observation() }));
|
|
63
135
|
}
|
|
64
136
|
model.onChange(() => {
|
|
65
|
-
cache.clear(); cacheBytes = 0;
|
|
66
137
|
if (revisionPending) revisionDirty = true;
|
|
67
138
|
else revision();
|
|
68
139
|
});
|
|
@@ -85,35 +156,61 @@ function session(id) {
|
|
|
85
156
|
}
|
|
86
157
|
|
|
87
158
|
parentPort.on("message", async message => {
|
|
159
|
+
if (message.type === "heartbeat-consumed") { heartbeatPending = false; return; }
|
|
160
|
+
if (message.type === "cancel") {
|
|
161
|
+
const request = requests.get(message.id);
|
|
162
|
+
if (request) {
|
|
163
|
+
request.cancelled = true;
|
|
164
|
+
requests.delete(message.id);
|
|
165
|
+
parentPort.postMessage({ type: "reply", id: message.id, error: "runtime-timeout: read cancelled" });
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (message.type === "terminal-logs-consumed") { if (terminalLogsPending) model.acknowledgeTerminalLogs(terminalLogsPending); terminalLogsPending = undefined; sendTerminalLogs(); return; }
|
|
88
170
|
if (message.type === "revision-consumed") {
|
|
89
171
|
revisionPending = false;
|
|
90
172
|
if (revisionDirty) { revisionDirty = false; revision(); }
|
|
91
173
|
return;
|
|
92
174
|
}
|
|
93
|
-
if (message.type === "detach") {
|
|
175
|
+
if (message.type === "detach") {
|
|
176
|
+
for (const request of requests.values()) if (request.connection === message.connection) request.cancelled = true;
|
|
177
|
+
sessions.get(message.connection)?.queries.close(); sessions.delete(message.connection); return;
|
|
178
|
+
}
|
|
94
179
|
if (message.type === "event-consumed") {
|
|
95
180
|
const state = sessions.get(message.connection);
|
|
96
181
|
if (state?.awaiting && state.serial === message.serial) { state.awaiting = false; state.flush(); }
|
|
97
182
|
return;
|
|
98
183
|
}
|
|
99
184
|
if (message.type !== "query") return;
|
|
185
|
+
const request = { connection: message.connection, cancelled: false };
|
|
186
|
+
requests.set(message.id, request);
|
|
187
|
+
const release = budget.enter("query");
|
|
100
188
|
try {
|
|
189
|
+
if (!release) throw new Error("runtime-overloaded: shared source query budget exhausted");
|
|
101
190
|
const command = message.command;
|
|
102
|
-
if (command.type
|
|
191
|
+
if (["runtime_get_liveness", "runtime_get_upgrade_obligations"].includes(command.type)) {
|
|
103
192
|
await model.reconcile();
|
|
104
|
-
|
|
105
|
-
|
|
193
|
+
if (request.cancelled) return;
|
|
194
|
+
observeExecution("request", () => {
|
|
195
|
+
const observation = model.observation(command.type === "runtime_get_upgrade_obligations" ? model.upgradeObligations() : model.livenessReasons());
|
|
196
|
+
parentPort.postMessage({ type: "reply", id: message.id, json: JSON.stringify(observation.reasons), metrics: metrics(), observation });
|
|
197
|
+
});
|
|
106
198
|
return;
|
|
107
199
|
}
|
|
108
200
|
if (!["runtime_get_snapshot", "runtime_subscribe", "runtime_unsubscribe"].includes(command.type)) throw new Error("Unsupported read operation");
|
|
109
201
|
const indexed = command.type !== "runtime_get_snapshot" || !command.scope?.id || await model.ensureId(command.scope.id);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
202
|
+
if (request.cancelled) return;
|
|
203
|
+
observeExecution("request", () => {
|
|
204
|
+
const state = session(message.connection);
|
|
205
|
+
state.generation = message.generation; state.pending = undefined;
|
|
206
|
+
let value = state.queries.handle(command);
|
|
207
|
+
if (!indexed && !value.rows.length) value = { ...value, status: "rebuilding", reason: "The requested run is being indexed; retry after reconciliation." };
|
|
208
|
+
parentPort.postMessage({ type: "reply", id: message.id, json: encoded.get(value) ?? JSON.stringify(value), metrics: metrics() });
|
|
209
|
+
});
|
|
115
210
|
} catch (error) {
|
|
211
|
+
if (request.cancelled) return;
|
|
116
212
|
parentPort.postMessage({ type: "reply", id: message.id, error: String(error).slice(0, 512), metrics: metrics() });
|
|
117
|
-
}
|
|
213
|
+
} finally { release?.(); requests.delete(message.id); }
|
|
118
214
|
});
|
|
215
|
+
rpcInstalled = true;
|
|
119
216
|
void model.reconcile();
|