@hearsay-tools/squawk 0.18.0-dev.7804 → 0.18.0-dev.7808
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/dist/activity/read-model.js +1 -1
- package/dist/activity/read-model.js.map +1 -1
- package/dist/activity/requests.d.ts +3 -1
- package/dist/activity/requests.js +1 -1
- package/dist/activity/requests.js.map +1 -1
- package/dist/built-in-run-slots.d.ts +4 -3
- package/dist/built-in-run-slots.js +7 -3
- package/dist/built-in-run-slots.js.map +1 -1
- package/dist/delegation/execution-identity.d.ts +7 -2
- package/dist/delegation/execution-identity.js +34 -3
- package/dist/delegation/execution-identity.js.map +1 -1
- package/dist/delegation/family-end.d.ts +3 -1
- package/dist/delegation/private-record-file.js.map +1 -0
- package/dist/delegation/results.js +2 -2
- package/dist/delegation/results.js.map +1 -1
- package/dist/delegation/routes.d.ts +11 -11
- package/dist/delegation/scratch-cleanup.js +5 -5
- package/dist/delegation/scratch-cleanup.js.map +1 -1
- package/dist/delegation/service.js +5 -4
- package/dist/delegation/service.js.map +1 -1
- package/dist/delegation/transport.d.ts +4 -4
- package/dist/delegation/worker-cleanup.js +11 -10
- package/dist/delegation/worker-cleanup.js.map +1 -1
- package/dist/{runs → delegation}/worker-deletion-proof.d.ts +1 -1
- package/dist/delegation/worker-deletion-proof.js.map +1 -0
- package/dist/delegation/worker-executions.d.ts +70 -0
- package/dist/delegation/worker-executions.js +248 -0
- package/dist/delegation/worker-executions.js.map +1 -0
- package/dist/{runs → delegation}/worker-resource-holders.d.ts +1 -1
- package/dist/delegation/worker-resource-holders.js.map +1 -0
- package/dist/preview/host.d.ts +3 -1
- package/dist/preview/host.js +1 -1
- package/dist/preview/host.js.map +1 -1
- package/dist/runs/owned-run-create.d.ts +3 -3
- package/dist/runs/owned-run-create.js +1 -2
- package/dist/runs/owned-run-create.js.map +1 -1
- package/dist/runs/ports.d.ts +38 -14
- package/dist/runs/retention.d.ts +3 -1
- package/dist/runs/retention.js +3 -3
- package/dist/runs/retention.js.map +1 -1
- package/dist/runs/run-retention.d.ts +1 -1
- package/dist/runs/store.d.ts +6 -51
- package/dist/runs/store.js +21 -249
- package/dist/runs/store.js.map +1 -1
- package/dist/runs/worker-executions-registry.d.ts +31 -0
- package/dist/runs/worker-executions-registry.js +20 -0
- package/dist/runs/worker-executions-registry.js.map +1 -0
- package/dist/server/activity-routes.d.ts +23 -23
- package/dist/server/run-relationships.d.ts +3 -1
- package/dist/server/run-relationships.js +1 -1
- package/dist/server/run-relationships.js.map +1 -1
- package/dist/server/runners-routes.d.ts +10 -10
- package/dist/server/server.d.ts +6 -6
- package/dist/server/workspace-live-routes.d.ts +6 -6
- package/dist/workflows/run/completion-gate.js +1 -1
- package/dist/workflows/run/completion-gate.js.map +1 -1
- package/dist/workflows/run/continuation-session.js +1 -1
- package/dist/workflows/run/continuation-session.js.map +1 -1
- package/dist/workflows/run/family-reconciler.js +2 -2
- package/dist/workflows/run/family-reconciler.js.map +1 -1
- package/dist/workflows/run/launch-read-resolver.js +2 -2
- package/dist/workflows/run/launch-read-resolver.js.map +1 -1
- package/dist/workflows/run/run-cancel.js +4 -4
- package/dist/workflows/run/run-cancel.js.map +1 -1
- package/dist/workflows/run/run-recovery.js +2 -2
- package/dist/workflows/run/run-recovery.js.map +1 -1
- package/dist/workflows/run/step-loop.js +2 -2
- package/dist/workflows/run/step-loop.js.map +1 -1
- package/dist/workflows/run/step-session.js +1 -1
- package/dist/workflows/run/step-session.js.map +1 -1
- package/dist/workflows/run/worker-executions.js +6 -6
- package/dist/workflows/run/worker-executions.js.map +1 -1
- package/dist/workflows/run/worker-orphans.js +8 -8
- package/dist/workflows/run/worker-orphans.js.map +1 -1
- package/package.json +4 -4
- package/scripts/benchmark-stuck-destroys.ts +2 -2
- package/scripts/benchmark-worker-lifecycle.ts +3 -2
- package/dist/runs/private-record-file.js.map +0 -1
- package/dist/runs/worker-deletion-proof.js.map +0 -1
- package/dist/runs/worker-resource-holders.js.map +0 -1
- /package/dist/{runs → delegation}/private-record-file.d.ts +0 -0
- /package/dist/{runs → delegation}/private-record-file.js +0 -0
- /package/dist/{runs → delegation}/worker-deletion-proof.js +0 -0
- /package/dist/{runs → delegation}/worker-resource-holders.js +0 -0
package/dist/runs/ports.d.ts
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
import type { WorkerCollectedResult } from '../contract/index.js';
|
|
12
12
|
import type { RunStore } from './store.ts';
|
|
13
13
|
import type { TranscriptFacts } from './transcript-facts.ts';
|
|
14
|
+
import type { WorkerExecution } from './worker-execution.ts';
|
|
15
|
+
import type { WorkerProcessRecord } from '../core/process-stat.ts';
|
|
16
|
+
import type { AgentRunSpec } from '../core/agent-runner.ts';
|
|
14
17
|
export type { RunLifecycleSource } from './lifecycle.ts';
|
|
15
18
|
/** One run's record, by id. Nearly every caller needs only this. */
|
|
16
19
|
export interface RunLookup {
|
|
@@ -96,21 +99,42 @@ export interface WorkerResults {
|
|
|
96
99
|
ignoreCleanup?: boolean;
|
|
97
100
|
}): WorkerCollectedResult;
|
|
98
101
|
}
|
|
99
|
-
/**
|
|
102
|
+
/** The processes of a worker's scope that a core caller stops (`workflows/run/worker-orphans.ts`). */
|
|
103
|
+
export interface WorkerScopeControl {
|
|
104
|
+
empty(workerId: string): boolean;
|
|
105
|
+
stopped(workerId: string): boolean;
|
|
106
|
+
kill(workerId: string): void;
|
|
107
|
+
}
|
|
108
|
+
/** A worker's execution, scope and processes (`delegation/worker-executions.ts`, `store.workerExecutions`). */
|
|
100
109
|
export interface WorkerExecutions {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
readWorkerExecution(id: string): WorkerExecution | undefined;
|
|
111
|
+
workerResourcesSafe(id: string, generation: string, resourceId: string): boolean;
|
|
112
|
+
workerResourceHolders(id: string, generation: string, resourceId: string, opts?: {
|
|
113
|
+
admittingQueued?: boolean;
|
|
114
|
+
}): 'safe' | number[];
|
|
115
|
+
retainWorkerScratchCleanup(id: string): void;
|
|
116
|
+
workerScratchResourcesSafe(id: string, generation: string, resourceId: string): boolean;
|
|
117
|
+
commitWorkerExecutionStart(id: string): string;
|
|
118
|
+
readWorkerProcesses(id: string, generation: string): WorkerProcessRecord | 'absent' | 'unknown';
|
|
119
|
+
spawnScope(id: string): AgentRunSpec['scope'];
|
|
120
|
+
appendWorkerProcess(id: string, generation: string, pid: number, pgid?: number): boolean;
|
|
121
|
+
commitWorkerExecutionComplete(id: string, generation: string, opts?: {
|
|
122
|
+
interrupted?: boolean;
|
|
123
|
+
}): boolean;
|
|
124
|
+
readonly scopes: WorkerScopeControl;
|
|
125
|
+
}
|
|
126
|
+
/** The worker records the store's own paths write, check and remove: owned-run creation, the
|
|
127
|
+
* archive checks and the delegated deletion. */
|
|
128
|
+
export interface WorkerExecutionRecords {
|
|
129
|
+
/** `identity` is checked against the worker identity schema before it is written. */
|
|
130
|
+
writeWorkerIdentity(id: string, identity: unknown): void;
|
|
131
|
+
writeWorkerExecution(id: string, proof: WorkerExecution, fresh?: boolean): void;
|
|
132
|
+
/** A deleted child's receipt replaces the private proof only after the deletion checkpoint. */
|
|
133
|
+
workerDeletionEvidence(id: string): boolean;
|
|
134
|
+
identityPath(id: string, write?: boolean): string;
|
|
135
|
+
executionPath(id: string, write?: boolean): string;
|
|
136
|
+
processesPath(id: string, write?: boolean): string;
|
|
137
|
+
scopePath(id: string, write?: boolean): string;
|
|
114
138
|
}
|
|
115
139
|
/** Whether a run may go, and its deletion (`runs/run-retention.ts`, `store.retention`). */
|
|
116
140
|
export interface RunRetention {
|
package/dist/runs/retention.d.ts
CHANGED
|
@@ -25,7 +25,9 @@ export declare function isReclaimable(run: RunRecord, lookup?: (id: string) => R
|
|
|
25
25
|
*/
|
|
26
26
|
export declare function selectReclaimableWorktrees(runs: readonly RunRecord[], keep: number, lookup?: (id: string) => RunRecord | undefined, workersOf?: (parentId: string) => readonly RunRecord[]): string[];
|
|
27
27
|
/** The store members a real store has and a structural test store may lack: each use checks for it. */
|
|
28
|
-
type RealStoreMembers = Partial<RunAccess & RunFamilyReads & RunPins &
|
|
28
|
+
type RealStoreMembers = Partial<RunAccess & RunFamilyReads & RunPins & {
|
|
29
|
+
readonly workerExecutions: Partial<WorkerExecutions>;
|
|
30
|
+
}>;
|
|
29
31
|
/** The slice of the runs store the enforcer needs, and the worker results a reclaim preparation
|
|
30
32
|
* saves. Kept structural so the enforcer stays easy to test and never imports the concrete store. */
|
|
31
33
|
export interface RetentionStore {
|
package/dist/runs/retention.js
CHANGED
|
@@ -124,15 +124,15 @@ export async function rematerializeReclaimedWorktree(repoRoot, store, runId) {
|
|
|
124
124
|
* evidence or preview work. Structural test stores have no execution machinery and skip that part.
|
|
125
125
|
*/
|
|
126
126
|
export function cleanupSafety(repoRoot, store, run) {
|
|
127
|
-
const execution = store.readWorkerExecution?.(run.id);
|
|
127
|
+
const execution = store.workerExecutions?.readWorkerExecution?.(run.id);
|
|
128
128
|
return () => {
|
|
129
129
|
const refusal = deletionRefusal(run.id, 'worktree', store.sourceDataDir?.(run.id) ?? projectPaths(repoRoot).write);
|
|
130
130
|
if (refusal)
|
|
131
131
|
throw Error(refusal);
|
|
132
132
|
if (run.delegation?.role !== 'worker')
|
|
133
133
|
return;
|
|
134
|
-
if (typeof store.workerResourcesSafe === 'function' && (!execution ||
|
|
135
|
-
!store.workerResourcesSafe(run.id, execution.generation, run.delegation.workspace.resourceId)))
|
|
134
|
+
if (typeof store.workerExecutions?.workerResourcesSafe === 'function' && (!execution ||
|
|
135
|
+
!store.workerExecutions.workerResourcesSafe(run.id, execution.generation, run.delegation.workspace.resourceId)))
|
|
136
136
|
throw Error('Worker resources are not safe to reclaim');
|
|
137
137
|
};
|
|
138
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retention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KAAK,EAAE,CAAC,CAAC;QACxD,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;QAC3E,OAAO,IAAI,CAAC;IACd,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QAC3C,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -39,7 +39,7 @@ export interface RetentionState {
|
|
|
39
39
|
delegation: DelegationState;
|
|
40
40
|
}>): void;
|
|
41
41
|
applyArchived(run: RunRecord, archived: boolean): boolean;
|
|
42
|
-
/** The worker deletion checks
|
|
42
|
+
/** The worker deletion checks, in today's order (`store.workerExecutions`, hearsay-tools/squawk#4039). */
|
|
43
43
|
workerDeletionEvidence(id: string): boolean;
|
|
44
44
|
readonly workerResults: WorkerResults;
|
|
45
45
|
readWorkerExecution(id: string): WorkerExecution | undefined;
|
package/dist/runs/store.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { type RunLifecycleSource } from './lifecycle.ts';
|
|
2
2
|
import { type PeerTaskPageOptions } from './run-summary-page.ts';
|
|
3
3
|
export { parseStoredSummary } from './run-summary-page.ts';
|
|
4
|
-
import {
|
|
4
|
+
import type { WorkerExecutionRecords, WorkerExecutions } from './ports.ts';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
import { type ScopeRecord, type SpawnScope } from '../worker-scope/scope.ts';
|
|
7
|
-
import { WorkerScopes } from '../worker-scope/worker-scopes.ts';
|
|
8
6
|
import { queuedMessageSchema } from '../contract/index.js';
|
|
9
7
|
import { type WaitRegistrationReceipt } from '../contract/index.js';
|
|
10
8
|
import type { ArchiveFinishedScope, ArchivedRunsResponse, ArchivePullRequestIdentity, ConversationState, AgentInput, InboxClaim, DelegationState, MergedPullRequest, RunSummary, Wait, WorkerDestroyRetry } from '../contract/index.js';
|
|
11
9
|
import { type AutomationNames } from '../contract/index.js';
|
|
12
10
|
import { RunTranscriptFacts } from './transcript-facts-topic.ts';
|
|
13
|
-
import { type WorkerExecutionIdentity } from '../delegation/execution-identity.ts';
|
|
14
|
-
import { type WorkerProcessRecord } from '../core/process-stat.ts';
|
|
15
11
|
import { workflowDefSchema } from '../workflows/types.ts';
|
|
16
12
|
import { type OutcomeDependencies, type OutcomeReceipt, type RunOutcome } from './outcome-commit.ts';
|
|
17
13
|
import { type ExitCall, type RunExitId, type RunPatch } from './run-exits.ts';
|
|
@@ -3269,8 +3265,6 @@ export declare class RunStore {
|
|
|
3269
3265
|
readonly lifecycle: RunLifecycleSource;
|
|
3270
3266
|
/** The lifecycle events run exits write (B12). */
|
|
3271
3267
|
private readonly exitEvents;
|
|
3272
|
-
/** Every worker's process scope (ADR 0032): spawn sites, Continue and destroy reach it here. */
|
|
3273
|
-
readonly scopes: WorkerScopes;
|
|
3274
3268
|
/** Runs gone from memory whose rows the next save or commit deletes. */
|
|
3275
3269
|
private readonly deleted;
|
|
3276
3270
|
/** Deleted runs whose history files (events, handoff, images, artifacts) go once the delete of
|
|
@@ -3314,6 +3308,10 @@ export declare class RunStore {
|
|
|
3314
3308
|
readonly retention: RunRetentionTopic;
|
|
3315
3309
|
/** The saved snapshot of a worker's collected result (hearsay-tools/squawk#4038). */
|
|
3316
3310
|
readonly workerResults: WorkerResultsTopic;
|
|
3311
|
+
private executions;
|
|
3312
|
+
/** A worker's execution, process, identity and scope records (hearsay-tools/squawk#4039), built on
|
|
3313
|
+
* first use by the factory this process registered; throws when none is registered. */
|
|
3314
|
+
get workerExecutions(): WorkerExecutions & WorkerExecutionRecords;
|
|
3317
3315
|
private readonly liveItems;
|
|
3318
3316
|
/** Capture both sources on the same synchronous sequence boundary before history IO. */
|
|
3319
3317
|
liveReadSnapshot(runId: string): {
|
|
@@ -3749,7 +3747,7 @@ export declare class RunStore {
|
|
|
3749
3747
|
input: AgentInput;
|
|
3750
3748
|
}): void;
|
|
3751
3749
|
/** Create an owned worker run and its parent receipt; `createStoreOwnedRun` holds the checks. */
|
|
3752
|
-
createOwnedRun(input: Parameters<RunStore['createRun']>[0], parentId: string, requestId: string, worker: DelegationState, requestHash: string, spawnCapacityRefusal: SpawnCapacityRefusal, executionIdentity?:
|
|
3750
|
+
createOwnedRun(input: Parameters<RunStore['createRun']>[0], parentId: string, requestId: string, worker: DelegationState, requestHash: string, spawnCapacityRefusal: SpawnCapacityRefusal, executionIdentity?: unknown): RunRecord;
|
|
3753
3751
|
/**
|
|
3754
3752
|
* Durably replace or delete staged rows together with pending dirty rows. Persist before
|
|
3755
3753
|
* changing held objects or notifying subscribers. On failure retain all pending state; flush()
|
|
@@ -3933,49 +3931,6 @@ export declare class RunStore {
|
|
|
3933
3931
|
/** `readEvents` off the event loop (async read and async brotli), for collection paths. */
|
|
3934
3932
|
readEventsAsync(runId: string): Promise<RunEvent[]>;
|
|
3935
3933
|
readEvents(runId: string): RunEvent[];
|
|
3936
|
-
/** Private process-generation evidence; never part of run JSON or SSE. */
|
|
3937
|
-
private identityPath;
|
|
3938
|
-
readWorkerIdentity(id: string): WorkerExecutionIdentity | undefined;
|
|
3939
|
-
private writeWorkerIdentity;
|
|
3940
|
-
private executionPath;
|
|
3941
|
-
readWorkerExecution(id: string): WorkerExecution | undefined;
|
|
3942
|
-
private writeWorkerExecution;
|
|
3943
|
-
/** Complete execution is not permission to reuse/delete persistent resources (#738).
|
|
3944
|
-
* Synchronous, fresh and generation/resource fenced; callers hold admission off across awaits. */
|
|
3945
|
-
workerResourcesSafe(id: string, generation: string, resourceId: string): boolean;
|
|
3946
|
-
/** `workerResourcesSafe` with the refusal's live PIDs (empty when no PID explains it). */
|
|
3947
|
-
workerResourceHolders(id: string, generation: string, resourceId: string, opts?: {
|
|
3948
|
-
admittingQueued?: boolean;
|
|
3949
|
-
}): 'safe' | number[];
|
|
3950
|
-
/** Upgrade a legacy completed checkpoint while terminal task ownership is still known.
|
|
3951
|
-
* No holder scan here: settlement and scheduling must never wait on cleanup proof. */
|
|
3952
|
-
retainWorkerScratchCleanup(id: string): void;
|
|
3953
|
-
/** Cleanup can outlive its index row, but never its generation or terminal task intent. */
|
|
3954
|
-
workerScratchResourcesSafe(id: string, generation: string, resourceId: string): boolean;
|
|
3955
|
-
commitWorkerExecutionStart(id: string): string;
|
|
3956
|
-
/** Private process record (#469): which processes a generation spawned, never part of run JSON or SSE. */
|
|
3957
|
-
private processesPath;
|
|
3958
|
-
/** Tri-state: only ENOENT is `absent` (legacy, scan-only). A present record that is unreadable,
|
|
3959
|
-
* wrongly permissioned, malformed or of another generation is `unknown`: never finalized or reaped. */
|
|
3960
|
-
readWorkerProcesses(id: string, generation: string): WorkerProcessRecord | 'absent' | 'unknown';
|
|
3961
|
-
private writeWorkerProcesses;
|
|
3962
|
-
/** Private scope record: the cgroups and process groups the worker owns (ADR 0032). */
|
|
3963
|
-
private scopePath;
|
|
3964
|
-
/** Tri-state like the process record: only ENOENT is `absent`. */
|
|
3965
|
-
readWorkerScope(id: string): ScopeRecord | 'absent' | 'unknown';
|
|
3966
|
-
/** Durable before the caller acts on it. */
|
|
3967
|
-
writeWorkerScope(id: string, record: ScopeRecord): void;
|
|
3968
|
-
/** The scope a run's processes start in: a worker's own, none for any other run (ADR 0032). */
|
|
3969
|
-
spawnScope(id: string): SpawnScope | undefined;
|
|
3970
|
-
/** Bound to the current generation. Past the cap the record never drops an entry: the
|
|
3971
|
-
* working-directory scan is the remaining evidence. */
|
|
3972
|
-
appendWorkerProcess(id: string, generation: string, pid: number, pgid?: number): boolean;
|
|
3973
|
-
commitWorkerExecutionComplete(id: string, generation: string, opts?: {
|
|
3974
|
-
interrupted?: boolean;
|
|
3975
|
-
}): boolean;
|
|
3976
|
-
/** A deleted child's receipt replaces the private proof only after the deletion checkpoint. */
|
|
3977
|
-
private workerDeletionEvidence;
|
|
3978
|
-
private workerDeletionResult;
|
|
3979
3934
|
/** Write the pending rows out now (used on shutdown). */
|
|
3980
3935
|
flush(): void;
|
|
3981
3936
|
private seqs;
|
package/dist/runs/store.js
CHANGED
|
@@ -5,22 +5,15 @@ import { productEnv } from '../core/product-env.js';
|
|
|
5
5
|
import { registeredWaitRecord, registeredReceiptRecord } from './wait-registration-write.js';
|
|
6
6
|
import { stageCommit, stageLoaded, stageDurableUpdate, stageDebouncedUpdate, stageConversation, stageArchiveFields, stagePullRequests, stageStepUpdate, stepTotals, redactPatch, redactText, clearPin } from './record-write-rules.js';
|
|
7
7
|
import { publishRunWrite, RunLifecycle, snapshotRun } from './lifecycle.js';
|
|
8
|
-
import { workerDeletionProof } from './worker-deletion-proof.js';
|
|
9
|
-
import { recordedHolders, workerResourceAuthorized } from './worker-resource-holders.js';
|
|
10
8
|
import { listPeerTaskSummaries, parseStoredSummary } from './run-summary-page.js';
|
|
11
9
|
export { parseStoredSummary } from './run-summary-page.js';
|
|
12
10
|
import { defined } from '../core/defined.js';
|
|
13
|
-
import {
|
|
14
|
-
import { admissibleExecution, holderRefusal, SPAWN_NEXT, WorkerAdmissionRefusal, workerExecutionSchema } from './worker-execution.js';
|
|
15
|
-
import { agentTmpDirMayExist, agentTmpDirOwnershipProven } from './agent-tmpdir.js';
|
|
11
|
+
import { workerExecutionsFactory } from './worker-executions-registry.js';
|
|
16
12
|
import { randomUUID, createHash } from 'node:crypto';
|
|
17
13
|
import { isDeepStrictEqual } from 'node:util';
|
|
18
|
-
import { appendFileSync,
|
|
19
|
-
import { join
|
|
14
|
+
import { appendFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
20
16
|
import { z } from 'zod';
|
|
21
|
-
import { scopeRecordSchema } from '../worker-scope/scope.js';
|
|
22
|
-
import { WorkerScopes } from '../worker-scope/worker-scopes.js';
|
|
23
|
-
import { readPrivateRecord, writePrivateRecord } from './private-record-file.js';
|
|
24
17
|
import { delegationStateSchema, workerDestroyRetrySchema, } from '../contract/index.js';
|
|
25
18
|
import { agentInputSchema, inboxClaimSchema } from '../contract/index.js';
|
|
26
19
|
import { automationIdOf, stepStateSchema as contractStepStateSchema, toRunSummary, runRecordSchema as contractRunRecordSchema, runPullRequestSchema, mergedPullRequestSchema, } from '../contract/index.js';
|
|
@@ -36,8 +29,6 @@ import { LiveItemSnapshots } from './live-item-snapshots.js';
|
|
|
36
29
|
import { stampOf } from './transcript-facts.js';
|
|
37
30
|
import { RunTranscriptFacts } from './transcript-facts-topic.js';
|
|
38
31
|
import { hasPlainHistory, historyPaths, readHistoryText, readHistoryTextAsync, restoreHistory } from './history-file.js';
|
|
39
|
-
import { workerExecutionIdentitySchema } from '../delegation/execution-identity.js';
|
|
40
|
-
import { startToken } from '../core/process-stat.js';
|
|
41
32
|
import { collectSecretValues, redactDeep } from '../core/secret-redaction.js';
|
|
42
33
|
// Pure, dependency-free reference helpers — the same sanity bound the marker parser applies.
|
|
43
34
|
import { archivePullRequests, pullRequestKey } from './pull-requests.js';
|
|
@@ -401,11 +392,6 @@ function deepFreeze(value) {
|
|
|
401
392
|
}
|
|
402
393
|
return value;
|
|
403
394
|
}
|
|
404
|
-
const WORKER_PROCESS_CAP = 32;
|
|
405
|
-
const recordedProcessSchema = z.object({ pid: z.number().int().positive(), startToken: z.string().min(1).max(128).optional(),
|
|
406
|
-
pgid: z.number().int().positive().optional() }).strict();
|
|
407
|
-
const workerProcessRecordSchema = z.object({ generation: z.string().uuid(), controller: recordedProcessSchema,
|
|
408
|
-
processes: z.array(recordedProcessSchema).max(WORKER_PROCESS_CAP) }).strict();
|
|
409
395
|
/**
|
|
410
396
|
* Run rows in runs.db plus append-only NDJSON events and an in-process event bus. Hold live,
|
|
411
397
|
* pinned, related and unsettled records only. Optimistic writes debounce; durable commits
|
|
@@ -435,8 +421,6 @@ export class RunStore {
|
|
|
435
421
|
lifecycle = this.published;
|
|
436
422
|
/** The lifecycle events run exits write (B12). */
|
|
437
423
|
exitEvents = new ExitEvents((id, event) => this.appendEvent(id, event));
|
|
438
|
-
/** Every worker's process scope (ADR 0032): spawn sites, Continue and destroy reach it here. */
|
|
439
|
-
scopes = new WorkerScopes(this);
|
|
440
424
|
/** Runs gone from memory whose rows the next save or commit deletes. */
|
|
441
425
|
deleted = new Set();
|
|
442
426
|
/** Deleted runs whose history files (events, handoff, images, artifacts) go once the delete of
|
|
@@ -480,6 +464,16 @@ export class RunStore {
|
|
|
480
464
|
retention;
|
|
481
465
|
/** The saved snapshot of a worker's collected result (hearsay-tools/squawk#4038). */
|
|
482
466
|
workerResults;
|
|
467
|
+
executions;
|
|
468
|
+
/** A worker's execution, process, identity and scope records (hearsay-tools/squawk#4039), built on
|
|
469
|
+
* first use by the factory this process registered; throws when none is registered. */
|
|
470
|
+
get workerExecutions() {
|
|
471
|
+
return this.executions ??= workerExecutionsFactory()(this.dataDir, {
|
|
472
|
+
peek: (id) => this.peek(id), getRun: (id) => this.getRun(id), writeDir: (id) => this.writeDir(id),
|
|
473
|
+
sourceDataDir: (id) => this.sourceDataDir(id), commitIndex: (input) => this.commitIndex(input),
|
|
474
|
+
published: this.published, workerResults: this.workerResults,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
483
477
|
liveItems = new LiveItemSnapshots();
|
|
484
478
|
/** Capture both sources on the same synchronous sequence boundary before history IO. */
|
|
485
479
|
liveReadSnapshot(runId) {
|
|
@@ -511,11 +505,11 @@ export class RunStore {
|
|
|
511
505
|
claimFamilies: (families) => this.claimFamilies(families), markDeleted: (id, family) => this.markDeleted(id, family),
|
|
512
506
|
scheduleSave: () => this.scheduleSave(), commitIndex: (input) => this.commitIndex(input),
|
|
513
507
|
commitDelegation: (patches) => this.commitDelegation(patches), applyArchived: (run, archived) => this.applyArchived(run, archived),
|
|
514
|
-
workerDeletionEvidence: (id) => this.workerDeletionEvidence(id),
|
|
508
|
+
workerDeletionEvidence: (id) => this.workerExecutions.workerDeletionEvidence(id),
|
|
515
509
|
workerResults: this.workerResults,
|
|
516
|
-
readWorkerExecution: (id) => this.readWorkerExecution(id), identityPath: (id) => this.identityPath(id),
|
|
517
|
-
processesPath: (id) => this.processesPath(id), scopePath: (id) => this.scopePath(id),
|
|
518
|
-
executionPath: (id) => this.executionPath(id), handoffPath: (runId) => this.handoffPath(runId),
|
|
510
|
+
readWorkerExecution: (id) => this.workerExecutions.readWorkerExecution(id), identityPath: (id) => this.workerExecutions.identityPath(id),
|
|
511
|
+
processesPath: (id) => this.workerExecutions.processesPath(id), scopePath: (id) => this.workerExecutions.scopePath(id),
|
|
512
|
+
executionPath: (id) => this.workerExecutions.executionPath(id), handoffPath: (runId) => this.handoffPath(runId),
|
|
519
513
|
imagesDir: (runId) => this.imagesDir(runId),
|
|
520
514
|
});
|
|
521
515
|
this.compressor = new HistoryCompressor(dataDir, (id) => this.isHistoryCompressEligible(id), (id, plain, archive) => this.transcriptFacts.index.adoptArchive(id, plain, stampOf(archive)));
|
|
@@ -1820,8 +1814,8 @@ export class RunStore {
|
|
|
1820
1814
|
hasRun: (id) => this.hasRun(id),
|
|
1821
1815
|
held: this.held, deleted: this.deleted, db: this.db,
|
|
1822
1816
|
buildRun: (ownedInput, id) => this.buildRun(ownedInput, id),
|
|
1823
|
-
writeWorkerIdentity: (id, identity) => this.writeWorkerIdentity(id, identity),
|
|
1824
|
-
writeWorkerExecution: (id, proof, fresh) => this.writeWorkerExecution(id, proof, fresh),
|
|
1817
|
+
writeWorkerIdentity: (id, identity) => this.workerExecutions.writeWorkerIdentity(id, identity),
|
|
1818
|
+
writeWorkerExecution: (id, proof, fresh) => this.workerExecutions.writeWorkerExecution(id, proof, fresh),
|
|
1825
1819
|
commitIndex: (owned) => this.commitIndex(owned),
|
|
1826
1820
|
}, input, parentId, requestId, worker, requestHash, spawnCapacityRefusal, executionIdentity);
|
|
1827
1821
|
}
|
|
@@ -1882,7 +1876,7 @@ export class RunStore {
|
|
|
1882
1876
|
if (!facts || !['done', 'review', 'failed', 'cancelled'].includes(run.status) || run.waits?.some(wait => wait.phase === 'open') ||
|
|
1883
1877
|
run.hasPendingPermission || facts.pendingAsk !== undefined)
|
|
1884
1878
|
return 'Task or worker work still needs attention. Open the task or archive manually.';
|
|
1885
|
-
if (run.delegation?.role === 'invalid' || (run.delegation?.role === 'worker' && this.readWorkerExecution(run.id)?.phase !== 'complete'))
|
|
1879
|
+
if (run.delegation?.role === 'invalid' || (run.delegation?.role === 'worker' && this.workerExecutions.readWorkerExecution(run.id)?.phase !== 'complete'))
|
|
1886
1880
|
return 'Worker execution has not settled. Open the worker or archive manually.';
|
|
1887
1881
|
}
|
|
1888
1882
|
return undefined;
|
|
@@ -2086,7 +2080,7 @@ export class RunStore {
|
|
|
2086
2080
|
decodeCold: (row) => this.decodeCold(row),
|
|
2087
2081
|
writeRefusal: (memberId) => this.writeRefusal(memberId),
|
|
2088
2082
|
factsPeek: (memberId) => this.transcriptFacts.factsFor(memberId).peek(memberId),
|
|
2089
|
-
readWorkerExecution: (memberId) => this.readWorkerExecution(memberId),
|
|
2083
|
+
readWorkerExecution: (memberId) => this.workerExecutions.readWorkerExecution(memberId),
|
|
2090
2084
|
}, id, isActive);
|
|
2091
2085
|
}
|
|
2092
2086
|
/** Blockers are feedback, never archive authority or cleanup permission. */
|
|
@@ -2551,228 +2545,6 @@ export class RunStore {
|
|
|
2551
2545
|
return [];
|
|
2552
2546
|
}
|
|
2553
2547
|
}
|
|
2554
|
-
/** Private process-generation evidence; never part of run JSON or SSE. */
|
|
2555
|
-
identityPath(id, write = false) {
|
|
2556
|
-
return this.executionPath(id, write).replace(/\.execution\.json$/, '.identity.json');
|
|
2557
|
-
}
|
|
2558
|
-
readWorkerIdentity(id) {
|
|
2559
|
-
try {
|
|
2560
|
-
const fd = openSync(this.identityPath(id), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
2561
|
-
try {
|
|
2562
|
-
const info = fstatSync(fd);
|
|
2563
|
-
if (!info.isFile() || info.size > 16384 || (info.mode & 0o077))
|
|
2564
|
-
return undefined;
|
|
2565
|
-
const buffer = Buffer.alloc(16385);
|
|
2566
|
-
const count = readSync(fd, buffer, 0, buffer.length, 0);
|
|
2567
|
-
return workerExecutionIdentitySchema.parse(JSON.parse(buffer.subarray(0, count).toString('utf8')));
|
|
2568
|
-
}
|
|
2569
|
-
finally {
|
|
2570
|
-
closeSync(fd);
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2573
|
-
catch {
|
|
2574
|
-
return undefined;
|
|
2575
|
-
}
|
|
2576
|
-
}
|
|
2577
|
-
writeWorkerIdentity(id, identity) {
|
|
2578
|
-
// Immutable acceptance evidence. An orphan from failed index publication cannot be adopted.
|
|
2579
|
-
const fd = openSync(this.identityPath(id, true), constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
|
|
2580
|
-
try {
|
|
2581
|
-
writeFileSync(fd, JSON.stringify(identity));
|
|
2582
|
-
fsyncSync(fd);
|
|
2583
|
-
}
|
|
2584
|
-
finally {
|
|
2585
|
-
closeSync(fd);
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
executionPath(id, write = false) {
|
|
2589
|
-
z.string().uuid().parse(id);
|
|
2590
|
-
const dir = join(write ? this.writeDir(id) : this.sourceDataDir(id), 'runs');
|
|
2591
|
-
if (write)
|
|
2592
|
-
mkdirSync(dir, { recursive: true });
|
|
2593
|
-
if (lstatSync(dir).isSymbolicLink() || realpathSync(dir) !== resolve(dir))
|
|
2594
|
-
throw new Error('Unsafe execution directory');
|
|
2595
|
-
return join(dir, `${id}.execution.json`);
|
|
2596
|
-
}
|
|
2597
|
-
readWorkerExecution(id) {
|
|
2598
|
-
try {
|
|
2599
|
-
const proof = readPrivateRecord(this.executionPath(id), 16384, value => workerExecutionSchema.parse(value));
|
|
2600
|
-
return typeof proof === 'string' ? undefined : proof;
|
|
2601
|
-
}
|
|
2602
|
-
catch {
|
|
2603
|
-
return undefined;
|
|
2604
|
-
}
|
|
2605
|
-
}
|
|
2606
|
-
writeWorkerExecution(id, proof, fresh = false) {
|
|
2607
|
-
writePrivateRecord(this.executionPath(id, true), proof, { fresh });
|
|
2608
|
-
}
|
|
2609
|
-
/** Complete execution is not permission to reuse/delete persistent resources (#738).
|
|
2610
|
-
* Synchronous, fresh and generation/resource fenced; callers hold admission off across awaits. */
|
|
2611
|
-
workerResourcesSafe(id, generation, resourceId) {
|
|
2612
|
-
// Reclaim and history deletion also need an empty scope; admission does not (ADR 0032).
|
|
2613
|
-
return this.workerResourceHolders(id, generation, resourceId) === 'safe' && this.scopes.empty(id);
|
|
2614
|
-
}
|
|
2615
|
-
/** `workerResourcesSafe` with the refusal's live PIDs (empty when no PID explains it). */
|
|
2616
|
-
workerResourceHolders(id, generation, resourceId, opts = {}) {
|
|
2617
|
-
if (deletionRefusal(id, 'worktree', this.dataDir))
|
|
2618
|
-
return [];
|
|
2619
|
-
const run = this.peek(id);
|
|
2620
|
-
const proof = this.readWorkerExecution(id);
|
|
2621
|
-
if (!workerResourceAuthorized(run, proof, id, generation, resourceId, opts.admittingQueued))
|
|
2622
|
-
return [];
|
|
2623
|
-
const record = this.readWorkerProcesses(id, generation);
|
|
2624
|
-
if (record === 'unknown' || !agentTmpDirOwnershipProven(this.dataDir, id))
|
|
2625
|
-
return [];
|
|
2626
|
-
// Only the generation's recorded processes count; an outside process blocks nothing (ADR 0032).
|
|
2627
|
-
return recordedHolders(record);
|
|
2628
|
-
}
|
|
2629
|
-
/** Upgrade a legacy completed checkpoint while terminal task ownership is still known.
|
|
2630
|
-
* No holder scan here: settlement and scheduling must never wait on cleanup proof. */
|
|
2631
|
-
retainWorkerScratchCleanup(id) {
|
|
2632
|
-
const run = this.peek(id), proof = this.readWorkerExecution(id);
|
|
2633
|
-
if (run?.delegation?.role !== 'worker' || ['queued', 'running', 'waiting'].includes(run.status) || proof?.phase !== 'complete')
|
|
2634
|
-
return;
|
|
2635
|
-
const { resourceId, path } = run.delegation.workspace;
|
|
2636
|
-
if (proof.scratchCleanup?.resourceId === resourceId && proof.scratchCleanup.path === path)
|
|
2637
|
-
return;
|
|
2638
|
-
this.writeWorkerExecution(id, { ...proof, scratchCleanup: { resourceId, path } });
|
|
2639
|
-
}
|
|
2640
|
-
/** Cleanup can outlive its index row, but never its generation or terminal task intent. */
|
|
2641
|
-
workerScratchResourcesSafe(id, generation, resourceId) {
|
|
2642
|
-
if (deletionRefusal(id, 'worktree', this.dataDir))
|
|
2643
|
-
return false;
|
|
2644
|
-
const run = this.peek(id), proof = this.readWorkerExecution(id);
|
|
2645
|
-
if (proof?.phase !== 'complete' || proof.generation !== generation || proof.scratchCleanup?.resourceId !== resourceId ||
|
|
2646
|
-
(run && ['queued', 'running', 'waiting'].includes(run.status)))
|
|
2647
|
-
return false;
|
|
2648
|
-
// A process still in the worker's scope may use its scratch; one outside it is not the worker's.
|
|
2649
|
-
if (run?.delegation?.role === 'worker')
|
|
2650
|
-
return run.delegation.workspace.path === proof.scratchCleanup.path &&
|
|
2651
|
-
this.workerResourceHolders(id, generation, resourceId) === 'safe' && this.scopes.empty(id);
|
|
2652
|
-
// A valid different role contradicts the retained intent. Quarantined/missing metadata
|
|
2653
|
-
// supplies no new authority; only the private terminal checkpoint authorizes scratch.
|
|
2654
|
-
if (run && run.delegation?.role !== 'invalid')
|
|
2655
|
-
return false;
|
|
2656
|
-
const record = this.readWorkerProcesses(id, generation);
|
|
2657
|
-
if (record === 'unknown' || !agentTmpDirOwnershipProven(this.dataDir, id))
|
|
2658
|
-
return false;
|
|
2659
|
-
return recordedHolders(record) === 'safe' && this.scopes.empty(id);
|
|
2660
|
-
}
|
|
2661
|
-
commitWorkerExecutionStart(id) {
|
|
2662
|
-
const run = this.peek(id);
|
|
2663
|
-
if (run?.delegation?.role !== 'worker' || run.delegation.destroy)
|
|
2664
|
-
throw new WorkerAdmissionRefusal('the worker is being destroyed', SPAWN_NEXT);
|
|
2665
|
-
const prior = admissibleExecution(this.readWorkerExecution(id));
|
|
2666
|
-
const holders = this.workerResourceHolders(id, prior.generation, run.delegation.workspace.resourceId, { admittingQueued: true });
|
|
2667
|
-
if (holders !== 'safe')
|
|
2668
|
-
throw holderRefusal(holders, this.readWorkerProcesses(id, prior.generation));
|
|
2669
|
-
const generation = randomUUID();
|
|
2670
|
-
// #469: the controller is durable before `starting`, so a crash leaves a provable generation.
|
|
2671
|
-
this.writeWorkerProcesses(id, { generation, controller: { pid: process.pid, ...startToken(process.pid) }, processes: [] });
|
|
2672
|
-
this.writeWorkerExecution(id, { generation, phase: 'starting' });
|
|
2673
|
-
return generation;
|
|
2674
|
-
}
|
|
2675
|
-
/** Private process record (#469): which processes a generation spawned, never part of run JSON or SSE. */
|
|
2676
|
-
processesPath(id, write = false) {
|
|
2677
|
-
return this.executionPath(id, write).replace(/\.execution\.json$/, '.processes.json');
|
|
2678
|
-
}
|
|
2679
|
-
/** Tri-state: only ENOENT is `absent` (legacy, scan-only). A present record that is unreadable,
|
|
2680
|
-
* wrongly permissioned, malformed or of another generation is `unknown`: never finalized or reaped. */
|
|
2681
|
-
readWorkerProcesses(id, generation) {
|
|
2682
|
-
const record = readPrivateRecord(() => this.processesPath(id), 8192, value => workerProcessRecordSchema.parse(value));
|
|
2683
|
-
return typeof record === 'string' || record.generation === generation ? record : 'unknown';
|
|
2684
|
-
}
|
|
2685
|
-
writeWorkerProcesses(id, record) {
|
|
2686
|
-
writePrivateRecord(this.processesPath(id, true), workerProcessRecordSchema.parse(record));
|
|
2687
|
-
}
|
|
2688
|
-
/** Private scope record: the cgroups and process groups the worker owns (ADR 0032). */
|
|
2689
|
-
scopePath(id, write = false) {
|
|
2690
|
-
return this.executionPath(id, write).replace(/\.execution\.json$/, '.scope.json');
|
|
2691
|
-
}
|
|
2692
|
-
/** Tri-state like the process record: only ENOENT is `absent`. */
|
|
2693
|
-
readWorkerScope(id) {
|
|
2694
|
-
const record = readPrivateRecord(() => this.scopePath(id), 65_536, value => scopeRecordSchema.parse(value));
|
|
2695
|
-
return typeof record === 'string' || record.workerId === id ? record : 'unknown';
|
|
2696
|
-
}
|
|
2697
|
-
/** Durable before the caller acts on it. */
|
|
2698
|
-
writeWorkerScope(id, record) {
|
|
2699
|
-
writePrivateRecord(this.scopePath(id, true), scopeRecordSchema.parse(record));
|
|
2700
|
-
}
|
|
2701
|
-
/** The scope a run's processes start in: a worker's own, none for any other run (ADR 0032). */
|
|
2702
|
-
spawnScope(id) {
|
|
2703
|
-
return this.peek(id)?.delegation?.role === 'worker' ? this.scopes.spawnScope(id) : undefined;
|
|
2704
|
-
}
|
|
2705
|
-
/** Bound to the current generation. Past the cap the record never drops an entry: the
|
|
2706
|
-
* working-directory scan is the remaining evidence. */
|
|
2707
|
-
appendWorkerProcess(id, generation, pid, pgid) {
|
|
2708
|
-
const record = this.readWorkerProcesses(id, generation);
|
|
2709
|
-
if (typeof record === 'string' || this.readWorkerExecution(id)?.generation !== generation)
|
|
2710
|
-
return false;
|
|
2711
|
-
const entry = { pid, ...startToken(pid), ...(pgid === undefined ? {} : { pgid }) };
|
|
2712
|
-
if (record.processes.some(known => known.pid === entry.pid && known.startToken === entry.startToken))
|
|
2713
|
-
return true;
|
|
2714
|
-
if (record.processes.length >= WORKER_PROCESS_CAP)
|
|
2715
|
-
return false;
|
|
2716
|
-
this.writeWorkerProcesses(id, { ...record, processes: [...record.processes, entry] });
|
|
2717
|
-
return true;
|
|
2718
|
-
}
|
|
2719
|
-
commitWorkerExecutionComplete(id, generation, opts = {}) {
|
|
2720
|
-
const proof = this.readWorkerExecution(id);
|
|
2721
|
-
if (!proof || proof.generation !== generation)
|
|
2722
|
-
return false;
|
|
2723
|
-
if (proof.phase === 'queued' && this.peek(id)?.status !== 'cancelled')
|
|
2724
|
-
return false;
|
|
2725
|
-
try {
|
|
2726
|
-
const run = this.peek(id);
|
|
2727
|
-
if (run?.delegation?.role !== 'worker')
|
|
2728
|
-
return false;
|
|
2729
|
-
this.commitIndex(new Map([[id, run]]));
|
|
2730
|
-
if (this.readWorkerExecution(id)?.generation !== generation)
|
|
2731
|
-
return false;
|
|
2732
|
-
this.writeWorkerExecution(id, { generation, phase: 'complete',
|
|
2733
|
-
// Nothing abandons an execution any more (hearsay-tools/cezarion#889); keep a checkpoint that already was.
|
|
2734
|
-
...(proof.abandoned ? { abandoned: true } : {}),
|
|
2735
|
-
...(proof.interrupted || (opts.interrupted && proof.phase === 'starting') ? { interrupted: true } : {}),
|
|
2736
|
-
...(proof.phase === 'queued' || proof.neverMaterialized ? { neverMaterialized: true } : {}),
|
|
2737
|
-
...(!['queued', 'running', 'waiting'].includes(run.status) ? { scratchCleanup: {
|
|
2738
|
-
resourceId: run.delegation.workspace.resourceId, path: run.delegation.workspace.path
|
|
2739
|
-
} } : {}) });
|
|
2740
|
-
// The earlier index event cannot attest exit: subscribers must observe the
|
|
2741
|
-
// durable private proof before a terminal worker can satisfy a lifecycle wait.
|
|
2742
|
-
const settled = this.peek(id);
|
|
2743
|
-
this.published.publish('run.updated', { run: settled, before: snapshotRun(settled) });
|
|
2744
|
-
return true;
|
|
2745
|
-
}
|
|
2746
|
-
catch {
|
|
2747
|
-
return false;
|
|
2748
|
-
}
|
|
2749
|
-
}
|
|
2750
|
-
/** A deleted child's receipt replaces the private proof only after the deletion checkpoint. */
|
|
2751
|
-
workerDeletionEvidence(id) {
|
|
2752
|
-
const child = this.peek(id);
|
|
2753
|
-
if (child?.delegation?.role !== 'worker' || child.delegation.workspace.ownerRunId !== id ||
|
|
2754
|
-
child.delegation.destroy?.phase !== 'complete' || child.delegation.destroy.remaining.length ||
|
|
2755
|
-
!['review', 'done', 'failed', 'cancelled'].includes(child.status))
|
|
2756
|
-
return false;
|
|
2757
|
-
return this.workerDeletionResult(id, child);
|
|
2758
|
-
}
|
|
2759
|
-
workerDeletionResult(id, child) {
|
|
2760
|
-
const parent = this.peek(child.delegation.parentRunId);
|
|
2761
|
-
if (parent?.delegation?.role !== 'root' || parent.delegation.historyDeletion)
|
|
2762
|
-
return false;
|
|
2763
|
-
const receipt = parent.delegation.receipts.find(entry => entry.workerId === id);
|
|
2764
|
-
const result = this.workerResults.readWorkerResult(parent.id, id);
|
|
2765
|
-
if (!receipt || !result?.settled || result.cleanup !== 'complete' || result.status !== child.status ||
|
|
2766
|
-
result.revision !== (child.delegation.executionRevision ?? 0))
|
|
2767
|
-
return false;
|
|
2768
|
-
const { state: _state, ...workspace } = result.workspace;
|
|
2769
|
-
if (JSON.stringify(workspace) !== JSON.stringify(child.delegation.workspace))
|
|
2770
|
-
return false;
|
|
2771
|
-
return workerDeletionProof(receipt.deletion, result.revision, workspace.resourceId, {
|
|
2772
|
-
readProof: () => this.readWorkerExecution(id), resourcesSafe: generation => this.workerResourcesSafe(id, generation, workspace.resourceId),
|
|
2773
|
-
scratchMayExist: () => agentTmpDirMayExist(this.dataDir, id), executionExists: () => existsSync(this.executionPath(id)),
|
|
2774
|
-
});
|
|
2775
|
-
}
|
|
2776
2548
|
/** Write the pending rows out now (used on shutdown). */
|
|
2777
2549
|
flush() {
|
|
2778
2550
|
if (this.saveTimer) {
|