@noetic-tools/core 5.13.0 → 5.14.1
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/builders/decide-builders.d.ts +2 -2
- package/dist/builders/dynamic-workflow.js +2 -0
- package/dist/builders/provide-builder.d.ts +2 -2
- package/dist/builders/spawn-builder.d.ts +2 -2
- package/dist/builders/step-builders.d.ts +5 -5
- package/dist/builders/workflow-hydrator.d.ts +1 -1
- package/dist/builders/workflow-hydrator.js +53 -3
- package/dist/expression/check.js +14 -0
- package/dist/expression/jsonata.d.ts +7 -0
- package/dist/expression/jsonata.js +11 -1
- package/dist/harness/agent-harness.d.ts +59 -5
- package/dist/harness/agent-harness.js +176 -25
- package/dist/harness/deps/runtime.d.ts +4 -0
- package/dist/harness/deps/runtime.js +2 -0
- package/dist/harness/model-call.js +69 -0
- package/dist/harness/model-rounds.d.ts +52 -0
- package/dist/harness/model-rounds.js +115 -0
- package/dist/harness/thread-record.d.ts +54 -0
- package/dist/harness/thread-record.js +159 -0
- package/dist/index.d.ts +2 -2
- package/dist/interpreter/emit-items.d.ts +19 -0
- package/dist/interpreter/emit-items.js +106 -0
- package/dist/interpreter/execute-action.js +4 -1
- package/dist/interpreter/execute-control.js +7 -3
- package/dist/interpreter/execute.js +66 -9
- package/dist/observability/span-impl.d.ts +9 -0
- package/dist/observability/span-impl.js +13 -0
- package/dist/runtime/context-impl.d.ts +156 -14
- package/dist/runtime/context-impl.js +326 -28
- package/dist/runtime/durable/harness-checkpoints.d.ts +13 -3
- package/dist/runtime/durable/harness-checkpoints.js +66 -7
- package/dist/runtime/durable/session-store.d.ts +37 -0
- package/dist/runtime/durable/session-store.js +58 -0
- package/dist/runtime/durable/step-ledger.d.ts +77 -40
- package/dist/runtime/durable/step-ledger.js +193 -73
- package/dist/runtime/item-log-impl.d.ts +6 -0
- package/dist/runtime/item-log-impl.js +12 -0
- package/dist/runtime/session-runner.d.ts +25 -1
- package/dist/runtime/session-runner.js +83 -11
- package/dist/schemas/workflow.d.ts +1 -1
- package/dist/types/checkpoint.d.ts +21 -4
- package/dist/types/checkpoint.js +33 -3
- package/package.json +2 -2
- package/schema/noetic-workflow.schema.json +391 -0
|
@@ -43,11 +43,16 @@ export interface CheckpointHarnessHandle {
|
|
|
43
43
|
* `CheckpointStore` is configured — zero-config harnesses preserve
|
|
44
44
|
* ephemeral semantics. Save failures are logged rather than thrown,
|
|
45
45
|
* because a checkpoint failing must never abort an otherwise-successful
|
|
46
|
-
* step.
|
|
46
|
+
* step. Resolves true when a snapshot landed.
|
|
47
|
+
*
|
|
48
|
+
* The item log and dispatch counts are the run's baseline (see
|
|
49
|
+
* `ContextImpl.runBaseline`); layer state, channels, `ctx.state`, and usage are
|
|
50
|
+
* live, because replay does not redo those — a replayed step neither folds into
|
|
51
|
+
* layers nor writes state nor spends tokens.
|
|
47
52
|
*
|
|
48
53
|
* @internal
|
|
49
54
|
*/
|
|
50
|
-
export declare function captureCheckpoint(h: CheckpointHarnessHandle, ctx: Context): Promise<
|
|
55
|
+
export declare function captureCheckpoint(h: CheckpointHarnessHandle, ctx: Context): Promise<boolean>;
|
|
51
56
|
/**
|
|
52
57
|
* What `restoreFromCheckpoint` rebuilt. `fromSnapshot` is false for a ledger-only
|
|
53
58
|
* restore, whose layer state was never recovered — the harness must then let layer
|
|
@@ -61,7 +66,12 @@ export interface RestoredExecution {
|
|
|
61
66
|
}
|
|
62
67
|
/**
|
|
63
68
|
* Rebuild a `Context` for `executionId` from what a previous run recorded: the
|
|
64
|
-
* checkpoint snapshot and the step-completion ledger. Either is enough.
|
|
69
|
+
* checkpoint snapshot and the step-completion ledger. Either is enough.
|
|
70
|
+
*
|
|
71
|
+
* The restored context stands where the interrupted run began — its item log and
|
|
72
|
+
* dispatch counts are that run's baseline — with the live layer state, channels,
|
|
73
|
+
* `ctx.state`, and usage. Re-running the same step on the same input replays every
|
|
74
|
+
* recorded step and continues live from the first that was not. Returns
|
|
65
75
|
* `null` only when neither exists, so the caller starts a fresh execution.
|
|
66
76
|
*
|
|
67
77
|
* - With a snapshot, the item log, layer state, channel state, cwd, and thread/resource
|
|
@@ -8,14 +8,19 @@ import { StepLedger } from './step-ledger.js';
|
|
|
8
8
|
* `CheckpointStore` is configured — zero-config harnesses preserve
|
|
9
9
|
* ephemeral semantics. Save failures are logged rather than thrown,
|
|
10
10
|
* because a checkpoint failing must never abort an otherwise-successful
|
|
11
|
-
* step.
|
|
11
|
+
* step. Resolves true when a snapshot landed.
|
|
12
|
+
*
|
|
13
|
+
* The item log and dispatch counts are the run's baseline (see
|
|
14
|
+
* `ContextImpl.runBaseline`); layer state, channels, `ctx.state`, and usage are
|
|
15
|
+
* live, because replay does not redo those — a replayed step neither folds into
|
|
16
|
+
* layers nor writes state nor spends tokens.
|
|
12
17
|
*
|
|
13
18
|
* @internal
|
|
14
19
|
*/
|
|
15
20
|
export async function captureCheckpoint(h, ctx) {
|
|
16
21
|
const store = h.checkpointStore;
|
|
17
22
|
if (!store) {
|
|
18
|
-
return;
|
|
23
|
+
return false;
|
|
19
24
|
}
|
|
20
25
|
const impl = ctx instanceof ContextImpl ? ctx : null;
|
|
21
26
|
const frontier = impl ? impl.serialiseFrontier() : [];
|
|
@@ -26,6 +31,13 @@ export async function captureCheckpoint(h, ctx) {
|
|
|
26
31
|
layers[layer.id] = state;
|
|
27
32
|
}
|
|
28
33
|
}
|
|
34
|
+
const baseline = impl?.runBaseline() ?? {
|
|
35
|
+
items: [
|
|
36
|
+
...ctx.itemLog.items,
|
|
37
|
+
],
|
|
38
|
+
occurrences: {},
|
|
39
|
+
};
|
|
40
|
+
const state = jsonCopy(ctx.state);
|
|
29
41
|
const snapshot = {
|
|
30
42
|
schemaVersion: CheckpointSchemaVersion,
|
|
31
43
|
executionId: ctx.id,
|
|
@@ -43,9 +55,19 @@ export async function captureCheckpoint(h, ctx) {
|
|
|
43
55
|
// means future producers don't bump the schema version.
|
|
44
56
|
askUser: [],
|
|
45
57
|
itemLog: {
|
|
46
|
-
items:
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
items: baseline.items,
|
|
59
|
+
},
|
|
60
|
+
occurrences: baseline.occurrences,
|
|
61
|
+
...(state.ok
|
|
62
|
+
? {
|
|
63
|
+
state: state.value,
|
|
64
|
+
}
|
|
65
|
+
: {}),
|
|
66
|
+
usage: {
|
|
67
|
+
tokens: {
|
|
68
|
+
...ctx.tokens,
|
|
69
|
+
},
|
|
70
|
+
cost: ctx.cost,
|
|
49
71
|
},
|
|
50
72
|
// Channel state belongs to the root execution, so a child checkpoint
|
|
51
73
|
// carries the channels its root used.
|
|
@@ -54,14 +76,40 @@ export async function captureCheckpoint(h, ctx) {
|
|
|
54
76
|
};
|
|
55
77
|
try {
|
|
56
78
|
await store.save(snapshot);
|
|
79
|
+
return true;
|
|
57
80
|
}
|
|
58
81
|
catch (err) {
|
|
59
82
|
console.warn(`AgentHarness.checkpoint: failed to persist snapshot for execution "${ctx.id}":`, err);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** A JSON round-trip copy of `value`, or `ok: false` when it does not survive one. */
|
|
87
|
+
function jsonCopy(value) {
|
|
88
|
+
try {
|
|
89
|
+
const json = JSON.stringify(value);
|
|
90
|
+
return json === undefined
|
|
91
|
+
? {
|
|
92
|
+
ok: false,
|
|
93
|
+
}
|
|
94
|
+
: {
|
|
95
|
+
ok: true,
|
|
96
|
+
value: JSON.parse(json),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return {
|
|
101
|
+
ok: false,
|
|
102
|
+
};
|
|
60
103
|
}
|
|
61
104
|
}
|
|
62
105
|
/**
|
|
63
106
|
* Rebuild a `Context` for `executionId` from what a previous run recorded: the
|
|
64
|
-
* checkpoint snapshot and the step-completion ledger. Either is enough.
|
|
107
|
+
* checkpoint snapshot and the step-completion ledger. Either is enough.
|
|
108
|
+
*
|
|
109
|
+
* The restored context stands where the interrupted run began — its item log and
|
|
110
|
+
* dispatch counts are that run's baseline — with the live layer state, channels,
|
|
111
|
+
* `ctx.state`, and usage. Re-running the same step on the same input replays every
|
|
112
|
+
* recorded step and continues live from the first that was not. Returns
|
|
65
113
|
* `null` only when neither exists, so the caller starts a fresh execution.
|
|
66
114
|
*
|
|
67
115
|
* - With a snapshot, the item log, layer state, channel state, cwd, and thread/resource
|
|
@@ -117,13 +165,24 @@ function contextFromSnapshot(h, snapshot, opts) {
|
|
|
117
165
|
/* Caller wiring first, snapshot second: a host may legitimately swap the context
|
|
118
166
|
* layers or hang the restored execution under a new parent, but it must never be
|
|
119
167
|
* able to override the identity/history the snapshot is the record of. */
|
|
120
|
-
|
|
168
|
+
const ctx = h.createContext({
|
|
121
169
|
...opts,
|
|
170
|
+
state: opts?.state ?? snapshot.state,
|
|
122
171
|
items: h.itemSchemas.parseMany(snapshot.itemLog.items),
|
|
123
172
|
threadId: snapshot.threadId,
|
|
124
173
|
resourceId: snapshot.resourceId,
|
|
125
174
|
cwdInit: snapshot.cwd?.current ?? undefined,
|
|
126
175
|
});
|
|
176
|
+
if (ctx instanceof ContextImpl) {
|
|
177
|
+
ctx.restoreOccurrences(snapshot.occurrences);
|
|
178
|
+
if (snapshot.usage) {
|
|
179
|
+
ctx.tokens = {
|
|
180
|
+
...snapshot.usage.tokens,
|
|
181
|
+
};
|
|
182
|
+
ctx.cost = snapshot.usage.cost;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return ctx;
|
|
127
186
|
}
|
|
128
187
|
/**
|
|
129
188
|
* Give `ctx` the original execution id and the ledger recorded under it.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a session (`harness.execute()`) keeps in storage so a new harness can pick a
|
|
3
|
+
* thread up: the thread's history, what its turns spent, and the turn in flight.
|
|
4
|
+
*
|
|
5
|
+
* A turn's record is written before the turn runs and cleared when it finishes. A
|
|
6
|
+
* harness that finds one still set knows the turn was cut off. If the same messages
|
|
7
|
+
* arrive again — a host with at-least-once delivery re-sends what it never saw
|
|
8
|
+
* answered — the turn resumes on its recorded execution: finished steps replay and
|
|
9
|
+
* the turn continues from the step that was cut off.
|
|
10
|
+
*/
|
|
11
|
+
import type { StorageAdapter } from '@noetic-tools/context';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
declare const SessionRecordSchema: z.ZodObject<{
|
|
14
|
+
items: z.ZodArray<z.ZodUnknown>;
|
|
15
|
+
usage: z.ZodOptional<z.ZodObject<{
|
|
16
|
+
inputTokens: z.ZodNumber;
|
|
17
|
+
outputTokens: z.ZodNumber;
|
|
18
|
+
cachedTokens: z.ZodOptional<z.ZodNumber>;
|
|
19
|
+
cost: z.ZodOptional<z.ZodNumber>;
|
|
20
|
+
billedCost: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
}, z.core.$strip>>;
|
|
22
|
+
turn: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
executionId: z.ZodString;
|
|
24
|
+
messageIds: z.ZodArray<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
/** @internal One thread's stored session. */
|
|
28
|
+
export type SessionRecord = z.infer<typeof SessionRecordSchema>;
|
|
29
|
+
/** @internal Reads and writes session records under `session:<threadId>`. */
|
|
30
|
+
export interface SessionStore {
|
|
31
|
+
/** The thread's record, or undefined when none is stored or it does not parse. */
|
|
32
|
+
load(threadId: string): Promise<SessionRecord | undefined>;
|
|
33
|
+
save(threadId: string, record: SessionRecord): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** @internal */
|
|
36
|
+
export declare function createSessionStore(storage: StorageAdapter): SessionStore;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a session (`harness.execute()`) keeps in storage so a new harness can pick a
|
|
3
|
+
* thread up: the thread's history, what its turns spent, and the turn in flight.
|
|
4
|
+
*
|
|
5
|
+
* A turn's record is written before the turn runs and cleared when it finishes. A
|
|
6
|
+
* harness that finds one still set knows the turn was cut off. If the same messages
|
|
7
|
+
* arrive again — a host with at-least-once delivery re-sends what it never saw
|
|
8
|
+
* answered — the turn resumes on its recorded execution: finished steps replay and
|
|
9
|
+
* the turn continues from the step that was cut off.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
//#region Schema
|
|
13
|
+
const SessionRecordSchema = z.object({
|
|
14
|
+
/** The thread's history after its last finished turn. */
|
|
15
|
+
items: z.array(z.unknown()),
|
|
16
|
+
/** What the thread's turns have spent, summed as each turn settles. */
|
|
17
|
+
usage: z
|
|
18
|
+
.object({
|
|
19
|
+
inputTokens: z.number(),
|
|
20
|
+
outputTokens: z.number(),
|
|
21
|
+
cachedTokens: z.number().optional(),
|
|
22
|
+
cost: z.number().optional(),
|
|
23
|
+
billedCost: z.number().optional(),
|
|
24
|
+
})
|
|
25
|
+
.optional(),
|
|
26
|
+
/** The turn in flight, if one was cut off. */
|
|
27
|
+
turn: z
|
|
28
|
+
.object({
|
|
29
|
+
executionId: z.string(),
|
|
30
|
+
/** The ids of the messages the turn delivers, in order. */
|
|
31
|
+
messageIds: z.array(z.string()),
|
|
32
|
+
})
|
|
33
|
+
.optional(),
|
|
34
|
+
});
|
|
35
|
+
/** @internal */
|
|
36
|
+
export function createSessionStore(storage) {
|
|
37
|
+
return {
|
|
38
|
+
load: async (threadId) => {
|
|
39
|
+
const raw = await storage.get(sessionKey(threadId));
|
|
40
|
+
if (raw === null) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const parsed = SessionRecordSchema.safeParse(raw);
|
|
44
|
+
if (!parsed.success) {
|
|
45
|
+
console.warn(`SessionStore: discarding unreadable session "${threadId}": ${parsed.error.message}`);
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return parsed.data;
|
|
49
|
+
},
|
|
50
|
+
save: async (threadId, record) => {
|
|
51
|
+
await storage.set(sessionKey(threadId), record);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function sessionKey(threadId) {
|
|
56
|
+
return `session:${threadId}`;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
@@ -17,11 +17,19 @@
|
|
|
17
17
|
* `key:<replayKey>` instead: content-addressed, so it finds its output wherever it
|
|
18
18
|
* runs. A `durable: false` step has no key and is never recorded.
|
|
19
19
|
*
|
|
20
|
+
* An entry also carries what replay must put back: the items the step appended to its
|
|
21
|
+
* context's item log (a checkpoint holds the log as it stood when the run began, so the
|
|
22
|
+
* replayed steps rebuild the rest), and a hash of the step's input, so a step whose input
|
|
23
|
+
* changed since it was recorded runs again instead of replaying an answer to a
|
|
24
|
+
* different question.
|
|
25
|
+
*
|
|
20
26
|
* Sharding bounds the cost of one append but not the total, so retention is bounded on
|
|
21
27
|
* two axes (`StepLedgerRetention`): an oversized entry is dropped rather than written,
|
|
22
|
-
* and
|
|
23
|
-
*
|
|
24
|
-
*
|
|
28
|
+
* and once `maxEntries` are live nothing more is recorded. Entries beneath a parent that
|
|
29
|
+
* recorded are pruned, since a resumed run replays the parent without descending, so the
|
|
30
|
+
* live count tracks the open part of the run rather than its length. Both degradations
|
|
31
|
+
* are safe by construction — a missing entry re-runs its step, which costs work rather
|
|
32
|
+
* than correctness.
|
|
25
33
|
*/
|
|
26
34
|
import type { StorageAdapter } from '@noetic-tools/context';
|
|
27
35
|
import { z } from 'zod';
|
|
@@ -33,6 +41,9 @@ export declare const StepLedgerEntrySchema: z.ZodObject<{
|
|
|
33
41
|
stepId: z.ZodString;
|
|
34
42
|
kind: z.ZodString;
|
|
35
43
|
output: z.ZodUnknown;
|
|
44
|
+
inputHash: z.ZodOptional<z.ZodString>;
|
|
45
|
+
items: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
46
|
+
streamed: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
36
47
|
completedAt: z.ZodString;
|
|
37
48
|
}, z.core.$strip>;
|
|
38
49
|
/** @public A completed step recorded for replay. */
|
|
@@ -46,8 +57,9 @@ export type StepLedgerEntry = z.infer<typeof StepLedgerEntrySchema>;
|
|
|
46
57
|
*/
|
|
47
58
|
export interface StepLedgerRetention {
|
|
48
59
|
/**
|
|
49
|
-
* Largest
|
|
50
|
-
*
|
|
60
|
+
* Largest entry that will be recorded, in UTF-8 bytes of the JSON encoding of the
|
|
61
|
+
* step's output plus the items it appended. A step whose entry exceeds this is not
|
|
62
|
+
* recorded at all and re-runs on resume. Keeps one
|
|
51
63
|
* entry inside the per-value limit real storage backends impose (128 KiB on several)
|
|
52
64
|
* instead of failing the write. Pass `Infinity` to record any size.
|
|
53
65
|
*
|
|
@@ -55,9 +67,10 @@ export interface StepLedgerRetention {
|
|
|
55
67
|
*/
|
|
56
68
|
maxEntryBytes?: number;
|
|
57
69
|
/**
|
|
58
|
-
* Most entries
|
|
59
|
-
*
|
|
60
|
-
*
|
|
70
|
+
* Most live entries for one execution. Once the cap is reached nothing more is
|
|
71
|
+
* recorded, so resume replays the head of the run and runs the rest again. Entries
|
|
72
|
+
* beneath a parent that recorded do not count — they are pruned. Pass `Infinity` to
|
|
73
|
+
* record without limit.
|
|
61
74
|
*
|
|
62
75
|
* Defaults to `DEFAULT_STEP_LEDGER_RETENTION.maxEntries` (1000).
|
|
63
76
|
*/
|
|
@@ -77,22 +90,30 @@ export declare const DEFAULT_STEP_LEDGER_RETENTION: {
|
|
|
77
90
|
* @throws NoeticConfigError `code: 'STEP_LEDGER_RETENTION_INVALID'`
|
|
78
91
|
*/
|
|
79
92
|
export declare function resolveStepLedgerRetention(retention?: StepLedgerRetention): Required<StepLedgerRetention>;
|
|
93
|
+
/**
|
|
94
|
+
* @internal
|
|
95
|
+
* A short, stable hash of a step input's JSON encoding, or undefined when the input
|
|
96
|
+
* cannot be encoded (a cycle, a `BigInt`). A replayed output becomes the next step's
|
|
97
|
+
* input after a JSON round trip, and `JSON.stringify` gives the same text for a value
|
|
98
|
+
* and its round-tripped copy, so a resumed run hashes the same inputs the first run did.
|
|
99
|
+
*/
|
|
100
|
+
export declare function hashStepInput(input: unknown): string | undefined;
|
|
80
101
|
/** Storage key prefix owning every ledger entry for one execution. */
|
|
81
102
|
export declare function stepLedgerPrefix(executionId: string): string;
|
|
82
103
|
/**
|
|
83
104
|
* @public
|
|
84
105
|
* Everything one execution's ledger recovered from storage: the entries available for
|
|
85
106
|
* replay plus the sequence bookkeeping a further append needs. `nextSeq` cannot be
|
|
86
|
-
* derived from `entries.size` —
|
|
87
|
-
*
|
|
107
|
+
* derived from `entries.size` — pruning leaves gaps, and reusing a live sequence number
|
|
108
|
+
* would overwrite an entry the resumed run still has to replay.
|
|
88
109
|
*/
|
|
89
110
|
export interface StepLedgerWindow {
|
|
90
111
|
/** Recovered entries, keyed by execution path. Corrupt rows are skipped. */
|
|
91
112
|
entries: Map<string, StepLedgerEntry>;
|
|
113
|
+
/** Sequence number holding each recovered path, so pruning can delete it. */
|
|
114
|
+
seqs: Map<string, number>;
|
|
92
115
|
/** Sequence number the next append takes: highest recorded, plus one. */
|
|
93
116
|
nextSeq: number;
|
|
94
|
-
/** Lowest sequence number still in storage — where eviction resumes. */
|
|
95
|
-
oldestSeq: number;
|
|
96
117
|
}
|
|
97
118
|
/**
|
|
98
119
|
* @public
|
|
@@ -124,8 +145,16 @@ export interface StepLedgerStats {
|
|
|
124
145
|
droppedOversize: number;
|
|
125
146
|
/** Entries not written because their output does not survive JSON encoding. */
|
|
126
147
|
droppedUnserialisable: number;
|
|
127
|
-
/** Entries
|
|
128
|
-
|
|
148
|
+
/** Entries not written because `maxEntries` were already live. */
|
|
149
|
+
droppedFull: number;
|
|
150
|
+
/** Entries deleted because a parent above them recorded. */
|
|
151
|
+
pruned: number;
|
|
152
|
+
}
|
|
153
|
+
/** What a recorded step leaves for replay: the step's identity and input hash. */
|
|
154
|
+
export interface StepLedgerMatch {
|
|
155
|
+
id: string;
|
|
156
|
+
kind: string;
|
|
157
|
+
inputHash: string | undefined;
|
|
129
158
|
}
|
|
130
159
|
/**
|
|
131
160
|
* @public
|
|
@@ -134,16 +163,16 @@ export interface StepLedgerStats {
|
|
|
134
163
|
*
|
|
135
164
|
* Shared by reference across inParallel/spawn children so one execution has one ledger —
|
|
136
165
|
* path keys are globally unique across the step tree, so a flat map is correct. That
|
|
137
|
-
* sharing is also why retention lives here rather than in the store: the
|
|
138
|
-
*
|
|
166
|
+
* sharing is also why retention lives here rather than in the store: the live set that
|
|
167
|
+
* the entry cap counts belongs to the execution, not to the harness.
|
|
139
168
|
*/
|
|
140
169
|
export declare class StepLedger {
|
|
141
|
-
/** Recovered entries, by path.
|
|
170
|
+
/** Recovered entries, by path. */
|
|
142
171
|
private readonly replayable;
|
|
172
|
+
/** Sequence number holding each live entry, recovered or recorded, by path. */
|
|
173
|
+
private readonly live;
|
|
143
174
|
/** Sequence number the next recorded entry takes. */
|
|
144
175
|
private seq;
|
|
145
|
-
/** Lowest sequence number still in storage — advances as eviction proceeds. */
|
|
146
|
-
private oldestSeq;
|
|
147
176
|
private readonly store?;
|
|
148
177
|
private readonly executionId;
|
|
149
178
|
private readonly retention;
|
|
@@ -155,38 +184,46 @@ export declare class StepLedger {
|
|
|
155
184
|
recovered?: StepLedgerWindow;
|
|
156
185
|
retention?: StepLedgerRetention;
|
|
157
186
|
});
|
|
187
|
+
/**
|
|
188
|
+
* Take what storage now holds for this execution in place of what this ledger has
|
|
189
|
+
* in memory — for a run retried in place, which replays what was stored.
|
|
190
|
+
*/
|
|
191
|
+
adopt(recovered: StepLedgerWindow): void;
|
|
158
192
|
/** True when this execution has nothing recovered to replay (the common, fresh case). */
|
|
159
193
|
get isEmpty(): boolean;
|
|
160
194
|
/** What retention has done so far. A snapshot — safe to hold. */
|
|
161
195
|
get stats(): StepLedgerStats;
|
|
162
196
|
/**
|
|
163
|
-
* The recorded
|
|
164
|
-
* A divergence
|
|
165
|
-
* runs fresh. At a positional path it also discards every entry
|
|
166
|
-
* the subtree's
|
|
167
|
-
* entry discards only itself:
|
|
168
|
-
*
|
|
197
|
+
* The recorded entry for `path`, when a previous run completed the same step there on
|
|
198
|
+
* the same input. A divergence — a different step id, kind, or input — returns
|
|
199
|
+
* undefined so the step runs fresh. At a positional path it also discards every entry
|
|
200
|
+
* recorded beneath it: the subtree's outputs belong to a run that no longer exists. A
|
|
201
|
+
* `key:` entry discards only itself: nothing is nested under a content key.
|
|
202
|
+
*
|
|
203
|
+
* An entry recorded without an input hash matches on identity alone.
|
|
204
|
+
*/
|
|
205
|
+
take(path: string, step: StepLedgerMatch): StepLedgerEntry | undefined;
|
|
206
|
+
/**
|
|
207
|
+
* Record a completed step, then prune what it makes dead: a resumed run replays this
|
|
208
|
+
* entry without descending, so nothing recorded beneath it will be read again.
|
|
209
|
+
* Best-effort: a failed write costs resumability, not the run.
|
|
169
210
|
*/
|
|
170
|
-
take(path: string, step: {
|
|
171
|
-
id: string;
|
|
172
|
-
kind: string;
|
|
173
|
-
}): StepLedgerEntry | undefined;
|
|
174
|
-
/** Drop `path` and everything recorded below it. */
|
|
175
|
-
private discardSubtree;
|
|
176
|
-
/** Record a completed step. Best-effort: a failed write costs resumability, not the run. */
|
|
177
211
|
record(entry: StepLedgerEntry): Promise<void>;
|
|
178
212
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
213
|
+
* Drop every positional entry. A host calls this once a run has finished and the
|
|
214
|
+
* checkpoint holds its result: every later resume starts past them, so they are dead.
|
|
215
|
+
* `key:` entries stay — they are keyed by content, and a later run may ask the same.
|
|
182
216
|
*/
|
|
183
|
-
|
|
217
|
+
dropPaths(): Promise<void>;
|
|
218
|
+
private prune;
|
|
219
|
+
private deleteSeq;
|
|
184
220
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* correct without a `list()` per append.
|
|
221
|
+
* Whether this entry is small enough, encodable, and within the live cap. An entry
|
|
222
|
+
* that fails any test is not recorded, so its step re-runs on resume.
|
|
188
223
|
*/
|
|
189
|
-
private
|
|
224
|
+
private retainable;
|
|
225
|
+
/** Live entries once recording at `path` has pruned what lies beneath it. */
|
|
226
|
+
private liveAfter;
|
|
190
227
|
/** One warning per reason per execution — a long run would otherwise flood the log. */
|
|
191
228
|
private warnOnFirstDrop;
|
|
192
229
|
}
|