@hearsay-tools/squawk 0.18.0-pr4074.7790 → 0.18.0-pr4076.7799
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/autosave-removal-slots.d.ts +2 -2
- package/dist/autosave-removal-slots.js +2 -2
- package/dist/autosave-removal-slots.js.map +1 -1
- package/dist/ci-wait/controller.d.ts +46 -46
- package/dist/ci-wait/tools.d.ts +4 -4
- package/dist/delegation/routes.d.ts +15 -15
- package/dist/delegation/service.js +2 -2
- package/dist/delegation/service.js.map +1 -1
- package/dist/delegation/transport.d.ts +75 -75
- package/dist/delegation/worker-cleanup.js +1 -1
- package/dist/delegation/worker-cleanup.js.map +1 -1
- package/dist/jobs/removal-slot.d.ts +2 -2
- package/dist/jobs/removal-slot.js +3 -3
- package/dist/jobs/removal-slot.js.map +1 -1
- package/dist/runs/agent-tmpdir.d.ts +2 -0
- package/dist/runs/agent-tmpdir.js +40 -1
- package/dist/runs/agent-tmpdir.js.map +1 -1
- package/dist/runs/ports.d.ts +13 -9
- package/dist/runs/removal-slots.d.ts +4 -3
- package/dist/runs/removal-slots.js.map +1 -1
- package/dist/runs/run-retention.d.ts +84 -0
- package/dist/runs/run-retention.js +224 -0
- package/dist/runs/run-retention.js.map +1 -0
- package/dist/runs/run-row.d.ts +11 -0
- package/dist/runs/run-row.js +15 -0
- package/dist/runs/run-row.js.map +1 -1
- package/dist/runs/store.d.ts +6 -46
- package/dist/runs/store.js +54 -322
- package/dist/runs/store.js.map +1 -1
- package/dist/runs/transcript-facts-topic.d.ts +45 -0
- package/dist/runs/transcript-facts-topic.js +101 -0
- package/dist/runs/transcript-facts-topic.js.map +1 -0
- package/dist/server/models-routes.d.ts +13 -13
- package/dist/server/project-run-files.js +1 -1
- package/dist/server/project-run-files.js.map +1 -1
- package/dist/server/provider-sign-in-routes.d.ts +2 -2
- package/dist/server/reports-api.d.ts +2 -2
- package/dist/server/run-checkout.d.ts +3 -1
- package/dist/server/run-checkout.js +3 -3
- package/dist/server/run-checkout.js.map +1 -1
- package/dist/server/runner-install-routes.d.ts +10 -10
- package/dist/server/server.d.ts +1568 -1568
- package/dist/server/server.js +1 -1
- package/dist/server/server.js.map +1 -1
- package/dist/server/workspace-live-routes.d.ts +6 -6
- package/dist/workflows/run/continuation-acceptance.js +1 -1
- package/dist/workflows/run/continuation-acceptance.js.map +1 -1
- package/dist/workflows/run/continuation-session.js +2 -2
- 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/human-waits.js +4 -4
- package/dist/workflows/run/human-waits.js.map +1 -1
- package/dist/workflows/run/input-delivery.js +3 -3
- package/dist/workflows/run/input-delivery.js.map +1 -1
- package/dist/workflows/run/run-finish.js +3 -3
- package/dist/workflows/run/run-finish.js.map +1 -1
- package/dist/workflows/run/run-recovery.js +6 -6
- package/dist/workflows/run/run-recovery.js.map +1 -1
- package/dist/workflows/run/run-settlement.js +15 -5
- package/dist/workflows/run/run-settlement.js.map +1 -1
- package/dist/workflows/run/session-events.js +1 -1
- package/dist/workflows/run/session-events.js.map +1 -1
- package/dist/workflows/run/turn-nudges.js +2 -2
- package/dist/workflows/run/turn-nudges.js.map +1 -1
- package/dist/workflows/run/turn-settler.js +1 -1
- package/dist/workflows/run/turn-settler.js.map +1 -1
- package/dist/workflows/run/worker-questions.js +16 -16
- package/dist/workflows/run/worker-questions.js.map +1 -1
- package/dist/workflows/run.js +1 -1
- package/dist/workflows/run.js.map +1 -1
- package/package.json +4 -4
- package/scripts/measure-transcript-facts-health.mjs +2 -2
- package/scripts/measure-transcript-facts-lag.mjs +1 -1
- package/scripts/transcript-facts-fixture.mjs +1 -1
package/dist/runs/ports.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* that implements it. A later slice may move a method between ports when its topic moves. The store stays the only writer of status and exit fields (ADR 0056).
|
|
10
10
|
*/
|
|
11
11
|
import type { RunStore } from './store.ts';
|
|
12
|
+
import type { TranscriptFacts } from './transcript-facts.ts';
|
|
12
13
|
export type { RunLifecycleSource } from './lifecycle.ts';
|
|
13
14
|
/** One run's record, by id. Nearly every caller needs only this. */
|
|
14
15
|
export interface RunLookup {
|
|
@@ -78,11 +79,11 @@ export interface RunEventLog {
|
|
|
78
79
|
}
|
|
79
80
|
/** What the transcript says about a run. The type `TranscriptFacts` is the facts themselves. */
|
|
80
81
|
export interface TranscriptFactsPort {
|
|
81
|
-
transcriptFacts:
|
|
82
|
-
knownTranscriptFacts:
|
|
83
|
-
prepareTranscriptFacts:
|
|
84
|
-
prepareRecoveryFacts:
|
|
85
|
-
factsWarmIdle:
|
|
82
|
+
transcriptFacts(runId: string): Readonly<TranscriptFacts>;
|
|
83
|
+
knownTranscriptFacts(runId: string): Readonly<TranscriptFacts> | undefined;
|
|
84
|
+
prepareTranscriptFacts(runIds: Iterable<string>): Promise<void>;
|
|
85
|
+
prepareRecoveryFacts(familyRootId?: string): Promise<void>;
|
|
86
|
+
factsWarmIdle(): Promise<void>;
|
|
86
87
|
}
|
|
87
88
|
/** A worker's collected result. */
|
|
88
89
|
export interface WorkerResults {
|
|
@@ -108,11 +109,14 @@ export interface WorkerExecutions {
|
|
|
108
109
|
appendWorkerProcess: RunStore['appendWorkerProcess'];
|
|
109
110
|
commitWorkerExecutionComplete: RunStore['commitWorkerExecutionComplete'];
|
|
110
111
|
}
|
|
111
|
-
/**
|
|
112
|
+
/** Whether a run may go, and its deletion (`runs/run-retention.ts`, `store.retention`). */
|
|
112
113
|
export interface RunRetention {
|
|
113
|
-
canDeleteRun:
|
|
114
|
-
deleteRun:
|
|
115
|
-
fallbackDeleteError:
|
|
114
|
+
canDeleteRun(id: string, kind?: 'record' | 'worktree'): boolean;
|
|
115
|
+
deleteRun(id: string): boolean;
|
|
116
|
+
fallbackDeleteError(id: string, kind?: 'record' | 'worktree'): string | undefined;
|
|
117
|
+
}
|
|
118
|
+
/** The archive methods. */
|
|
119
|
+
export interface RunArchive {
|
|
116
120
|
setArchived: RunStore['setArchived'];
|
|
117
121
|
archiveFinished: RunStore['archiveFinished'];
|
|
118
122
|
archiveOnMergeSnapshot: RunStore['archiveOnMergeSnapshot'];
|
|
@@ -10,9 +10,10 @@ import type { RunRecord } from './store.ts';
|
|
|
10
10
|
* Fail closed: until the registry is sealed, every read throws an error that names the missing
|
|
11
11
|
* registration, and each removal path reads it before its first side effect.
|
|
12
12
|
*/
|
|
13
|
-
/** What a deletion removes: a run's history, its worktree or worker resources,
|
|
14
|
-
* directory of an archived family member
|
|
15
|
-
|
|
13
|
+
/** What a deletion removes: a run's history, its worktree or worker resources, the agent tmp
|
|
14
|
+
* directory of an archived family member, or the agent tmp directory (scratch) of a run that ended
|
|
15
|
+
* or of an orphan the startup sweep found. */
|
|
16
|
+
export type DeletionKind = 'history' | 'worktree' | 'archive-tmp' | 'scratch';
|
|
16
17
|
/** Refuses a deletion while the feature still needs what it removes. */
|
|
17
18
|
export interface DeletionGate {
|
|
18
19
|
readonly name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removal-slots.js","sourceRoot":"","sources":["../../src/runs/removal-slots.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"removal-slots.js","sourceRoot":"","sources":["../../src/runs/removal-slots.ts"],"names":[],"mappings":"AAmDA,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,C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,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"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The retention and deletion topic of the run store (hearsay-tools/squawk#4037): whether a run's
|
|
3
|
+
* history or worktree may go, the deletion itself (plain and delegated), the history files a
|
|
4
|
+
* committed delete still owes, and the count-based archive of settled families. It asks the
|
|
5
|
+
* removal slots (`runs/removal-slots.ts`) on every path. `RunStore` keeps one of these as
|
|
6
|
+
* `store.retention`; worktree retention is `runs/retention.ts`.
|
|
7
|
+
*/
|
|
8
|
+
import type { DelegationState, RunRecord, WorkerCollectedResult } from '../contract/index.js';
|
|
9
|
+
import type { RunLifecycle } from './lifecycle.ts';
|
|
10
|
+
import type { RunRetention } from './ports.ts';
|
|
11
|
+
import type { RunDatabase } from './run-database.ts';
|
|
12
|
+
import { type ListOrder } from './run-row.ts';
|
|
13
|
+
import type { RunTranscriptFacts } from './transcript-facts-topic.ts';
|
|
14
|
+
import { type WorkerExecution } from './worker-execution.ts';
|
|
15
|
+
/** What the topic asks of the store; no import of `store.ts`. */
|
|
16
|
+
export interface RetentionState {
|
|
17
|
+
/** The open database; null for an unavailable or closed store. */
|
|
18
|
+
db(): RunDatabase | null;
|
|
19
|
+
readonly held: Map<string, RunRecord>;
|
|
20
|
+
readonly deleted: ReadonlySet<string>;
|
|
21
|
+
readonly quarantined: ReadonlySet<string>;
|
|
22
|
+
readonly historyOwed: Set<string>;
|
|
23
|
+
readonly seqs: Map<string, number>;
|
|
24
|
+
readonly published: RunLifecycle;
|
|
25
|
+
readonly transcriptFacts: RunTranscriptFacts;
|
|
26
|
+
peek(id: string): RunRecord | undefined;
|
|
27
|
+
hasRun(id: string): boolean;
|
|
28
|
+
record(id: string): RunRecord | undefined;
|
|
29
|
+
listWorkersOf(parentId: string): RunRecord[];
|
|
30
|
+
isFallbackRun(id: string): boolean;
|
|
31
|
+
hasFallbackRun(id: string): boolean;
|
|
32
|
+
listOrder(run: RunRecord): ListOrder;
|
|
33
|
+
claimFamilies(families: Iterable<string>): Set<string>;
|
|
34
|
+
markDeleted(id: string, family: string): void;
|
|
35
|
+
scheduleSave(): void;
|
|
36
|
+
commitIndex(input: ReadonlyMap<string, RunRecord | null>): void;
|
|
37
|
+
commitDelegation(patches: ReadonlyArray<{
|
|
38
|
+
id: string;
|
|
39
|
+
delegation: DelegationState;
|
|
40
|
+
}>): void;
|
|
41
|
+
applyArchived(run: RunRecord, archived: boolean): boolean;
|
|
42
|
+
/** The worker deletion checks stay in the store, in today's order, until D5 (C1 decision). */
|
|
43
|
+
workerDeletionEvidence(id: string): boolean;
|
|
44
|
+
readWorkerResult(parentId: string, workerId: string): WorkerCollectedResult | undefined;
|
|
45
|
+
readWorkerResultDiff(parentId: string, workerId: string): string | undefined;
|
|
46
|
+
readDeletedWorkerResult(parentId: string, workerId: string): WorkerCollectedResult | undefined;
|
|
47
|
+
commitWorkerResult(parentId: string, value: WorkerCollectedResult, diffSnapshot?: string): WorkerCollectedResult;
|
|
48
|
+
readWorkerExecution(id: string): WorkerExecution | undefined;
|
|
49
|
+
identityPath(id: string): string;
|
|
50
|
+
processesPath(id: string): string;
|
|
51
|
+
scopePath(id: string): string;
|
|
52
|
+
executionPath(id: string): string;
|
|
53
|
+
handoffPath(runId: string): string;
|
|
54
|
+
imagesDir(runId: string): string;
|
|
55
|
+
}
|
|
56
|
+
export declare class RunRetentionTopic implements RunRetention {
|
|
57
|
+
private readonly dataDir;
|
|
58
|
+
private readonly state;
|
|
59
|
+
constructor(dataDir: string, state: RetentionState);
|
|
60
|
+
fallbackDeleteError(id: string, kind?: 'record' | 'worktree'): string | undefined;
|
|
61
|
+
canDeleteRun(id: string, kind?: 'record' | 'worktree'): boolean;
|
|
62
|
+
/** Delegated history deletion is synchronous and checkpointed; any failed byte/index removal remains retryable. */
|
|
63
|
+
private deleteDelegatedRun;
|
|
64
|
+
private removeRunHistoryBytes;
|
|
65
|
+
/** The run's history, handoff and images, then the removal cleanups (`runs/removal-slots.ts`). */
|
|
66
|
+
private removeHistoryFiles;
|
|
67
|
+
deleteRun(id: string): boolean;
|
|
68
|
+
/** A deleted run's history files and removal cleanups, once the delete of its row has committed.
|
|
69
|
+
* Best effort: a failure is logged, and the row stays deleted. */
|
|
70
|
+
removeOwedHistory(id: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Count-based history retention: of the runs past the newest `MAX_RUNS_KEPT` unarchived ones,
|
|
73
|
+
* archive each settled task that is not pinned and whose family this store can claim, together
|
|
74
|
+
* with its workers, once no member of the family is live (hearsay-tools/squawk#777). Ranked over the row keys (the `created_at` index, no record decoded) with memory
|
|
75
|
+
* laid over them, since a run created or archived since the last save has no row yet; the rows
|
|
76
|
+
* past the cut are then filtered in `runs.db`, so only real candidates decode. Archived runs
|
|
77
|
+
* are never deleted by retention — only an explicit delete, worker destruction, or history
|
|
78
|
+
* deletion removes a run.
|
|
79
|
+
*/
|
|
80
|
+
pruneOldRuns(): void;
|
|
81
|
+
/** Archive a root with its workers unless a member is live, mid-destroy or pinned, or a history
|
|
82
|
+
* deletion is under way. Each member is marked dirty: the next save writes the family at once. */
|
|
83
|
+
private archiveSettledFamily;
|
|
84
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { RETENTION_RUN_RULE } from '../contract/index.js';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { realpathSync, rmSync } from 'node:fs';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { dataReadDirs, runDataDir } from '../project-paths.js';
|
|
7
|
+
import { agentTmpDirMayExist, removeAgentTmpDir } from './agent-tmpdir.js';
|
|
8
|
+
import { guardedJsonSql } from './guarded-json-sql.js';
|
|
9
|
+
import { removeHistory } from './history-file.js';
|
|
10
|
+
import { fallbackRunDeleteError } from './project-run-sources.js';
|
|
11
|
+
import { assertRunSlotsSealed, deletionRefusal, runRemovalCleanups } from './removal-slots.js';
|
|
12
|
+
import { familyKey, rowFamily } from './run-claims.js';
|
|
13
|
+
import { isLiveRecord, newestFirst } from './run-row.js';
|
|
14
|
+
import { supervisedWorkers } from './supervised.js';
|
|
15
|
+
import { workerEvidenceRunIds } from './worker-execution.js';
|
|
16
|
+
const MAX_RUNS_KEPT = 300;
|
|
17
|
+
export class RunRetentionTopic {
|
|
18
|
+
dataDir;
|
|
19
|
+
state;
|
|
20
|
+
constructor(dataDir, state) {
|
|
21
|
+
this.dataDir = dataDir;
|
|
22
|
+
this.state = state;
|
|
23
|
+
}
|
|
24
|
+
fallbackDeleteError(id, kind = 'record') { return fallbackRunDeleteError(this.dataDir, kind === 'record' ? this.state.hasFallbackRun(id) : this.state.isFallbackRun(id), this.state.peek(id)?.worktreePath); }
|
|
25
|
+
canDeleteRun(id, kind = 'record') {
|
|
26
|
+
if (this.fallbackDeleteError(id, kind))
|
|
27
|
+
return false;
|
|
28
|
+
if (deletionRefusal(id, kind === 'record' ? 'history' : 'worktree', this.dataDir))
|
|
29
|
+
return false;
|
|
30
|
+
const run = this.state.peek(id);
|
|
31
|
+
if (run?.delegation?.role === 'invalid')
|
|
32
|
+
return false;
|
|
33
|
+
if (run?.delegation?.role === 'worker')
|
|
34
|
+
return supervisedWorkers(this.state, run).length === 0 && this.state.workerDeletionEvidence(id);
|
|
35
|
+
const privateWorkers = workerEvidenceRunIds(this.dataDir);
|
|
36
|
+
if (!privateWorkers || privateWorkers.includes(id))
|
|
37
|
+
return false;
|
|
38
|
+
if (run?.delegation?.role === 'root') {
|
|
39
|
+
if (run.delegation.finishRequestedAt && ['queued', 'running', 'waiting'].includes(run.status))
|
|
40
|
+
return false;
|
|
41
|
+
// Keep the parent's receipt and result ownership until each child history is explicitly removed.
|
|
42
|
+
if (this.state.listWorkersOf(id).length > 0)
|
|
43
|
+
return false;
|
|
44
|
+
return run.delegation.receipts.every(receipt => {
|
|
45
|
+
if (this.state.hasRun(receipt.workerId) || receipt.deletion?.phase !== 'complete')
|
|
46
|
+
return false;
|
|
47
|
+
// A pending parent deletion already validated the results before removing their bytes.
|
|
48
|
+
if (run.delegation?.role === 'root' && run.delegation.historyDeletion === 'pending')
|
|
49
|
+
return true;
|
|
50
|
+
return this.state.readDeletedWorkerResult(id, receipt.workerId) !== undefined;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return this.state.listWorkersOf(id).length === 0;
|
|
54
|
+
}
|
|
55
|
+
/** Delegated history deletion is synchronous and checkpointed; any failed byte/index removal remains retryable. */
|
|
56
|
+
deleteDelegatedRun(id) {
|
|
57
|
+
const run = this.state.peek(id);
|
|
58
|
+
try {
|
|
59
|
+
if (run.delegation?.role === 'worker') {
|
|
60
|
+
const parent = this.state.peek(run.delegation.parentRunId);
|
|
61
|
+
if (parent.delegation?.role !== 'root')
|
|
62
|
+
return false;
|
|
63
|
+
const receipt = parent.delegation.receipts.find(entry => entry.workerId === id);
|
|
64
|
+
const result = this.state.readWorkerResult(parent.id, id);
|
|
65
|
+
const deletion = receipt.deletion ?? { phase: 'pending', revision: result.revision,
|
|
66
|
+
resourceId: run.delegation.workspace.resourceId, generation: this.state.readWorkerExecution(id).generation };
|
|
67
|
+
this.state.commitDelegation([{ id: parent.id, delegation: { ...parent.delegation,
|
|
68
|
+
receipts: parent.delegation.receipts.map(entry => entry.workerId === id ? { ...entry, deletion } : entry),
|
|
69
|
+
} }]);
|
|
70
|
+
// Do not advertise artifact bytes as retained while interrupted deletion is in progress.
|
|
71
|
+
this.state.commitWorkerResult(parent.id, { ...result, observedAt: new Date().toISOString(),
|
|
72
|
+
diff: result.diff.state === 'available' ? { ...result.diff, snapshotId: randomUUID() } : result.diff,
|
|
73
|
+
artifacts: result.artifacts.state === 'available' ? { ...result.artifacts,
|
|
74
|
+
items: result.artifacts.items.map(item => ({ state: 'unavailable', reason: 'unreadable',
|
|
75
|
+
detail: 'History deletion is in progress', id: item.id, path: item.path })),
|
|
76
|
+
} : result.artifacts,
|
|
77
|
+
}, this.state.readWorkerResultDiff(parent.id, id));
|
|
78
|
+
this.removeRunHistoryBytes(id);
|
|
79
|
+
// Delete scratch while its generation evidence still exists; failed removal keeps it.
|
|
80
|
+
removeAgentTmpDir(this.dataDir, id);
|
|
81
|
+
if (agentTmpDirMayExist(this.dataDir, id))
|
|
82
|
+
return false;
|
|
83
|
+
// Private process/account evidence is now replaced by the exact parent receipt.
|
|
84
|
+
rmSync(this.state.identityPath(id), { force: true });
|
|
85
|
+
rmSync(this.state.processesPath(id), { force: true });
|
|
86
|
+
rmSync(this.state.scopePath(id), { force: true });
|
|
87
|
+
rmSync(this.state.executionPath(id), { force: true });
|
|
88
|
+
const retained = this.state.readWorkerResult(parent.id, id);
|
|
89
|
+
this.state.commitWorkerResult(parent.id, { ...retained, observedAt: new Date().toISOString(),
|
|
90
|
+
diff: retained.diff.state === 'available' ? { ...retained.diff, snapshotId: randomUUID() } : retained.diff,
|
|
91
|
+
artifacts: retained.artifacts.state === 'available' ? { ...retained.artifacts,
|
|
92
|
+
items: retained.artifacts.items.map(item => ({ state: 'deleted', reason: 'missing', id: item.id, path: item.path })),
|
|
93
|
+
} : retained.artifacts,
|
|
94
|
+
}, this.state.readWorkerResultDiff(parent.id, id));
|
|
95
|
+
this.state.commitIndex(new Map([[parent.id, { ...parent, delegation: { ...parent.delegation,
|
|
96
|
+
receipts: parent.delegation.receipts.map(entry => entry.workerId === id ? { ...entry, deletion: { ...deletion, phase: 'complete' } } : entry),
|
|
97
|
+
} }], [id, null]]));
|
|
98
|
+
}
|
|
99
|
+
else if (run.delegation?.role === 'root') {
|
|
100
|
+
this.state.commitDelegation([{ id, delegation: { ...run.delegation, historyDeletion: 'pending' } }]);
|
|
101
|
+
this.removeRunHistoryBytes(id);
|
|
102
|
+
rmSync(join(runDataDir(this.dataDir, id), 'runs', `${id}-worker-results`), { recursive: true, force: true });
|
|
103
|
+
this.state.commitIndex(new Map([[id, null]]));
|
|
104
|
+
}
|
|
105
|
+
else
|
|
106
|
+
return false;
|
|
107
|
+
removeAgentTmpDir(this.dataDir, id);
|
|
108
|
+
this.state.seqs.delete(id);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
removeRunHistoryBytes(id) {
|
|
116
|
+
// Fixed owned paths only: never follow context descriptors supplied in persisted metadata.
|
|
117
|
+
z.uuid().parse(id);
|
|
118
|
+
const dir = join(runDataDir(this.dataDir, id), 'runs');
|
|
119
|
+
if (realpathSync(dir) !== resolve(dir))
|
|
120
|
+
throw new Error('History storage redirected');
|
|
121
|
+
this.removeHistoryFiles(id);
|
|
122
|
+
}
|
|
123
|
+
/** The run's history, handoff and images, then the removal cleanups (`runs/removal-slots.ts`). */
|
|
124
|
+
removeHistoryFiles(id) {
|
|
125
|
+
this.state.transcriptFacts.index.forget(id);
|
|
126
|
+
removeHistory(this.dataDir, id);
|
|
127
|
+
rmSync(this.state.handoffPath(id), { force: true });
|
|
128
|
+
rmSync(this.state.imagesDir(id), { recursive: true, force: true });
|
|
129
|
+
runRemovalCleanups(id, this.dataDir);
|
|
130
|
+
}
|
|
131
|
+
deleteRun(id) {
|
|
132
|
+
const refusal = this.fallbackDeleteError(id);
|
|
133
|
+
if (refusal)
|
|
134
|
+
throw new Error(refusal);
|
|
135
|
+
if (!this.canDeleteRun(id))
|
|
136
|
+
return false;
|
|
137
|
+
const run = this.state.peek(id);
|
|
138
|
+
if (run && this.state.db() && (this.state.quarantined.has(id) || !this.state.claimFamilies([familyKey(run)]).size))
|
|
139
|
+
return false;
|
|
140
|
+
if (run?.delegation?.role === 'worker' || run?.delegation?.role === 'root')
|
|
141
|
+
return this.deleteDelegatedRun(id);
|
|
142
|
+
const existed = run !== undefined;
|
|
143
|
+
this.state.held.delete(id);
|
|
144
|
+
if (existed) {
|
|
145
|
+
this.state.markDeleted(id, familyKey(run));
|
|
146
|
+
removeAgentTmpDir(this.dataDir, id);
|
|
147
|
+
this.state.seqs.delete(id);
|
|
148
|
+
this.state.scheduleSave();
|
|
149
|
+
this.state.published.publish('run.deleted', { runId: id });
|
|
150
|
+
}
|
|
151
|
+
return existed;
|
|
152
|
+
}
|
|
153
|
+
/** A deleted run's history files and removal cleanups, once the delete of its row has committed.
|
|
154
|
+
* Best effort: a failure is logged, and the row stays deleted. */
|
|
155
|
+
removeOwedHistory(id) {
|
|
156
|
+
if (!this.state.historyOwed.delete(id))
|
|
157
|
+
return;
|
|
158
|
+
try {
|
|
159
|
+
this.removeHistoryFiles(id);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.warn(`[hsq] History cleanup of run ${id} is incomplete: ${error instanceof Error ? error.message : String(error)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Count-based history retention: of the runs past the newest `MAX_RUNS_KEPT` unarchived ones,
|
|
167
|
+
* archive each settled task that is not pinned and whose family this store can claim, together
|
|
168
|
+
* with its workers, once no member of the family is live (hearsay-tools/squawk#777). Ranked over the row keys (the `created_at` index, no record decoded) with memory
|
|
169
|
+
* laid over them, since a run created or archived since the last save has no row yet; the rows
|
|
170
|
+
* past the cut are then filtered in `runs.db`, so only real candidates decode. Archived runs
|
|
171
|
+
* are never deleted by retention — only an explicit delete, worker destruction, or history
|
|
172
|
+
* deletion removes a run.
|
|
173
|
+
*/
|
|
174
|
+
pruneOldRuns() {
|
|
175
|
+
const ranked = new Map();
|
|
176
|
+
for (const key of this.state.db()?.listKeysWhere('archived = ?', [0]) ?? []) {
|
|
177
|
+
if (!this.state.held.has(key.id) && !this.state.deleted.has(key.id))
|
|
178
|
+
ranked.set(key.id, key);
|
|
179
|
+
}
|
|
180
|
+
for (const run of this.state.held.values())
|
|
181
|
+
if (!run.archived)
|
|
182
|
+
ranked.set(run.id, { id: run.id, ...this.state.listOrder(run) });
|
|
183
|
+
const overflow = [...ranked.values()].sort(newestFirst).slice(MAX_RUNS_KEPT).map((key) => key.id);
|
|
184
|
+
if (overflow.length === 0)
|
|
185
|
+
return;
|
|
186
|
+
const stale = overflow.flatMap((id) => {
|
|
187
|
+
const run = this.state.held.get(id);
|
|
188
|
+
// Retention must not archive a live task between turns, a pinned run, or a worker on its own.
|
|
189
|
+
return run && !this.state.hasFallbackRun(id) && RETENTION_RUN_RULE.matches(run) ? [id] : [];
|
|
190
|
+
});
|
|
191
|
+
const skipped = overflow.filter(id => this.state.hasFallbackRun(id)).length;
|
|
192
|
+
if (skipped)
|
|
193
|
+
console.info(`[hsq] Retention skipped ${skipped} read-only fallback run(s) under ${dataReadDirs(this.dataDir)[1]}.`);
|
|
194
|
+
const cold = overflow.filter((id) => !this.state.held.has(id) && !this.state.hasFallbackRun(id));
|
|
195
|
+
if (cold.length > 0) {
|
|
196
|
+
// Another process's runs are its own to keep or archive (#779, plan step 3).
|
|
197
|
+
const rows = this.state.db().listWhere(guardedJsonSql(RETENTION_RUN_RULE.sql, 0), [JSON.stringify(cold)]);
|
|
198
|
+
const writable = this.state.claimFamilies(rows.map(rowFamily));
|
|
199
|
+
for (const row of rows)
|
|
200
|
+
if (writable.has(rowFamily(row)))
|
|
201
|
+
stale.push(row.id);
|
|
202
|
+
}
|
|
203
|
+
for (const id of stale) {
|
|
204
|
+
const run = this.state.record(id);
|
|
205
|
+
if (!run || run.archived || !RETENTION_RUN_RULE.matches(run))
|
|
206
|
+
continue;
|
|
207
|
+
this.archiveSettledFamily(run);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/** Archive a root with its workers unless a member is live, mid-destroy or pinned, or a history
|
|
211
|
+
* deletion is under way. Each member is marked dirty: the next save writes the family at once. */
|
|
212
|
+
archiveSettledFamily(root) {
|
|
213
|
+
assertRunSlotsSealed();
|
|
214
|
+
const workers = this.state.listWorkersOf(root.id), family = [root, ...workers];
|
|
215
|
+
if (family.some((run) => isLiveRecord(run) || run.pinned) || (root.delegation?.role === 'root' && root.delegation.historyDeletion))
|
|
216
|
+
return;
|
|
217
|
+
for (const member of [root, ...workers.flatMap((worker) => this.state.record(worker.id) ?? [])].filter((run) => !run.archived)) {
|
|
218
|
+
this.state.applyArchived(member, true);
|
|
219
|
+
if (!deletionRefusal(member.id, 'archive-tmp', this.dataDir))
|
|
220
|
+
removeAgentTmpDir(this.dataDir, member.id);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=run-retention.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-retention.js","sourceRoot":"","sources":["../../src/runs/run-retention.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG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AAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC;YAAE,OAAO;QAC3I,KAAK,MAAM,MAAM,IAAI,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/H,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC;gBAAE,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAC3G,CAAC;IACH,CAAC;CACF"}
|
package/dist/runs/run-row.d.ts
CHANGED
|
@@ -7,6 +7,17 @@ export { isLiveStatus } from '../contract/index.js';
|
|
|
7
7
|
* the live column.
|
|
8
8
|
*/
|
|
9
9
|
export declare function isLiveRecord(run: RunRecord): boolean;
|
|
10
|
+
/** Where a run lists: by `createdAt`, then by `seq`, its row's insertion order (see the `runs`
|
|
11
|
+
* schema). A `RunRow` is one. */
|
|
12
|
+
export interface ListOrder {
|
|
13
|
+
createdAt: string;
|
|
14
|
+
seq: number;
|
|
15
|
+
}
|
|
16
|
+
/** Newest first, runs created in the same millisecond in insertion order: the order `runs.db`
|
|
17
|
+
* lists in, and the order every list had while it was a stable sort of the in-memory map. */
|
|
18
|
+
export declare function newestFirst(a: ListOrder, b: ListOrder): number;
|
|
19
|
+
/** The family a run belongs to, by its root's id. A worker a worker started is filed under the root too. */
|
|
20
|
+
export declare function familyRootOf(run: Pick<RunRecord, 'id' | 'delegation'>): string | undefined;
|
|
10
21
|
/** A worker family's root once the family may end (hearsay-tools/squawk#911): archived, settled
|
|
11
22
|
* (done, failed or cancelled) and not live. A user may archive a running root; that is no end. */
|
|
12
23
|
export declare function isEndedRoot(run: RunRecord): boolean;
|
package/dist/runs/run-row.js
CHANGED
|
@@ -24,6 +24,21 @@ export function isLiveRecord(run) {
|
|
|
24
24
|
return true;
|
|
25
25
|
return run.stopping !== undefined;
|
|
26
26
|
}
|
|
27
|
+
/** Newest first, runs created in the same millisecond in insertion order: the order `runs.db`
|
|
28
|
+
* lists in, and the order every list had while it was a stable sort of the in-memory map. */
|
|
29
|
+
export function newestFirst(a, b) {
|
|
30
|
+
if (a.createdAt !== b.createdAt)
|
|
31
|
+
return a.createdAt < b.createdAt ? 1 : -1;
|
|
32
|
+
return a.seq < b.seq ? -1 : a.seq > b.seq ? 1 : 0;
|
|
33
|
+
}
|
|
34
|
+
/** The family a run belongs to, by its root's id. A worker a worker started is filed under the root too. */
|
|
35
|
+
export function familyRootOf(run) {
|
|
36
|
+
if (run.delegation?.role === 'root')
|
|
37
|
+
return run.id;
|
|
38
|
+
if (run.delegation?.role === 'worker')
|
|
39
|
+
return run.delegation.parentRunId;
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
27
42
|
/** A worker family's root once the family may end (hearsay-tools/squawk#911): archived, settled
|
|
28
43
|
* (done, failed or cancelled) and not live. A user may archive a running root; that is no end. */
|
|
29
44
|
export function isEndedRoot(run) {
|
package/dist/runs/run-row.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-row.js","sourceRoot":"","sources":["../../src/runs/run-row.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE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rationReceipt } from '../contract/index.js';
|
|
10
10
|
import type { ArchiveFinishedScope, ArchivedRunsResponse, ArchivePullRequestIdentity, ConversationState, AgentInput, InboxClaim, DelegationState, MergedPullRequest, RunSummary, Wait, WorkerCollectedResult, WorkerDestroyRetry } from '../contract/index.js';
|
|
11
11
|
import { type AutomationNames } from '../contract/index.js';
|
|
12
|
-
import {
|
|
12
|
+
import { RunTranscriptFacts } from './transcript-facts-topic.ts';
|
|
13
13
|
import { type WorkerExecutionIdentity } from '../delegation/execution-identity.ts';
|
|
14
14
|
import { type WorkerProcessRecord } from '../core/process-stat.ts';
|
|
15
15
|
import { workflowDefSchema } from '../workflows/types.ts';
|
|
@@ -20,6 +20,7 @@ export { ConversationIdInUseError } from './conversation-identity.ts';
|
|
|
20
20
|
import { RunDatabase, type RunDatabaseChanges, type RunDatabaseCommit } from './run-database.ts';
|
|
21
21
|
import { type BranchOwner } from './branch-owners.ts';
|
|
22
22
|
export { ciWaitEntry, holdsWorkerWait, upgradeLegacyWaits, workerWaitEntry } from './legacy-waits.ts';
|
|
23
|
+
import { RunRetentionTopic } from './run-retention.ts';
|
|
23
24
|
import { type RawExtras } from './raw-record.ts';
|
|
24
25
|
import { RunStoreOpenError } from './store-open-error.ts';
|
|
25
26
|
import { type SpawnCapacityRefusal } from './owned-run-create.ts';
|
|
@@ -3231,8 +3232,6 @@ export declare class RunWriteRefusedError extends Error {
|
|
|
3231
3232
|
readonly ownership: Exclude<RunOwnership, 'held' | 'free'>;
|
|
3232
3233
|
constructor(runId: string, ownership: Exclude<RunOwnership, 'held' | 'free'>, fallbackError?: string);
|
|
3233
3234
|
}
|
|
3234
|
-
/** Newest first, runs created in the same millisecond in insertion order: the order `runs.db`
|
|
3235
|
-
* lists in, and the order every list had while it was a stable sort of the in-memory map. */
|
|
3236
3235
|
/** Why a `run` event fired, when a delegation checkpoint caused it or nothing durable changed
|
|
3237
3236
|
* (`republish`) (in-process only). */
|
|
3238
3237
|
export type CommitSource = 'delegation-checkpoint' | 'delegation-destroy-progress' | 'live-release';
|
|
@@ -3308,11 +3307,11 @@ export declare class RunStore {
|
|
|
3308
3307
|
private readonly unreadable;
|
|
3309
3308
|
/** Background one-at-a-time compressor for archived transcripts (#818). */
|
|
3310
3309
|
private readonly compressor;
|
|
3311
|
-
/**
|
|
3312
|
-
|
|
3310
|
+
/** What the transcript says about a run (hearsay-tools/squawk#4036). */
|
|
3311
|
+
readonly transcriptFacts: RunTranscriptFacts;
|
|
3312
|
+
/** Whether a run may go, and its deletion; the count-based archive (hearsay-tools/squawk#4037). */
|
|
3313
|
+
readonly retention: RunRetentionTopic;
|
|
3313
3314
|
private readonly liveItems;
|
|
3314
|
-
private fallbackFacts;
|
|
3315
|
-
private factsFor;
|
|
3316
3315
|
/** Capture both sources on the same synchronous sequence boundary before history IO. */
|
|
3317
3316
|
liveReadSnapshot(runId: string): {
|
|
3318
3317
|
events: {
|
|
@@ -3364,7 +3363,6 @@ export declare class RunStore {
|
|
|
3364
3363
|
sourceDataDir(id: string): string;
|
|
3365
3364
|
isFallbackRun(id: string): boolean;
|
|
3366
3365
|
hasFallbackRun(id: string): boolean;
|
|
3367
|
-
fallbackDeleteError(id: string, kind?: 'record' | 'worktree'): string | undefined;
|
|
3368
3366
|
/**
|
|
3369
3367
|
* Open-time load: the live rows, the finished rows a load normalization repairs, then the
|
|
3370
3368
|
* delegation families of the live ones. A row that does not parse is skipped and left in the
|
|
@@ -3935,24 +3933,9 @@ export declare class RunStore {
|
|
|
3935
3933
|
* the `CEZ_REDACT_SECRETS=0` opt-out itself so every caller inherits it. */
|
|
3936
3934
|
redactText(text: string): string;
|
|
3937
3935
|
private hostSecrets;
|
|
3938
|
-
/** The run's indexed transcript facts (#880): a read-only view, never a transcript read once
|
|
3939
|
-
* the run's index is loaded. An unreadable transcript answers as empty, as readEvents does. */
|
|
3940
|
-
transcriptFacts(runId: string): Readonly<TranscriptFacts>;
|
|
3941
|
-
/** The run's transcript facts when they are known: undefined when the transcript exists but its
|
|
3942
|
-
* facts are not current or cannot be read, so a caller can tell "no ask" from "no evidence". */
|
|
3943
|
-
knownTranscriptFacts(runId: string): Readonly<TranscriptFacts> | undefined;
|
|
3944
3936
|
hasProjection(runId: string, projectionId: string): boolean;
|
|
3945
|
-
private factsWarming;
|
|
3946
3937
|
/** Indexed family enumeration, including members not yet flushed to SQLite. */
|
|
3947
3938
|
listFamilyRunIds(rootId: string): string[];
|
|
3948
|
-
private recoveryFactIds;
|
|
3949
|
-
/** Readiness owns no run snapshot across an await: refresh only the currently held owner. */
|
|
3950
|
-
prepareTranscriptFacts(runIds: Iterable<string>): Promise<void>;
|
|
3951
|
-
prepareRecoveryFacts(familyRootId?: string): Promise<void>;
|
|
3952
|
-
/** Register IDs only here; the index yields between cache reads and off-loop rebuilds. */
|
|
3953
|
-
private warmTranscriptFacts;
|
|
3954
|
-
/** Resolves when the open-time warm-up is done (tests). */
|
|
3955
|
-
factsWarmIdle(): Promise<void>;
|
|
3956
3939
|
/** `readEvents` off the event loop (async read and async brotli), for collection paths. */
|
|
3957
3940
|
readEventsAsync(runId: string): Promise<RunEvent[]>;
|
|
3958
3941
|
readEvents(runId: string): RunEvent[];
|
|
@@ -4001,13 +3984,6 @@ export declare class RunStore {
|
|
|
4001
3984
|
/** A deleted child's receipt replaces the private proof only after the deletion checkpoint. */
|
|
4002
3985
|
private workerDeletionEvidence;
|
|
4003
3986
|
private workerDeletionResult;
|
|
4004
|
-
canDeleteRun(id: string, kind?: 'record' | 'worktree'): boolean;
|
|
4005
|
-
/** Delegated history deletion is synchronous and checkpointed; any failed byte/index removal remains retryable. */
|
|
4006
|
-
private deleteDelegatedRun;
|
|
4007
|
-
private removeRunHistoryBytes;
|
|
4008
|
-
/** The run's history, handoff and images, then the removal cleanups (`runs/removal-slots.ts`). */
|
|
4009
|
-
private removeHistoryFiles;
|
|
4010
|
-
deleteRun(id: string): boolean;
|
|
4011
3987
|
/** Write the pending rows out now (used on shutdown). */
|
|
4012
3988
|
flush(): void;
|
|
4013
3989
|
private seqs;
|
|
@@ -4031,22 +4007,6 @@ export declare class RunStore {
|
|
|
4031
4007
|
/** The held record is gone; the next save or commit deletes its row, fenced by `family`'s claim
|
|
4032
4008
|
* and by the revision this store last saw (kept in `base` until the delete is written). */
|
|
4033
4009
|
private markDeleted;
|
|
4034
|
-
/** A deleted run's history files and removal cleanups, once the delete of its row has committed.
|
|
4035
|
-
* Best effort: a failure is logged, and the row stays deleted. */
|
|
4036
|
-
private removeOwedHistory;
|
|
4037
|
-
/**
|
|
4038
|
-
* Count-based history retention: of the runs past the newest `MAX_RUNS_KEPT` unarchived ones,
|
|
4039
|
-
* archive each settled task that is not pinned and whose family this store can claim, together
|
|
4040
|
-
* with its workers, once no member of the family is live (hearsay-tools/squawk#777). Ranked over the row keys (the `created_at` index, no record decoded) with memory
|
|
4041
|
-
* laid over them, since a run created or archived since the last save has no row yet; the rows
|
|
4042
|
-
* past the cut are then filtered in `runs.db`, so only real candidates decode. Archived runs
|
|
4043
|
-
* are never deleted by retention — only an explicit delete, worker destruction, or history
|
|
4044
|
-
* deletion removes a run.
|
|
4045
|
-
*/
|
|
4046
|
-
private pruneOldRuns;
|
|
4047
|
-
/** Archive a root with its workers unless a member is live, mid-destroy or pinned, or a history
|
|
4048
|
-
* deletion is under way. Each member is marked dirty: the next save writes the family at once. */
|
|
4049
|
-
private archiveSettledFamily;
|
|
4050
4010
|
/** Debounced so token-usage updates don't rewrite a row per event. Nothing to schedule without
|
|
4051
4011
|
* a database: a `RunStore.unavailable` store, or a closed one, writes nothing. */
|
|
4052
4012
|
private scheduleSave;
|