pi-better-server 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -1
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +37 -5
- package/scripts/event-publication/writer.mjs +3 -8
- package/scripts/measure-full-runtime/probe.mjs +4 -2
- package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
- package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
- package/scripts/measure-shared-reads.mjs +2 -1
- package/scripts/private-runtime/package-lock.json +18 -0
- package/scripts/private-runtime/package.json +4 -1
- package/scripts/source-provenance.mjs +2 -2
- package/scripts/test-on-pi.sh +2 -9
- package/src/handshake.ts +1 -1
- package/src/hosted-session.ts +32 -4
- package/src/maintenance.ts +35 -7
- package/src/registry.ts +28 -4
- package/src/runtime/attempt-invalidation.ts +54 -0
- package/src/runtime/background-history.ts +151 -45
- package/src/runtime/background-policy.ts +9 -4
- package/src/runtime/background-tools.ts +131 -23
- package/src/runtime/background.ts +351 -68
- package/src/runtime/cancellation.ts +28 -7
- package/src/runtime/catalog-sources.ts +199 -0
- package/src/runtime/catalog.ts +53 -21
- package/src/runtime/client.ts +22 -2
- package/src/runtime/domain/assignment-inbox.mjs +119 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +43 -35
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +3 -3
- package/src/runtime/domain/background/registry.mjs +61 -3
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +1 -1
- package/src/runtime/domain/background-service/adapter-contract.ts +1 -1
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +35 -16
- package/src/runtime/domain/background-service/goal-provider.ts +31 -16
- package/src/runtime/domain/background-service/index.domain.mjs +6 -9
- package/src/runtime/domain/background-service/index.ts +6 -9
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +6 -3
- package/src/runtime/domain/background-service/managed-authority.ts +5 -3
- package/src/runtime/domain/background-service/managed-client.domain.mjs +21 -7
- package/src/runtime/domain/background-service/managed-client.ts +20 -7
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +75 -17
- package/src/runtime/domain/background-service/managed-frontend.ts +62 -17
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +16 -5
- package/src/runtime/domain/background-service/navigator-provider.ts +15 -5
- package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
- package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +170 -27
- package/src/runtime/domain/background-service/observed-waits.ts +154 -30
- package/src/runtime/domain/background-service/process-identity.domain.mjs +20 -2
- package/src/runtime/domain/background-service/process-identity.ts +18 -2
- package/src/runtime/domain/background-service/process.domain.mjs +3 -3
- package/src/runtime/domain/background-service/process.ts +3 -3
- package/src/runtime/domain/background-service/registry.domain.mjs +61 -3
- package/src/runtime/domain/background-service/registry.ts +53 -5
- package/src/runtime/domain/background-service/runtime.domain.mjs +32 -16
- package/src/runtime/domain/background-service/runtime.ts +19 -9
- package/src/runtime/domain/background-service/sandbox.domain.mjs +14 -15
- package/src/runtime/domain/background-service/sandbox.ts +14 -11
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +218 -13
- package/src/runtime/domain/background-service/shared-navigator.ts +197 -14
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +21 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +34 -8
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/background-service/shared-work-client.mjs +174 -7
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +3 -3
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +1 -1
- package/src/runtime/domain/background-service/task-diagnostics.ts +1 -1
- package/src/runtime/domain/background-service/tools.domain.mjs +31 -24
- package/src/runtime/domain/background-service/tools.ts +41 -38
- package/src/runtime/domain/background-service/types.domain.mjs +1 -0
- package/src/runtime/domain/background-service/types.ts +3 -1
- package/src/runtime/domain/background-service/work-observation.domain.mjs +46 -20
- package/src/runtime/domain/background-service/work-observation.ts +46 -19
- package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
- package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
- package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +11 -2
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +42 -21
- package/src/runtime/domain/coordinator/src/store.mjs +21 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +23 -1
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +50 -5
- package/src/runtime/domain/sandbox-policy/README.md +61 -63
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +11 -8
- package/src/runtime/domain/sandbox-policy/commands.ts +12 -7
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +53 -9
- package/src/runtime/domain/sandbox-policy/index.ts +52 -9
- package/src/runtime/domain/sandbox-policy/package.json +1 -1
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +5 -2
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +9 -2
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +56 -137
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +52 -130
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +1 -6
- package/src/runtime/domain/sandbox-policy/permissions.ts +1 -6
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +12 -1
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/README.md +1 -1
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +12 -6
- package/src/runtime/domain/subagents/assignment-outcomes.ts +11 -5
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +87 -24
- package/src/runtime/domain/subagents/assignment-report.ts +83 -19
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +21 -3
- package/src/runtime/domain/subagents/catalog-host-admission.ts +19 -3
- package/src/runtime/domain/subagents/catalog-preferences.ts +1 -1
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +35 -1
- package/src/runtime/domain/subagents/catalog-resolver.ts +35 -1
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +20 -22
- package/src/runtime/domain/subagents/catalog-store.ts +27 -20
- package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
- package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +27 -15
- package/src/runtime/domain/subagents/child-operations.domain.mjs +80 -2
- package/src/runtime/domain/subagents/child-operations.ts +80 -1
- package/src/runtime/domain/subagents/child-preflight.mjs +9 -2
- package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
- package/src/runtime/domain/subagents/child-process-list.ts +8 -0
- package/src/runtime/domain/subagents/config.domain.mjs +49 -2
- package/src/runtime/domain/subagents/config.ts +46 -2
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +5 -1
- package/src/runtime/domain/subagents/continuation-authority.ts +3 -1
- package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
- package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
- package/src/runtime/domain/subagents/extensions.mjs +11 -13
- package/src/runtime/domain/subagents/finalization.domain.mjs +12 -0
- package/src/runtime/domain/subagents/finalization.ts +15 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +44 -2
- package/src/runtime/domain/subagents/goal-provider.ts +44 -2
- package/src/runtime/domain/subagents/health-observation.domain.mjs +189 -190
- package/src/runtime/domain/subagents/health-observation.ts +43 -48
- package/src/runtime/domain/subagents/index.domain.mjs +296 -123
- package/src/runtime/domain/subagents/index.ts +257 -98
- package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
- package/src/runtime/domain/subagents/launch-context.ts +23 -0
- package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +85 -16
- package/src/runtime/domain/subagents/log-cursor.ts +91 -15
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +2 -2
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +6 -3
- package/src/runtime/domain/subagents/managed-launch-client.ts +6 -3
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +222 -14
- package/src/runtime/domain/subagents/managed-launch-host.ts +168 -15
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +1 -5
- package/src/runtime/domain/subagents/managed-launch-port.ts +4 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +27 -2
- package/src/runtime/domain/subagents/operation-bridge-types.ts +27 -2
- package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
- package/src/runtime/domain/subagents/owned-exit.ts +12 -0
- package/src/runtime/domain/subagents/package.json +1 -1
- package/src/runtime/domain/subagents/parse.domain.mjs +50 -5
- package/src/runtime/domain/subagents/parse.ts +48 -6
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +32 -8
- package/src/runtime/domain/subagents/permission-policy.ts +41 -8
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +47 -33
- package/src/runtime/domain/subagents/registry.ts +54 -33
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +6 -23
- package/src/runtime/domain/subagents/shared-catalog.ts +6 -14
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +218 -13
- package/src/runtime/domain/subagents/shared-navigator.ts +197 -14
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +21 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +34 -8
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/subagents/shared-task-exec.ts +12 -1
- package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/subagents/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/subagents/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/shared-work-client.mjs +174 -7
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +22 -38
- package/src/runtime/domain/subagents/subagent-tools.ts +28 -34
- package/src/runtime/domain/subagents/task-policy.domain.mjs +1 -1
- package/src/runtime/domain/subagents/task-policy.ts +3 -1
- package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
- package/src/runtime/domain/subagents/timing.ts +10 -1
- package/src/runtime/domain/subagents/work-observation.domain.mjs +77 -16
- package/src/runtime/domain/subagents/work-observation.ts +71 -16
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +9 -4
- package/src/runtime/domain/subagents/worker-operations-host.ts +12 -4
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +89 -35
- package/src/runtime/domain/subagents/worker-waits.ts +93 -34
- package/src/runtime/health-config.ts +27 -11
- package/src/runtime/log-checkpoints.ts +117 -0
- package/src/runtime/mutation-store.ts +5 -4
- package/src/runtime/queries.ts +25 -2
- package/src/runtime/query-executor.ts +149 -28
- package/src/runtime/query-worker.mjs +106 -21
- package/src/runtime/read-model.ts +846 -120
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +11 -4
- package/src/runtime/work-budget.ts +130 -0
- package/src/runtime/work-client.d.mts +8 -0
- package/src/runtime/work-client.mjs +150 -7
- package/src/server.ts +104 -23
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -16,8 +16,9 @@ import { actionableFailures, failureLabel, readFailureState } from "./shared-fai
|
|
|
16
16
|
import { failurePath, failureView } from "./failures.js";
|
|
17
17
|
import { readLog } from "./logs.js";
|
|
18
18
|
import { listMetasForOrigin, onMetaChanged, readMeta, writeMeta } from "./registry.js";
|
|
19
|
-
import { getObservedWaitHost
|
|
20
|
-
import {
|
|
19
|
+
import { getObservedWaitHost } from "./observed-wait-client.js";
|
|
20
|
+
import type { DurableTaskProjection } from "./observed-waits.js";
|
|
21
|
+
import type { BackgroundTaskRuntime } from "./runtime.js";
|
|
21
22
|
import { formatBackgroundTaskStall, observeBackgroundTaskStall } from "./stall.js";
|
|
22
23
|
import type { BackgroundTaskCallbackOrigin, BackgroundTaskMeta, BackgroundTaskStatus } from "./types.js";
|
|
23
24
|
|
|
@@ -30,12 +31,13 @@ let durableRowCache: {
|
|
|
30
31
|
} | undefined;
|
|
31
32
|
|
|
32
33
|
export interface ManagedBackgroundNavigator {
|
|
34
|
+
onOpen?(): void;
|
|
33
35
|
rows(): BackgroundWorkRow[];
|
|
34
36
|
prepareDetail(id:string,options?:{logTailLines?:number}): void;
|
|
35
37
|
detail(id: string, now: number, options?: {logTailLines?: number}): BackgroundWorkDetail | null;
|
|
36
38
|
close(id: string): {action:string;providerId:string;id:string;status?:string};
|
|
37
39
|
}
|
|
38
|
-
export function createBackgroundTasksNavigator(runtime
|
|
40
|
+
export function createBackgroundTasksNavigator(runtime?: Pick<BackgroundTaskRuntime, "stopTask">, managed?: ManagedBackgroundNavigator) {
|
|
39
41
|
const owner = Symbol("background-tasks navigator factory");
|
|
40
42
|
let unregister: (() => void) | undefined;
|
|
41
43
|
let navigatorContext: ExtensionContext | undefined;
|
|
@@ -93,6 +95,7 @@ const provider: BackgroundWorkProvider = {
|
|
|
93
95
|
id: "background-tasks",
|
|
94
96
|
label: "Background Tasks",
|
|
95
97
|
priority: 20,
|
|
98
|
+
onOpen: managed?.onOpen,
|
|
96
99
|
visibleCount: () => {
|
|
97
100
|
const now = Date.now();
|
|
98
101
|
return (managed ? managed.rows().filter(row => row.status === "running").length : visibleMetas(now).filter((meta) => meta.status === "running").length)
|
|
@@ -110,8 +113,10 @@ const provider: BackgroundWorkProvider = {
|
|
|
110
113
|
},
|
|
111
114
|
armCloseLabel: (row) => row.status === "running" || row.status === "starting" ? "x again to stop" : "x again to dismiss",
|
|
112
115
|
close: (id) => {
|
|
116
|
+
if (durableTask(id)?.readOnly) return {action: "not-closable", providerId: "background-tasks", id};
|
|
113
117
|
if(managed)return managed.close(id);
|
|
114
118
|
const durable = durableTask(id);
|
|
119
|
+
if (durable?.readOnly) return {action: "not-closable", providerId: "background-tasks", id};
|
|
115
120
|
if (durable) {
|
|
116
121
|
const host = navigatorHost();
|
|
117
122
|
const origin = activeNavigatorOrigin;
|
|
@@ -128,7 +133,9 @@ const provider: BackgroundWorkProvider = {
|
|
|
128
133
|
const meta = readMeta(id);
|
|
129
134
|
if (!meta) return { action: "missing", providerId: "background-tasks", id };
|
|
130
135
|
if (meta.status === "running") {
|
|
131
|
-
|
|
136
|
+
const pi = piRef as ExtensionAPI;
|
|
137
|
+
if (runtime) void runtime.stopTask(pi, id);
|
|
138
|
+
else void import("./runtime.js").then(({ stopTask }) => stopTask(pi, id));
|
|
132
139
|
return { action: "stopped", providerId: "background-tasks", id, status: "stopping" };
|
|
133
140
|
}
|
|
134
141
|
meta.dismissedAt = Date.now();
|
|
@@ -192,6 +199,8 @@ function rowFromDurable(task: DurableTaskProjection, now: number): BackgroundWor
|
|
|
192
199
|
return {
|
|
193
200
|
providerId: "background-tasks",
|
|
194
201
|
id: task.id,
|
|
202
|
+
parentAgentId: task.parentAgentId,
|
|
203
|
+
readOnly: task.readOnly,
|
|
195
204
|
name: task.name,
|
|
196
205
|
status: task.status,
|
|
197
206
|
statusTone: toneForDurableStatus(task.status),
|
|
@@ -217,6 +226,7 @@ function detailFromDurable(task: DurableTaskProjection, options?: { logTailLines
|
|
|
217
226
|
const metadata = [
|
|
218
227
|
{ label: "provider", value: "Background Tasks (durable)" },
|
|
219
228
|
{ label: "kind", value: task.kind },
|
|
229
|
+
...(task.parentAgentId ? [{label: "agent", value: task.parentAgentId}] : []),
|
|
220
230
|
{ label: "operation", value: task.operationId },
|
|
221
231
|
{ label: "status", value: `${task.status}${task.terminalOutcome ? ` (${task.terminalOutcome})` : ""}` },
|
|
222
232
|
{ label: "started", value: new Date(task.startedAt).toISOString() },
|
|
@@ -255,7 +265,7 @@ function detailFromDurable(task: DurableTaskProjection, options?: { logTailLines
|
|
|
255
265
|
label: log?.truncated ? "log tail" : "log",
|
|
256
266
|
text: evidenceText,
|
|
257
267
|
},
|
|
258
|
-
footerActions: [task.active ? "x stop" : "x dismiss"],
|
|
268
|
+
footerActions: task.readOnly ? ["Managed by owning agent"] : [task.active ? "x stop" : "x dismiss"],
|
|
259
269
|
};
|
|
260
270
|
}
|
|
261
271
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-background-tasks/src/observed-wait-client.ts. Do not edit directly.
|
|
2
|
+
const hosts = new WeakMap();
|
|
3
|
+
export function registerObservedWaitClient(pi, host) { hosts.set(pi, host); }
|
|
4
|
+
export function getObservedWaitHost(pi) {
|
|
5
|
+
return pi && typeof pi === "object" ? hosts.get(pi) : undefined;
|
|
6
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ObservedWaitHost } from "./observed-waits.js";
|
|
3
|
+
|
|
4
|
+
const hosts = new WeakMap<object, ObservedWaitHost>();
|
|
5
|
+
|
|
6
|
+
export function registerObservedWaitClient(pi: ExtensionAPI, host: ObservedWaitHost): void { hosts.set(pi as object, host); }
|
|
7
|
+
|
|
8
|
+
export function getObservedWaitHost(pi: unknown): ObservedWaitHost | undefined {
|
|
9
|
+
return pi && typeof pi === "object" ? hosts.get(pi as object) : undefined;
|
|
10
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-background-tasks/src/observed-waits.ts. Do not edit directly.
|
|
2
|
+
import { getObservedWaitHost, registerObservedWaitClient } from "./observed-wait-client.domain.mjs";
|
|
3
|
+
export { getObservedWaitHost, registerObservedWaitClient } from "./observed-wait-client.domain.mjs";
|
|
2
4
|
/**
|
|
3
5
|
* Parent-side observed waits: the integration between background tasks, the
|
|
4
6
|
* detached local supervisor and the durable operation coordinator.
|
|
@@ -21,7 +23,7 @@
|
|
|
21
23
|
* calling the existing `resolve*SandboxPlan` helpers.
|
|
22
24
|
*/
|
|
23
25
|
import { createHash, randomUUID } from "node:crypto";
|
|
24
|
-
import { closeSync, existsSync, fstatSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
26
|
+
import { closeSync, existsSync, fstatSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, watch } from "node:fs";
|
|
25
27
|
import { homedir } from "node:os";
|
|
26
28
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
27
29
|
import { validateCondition } from "./conditions.domain.mjs";
|
|
@@ -30,6 +32,8 @@ import { currentProcessStartToken, readProcessStartToken } from "./process-ident
|
|
|
30
32
|
import { assertBackgroundExecutionAllowed, backgroundExecutionLimits, confineCommandSpec, resolveForegroundSandboxPlan, currentForegroundSandboxPolicy, resolveWorkerSandboxPlan, sandboxProvenance, } from "./sandbox.domain.mjs";
|
|
31
33
|
import { openStore, cancellationCredential, } from "./shared-operation-coordinator/index.domain.mjs";
|
|
32
34
|
import { createLocalSupervisor, defaultSupervisorDirectory, supervisorPaths, supervisorTaskIdForToken, } from "./supervisor/index.domain.mjs";
|
|
35
|
+
import { processGroupAlive } from "./supervisor/identity.domain.mjs";
|
|
36
|
+
import { readStopRequest } from "./supervisor/store.domain.mjs";
|
|
33
37
|
export const OBSERVED_WAITS_SERVICE_VERSION = 2;
|
|
34
38
|
export const OBSERVED_WAITS_SERVICE_CHANNEL = "pi-better-background-tasks:observed-waits-service";
|
|
35
39
|
export const OBSERVED_WAITS_SERVICE_REQUEST_CHANNEL = "pi-better-background-tasks:observed-waits-service-request";
|
|
@@ -165,19 +169,14 @@ export function observedWaitServiceUnavailableReason(pi) {
|
|
|
165
169
|
const events = eventBusOf(pi);
|
|
166
170
|
return events ? serviceErrors.get(events) : undefined;
|
|
167
171
|
}
|
|
168
|
-
const hosts = new WeakMap();
|
|
169
172
|
export function createObservedWaitHost(pi, options = {}) {
|
|
170
|
-
const existing =
|
|
173
|
+
const existing = getObservedWaitHost(pi);
|
|
171
174
|
if (existing && existing !== undefined)
|
|
172
175
|
existing.close();
|
|
173
176
|
const host = new ObservedWaitHost(pi, options);
|
|
174
|
-
|
|
177
|
+
registerObservedWaitClient(pi, host);
|
|
175
178
|
return host;
|
|
176
179
|
}
|
|
177
|
-
export function registerObservedWaitClient(pi, host) { hosts.set(pi, host); }
|
|
178
|
-
export function getObservedWaitHost(pi) {
|
|
179
|
-
return pi && typeof pi === "object" ? hosts.get(pi) : undefined;
|
|
180
|
-
}
|
|
181
180
|
function branchIdsOf(ctx) {
|
|
182
181
|
try {
|
|
183
182
|
const branch = ctx.sessionManager?.getBranch?.();
|
|
@@ -361,6 +360,51 @@ export class ObservedWaitHost {
|
|
|
361
360
|
pollMs;
|
|
362
361
|
options;
|
|
363
362
|
timer;
|
|
363
|
+
changeWatcher;
|
|
364
|
+
changeRepair;
|
|
365
|
+
changePosition;
|
|
366
|
+
changeScheduled = false;
|
|
367
|
+
managedDirty = false;
|
|
368
|
+
managedAfter = 0;
|
|
369
|
+
observeManagedChanges() {
|
|
370
|
+
const schedule = () => {
|
|
371
|
+
if (this.closed || this.changeScheduled)
|
|
372
|
+
return;
|
|
373
|
+
this.changeScheduled = true;
|
|
374
|
+
setImmediate(() => {
|
|
375
|
+
this.changeScheduled = false;
|
|
376
|
+
if (this.closed || !this.store)
|
|
377
|
+
return;
|
|
378
|
+
try {
|
|
379
|
+
const page = this.store.resultSupervisionChanges(this.changePosition);
|
|
380
|
+
const changed = page.reset || page.seq !== this.changePosition?.seq;
|
|
381
|
+
this.changePosition = { generation: page.generation, seq: page.seq };
|
|
382
|
+
this.managedDirty ||= changed;
|
|
383
|
+
if (this.managedDirty && Date.now() >= this.managedAfter) {
|
|
384
|
+
this.managedDirty = false;
|
|
385
|
+
this.managedAfter = Date.now() + 1000;
|
|
386
|
+
void this.reconcileNow();
|
|
387
|
+
}
|
|
388
|
+
if (page.more)
|
|
389
|
+
schedule();
|
|
390
|
+
}
|
|
391
|
+
catch { /* Existing authority remains unchanged; the bounded feed repair retries. */ }
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
this.changeWatcher = watch(dirname(this.storePath), (_event, file) => {
|
|
395
|
+
if (!file || String(file).startsWith("operation-coordinator.sqlite"))
|
|
396
|
+
schedule();
|
|
397
|
+
});
|
|
398
|
+
this.changeWatcher.on("error", () => { this.changeWatcher?.close(); this.changeWatcher = undefined; });
|
|
399
|
+
const repair = () => {
|
|
400
|
+
if (this.closed)
|
|
401
|
+
return;
|
|
402
|
+
schedule();
|
|
403
|
+
this.changeRepair = setTimeout(repair, 1000);
|
|
404
|
+
this.changeRepair.unref();
|
|
405
|
+
};
|
|
406
|
+
repair();
|
|
407
|
+
}
|
|
364
408
|
closed = false;
|
|
365
409
|
activationAttempted = false;
|
|
366
410
|
unavailableReason;
|
|
@@ -392,6 +436,7 @@ export class ObservedWaitHost {
|
|
|
392
436
|
continuationError;
|
|
393
437
|
launches = new Map();
|
|
394
438
|
localCancels = new Set();
|
|
439
|
+
assignmentCleanupCursor;
|
|
395
440
|
resultHandoffs = new Set();
|
|
396
441
|
rpcRuns = new Map();
|
|
397
442
|
waitOwners = new Map();
|
|
@@ -406,6 +451,7 @@ export class ObservedWaitHost {
|
|
|
406
451
|
discoveryToken;
|
|
407
452
|
discoveryRole;
|
|
408
453
|
reconcileInFlight;
|
|
454
|
+
reconcileScope;
|
|
409
455
|
authorityPassCache;
|
|
410
456
|
/** Running operations this follower is currently assigned to supervise. */
|
|
411
457
|
followerRunningTasks = new Set();
|
|
@@ -414,7 +460,8 @@ export class ObservedWaitHost {
|
|
|
414
460
|
recoveryScopeState() {
|
|
415
461
|
if (!this.activeOrigin)
|
|
416
462
|
return this.unscopedCallbackRecovery;
|
|
417
|
-
|
|
463
|
+
// Concurrent foregrounds can retain different branch snapshots of one session.
|
|
464
|
+
const key = JSON.stringify([this.activeOrigin.cwd, this.activeOrigin.sessionId, branchIdsOf(this.activeContext)]);
|
|
418
465
|
let state = this.callbackRecoveryScopes.get(key);
|
|
419
466
|
if (!state) {
|
|
420
467
|
if (this.callbackRecoveryScopes.size >= 128)
|
|
@@ -491,6 +538,16 @@ export class ObservedWaitHost {
|
|
|
491
538
|
}
|
|
492
539
|
get usesServerResults() { return this.options.serverOwnedResults === true; }
|
|
493
540
|
get hasActivated() { return this.activationAttempted; }
|
|
541
|
+
/** Ready worker continuations can advance; held decisions and unread results cannot. */
|
|
542
|
+
advancingWaits() {
|
|
543
|
+
if (!this.store || !this.continuation)
|
|
544
|
+
return [];
|
|
545
|
+
return this.store.listWaits({ phase: ["ready", "resuming"], pendingOnly: true })
|
|
546
|
+
.filter(wait => wait.owner.kind === "worker-conversation")
|
|
547
|
+
.map(wait => ({ kind: "advancing-wait", id: wait.waitId, generation: wait.generation, owner: wait.owner,
|
|
548
|
+
lastProgressAt: wait.updatedAt, nextDeadline: wait.updatedAt + (this.options.verificationMs ?? 30000), recovery: "captured-worker-continuation" }))
|
|
549
|
+
.filter(wait => wait.nextDeadline > Date.now());
|
|
550
|
+
}
|
|
494
551
|
get reason() {
|
|
495
552
|
return this.unavailableReason;
|
|
496
553
|
}
|
|
@@ -534,7 +591,10 @@ export class ObservedWaitHost {
|
|
|
534
591
|
void this.reconcileNow();
|
|
535
592
|
this.recoverTerminalNotifications();
|
|
536
593
|
this.terminalRecoveryNeeded = false;
|
|
537
|
-
if (this.
|
|
594
|
+
if (this.options.serverOwnedResults && this.options.sharedStore) {
|
|
595
|
+
this.observeManagedChanges();
|
|
596
|
+
}
|
|
597
|
+
else if (this.pollMs > 0) {
|
|
538
598
|
this.timer = setInterval(() => { void this.reconcileNow(); }, this.pollMs);
|
|
539
599
|
this.timer.unref?.();
|
|
540
600
|
}
|
|
@@ -546,6 +606,12 @@ export class ObservedWaitHost {
|
|
|
546
606
|
HOST_INSTANCE_STATE.closed.add(this.hostId);
|
|
547
607
|
if (this.timer)
|
|
548
608
|
clearInterval(this.timer);
|
|
609
|
+
this.changeWatcher?.close();
|
|
610
|
+
this.changeWatcher = undefined;
|
|
611
|
+
if (this.changeRepair)
|
|
612
|
+
clearTimeout(this.changeRepair);
|
|
613
|
+
this.changeRepair = undefined;
|
|
614
|
+
this.changePosition = undefined;
|
|
549
615
|
this.timer = undefined;
|
|
550
616
|
this.releaseDiscoveryAuthority();
|
|
551
617
|
this.releaseSupervisionAuthority();
|
|
@@ -684,16 +750,31 @@ export class ObservedWaitHost {
|
|
|
684
750
|
}
|
|
685
751
|
/** A deterministic, awaitable reconciliation pass for tests and session activation. */
|
|
686
752
|
async reconcileNow() {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
753
|
+
const scope = this.recoveryScopeState();
|
|
754
|
+
if (this.reconcileInFlight) {
|
|
755
|
+
const sameScope = this.reconcileScope === scope;
|
|
756
|
+
await this.reconcileInFlight;
|
|
757
|
+
// Startup or another foreground's pass cannot verify this scope's recovery.
|
|
758
|
+
if (!sameScope)
|
|
759
|
+
return this.reconcileNow();
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const release = this.options.enterControl?.();
|
|
763
|
+
if (this.options.enterControl && !release) {
|
|
764
|
+
this.managedDirty = true;
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
this.reconcileScope = scope;
|
|
768
|
+
const pass = this.reconcilePass().finally(() => release?.());
|
|
690
769
|
this.reconcileInFlight = pass;
|
|
691
770
|
try {
|
|
692
771
|
await pass;
|
|
693
772
|
}
|
|
694
773
|
finally {
|
|
695
|
-
if (this.reconcileInFlight === pass)
|
|
774
|
+
if (this.reconcileInFlight === pass) {
|
|
696
775
|
this.reconcileInFlight = undefined;
|
|
776
|
+
this.reconcileScope = undefined;
|
|
777
|
+
}
|
|
697
778
|
}
|
|
698
779
|
}
|
|
699
780
|
async reconcilePass() {
|
|
@@ -716,6 +797,8 @@ export class ObservedWaitHost {
|
|
|
716
797
|
if (role === "holder") {
|
|
717
798
|
this.discoverObservedTasks();
|
|
718
799
|
this.reconcileGlobalRunning();
|
|
800
|
+
if (discovery.hasAssignmentTasks)
|
|
801
|
+
await this.reconcileAssignmentCleanup();
|
|
719
802
|
}
|
|
720
803
|
else {
|
|
721
804
|
this.reconcileFollowerRunning();
|
|
@@ -728,6 +811,43 @@ export class ObservedWaitHost {
|
|
|
728
811
|
this.authorityPassCache = undefined;
|
|
729
812
|
}
|
|
730
813
|
}
|
|
814
|
+
async reconcileAssignmentCleanup() {
|
|
815
|
+
const store = this.requireStore();
|
|
816
|
+
const [candidate] = store.listAssignmentCleanupOperations(1, this.assignmentCleanupCursor);
|
|
817
|
+
this.assignmentCleanupCursor = candidate?.operationId;
|
|
818
|
+
if (!candidate || candidate.resultManaged || this.supervisionAuthority(candidate) !== "self")
|
|
819
|
+
return;
|
|
820
|
+
const { taskId, launchToken } = candidate;
|
|
821
|
+
try {
|
|
822
|
+
const inspection = this.supervisor.snapshot(taskId);
|
|
823
|
+
const stop = readStopRequest(this.directory, taskId);
|
|
824
|
+
if (inspection?.token !== launchToken || (stop && stop.token !== launchToken))
|
|
825
|
+
return;
|
|
826
|
+
if (inspection.terminal) {
|
|
827
|
+
if (inspection.status !== "lost" && inspection.result?.groupCleanup !== "unproven")
|
|
828
|
+
return;
|
|
829
|
+
const pgid = inspection.command?.pgid ?? inspection.command?.pid;
|
|
830
|
+
if (inspection.cleanup?.groupEmpty === true || (pgid && !processGroupAlive(pgid))) {
|
|
831
|
+
store.verifyAssignmentCleanup(candidate.operationId, launchToken, candidate.terminalRevision);
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
if (!pgid)
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
if (!this.localCancels.has(taskId)) {
|
|
838
|
+
this.localCancels.add(taskId);
|
|
839
|
+
try {
|
|
840
|
+
await this.supervisor.stop(taskId, { token: launchToken, reason: "owning assignment ended" });
|
|
841
|
+
}
|
|
842
|
+
finally {
|
|
843
|
+
this.localCancels.delete(taskId);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
catch (error) {
|
|
848
|
+
this.options.logger?.(`Assignment cleanup for ${taskId}: ${String(error)}`);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
731
851
|
reconcileGlobalRunning() {
|
|
732
852
|
const store = this.store;
|
|
733
853
|
if (!store)
|
|
@@ -886,7 +1006,7 @@ export class ObservedWaitHost {
|
|
|
886
1006
|
const owner = this.ownerFor(input.ctx);
|
|
887
1007
|
const prepared = this.prepareLaunch(input.kind, input.params, "bg_task_spawn", owner, undefined);
|
|
888
1008
|
if (this.options.serverOwnedResults) {
|
|
889
|
-
this.
|
|
1009
|
+
this.assertManagedResultAdmission(prepared.provenance);
|
|
890
1010
|
const client = await this.resultSupervisionClient();
|
|
891
1011
|
client.close();
|
|
892
1012
|
}
|
|
@@ -924,7 +1044,7 @@ export class ObservedWaitHost {
|
|
|
924
1044
|
this.writeLaunchContext(taskId, launchContext);
|
|
925
1045
|
this.launches.set(taskId, launchContext);
|
|
926
1046
|
if (this.options.serverOwnedResults)
|
|
927
|
-
await this.handoffResults([store.getOperation(operationId)]);
|
|
1047
|
+
await this.handoffResults([store.getOperation(operationId)], true);
|
|
928
1048
|
const started = await this.startSupervisor({
|
|
929
1049
|
token, taskId, kind: input.kind, params: input.params, prepared, operationId,
|
|
930
1050
|
});
|
|
@@ -1273,7 +1393,7 @@ export class ObservedWaitHost {
|
|
|
1273
1393
|
if (owner.kind !== "parent-session" || this.activeOwnerRelation(owner) !== "match")
|
|
1274
1394
|
return;
|
|
1275
1395
|
this.invalidateDurableProjection(owner);
|
|
1276
|
-
const change = { sessionId: owner.sessionId, workspace: owner.workspace };
|
|
1396
|
+
const change = { sessionId: owner.sessionId, workspace: owner.workspace, branchId: owner.branchId ?? null };
|
|
1277
1397
|
for (const listener of [...this.durableChangeListeners]) {
|
|
1278
1398
|
try {
|
|
1279
1399
|
listener(change);
|
|
@@ -1353,7 +1473,7 @@ export class ObservedWaitHost {
|
|
|
1353
1473
|
logPaths: { stdout: pathSet.stdout, stderr: pathSet.stderr, events: pathSet.events },
|
|
1354
1474
|
waits,
|
|
1355
1475
|
...(context?.sandbox ? { sandbox: context.sandbox } : {}),
|
|
1356
|
-
owner: { sessionId: operation.owner.sessionId, workspace: operation.owner.workspace },
|
|
1476
|
+
owner: { sessionId: operation.owner.sessionId, workspace: operation.owner.workspace, branchId: operation.owner.branchId ?? null },
|
|
1357
1477
|
};
|
|
1358
1478
|
}
|
|
1359
1479
|
status(taskId, owner) {
|
|
@@ -1564,6 +1684,11 @@ export class ObservedWaitHost {
|
|
|
1564
1684
|
throw new Error("Terminal runner evidence is awaiting authoritative server import; supervision is unavailable.");
|
|
1565
1685
|
return imported;
|
|
1566
1686
|
}
|
|
1687
|
+
assertManagedResultAdmission(captured) {
|
|
1688
|
+
if (captured.policySource !== "no-publisher" && !currentForegroundSandboxPolicy(this.pi)) {
|
|
1689
|
+
throw new Error("permission-unavailable: expected current Background permission source is unavailable");
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1567
1692
|
assertResultAdmission(captured, transferring = new Set()) {
|
|
1568
1693
|
const discovery = this.requireStore().readDiscoveryClaim(this.discoveryScope);
|
|
1569
1694
|
if (discovery && discovery.hostId !== this.hostId && this.discoveryHolderState(discovery.hostId) !== "dead") {
|
|
@@ -1589,12 +1714,16 @@ export class ObservedWaitHost {
|
|
|
1589
1714
|
}
|
|
1590
1715
|
}
|
|
1591
1716
|
}
|
|
1592
|
-
async handoffResults(operations) {
|
|
1717
|
+
async handoffResults(operations, newManaged = false) {
|
|
1593
1718
|
const client = await this.resultSupervisionClient();
|
|
1594
1719
|
try {
|
|
1595
1720
|
const manager = await client.request("runtime_result_supervision");
|
|
1721
|
+
// Already granted dependencies need no discovery scope transfer. Legacy
|
|
1722
|
+
// holders may keep supervising unrelated work beside server-owned tasks.
|
|
1723
|
+
if (operations.every(operation => this.requireStore().resultSupervision(operation.operationId)))
|
|
1724
|
+
return;
|
|
1596
1725
|
const discovery = this.requireStore().readDiscoveryClaim(this.discoveryScope);
|
|
1597
|
-
if (discovery && discovery.hostId !== this.hostId && this.discoveryHolderState(discovery.hostId) !== "dead") {
|
|
1726
|
+
if (!newManaged && discovery && discovery.hostId !== this.hostId && this.discoveryHolderState(discovery.hostId) !== "dead") {
|
|
1598
1727
|
throw new Error("permission-unavailable: live or unknown original discovery holder prevents scope handoff");
|
|
1599
1728
|
}
|
|
1600
1729
|
const transfers = [];
|
|
@@ -1608,7 +1737,10 @@ export class ObservedWaitHost {
|
|
|
1608
1737
|
const context = this.launchContext(operation.taskId);
|
|
1609
1738
|
if (!context?.sandbox || !context.supervisionPolicy || !operation.authorityRef)
|
|
1610
1739
|
throw new Error("permission-unavailable: captured Background authority is unavailable");
|
|
1611
|
-
|
|
1740
|
+
if (newManaged)
|
|
1741
|
+
this.assertManagedResultAdmission(context.sandbox);
|
|
1742
|
+
else
|
|
1743
|
+
this.assertResultAdmission(context.sandbox, transferring);
|
|
1612
1744
|
const current = currentForegroundSandboxPolicy(this.pi);
|
|
1613
1745
|
if (context.sandbox.policySource !== "no-publisher" && !current)
|
|
1614
1746
|
throw new Error("permission-unavailable: expected current Background permission source is unavailable");
|
|
@@ -1620,10 +1752,16 @@ export class ObservedWaitHost {
|
|
|
1620
1752
|
for (const transfer of transfers)
|
|
1621
1753
|
this.resultHandoffs.add(transfer.operationId);
|
|
1622
1754
|
try {
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1755
|
+
if (newManaged) {
|
|
1756
|
+
// New work grants only its own results; legacy discovery remains live.
|
|
1757
|
+
this.requireStore().handoffResultSupervisions(transfers);
|
|
1758
|
+
}
|
|
1759
|
+
else {
|
|
1760
|
+
this.requireStore().handoffResultScope({ scope: this.discoveryScope,
|
|
1761
|
+
expectedDiscovery: discovery ? { hostId: discovery.hostId, token: discovery.token } : null, grants: transfers });
|
|
1762
|
+
this.discoveryToken = undefined;
|
|
1763
|
+
this.discoveryRole = "follower";
|
|
1764
|
+
}
|
|
1627
1765
|
}
|
|
1628
1766
|
catch (error) {
|
|
1629
1767
|
// The transaction rolled back; only these uncommitted local fences may reopen.
|
|
@@ -1679,7 +1817,7 @@ export class ObservedWaitHost {
|
|
|
1679
1817
|
const assertWorkerPolicy = this.options.prepareWorkerPolicy?.(run);
|
|
1680
1818
|
const prepared = this.prepareLaunch(input.kind, input.params, input.kind === "watch" ? "bg_task_watch" : "bg_task_spawn", owner, input.policy, run.workspace);
|
|
1681
1819
|
if (this.options.serverOwnedResults)
|
|
1682
|
-
this.
|
|
1820
|
+
this.assertManagedResultAdmission(prepared.provenance);
|
|
1683
1821
|
const operationId = `op_${randomUUID()}`;
|
|
1684
1822
|
const token = `launch_${randomUUID()}`;
|
|
1685
1823
|
const taskId = supervisorTaskIdForToken(token);
|
|
@@ -1692,8 +1830,10 @@ export class ObservedWaitHost {
|
|
|
1692
1830
|
supervision: this.supervision(),
|
|
1693
1831
|
authorityRef: authorityReference(`worker:${run.authorityReference}`),
|
|
1694
1832
|
intentRef: typeof input.params.operation_id === "string" ? input.params.operation_id : null,
|
|
1833
|
+
...(run.assignmentAttemptId ? { assignmentAttemptId: run.assignmentAttemptId } : {}),
|
|
1695
1834
|
});
|
|
1696
1835
|
const launchContext = {
|
|
1836
|
+
workerAttemptId: run.runId,
|
|
1697
1837
|
kind: input.kind,
|
|
1698
1838
|
parentOrigin: this.parentOrigin,
|
|
1699
1839
|
gated: prepared.gated,
|
|
@@ -1709,7 +1849,7 @@ export class ObservedWaitHost {
|
|
|
1709
1849
|
this.writeLaunchContext(taskId, launchContext);
|
|
1710
1850
|
this.launches.set(taskId, launchContext);
|
|
1711
1851
|
if (this.options.serverOwnedResults)
|
|
1712
|
-
await this.handoffResults([store.getOperation(operationId)]);
|
|
1852
|
+
await this.handoffResults([store.getOperation(operationId)], true);
|
|
1713
1853
|
const started = await this.startSupervisor({
|
|
1714
1854
|
token, taskId, kind: input.kind, params: input.params, prepared, operationId, assertDispatch: assertWorkerPolicy,
|
|
1715
1855
|
});
|
|
@@ -2058,6 +2198,7 @@ export class ObservedWaitHost {
|
|
|
2058
2198
|
: {};
|
|
2059
2199
|
this.rpcRuns.set(runId, Object.freeze({
|
|
2060
2200
|
runId,
|
|
2201
|
+
assignmentTaskOwnership: params.assignmentTaskOwnership === true,
|
|
2061
2202
|
conversationId,
|
|
2062
2203
|
attemptId,
|
|
2063
2204
|
workspace,
|
|
@@ -2411,6 +2552,7 @@ export class ObservedWaitHost {
|
|
|
2411
2552
|
rpcScope(binding) {
|
|
2412
2553
|
return {
|
|
2413
2554
|
runId: binding.runId,
|
|
2555
|
+
...(binding.assignmentTaskOwnership ? { assignmentAttemptId: binding.attemptId } : {}),
|
|
2414
2556
|
conversationId: binding.conversationId,
|
|
2415
2557
|
workspace: binding.workspace,
|
|
2416
2558
|
authorityReference: binding.authorityReference,
|
|
@@ -3219,6 +3361,7 @@ export class ObservedWaitHost {
|
|
|
3219
3361
|
const outcome = await adapter.onWaitReady({
|
|
3220
3362
|
waitId: event.waitId,
|
|
3221
3363
|
generation: event.generation,
|
|
3364
|
+
...(wait?.park?.attemptId ? { parkedAttemptId: wait.park.attemptId } : {}),
|
|
3222
3365
|
owner,
|
|
3223
3366
|
...(taskId && this.launches.get(taskId)?.parentOrigin
|
|
3224
3367
|
? { parentOrigin: this.launches.get(taskId).parentOrigin }
|