@hearsay-tools/squawk 0.18.0-dev.7777 → 0.18.0-dev.7788
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/artifacts/removal-slot.d.ts +3 -0
- package/dist/artifacts/removal-slot.js +7 -0
- package/dist/artifacts/removal-slot.js.map +1 -0
- package/dist/autosave-removal-slots.d.ts +6 -0
- package/dist/autosave-removal-slots.js +13 -0
- package/dist/autosave-removal-slots.js.map +1 -0
- package/dist/built-in-run-slots.d.ts +9 -0
- package/dist/built-in-run-slots.js +21 -0
- package/dist/built-in-run-slots.js.map +1 -0
- package/dist/delegation/family-end.js +5 -1
- package/dist/delegation/family-end.js.map +1 -1
- package/dist/delegation/removal-slot.d.ts +4 -0
- package/dist/delegation/removal-slot.js +20 -0
- package/dist/delegation/removal-slot.js.map +1 -0
- package/dist/delegation/routes.d.ts +79 -79
- package/dist/delegation/transport.d.ts +11 -11
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs/removal-slot.d.ts +4 -0
- package/dist/jobs/removal-slot.js +10 -0
- package/dist/jobs/removal-slot.js.map +1 -0
- package/dist/runs/lifecycle.d.ts +1 -1
- package/dist/runs/ports.d.ts +0 -11
- package/dist/runs/removal-slots.d.ts +56 -0
- package/dist/runs/removal-slots.js +66 -0
- package/dist/runs/removal-slots.js.map +1 -0
- package/dist/runs/retention.d.ts +10 -7
- package/dist/runs/retention.js +8 -19
- package/dist/runs/retention.js.map +1 -1
- package/dist/runs/store.d.ts +6 -5
- package/dist/runs/store.js +23 -42
- package/dist/runs/store.js.map +1 -1
- package/dist/server/live-routes.d.ts +6 -6
- package/dist/server/models-routes.d.ts +13 -13
- package/dist/server/project-context.js +3 -3
- package/dist/server/project-context.js.map +1 -1
- package/dist/server/reports-api.d.ts +2 -2
- package/dist/server/workspace-live-routes.d.ts +6 -6
- package/package.json +4 -4
- package/scripts/benchmark-family-reconcile.ts +2 -0
- package/scripts/benchmark-run-store.ts +2 -0
- package/scripts/benchmark-stuck-destroys.ts +2 -0
- package/scripts/benchmark-worker-lifecycle.ts +2 -0
- package/scripts/benchmark-workspace-events.ts +2 -0
- package/scripts/benchmark-worktree-retention.ts +2 -0
- package/scripts/measure-transcript-facts-health.mjs +4 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const gates = [];
|
|
2
|
+
const preparations = [];
|
|
3
|
+
const cleanups = [];
|
|
4
|
+
let sealed = false;
|
|
5
|
+
function add(list, slots) {
|
|
6
|
+
for (const slot of slots ?? []) {
|
|
7
|
+
if (list.includes(slot))
|
|
8
|
+
continue;
|
|
9
|
+
if (sealed)
|
|
10
|
+
throw new Error('The removal slots are sealed: register every slot before sealRunSlots().');
|
|
11
|
+
list.push(slot);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Add slots, in call order. Registering the same slot object again does nothing. */
|
|
15
|
+
export function registerRunSlots(slots) {
|
|
16
|
+
add(gates, slots.gates);
|
|
17
|
+
add(preparations, slots.preparations);
|
|
18
|
+
add(cleanups, slots.cleanups);
|
|
19
|
+
}
|
|
20
|
+
/** Close the registry: removals may run, and no new slot may register. */
|
|
21
|
+
export function sealRunSlots() {
|
|
22
|
+
sealed = true;
|
|
23
|
+
}
|
|
24
|
+
/** Whether this process sealed its removal slots. Never throws. */
|
|
25
|
+
export function runSlotsSealed() {
|
|
26
|
+
return sealed;
|
|
27
|
+
}
|
|
28
|
+
/** Throws unless the registry is sealed. A removal path calls it before its first side effect. */
|
|
29
|
+
export function assertRunSlotsSealed() {
|
|
30
|
+
if (!sealed) {
|
|
31
|
+
throw new Error('No removal slot is registered: call registerBuiltInRunSlots() from built-in-run-slots.ts at the process entry, '
|
|
32
|
+
+ 'or seal the slots this test uses with sealTestRunSlots() from runs/removal-slots.testkit.ts.');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** The first gate's reason to refuse this deletion, in registration order. */
|
|
36
|
+
export function deletionRefusal(runId, kind, dataDir) {
|
|
37
|
+
assertRunSlotsSealed();
|
|
38
|
+
for (const gate of gates) {
|
|
39
|
+
const reason = gate.refuse(runId, kind, dataDir);
|
|
40
|
+
if (reason)
|
|
41
|
+
return reason;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
/** Run every preparation in registration order; the first rejection stops the rest. */
|
|
46
|
+
export async function prepareReclaim(run, context) {
|
|
47
|
+
assertRunSlotsSealed();
|
|
48
|
+
for (const preparation of preparations)
|
|
49
|
+
await preparation.prepare(run, context);
|
|
50
|
+
}
|
|
51
|
+
/** Run every cleanup in registration order, then throw the first failure. */
|
|
52
|
+
export function runRemovalCleanups(runId, dataDir) {
|
|
53
|
+
assertRunSlotsSealed();
|
|
54
|
+
const failures = [];
|
|
55
|
+
for (const cleanup of cleanups) {
|
|
56
|
+
try {
|
|
57
|
+
cleanup.removed(runId, dataDir);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
failures.push(error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (failures.length)
|
|
64
|
+
throw failures[0];
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=removal-slots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removal-slots.js","sourceRoot":"","sources":["../../src/runs/removal-slots.ts"],"names":[],"mappings":"AAkDA,MAAM,KAAK,GAAmB,EAAE,CAAC;AACjC,MAAM,YAAY,GAAyB,EAAE,CAAC;AAC9C,MAAM,QAAQ,GAAqB,EAAE,CAAC;AACtC,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,SAAS,GAAG,CAAI,IAAS,EAAE,KAA+B;IACxD,KAAK,MAAM,IAAI,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QAC/B,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,SAAS;QAClC,IAAI,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,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B,CAAC,KAAa,EAAE,OAAe;IAC/D,oBAAoB,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC;YAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAAC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAAC,CAAC;IAClF,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM;QAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/runs/retention.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { PreviewHostLike } from '../preview/registration.ts';
|
|
2
1
|
import type { RunPins, RunAccess, RunFamilyReads, WorkerExecutions, WorkerResults } from './ports.ts';
|
|
3
2
|
import type { RunRecord } from './store.ts';
|
|
4
3
|
/** Whether an owned worker's family has ended: its parent was archived, by the user or by history
|
|
@@ -27,9 +26,9 @@ export declare function isReclaimable(run: RunRecord, lookup?: (id: string) => R
|
|
|
27
26
|
export declare function selectReclaimableWorktrees(runs: readonly RunRecord[], keep: number, lookup?: (id: string) => RunRecord | undefined, workersOf?: (parentId: string) => readonly RunRecord[]): string[];
|
|
28
27
|
/** The store members a real store has and a structural test store may lack: each use checks for it. */
|
|
29
28
|
type RealStoreMembers = Partial<RunAccess & RunFamilyReads & RunPins & WorkerExecutions & WorkerResults>;
|
|
30
|
-
/** The slice of the runs store the enforcer needs
|
|
31
|
-
* enforcer stays easy to test and never imports the concrete store. */
|
|
32
|
-
export interface RetentionStore {
|
|
29
|
+
/** The slice of the runs store the enforcer needs, and the worker results a reclaim preparation
|
|
30
|
+
* saves. Kept structural so the enforcer stays easy to test and never imports the concrete store. */
|
|
31
|
+
export interface RetentionStore extends WorkerResults {
|
|
33
32
|
/** The candidates: runs with a materialized worktree (an indexed query, #779). */
|
|
34
33
|
listRunsWithWorktree(): RunRecord[];
|
|
35
34
|
getRun(id: string): RunRecord | undefined;
|
|
@@ -81,13 +80,17 @@ export interface ReclaimOptions {
|
|
|
81
80
|
* the forced removal is about to delete. The run manager's `claimWorktreeReclaim` is the one
|
|
82
81
|
* that also blocks admission; startup sweeps run before any run can start and omit it. */
|
|
83
82
|
claim?: (run: RunRecord) => (() => void) | null;
|
|
84
|
-
/** The workspace preview host (#781): the default reclaimer releases the run's preview
|
|
85
|
-
|
|
83
|
+
/** The workspace preview host (#781): the default reclaimer releases the run's preview once the
|
|
84
|
+
* removal goes ahead. */
|
|
85
|
+
previewHost?: {
|
|
86
|
+
release(runId: string): Promise<void>;
|
|
87
|
+
} | undefined;
|
|
86
88
|
}
|
|
87
89
|
/**
|
|
88
90
|
* The proof a destructive step on `run`'s resources re-checks right before each step, as a
|
|
89
91
|
* function that throws when it fails. Startup has no manager claim, and a terminal execution can
|
|
90
|
-
* still have a retained autosave writer, so the
|
|
92
|
+
* still have a retained autosave writer, so the deletion gates (`runs/removal-slots.ts`) are asked
|
|
93
|
+
* each time. An
|
|
91
94
|
* owned worker's generation and fresh resource holders must also be safe, including after async
|
|
92
95
|
* evidence or preview work. Structural test stores have no execution machinery and skip that part.
|
|
93
96
|
*/
|
package/dist/runs/retention.js
CHANGED
|
@@ -6,9 +6,8 @@ import { isFallbackProjectPath, projectPaths } from '../project-paths.js';
|
|
|
6
6
|
// recoverable) and the thin I/O enforcer that performs the reclaim. The selector
|
|
7
7
|
// is pure and unit-testable; the enforcer never throws (helper discipline).
|
|
8
8
|
import { existsSync } from 'node:fs';
|
|
9
|
-
import {
|
|
9
|
+
import { assertRunSlotsSealed, deletionRefusal, prepareReclaim } from './removal-slots.js';
|
|
10
10
|
import { hostsLiveSharedWorker } from './shared-hosts.js';
|
|
11
|
-
import { collectWorkerEvidence } from '../delegation/results.js';
|
|
12
11
|
import { createWorktree } from '../git-worktree.js';
|
|
13
12
|
import { releaseThenRemoveWorktree } from '../git-worktree-release.js';
|
|
14
13
|
import { isEndedRoot, isLiveRecord } from './run-row.js';
|
|
@@ -116,31 +115,20 @@ export async function rematerializeReclaimedWorktree(repoRoot, store, runId) {
|
|
|
116
115
|
return false;
|
|
117
116
|
}
|
|
118
117
|
}
|
|
119
|
-
/** Snapshot parent-owned worker evidence before the checkout goes.
|
|
120
|
-
* Test fakes without `commitWorkerResult` skip this. A collect/commit failure
|
|
121
|
-
* returns false so the directory is left for the next pass. */
|
|
122
|
-
async function preserveWorkerResult(repoRoot, store, run) {
|
|
123
|
-
if (run.delegation?.role !== 'worker')
|
|
124
|
-
return true;
|
|
125
|
-
const commit = store.commitWorkerResult;
|
|
126
|
-
if (typeof commit !== 'function')
|
|
127
|
-
return true;
|
|
128
|
-
const evidence = await collectWorkerEvidence(repoRoot, store, run);
|
|
129
|
-
commit.call(store, run.delegation.parentRunId, evidence.result, evidence.diffSnapshot);
|
|
130
|
-
return evidence.diffSnapshot !== undefined || evidence.result.diff.state === 'available';
|
|
131
|
-
}
|
|
132
118
|
/**
|
|
133
119
|
* The proof a destructive step on `run`'s resources re-checks right before each step, as a
|
|
134
120
|
* function that throws when it fails. Startup has no manager claim, and a terminal execution can
|
|
135
|
-
* still have a retained autosave writer, so the
|
|
121
|
+
* still have a retained autosave writer, so the deletion gates (`runs/removal-slots.ts`) are asked
|
|
122
|
+
* each time. An
|
|
136
123
|
* owned worker's generation and fresh resource holders must also be safe, including after async
|
|
137
124
|
* evidence or preview work. Structural test stores have no execution machinery and skip that part.
|
|
138
125
|
*/
|
|
139
126
|
export function cleanupSafety(repoRoot, store, run) {
|
|
140
127
|
const execution = store.readWorkerExecution?.(run.id);
|
|
141
128
|
return () => {
|
|
142
|
-
|
|
143
|
-
|
|
129
|
+
const refusal = deletionRefusal(run.id, 'worktree', store.sourceDataDir?.(run.id) ?? projectPaths(repoRoot).write);
|
|
130
|
+
if (refusal)
|
|
131
|
+
throw Error(refusal);
|
|
144
132
|
if (run.delegation?.role !== 'worker')
|
|
145
133
|
return;
|
|
146
134
|
if (typeof store.workerResourcesSafe === 'function' && (!execution ||
|
|
@@ -180,6 +168,7 @@ export async function reclaimWorktrees(repoRoot, store, keep, opts = {}) {
|
|
|
180
168
|
* preserved). Never throws.
|
|
181
169
|
*/
|
|
182
170
|
export async function reclaimWorktree(repoRoot, store, run, opts = {}) {
|
|
171
|
+
assertRunSlotsSealed();
|
|
183
172
|
if (readOnlyWorktree(repoRoot, store, run))
|
|
184
173
|
return null;
|
|
185
174
|
const now = opts.now ?? (() => new Date().toISOString());
|
|
@@ -208,7 +197,7 @@ export async function reclaimWorktree(repoRoot, store, run, opts = {}) {
|
|
|
208
197
|
}
|
|
209
198
|
try {
|
|
210
199
|
assertSafe();
|
|
211
|
-
if (!(await
|
|
200
|
+
if (!(await prepareReclaim(run, { repoRoot, store }).then(() => true, () => false)))
|
|
212
201
|
return null;
|
|
213
202
|
if (opts.remove)
|
|
214
203
|
assertSafe(); // injected reclaimer has no final callback
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retention.js","sourceRoot":"","sources":["../../src/runs/retention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC1E,6EAA6E;AAC7E,iFAAiF;AACjF,+EAA+E;AAC/E,iFAAiF;AACjF,iFAAiF;AACjF,4EAA4E;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"retention.js","sourceRoot":"","sources":["../../src/runs/retention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC1E,6EAA6E;AAC7E,iFAAiF;AACjF,+EAA+E;AAC/E,iFAAiF;AACjF,iFAAiF;AACjF,4EAA4E;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;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IAC5G,IAAI,CAAC,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,CAAC;QAAC,OAAO,IAAI,CAAC;IAAC,CAAC;IACxC,IAAI,CAAC;QACH,UAAU,EAAE,CAAC;QACb,IAAI,CAAC,CAAC,MAAM,cAAc,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;QACjG,IAAI,IAAI,CAAC,MAAM;YAAE,UAAU,EAAE,CAAC,CAAC,2CAA2C;QAC1E,MAAM,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;QACzC,IAAI,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC;YAAE,OAAO,IAAI,CAAC,CAAC,kCAAkC;QACjF,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC;QACpB,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,mBAAmB,EAAE,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"}
|
package/dist/runs/store.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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 { EventEmitter } from 'node:events';
|
|
5
4
|
import { type WorkerExecution } from './worker-execution.ts';
|
|
6
5
|
import { z } from 'zod';
|
|
7
6
|
import { type ScopeRecord, type SpawnScope } from '../worker-scope/scope.ts';
|
|
@@ -3241,7 +3240,7 @@ export type CommitSource = 'delegation-checkpoint' | 'delegation-destroy-progres
|
|
|
3241
3240
|
* pinned, related and unsettled records only. Optimistic writes debounce; durable commits
|
|
3242
3241
|
* publish after persistence. Family claims fence every write.
|
|
3243
3242
|
*/
|
|
3244
|
-
export declare class RunStore
|
|
3243
|
+
export declare class RunStore {
|
|
3245
3244
|
private readonly dataDir;
|
|
3246
3245
|
/** The held set: every record this store keeps in memory, by id. */
|
|
3247
3246
|
private readonly held;
|
|
@@ -3264,7 +3263,7 @@ export declare class RunStore extends EventEmitter {
|
|
|
3264
3263
|
private persistence;
|
|
3265
3264
|
/** Runs whose held record is ahead of its row; the next save or commit writes them. */
|
|
3266
3265
|
private readonly dirty;
|
|
3267
|
-
/** The typed lifecycle events
|
|
3266
|
+
/** The typed lifecycle events the store publishes after each write (lifecycle.ts). */
|
|
3268
3267
|
private readonly published;
|
|
3269
3268
|
readonly lifecycle: RunLifecycleSource;
|
|
3270
3269
|
/** The lifecycle events run exits write (B12). */
|
|
@@ -4005,6 +4004,8 @@ export declare class RunStore extends EventEmitter {
|
|
|
4005
4004
|
/** Delegated history deletion is synchronous and checkpointed; any failed byte/index removal remains retryable. */
|
|
4006
4005
|
private deleteDelegatedRun;
|
|
4007
4006
|
private removeRunHistoryBytes;
|
|
4007
|
+
/** The run's history, handoff and images, then the removal cleanups (`runs/removal-slots.ts`). */
|
|
4008
|
+
private removeHistoryFiles;
|
|
4008
4009
|
deleteRun(id: string): boolean;
|
|
4009
4010
|
/** Write the pending rows out now (used on shutdown). */
|
|
4010
4011
|
flush(): void;
|
|
@@ -4029,8 +4030,8 @@ export declare class RunStore extends EventEmitter {
|
|
|
4029
4030
|
/** The held record is gone; the next save or commit deletes its row, fenced by `family`'s claim
|
|
4030
4031
|
* and by the revision this store last saw (kept in `base` until the delete is written). */
|
|
4031
4032
|
private markDeleted;
|
|
4032
|
-
/** A deleted run's history files, once the delete of its row has committed.
|
|
4033
|
-
*
|
|
4033
|
+
/** A deleted run's history files and removal cleanups, once the delete of its row has committed.
|
|
4034
|
+
* Best effort: a failure is logged, and the row stays deleted. */
|
|
4034
4035
|
private removeOwedHistory;
|
|
4035
4036
|
/**
|
|
4036
4037
|
* Count-based history retention: of the runs past the newest `MAX_RUNS_KEPT` unarchived ones,
|
package/dist/runs/store.js
CHANGED
|
@@ -10,12 +10,9 @@ import { recordedHolders, workerResourceAuthorized } from './worker-resource-hol
|
|
|
10
10
|
import { listPeerTaskSummaries, parseStoredSummary } from './run-summary-page.js';
|
|
11
11
|
export { parseStoredSummary } from './run-summary-page.js';
|
|
12
12
|
import { defined } from '../core/defined.js';
|
|
13
|
-
import {
|
|
14
|
-
import { EventEmitter } from 'node:events';
|
|
13
|
+
import { assertRunSlotsSealed, deletionRefusal, runRemovalCleanups } from './removal-slots.js';
|
|
15
14
|
import { admissibleExecution, holderRefusal, SPAWN_NEXT, WorkerAdmissionRefusal, workerEvidenceRunIds, workerExecutionSchema } from './worker-execution.js';
|
|
16
|
-
import {
|
|
17
|
-
import { jobRunsIn } from '../jobs/job.js';
|
|
18
|
-
import { removeArtifacts } from '../artifacts/lifecycle.js';
|
|
15
|
+
import { agentTmpDirMayExist, agentTmpDirOwnershipProven, removeAgentTmpDir } from './agent-tmpdir.js';
|
|
19
16
|
import { randomUUID, createHash } from 'node:crypto';
|
|
20
17
|
import { isDeepStrictEqual } from 'node:util';
|
|
21
18
|
import { appendFileSync, closeSync, constants, fstatSync, fsyncSync, lstatSync, openSync, readSync, realpathSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
@@ -431,7 +428,7 @@ const startToken = (pid) => { const token = processStartToken(pid); return token
|
|
|
431
428
|
* pinned, related and unsettled records only. Optimistic writes debounce; durable commits
|
|
432
429
|
* publish after persistence. Family claims fence every write.
|
|
433
430
|
*/
|
|
434
|
-
export class RunStore
|
|
431
|
+
export class RunStore {
|
|
435
432
|
dataDir;
|
|
436
433
|
/** The held set: every record this store keeps in memory, by id. */
|
|
437
434
|
held = new Map();
|
|
@@ -450,7 +447,7 @@ export class RunStore extends EventEmitter {
|
|
|
450
447
|
persistence;
|
|
451
448
|
/** Runs whose held record is ahead of its row; the next save or commit writes them. */
|
|
452
449
|
dirty = new Set();
|
|
453
|
-
/** The typed lifecycle events
|
|
450
|
+
/** The typed lifecycle events the store publishes after each write (lifecycle.ts). */
|
|
454
451
|
published = new RunLifecycle();
|
|
455
452
|
lifecycle = this.published;
|
|
456
453
|
/** The lifecycle events run exits write (B12). */
|
|
@@ -504,9 +501,7 @@ export class RunStore extends EventEmitter {
|
|
|
504
501
|
return { events: this.liveItems.read(runId), throughSeq: this.seqs.get(runId) ?? Infinity };
|
|
505
502
|
}
|
|
506
503
|
constructor(dataDir) {
|
|
507
|
-
super();
|
|
508
504
|
this.dataDir = dataDir;
|
|
509
|
-
this.setMaxListeners(100);
|
|
510
505
|
this.facts = new TranscriptFactsIndex(dataDir);
|
|
511
506
|
this.compressor = new HistoryCompressor(dataDir, (id) => this.isHistoryCompressEligible(id), (id, plain, archive) => this.facts.adoptArchive(id, plain, stampOf(archive)));
|
|
512
507
|
}
|
|
@@ -973,10 +968,8 @@ export class RunStore extends EventEmitter {
|
|
|
973
968
|
* verdict reads (hearsay-tools/cezarion#1301). */
|
|
974
969
|
republish(id) {
|
|
975
970
|
const run = this.peek(id);
|
|
976
|
-
if (run)
|
|
971
|
+
if (run)
|
|
977
972
|
this.published.publish('run.updated', { run, before: snapshotRun(run), source: 'live-release' });
|
|
978
|
-
this.emit('run', run, 'live-release');
|
|
979
|
-
}
|
|
980
973
|
}
|
|
981
974
|
/** Release `holder`'s pin. The run leaves memory at the next sweep once nothing else holds it. */
|
|
982
975
|
unpin(id, holder) {
|
|
@@ -1908,14 +1901,10 @@ export class RunStore extends EventEmitter {
|
|
|
1908
1901
|
try {
|
|
1909
1902
|
for (const id of staged.keys()) {
|
|
1910
1903
|
const run = this.held.get(id);
|
|
1911
|
-
if (run)
|
|
1904
|
+
if (run)
|
|
1912
1905
|
publishRunWrite(this.published, committed.get(id) ?? run, before.get(id), source, exits.get(id));
|
|
1913
|
-
|
|
1914
|
-
}
|
|
1915
|
-
else {
|
|
1906
|
+
else
|
|
1916
1907
|
this.published.publish('run.deleted', { runId: id });
|
|
1917
|
-
this.emit('deleted', id);
|
|
1918
|
-
}
|
|
1919
1908
|
}
|
|
1920
1909
|
}
|
|
1921
1910
|
finally {
|
|
@@ -2450,7 +2439,6 @@ export class RunStore extends EventEmitter {
|
|
|
2450
2439
|
this.maybeEnqueueHistoryCompress(run);
|
|
2451
2440
|
this.liveItems.observe(runId, full, false);
|
|
2452
2441
|
this.published.publish('run.event', { runId, event: full });
|
|
2453
|
-
this.emit('event', { runId, event: full });
|
|
2454
2442
|
// Reference discovery runs last, after the event is persisted, indexed and
|
|
2455
2443
|
// published: the janitor reads the event text and may still update the run.
|
|
2456
2444
|
const before = snapshotRun(run);
|
|
@@ -2539,7 +2527,6 @@ export class RunStore extends EventEmitter {
|
|
|
2539
2527
|
const full = this.redact({ ...event, seq: this.nextSeq(runId), ts: new Date().toISOString() });
|
|
2540
2528
|
this.liveItems.observe(runId, full, true);
|
|
2541
2529
|
this.published.publish('run.event', { runId, event: full });
|
|
2542
|
-
this.emit('event', { runId, event: full });
|
|
2543
2530
|
return full;
|
|
2544
2531
|
}
|
|
2545
2532
|
/** Lazily-collected concrete secret values from the host env (#427). */
|
|
@@ -2746,7 +2733,7 @@ export class RunStore extends EventEmitter {
|
|
|
2746
2733
|
}
|
|
2747
2734
|
/** `workerResourcesSafe` with the refusal's live PIDs (empty when no PID explains it). */
|
|
2748
2735
|
workerResourceHolders(id, generation, resourceId, opts = {}) {
|
|
2749
|
-
if (
|
|
2736
|
+
if (deletionRefusal(id, 'worktree', this.dataDir))
|
|
2750
2737
|
return [];
|
|
2751
2738
|
const run = this.peek(id);
|
|
2752
2739
|
const proof = this.readWorkerExecution(id);
|
|
@@ -2771,7 +2758,7 @@ export class RunStore extends EventEmitter {
|
|
|
2771
2758
|
}
|
|
2772
2759
|
/** Cleanup can outlive its index row, but never its generation or terminal task intent. */
|
|
2773
2760
|
workerScratchResourcesSafe(id, generation, resourceId) {
|
|
2774
|
-
if (
|
|
2761
|
+
if (deletionRefusal(id, 'worktree', this.dataDir))
|
|
2775
2762
|
return false;
|
|
2776
2763
|
const run = this.peek(id), proof = this.readWorkerExecution(id);
|
|
2777
2764
|
if (proof?.phase !== 'complete' || proof.generation !== generation || proof.scratchCleanup?.resourceId !== resourceId ||
|
|
@@ -2873,7 +2860,6 @@ export class RunStore extends EventEmitter {
|
|
|
2873
2860
|
// durable private proof before a terminal worker can satisfy a lifecycle wait.
|
|
2874
2861
|
const settled = this.peek(id);
|
|
2875
2862
|
this.published.publish('run.updated', { run: settled, before: snapshotRun(settled) });
|
|
2876
|
-
this.emit('run', settled);
|
|
2877
2863
|
return true;
|
|
2878
2864
|
}
|
|
2879
2865
|
catch {
|
|
@@ -2924,7 +2910,7 @@ export class RunStore extends EventEmitter {
|
|
|
2924
2910
|
canDeleteRun(id, kind = 'record') {
|
|
2925
2911
|
if (this.fallbackDeleteError(id, kind))
|
|
2926
2912
|
return false;
|
|
2927
|
-
if (
|
|
2913
|
+
if (deletionRefusal(id, kind === 'record' ? 'history' : 'worktree', this.dataDir))
|
|
2928
2914
|
return false;
|
|
2929
2915
|
const run = this.peek(id);
|
|
2930
2916
|
if (run?.delegation?.role === 'invalid')
|
|
@@ -3017,12 +3003,15 @@ export class RunStore extends EventEmitter {
|
|
|
3017
3003
|
const dir = join(runDataDir(this.dataDir, id), 'runs');
|
|
3018
3004
|
if (realpathSync(dir) !== resolve(dir))
|
|
3019
3005
|
throw new Error('History storage redirected');
|
|
3006
|
+
this.removeHistoryFiles(id);
|
|
3007
|
+
}
|
|
3008
|
+
/** The run's history, handoff and images, then the removal cleanups (`runs/removal-slots.ts`). */
|
|
3009
|
+
removeHistoryFiles(id) {
|
|
3020
3010
|
this.facts.forget(id);
|
|
3021
3011
|
removeHistory(this.dataDir, id);
|
|
3022
3012
|
rmSync(this.handoffPath(id), { force: true });
|
|
3023
3013
|
rmSync(this.imagesDir(id), { recursive: true, force: true });
|
|
3024
|
-
|
|
3025
|
-
clearAutosaveCleanup(this.dataDir, id);
|
|
3014
|
+
runRemovalCleanups(id, this.dataDir);
|
|
3026
3015
|
}
|
|
3027
3016
|
deleteRun(id) {
|
|
3028
3017
|
const refusal = this.fallbackDeleteError(id);
|
|
@@ -3035,8 +3024,6 @@ export class RunStore extends EventEmitter {
|
|
|
3035
3024
|
return false;
|
|
3036
3025
|
if (run?.delegation?.role === 'worker' || run?.delegation?.role === 'root')
|
|
3037
3026
|
return this.deleteDelegatedRun(id);
|
|
3038
|
-
if (run)
|
|
3039
|
-
clearAutosaveCleanup(this.dataDir, id);
|
|
3040
3027
|
const existed = run !== undefined;
|
|
3041
3028
|
this.held.delete(id);
|
|
3042
3029
|
if (existed) {
|
|
@@ -3045,7 +3032,6 @@ export class RunStore extends EventEmitter {
|
|
|
3045
3032
|
this.seqs.delete(id);
|
|
3046
3033
|
this.scheduleSave();
|
|
3047
3034
|
this.published.publish('run.deleted', { runId: id });
|
|
3048
|
-
this.emit('deleted', id);
|
|
3049
3035
|
}
|
|
3050
3036
|
return existed;
|
|
3051
3037
|
}
|
|
@@ -3089,7 +3075,6 @@ export class RunStore extends EventEmitter {
|
|
|
3089
3075
|
this.dirty.add(run.id);
|
|
3090
3076
|
this.scheduleSave();
|
|
3091
3077
|
publishRunWrite(this.published, run, before, undefined, exit);
|
|
3092
|
-
this.emit('run', run);
|
|
3093
3078
|
this.maybeEnqueueHistoryCompress(run);
|
|
3094
3079
|
}
|
|
3095
3080
|
/** Form follows archived: a terminal archived run with a plain transcript is queued again. */
|
|
@@ -3111,19 +3096,17 @@ export class RunStore extends EventEmitter {
|
|
|
3111
3096
|
this.deletedFamilies.set(id, family);
|
|
3112
3097
|
this.historyOwed.add(id);
|
|
3113
3098
|
}
|
|
3114
|
-
/** A deleted run's history files, once the delete of its row has committed.
|
|
3115
|
-
*
|
|
3099
|
+
/** A deleted run's history files and removal cleanups, once the delete of its row has committed.
|
|
3100
|
+
* Best effort: a failure is logged, and the row stays deleted. */
|
|
3116
3101
|
removeOwedHistory(id) {
|
|
3117
3102
|
if (!this.historyOwed.delete(id))
|
|
3118
3103
|
return;
|
|
3119
3104
|
try {
|
|
3120
|
-
this.
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
removeArtifacts(this.dataDir, id);
|
|
3105
|
+
this.removeHistoryFiles(id);
|
|
3106
|
+
}
|
|
3107
|
+
catch (error) {
|
|
3108
|
+
console.warn(`[hsq] History cleanup of run ${id} is incomplete: ${error instanceof Error ? error.message : String(error)}`);
|
|
3125
3109
|
}
|
|
3126
|
-
catch { /* best effort */ }
|
|
3127
3110
|
}
|
|
3128
3111
|
/**
|
|
3129
3112
|
* Count-based history retention: of the runs past the newest `MAX_RUNS_KEPT` unarchived ones,
|
|
@@ -3173,12 +3156,13 @@ export class RunStore extends EventEmitter {
|
|
|
3173
3156
|
/** Archive a root with its workers unless a member is live, mid-destroy or pinned, or a history
|
|
3174
3157
|
* deletion is under way. Each member is marked dirty: the next save writes the family at once. */
|
|
3175
3158
|
archiveSettledFamily(root) {
|
|
3159
|
+
assertRunSlotsSealed();
|
|
3176
3160
|
const workers = this.listWorkersOf(root.id), family = [root, ...workers];
|
|
3177
3161
|
if (family.some((run) => isLiveRecord(run) || run.pinned) || (root.delegation?.role === 'root' && root.delegation.historyDeletion))
|
|
3178
3162
|
return;
|
|
3179
3163
|
for (const member of [root, ...workers.flatMap((worker) => this.record(worker.id) ?? [])].filter((run) => !run.archived)) {
|
|
3180
3164
|
this.applyArchived(member, true);
|
|
3181
|
-
if (!
|
|
3165
|
+
if (!deletionRefusal(member.id, 'archive-tmp', this.dataDir))
|
|
3182
3166
|
removeAgentTmpDir(this.dataDir, member.id);
|
|
3183
3167
|
}
|
|
3184
3168
|
}
|
|
@@ -3353,13 +3337,11 @@ export class RunStore extends EventEmitter {
|
|
|
3353
3337
|
replaceRecord(held, current);
|
|
3354
3338
|
this.base.set(conflict.id, { revision: conflict.current.revision, seq: conflict.current.seq, data: conflict.current.data, extras: decoded.extras });
|
|
3355
3339
|
publishRunWrite(this.published, held ?? current, before ?? snapshotRun(current), 'conflict');
|
|
3356
|
-
this.emit('run', held ?? current);
|
|
3357
3340
|
}
|
|
3358
3341
|
else {
|
|
3359
3342
|
this.held.delete(conflict.id);
|
|
3360
3343
|
this.base.delete(conflict.id);
|
|
3361
3344
|
this.published.publish('run.deleted', { runId: conflict.id });
|
|
3362
|
-
this.emit('deleted', conflict.id);
|
|
3363
3345
|
}
|
|
3364
3346
|
console.error(`[hsq] run ${conflict.id} was changed by another writer (${conflict.reason}); this process will not write it again until Squawk restarts. Evidence: ${join(this.dataDir, RUNS_DB_FILE)}, table run_conflicts, seq ${seqs[index]}.`);
|
|
3365
3347
|
});
|
|
@@ -3400,7 +3382,6 @@ export class RunStore extends EventEmitter {
|
|
|
3400
3382
|
this.liveItems.clear();
|
|
3401
3383
|
// Demand-bound feeds stop before storage disappears during project removal/shutdown.
|
|
3402
3384
|
this.published.publish('store.closed', {});
|
|
3403
|
-
this.emit('closed');
|
|
3404
3385
|
this.compressor.stop();
|
|
3405
3386
|
this.fallbackFacts?.stop();
|
|
3406
3387
|
this.facts.stop();
|