@noetic-tools/core 5.12.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/adapters/in-memory-subprocess/step-completion.d.ts +2 -2
  2. package/dist/adapters/in-memory-subprocess/step-completion.js +48 -52
  3. package/dist/adapters/in-memory-subprocess/types.d.ts +3 -6
  4. package/dist/adapters/in-memory-subprocess-adapter.js +30 -48
  5. package/dist/adapters/live-handles.d.ts +26 -0
  6. package/dist/adapters/live-handles.js +50 -0
  7. package/dist/builders/workflow-hydrator.js +1 -3
  8. package/dist/harness/agent-harness.d.ts +52 -5
  9. package/dist/harness/agent-harness.js +175 -25
  10. package/dist/harness/deps/runtime.d.ts +4 -0
  11. package/dist/harness/deps/runtime.js +2 -0
  12. package/dist/harness/model-call.js +69 -0
  13. package/dist/harness/model-rounds.d.ts +52 -0
  14. package/dist/harness/model-rounds.js +115 -0
  15. package/dist/harness/thread-record.d.ts +54 -0
  16. package/dist/harness/thread-record.js +159 -0
  17. package/dist/index.d.ts +5 -1
  18. package/dist/index.js +2 -0
  19. package/dist/interpreter/execute-action.js +3 -0
  20. package/dist/interpreter/execute-control.js +3 -0
  21. package/dist/interpreter/execute.js +59 -12
  22. package/dist/interpreter/step-dispatcher.d.ts +2 -2
  23. package/dist/interpreter/step-dispatcher.js +3 -5
  24. package/dist/runtime/context-impl.d.ts +93 -4
  25. package/dist/runtime/context-impl.js +191 -14
  26. package/dist/runtime/durable/harness-checkpoints.d.ts +13 -3
  27. package/dist/runtime/durable/harness-checkpoints.js +66 -7
  28. package/dist/runtime/durable/session-store.d.ts +37 -0
  29. package/dist/runtime/durable/session-store.js +58 -0
  30. package/dist/runtime/durable/step-ledger.d.ts +76 -40
  31. package/dist/runtime/durable/step-ledger.js +188 -73
  32. package/dist/runtime/item-log-impl.d.ts +6 -0
  33. package/dist/runtime/item-log-impl.js +12 -0
  34. package/dist/runtime/session-runner.d.ts +25 -1
  35. package/dist/runtime/session-runner.js +83 -11
  36. package/dist/types/checkpoint.d.ts +21 -4
  37. package/dist/types/checkpoint.js +33 -3
  38. package/dist/util/detached-handle.d.ts +9 -20
  39. package/dist/util/detached-handle.js +7 -108
  40. package/package.json +2 -2
@@ -1,3 +1,3 @@
1
1
  import type { CompleteProcessRunParams, CompleteStepRunParams } from './types.js';
2
- export declare function completeProcessRun({ request, handle, run, handles, active, save, clearIfDurable, }: CompleteProcessRunParams): Promise<void>;
3
- export declare function completeStepRun({ request, handle, stepRunner, handles, active, save, clearIfDurable, }: CompleteStepRunParams): Promise<void>;
2
+ export declare function completeProcessRun({ request, handle, run, live, clearIfDurable, }: CompleteProcessRunParams): Promise<void>;
3
+ export declare function completeStepRun({ request, handle, stepRunner, live, clearIfDurable, }: CompleteStepRunParams): Promise<void>;
@@ -1,42 +1,26 @@
1
1
  import { nowIso, serializeError } from './metadata.js';
2
2
  //#region Completion handlers
3
- export async function completeProcessRun({ request, handle, run, handles, active, save, clearIfDurable, }) {
3
+ export async function completeProcessRun({ request, handle, run, live, clearIfDurable, }) {
4
4
  try {
5
5
  await run?.(request, handle);
6
- const latest = handles.get(handle.id);
7
- if (!latest || latest.status !== 'running') {
8
- return;
9
- }
10
- active.delete(handle.id);
11
- await save({
12
- ...latest,
6
+ await finish({
7
+ live,
8
+ clearIfDurable,
9
+ }, handle.id, {
13
10
  status: 'completed',
14
- updatedAt: nowIso(),
15
11
  });
16
- // Clear the durable handle manifest once the run has terminated so
17
- // `listLive()` stops returning this handle. Without this call the
18
- // manifest would persist until `stop()` was called, making every
19
- // completed step look live from the adapter's persistence layer.
20
- await clearIfDurable(handle.id);
21
12
  }
22
13
  catch (err) {
23
- active.delete(handle.id);
24
- const latest = handles.get(handle.id) ?? handle;
25
- await save({
26
- ...latest,
14
+ await finish({
15
+ live,
16
+ clearIfDurable,
17
+ }, handle.id, {
27
18
  status: 'failed',
28
- updatedAt: nowIso(),
29
- metadata: {
30
- ...(latest.metadata ?? {}),
31
- error: serializeError(err),
32
- },
19
+ error: serializeError(err),
33
20
  });
34
- // Same rationale as the success path above — clear the durable
35
- // manifest so `listLive()` doesn't resurrect this handle on reboot.
36
- await clearIfDurable(handle.id);
37
21
  }
38
22
  }
39
- export async function completeStepRun({ request, handle, stepRunner, handles, active, save, clearIfDurable, }) {
23
+ export async function completeStepRun({ request, handle, stepRunner, live, clearIfDurable, }) {
40
24
  try {
41
25
  const executor = request._localExecutor;
42
26
  let result;
@@ -50,37 +34,49 @@ export async function completeStepRun({ request, handle, stepRunner, handles, ac
50
34
  throw new Error(`In-memory subprocess adapter has no executor for step "${request.stepId}". ` +
51
35
  'Provide a stepRunner option or dispatch via AgentHarness.');
52
36
  }
53
- const latest = handles.get(handle.id);
54
- if (!latest || latest.status !== 'running') {
55
- return;
56
- }
57
- active.delete(handle.id);
58
- await save({
59
- ...latest,
37
+ await finish({
38
+ live,
39
+ clearIfDurable,
40
+ }, handle.id, {
60
41
  status: 'completed',
61
- updatedAt: nowIso(),
62
- metadata: {
63
- ...(latest.metadata ?? {}),
64
- result,
65
- },
42
+ result,
66
43
  });
67
- // Clear the durable step manifest once the run has terminated —
68
- // see `completeProcessRun` above for the rationale.
69
- await clearIfDurable(handle.id);
70
44
  }
71
45
  catch (err) {
72
- active.delete(handle.id);
73
- const latest = handles.get(handle.id) ?? handle;
74
- await save({
75
- ...latest,
46
+ await finish({
47
+ live,
48
+ clearIfDurable,
49
+ }, handle.id, {
76
50
  status: 'failed',
77
- updatedAt: nowIso(),
78
- metadata: {
79
- ...(latest.metadata ?? {}),
80
- error: serializeError(err),
81
- },
51
+ error: serializeError(err),
82
52
  });
83
- await clearIfDurable(handle.id);
84
53
  }
85
54
  }
55
+ /**
56
+ * Settles a run that ended on its own. The caller hears first; the durable
57
+ * manifest clears after, so a slow storage write never delays the result.
58
+ * A handle already stopped has settled, so its late outcome is dropped.
59
+ */
60
+ async function finish({ live, clearIfDurable }, handleId, outcome) {
61
+ const latest = live.get(handleId);
62
+ if (!latest) {
63
+ return;
64
+ }
65
+ const metadata = {
66
+ ...(latest.metadata ?? {}),
67
+ };
68
+ if (outcome.result !== undefined) {
69
+ metadata.result = outcome.result;
70
+ }
71
+ if (outcome.error !== undefined) {
72
+ metadata.error = outcome.error;
73
+ }
74
+ live.settle({
75
+ ...latest,
76
+ status: outcome.status,
77
+ updatedAt: nowIso(),
78
+ metadata,
79
+ });
80
+ await clearIfDurable(handleId);
81
+ }
86
82
  //#endregion
@@ -1,5 +1,6 @@
1
1
  import type { StorageAdapter } from '@noetic-tools/context';
2
2
  import type { ProcessSubprocessRequest, StepSubprocessRequest, SubprocessHandle, SubprocessHandleMetadata, SubprocessRequest } from '@noetic-tools/types';
3
+ import type { LiveHandles } from '../live-handles.js';
3
4
  /**
4
5
  * @public
5
6
  * Options for `createInMemorySubprocessAdapter`. All hooks are optional;
@@ -48,9 +49,7 @@ export interface CompleteProcessRunParams {
48
49
  request: ProcessSubprocessRequest;
49
50
  handle: SubprocessHandle;
50
51
  run: CreateInMemorySubprocessAdapterOptions['run'];
51
- handles: Map<string, SubprocessHandle>;
52
- active: Set<string>;
53
- save: (handle: SubprocessHandle) => Promise<SubprocessHandle>;
52
+ live: LiveHandles;
54
53
  /** Invoked on terminal transitions so the durable handle manifest
55
54
  * does not linger after the step is done — otherwise `listLive()`
56
55
  * would return phantom handles for every step ever completed
@@ -61,9 +60,7 @@ export interface CompleteStepRunParams {
61
60
  request: StepSubprocessRequest;
62
61
  handle: SubprocessHandle;
63
62
  stepRunner: CreateInMemorySubprocessAdapterOptions['stepRunner'];
64
- handles: Map<string, SubprocessHandle>;
65
- active: Set<string>;
66
- save: (handle: SubprocessHandle) => Promise<SubprocessHandle>;
63
+ live: LiveHandles;
67
64
  /** See `CompleteProcessRunParams.clearIfDurable`. */
68
65
  clearIfDurable: (handleId: string) => Promise<void>;
69
66
  }
@@ -1,6 +1,7 @@
1
1
  import { clearManifest, listManifests, loadManifest, persistStepManifest, } from './in-memory-subprocess/manifest-persistence.js';
2
2
  import { buildProcessMetadata, buildStepMetadata, isProcessRequest, isStepRequest, nowIso, } from './in-memory-subprocess/metadata.js';
3
3
  import { completeProcessRun, completeStepRun } from './in-memory-subprocess/step-completion.js';
4
+ import { createLiveHandles } from './live-handles.js';
4
5
  //#region Factory
5
6
  /**
6
7
  * @public
@@ -12,13 +13,8 @@ import { completeProcessRun, completeStepRun } from './in-memory-subprocess/step
12
13
  * a live process (there is none to bind to for in-memory).
13
14
  */
14
15
  export function createInMemorySubprocessAdapter(options = {}) {
15
- const handles = new Map();
16
- const active = new Set();
16
+ const live = createLiveHandles();
17
17
  const storage = options.storage;
18
- async function save(handle) {
19
- handles.set(handle.id, handle);
20
- return handle;
21
- }
22
18
  /**
23
19
  * Persist a step manifest after spawn so `reattach` and `listLive` can
24
20
  * find this handle again on a subsequent adapter instance. Errors are
@@ -58,48 +54,40 @@ export function createInMemorySubprocessAdapter(options = {}) {
58
54
  }
59
55
  async function spawnStepHandle(request) {
60
56
  const now = nowIso();
61
- const handle = {
57
+ const spawned = live.add({
62
58
  id: `subprocess-${crypto.randomUUID()}`,
63
59
  status: 'running',
64
60
  startedAt: now,
65
61
  updatedAt: now,
66
62
  metadata: injectMetadata(request, buildStepMetadata(request)),
67
- };
68
- active.add(handle.id);
69
- await save(handle);
70
- await persistIfDurable(request, handle);
63
+ });
64
+ await persistIfDurable(request, spawned.handle);
71
65
  void completeStepRun({
72
66
  request,
73
- handle,
67
+ handle: spawned.handle,
74
68
  stepRunner: options.stepRunner,
75
- handles,
76
- active,
77
- save,
69
+ live,
78
70
  clearIfDurable,
79
71
  });
80
- return handle;
72
+ return spawned;
81
73
  }
82
- async function spawnProcessHandle(request) {
74
+ function spawnProcessHandle(request) {
83
75
  const now = nowIso();
84
- const handle = {
76
+ const spawned = live.add({
85
77
  id: `subprocess-${crypto.randomUUID()}`,
86
78
  status: 'running',
87
79
  startedAt: now,
88
80
  updatedAt: now,
89
81
  metadata: injectMetadata(request, buildProcessMetadata(request)),
90
- };
91
- active.add(handle.id);
92
- await save(handle);
82
+ });
93
83
  void completeProcessRun({
94
84
  request,
95
- handle,
85
+ handle: spawned.handle,
96
86
  run: options.run,
97
- handles,
98
- active,
99
- save,
87
+ live,
100
88
  clearIfDurable,
101
89
  });
102
- return handle;
90
+ return spawned;
103
91
  }
104
92
  /**
105
93
  * Build a hydrated handle from a persisted manifest. Status is `running`
@@ -134,19 +122,17 @@ export function createInMemorySubprocessAdapter(options = {}) {
134
122
  throw new Error('Unsupported subprocess request variant.');
135
123
  },
136
124
  async get(handleId) {
137
- return handles.get(handleId) ?? null;
125
+ return live.get(handleId) ?? null;
138
126
  },
139
127
  async stop(handleId, reason) {
140
- const handle = handles.get(handleId);
128
+ const handle = live.get(handleId);
141
129
  if (!handle) {
142
130
  return {
143
131
  kind: 'not_found',
144
132
  handleId,
145
133
  };
146
134
  }
147
- active.delete(handleId);
148
- await clearIfDurable(handleId);
149
- const next = await save({
135
+ const next = {
150
136
  ...handle,
151
137
  status: 'stopped',
152
138
  updatedAt: nowIso(),
@@ -154,7 +140,9 @@ export function createInMemorySubprocessAdapter(options = {}) {
154
140
  ...(handle.metadata ?? {}),
155
141
  stopReason: reason,
156
142
  },
157
- });
143
+ };
144
+ live.settle(next);
145
+ await clearIfDurable(handleId);
158
146
  return {
159
147
  kind: 'stopped',
160
148
  handleId,
@@ -162,7 +150,7 @@ export function createInMemorySubprocessAdapter(options = {}) {
162
150
  };
163
151
  },
164
152
  async pause(handleId) {
165
- const handle = handles.get(handleId);
153
+ const handle = live.get(handleId);
166
154
  if (!handle) {
167
155
  return {
168
156
  kind: 'not_found',
@@ -176,7 +164,7 @@ export function createInMemorySubprocessAdapter(options = {}) {
176
164
  };
177
165
  },
178
166
  async resume(handleId) {
179
- const handle = handles.get(handleId);
167
+ const handle = live.get(handleId);
180
168
  if (!handle) {
181
169
  return {
182
170
  kind: 'not_found',
@@ -190,7 +178,7 @@ export function createInMemorySubprocessAdapter(options = {}) {
190
178
  };
191
179
  },
192
180
  async isAlive(handle) {
193
- return active.has(handle.id);
181
+ return live.get(handle.id) !== undefined;
194
182
  },
195
183
  /**
196
184
  * Idempotent re-run of a persisted step, not a "resume" — for in-memory
@@ -207,29 +195,23 @@ export function createInMemorySubprocessAdapter(options = {}) {
207
195
  if (!manifest) {
208
196
  return null;
209
197
  }
210
- const handle = handleFromManifest(manifest);
211
- active.add(handle.id);
212
- await save(handle);
213
- return handle;
198
+ return live.add(handleFromManifest(manifest)).handle;
214
199
  },
215
200
  async listLive() {
216
- const live = new Map();
217
- for (const id of active) {
218
- const handle = handles.get(id);
219
- if (handle) {
220
- live.set(handle.id, handle);
221
- }
201
+ const found = new Map();
202
+ for (const handle of live.values()) {
203
+ found.set(handle.id, handle);
222
204
  }
223
205
  if (storage) {
224
206
  const manifests = await listManifests(storage);
225
207
  for (const manifest of manifests) {
226
- if (!live.has(manifest.handleId)) {
227
- live.set(manifest.handleId, handleFromManifest(manifest));
208
+ if (!found.has(manifest.handleId)) {
209
+ found.set(manifest.handleId, handleFromManifest(manifest));
228
210
  }
229
211
  }
230
212
  }
231
213
  return [
232
- ...live.values(),
214
+ ...found.values(),
233
215
  ];
234
216
  },
235
217
  };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The running handles a `SubprocessAdapter` holds, each paired with the
3
+ * promise its `spawn()` caller waits on. A handle leaves the table the moment
4
+ * it settles, so callers hear about a finished child at once (no polling) and
5
+ * the adapter keeps nothing once the result is delivered.
6
+ */
7
+ import type { SpawnedSubprocess, SubprocessHandle } from '@noetic-tools/types';
8
+ /** @public Running handles keyed by id; see `createLiveHandles`. */
9
+ export interface LiveHandles {
10
+ /** Tracks a running handle. Returns what `spawn()` hands back. */
11
+ add(handle: SubprocessHandle): SpawnedSubprocess;
12
+ /** The running handle with this id, or `undefined` once it has settled. */
13
+ get(handleId: string): SubprocessHandle | undefined;
14
+ /** Replaces a running handle, e.g. on pause or resume. Ignored once it has settled. */
15
+ update(handle: SubprocessHandle): void;
16
+ /**
17
+ * Ends a handle: resolves its `settled` with `handle` (which carries the
18
+ * final status) and forgets it. Returns `false`, changing nothing, when the
19
+ * handle already settled — a stopped child that finishes late, say.
20
+ */
21
+ settle(handle: SubprocessHandle): boolean;
22
+ /** Every running handle. */
23
+ values(): IterableIterator<SubprocessHandle>;
24
+ }
25
+ /** @public Creates an empty `LiveHandles` table for a `SubprocessAdapter`. */
26
+ export declare function createLiveHandles(): LiveHandles;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The running handles a `SubprocessAdapter` holds, each paired with the
3
+ * promise its `spawn()` caller waits on. A handle leaves the table the moment
4
+ * it settles, so callers hear about a finished child at once (no polling) and
5
+ * the adapter keeps nothing once the result is delivered.
6
+ */
7
+ //#endregion
8
+ //#region Public API
9
+ /** @public Creates an empty `LiveHandles` table for a `SubprocessAdapter`. */
10
+ export function createLiveHandles() {
11
+ const entries = new Map();
12
+ return {
13
+ add(handle) {
14
+ const settled = new Promise((resolve) => {
15
+ entries.set(handle.id, {
16
+ handle,
17
+ resolve,
18
+ });
19
+ });
20
+ return {
21
+ handle,
22
+ settled,
23
+ };
24
+ },
25
+ get(handleId) {
26
+ return entries.get(handleId)?.handle;
27
+ },
28
+ update(handle) {
29
+ const entry = entries.get(handle.id);
30
+ if (entry) {
31
+ entry.handle = handle;
32
+ }
33
+ },
34
+ settle(handle) {
35
+ const entry = entries.get(handle.id);
36
+ if (!entry) {
37
+ return false;
38
+ }
39
+ entries.delete(handle.id);
40
+ entry.resolve(handle);
41
+ return true;
42
+ },
43
+ *values() {
44
+ for (const entry of entries.values()) {
45
+ yield entry.handle;
46
+ }
47
+ },
48
+ };
49
+ }
50
+ //#endregion
@@ -791,12 +791,10 @@ async function runCodeViaSubprocess(opts) {
791
791
  input,
792
792
  },
793
793
  };
794
- const spawnPromise = adapter.spawn(request);
795
794
  const handle = new DetachedHandleImpl({
796
795
  id: `run-${nodeId}`,
797
796
  stepId: nodeId,
798
- adapter,
799
- spawnPromise,
797
+ spawned: adapter.spawn(request),
800
798
  });
801
799
  const result = await handle.await();
802
800
  return stringifyResult(result);
@@ -19,16 +19,18 @@ export interface StorageEnvironmentConfig {
19
19
  adapter?: StorageAdapter;
20
20
  /**
21
21
  * Checkpoint store used by `harness.checkpoint(ctx)` / `harness.restore()`.
22
- * When absent, checkpoint/restore are no-ops — a zero-config harness keeps
23
- * its current ephemeral semantics. Construct with `createCheckpointStore`
24
- * to enable durable execution.
22
+ * Defaults to a store over `adapter` when one is given, so configuring durable
23
+ * storage is enough for a later harness on the same storage to resume this one's
24
+ * executions (see the harness `durability` option to turn that off). With no
25
+ * adapter and no store, checkpoint/restore are no-ops — a zero-config harness keeps
26
+ * its ephemeral semantics.
25
27
  */
26
28
  checkpointStore?: CheckpointStore;
27
29
  /** Layer-state store override. Defaults to an in-memory store. */
28
30
  layerStateStore?: LayerStateStore;
29
31
  /**
30
32
  * Bounds on the step-completion ledger that backs step-level resume. Only meaningful
31
- * alongside a `checkpointStore`. Defaults to `DEFAULT_STEP_LEDGER_RETENTION` — 128 KiB
33
+ * when durability is on (a `checkpointStore`, given or defaulted). Defaults to `DEFAULT_STEP_LEDGER_RETENTION` — 128 KiB
32
34
  * per entry, 1000 entries per execution — so an unbounded run cannot grow an unbounded
33
35
  * ledger. Exceeding either cap costs resumability for the affected steps (they re-run),
34
36
  * never correctness.
@@ -57,6 +59,14 @@ interface AgentHarnessOpts<TParams extends Record<string, unknown> = Record<stri
57
59
  agentGraph?: Step<ContextData, string, string>;
58
60
  /** Default context layers applied to every context created via `createContext()` / `execute()`. */
59
61
  contextLayers?: ContextLayer[];
62
+ /**
63
+ * Whether runs and sessions are durable: checkpointed, recorded to the step ledger,
64
+ * and resumable on a later harness over the same storage. Defaults to true whenever
65
+ * `environment.storage` gives an adapter or a checkpoint store. `false` turns every
66
+ * durability surface off even then — the adapter still backs context-layer
67
+ * persistence.
68
+ */
69
+ durability?: boolean;
60
70
  hooks?: AgentHooks;
61
71
  /**
62
72
  * Harness-wide tool pool. Merged (identity-deduplicated) with tools
@@ -147,7 +157,8 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
147
157
  readonly checkpointStore?: CheckpointStore;
148
158
  /**
149
159
  * Append-only step ledger backing resume. Present exactly when durability is on
150
- * (a `CheckpointStore` is configured), so a zero-config harness records nothing.
160
+ * (a `CheckpointStore` is configured or defaulted), so a zero-config harness records
161
+ * nothing.
151
162
  * @internal
152
163
  */
153
164
  readonly stepLedgerStore?: StepLedgerStore;
@@ -177,6 +188,10 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
177
188
  * re-entrant run depth — see `executeClosingChannels`.
178
189
  */
179
190
  private readonly liveRoots;
191
+ /** Stored sessions for `execute()` threads. Present exactly when durability is on. */
192
+ private readonly sessionStore?;
193
+ /** Checkpoint capture in flight per execution id — see `saveCheckpoint`. */
194
+ private readonly pendingCheckpoints;
180
195
  private readonly callModelOverride?;
181
196
  private readonly defaultDeliveryMode;
182
197
  private readonly sessions;
@@ -268,6 +283,8 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
268
283
  getUsage(scope?: SessionScope): SessionUsage;
269
284
  seedSessionHistory(threadId: string, items: ReadonlyArray<Item>): void;
270
285
  private getOrCreateSession;
286
+ /** The stored record for `threadId`, when durability is on. */
287
+ private threadRecord;
271
288
  private requireSession;
272
289
  callModel(request: CallModelRequest): Promise<LLMResponse>;
273
290
  decide(request: DecideRequest): Promise<DecideResponse>;
@@ -292,6 +309,29 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
292
309
  * close anything.
293
310
  */
294
311
  private executeClosingChannels;
312
+ /**
313
+ * Fix the point a resume of this run starts from, and queue it for saving — so even
314
+ * a run whose first step dies leaves a snapshot to restore. The save is not awaited:
315
+ * the steps' own checkpoints queue behind it.
316
+ *
317
+ * When the context's last run never finished, the run repeats it, and it does so
318
+ * from storage — the stored baseline and ledger — exactly as a new harness resuming
319
+ * the execution would, not from what the failed attempt left in memory.
320
+ */
321
+ private beginDurableRun;
322
+ /**
323
+ * Stand `ctx` at its stored baseline and give it the stored ledger. Without a
324
+ * snapshot (its save failed), the baseline the context fixed in memory when the run
325
+ * began is the best record left.
326
+ */
327
+ private rebuildFromStorage;
328
+ /**
329
+ * A finished run is the next run's starting point: persist the live log and counts,
330
+ * then drop the run's positional ledger entries, which no later resume can reach.
331
+ * They are kept when the snapshot failed to land, since that snapshot still points
332
+ * at this run's start. A failed run skips this entirely — it is what a resume repeats.
333
+ */
334
+ private endDurableRun;
295
335
  /**
296
336
  * Idempotently run layer `init` hooks for `ctx` (keyed by `ctx.id`). Init
297
337
  * MUST complete before any recall/store fires so init-bearing layers are not
@@ -371,6 +411,13 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
371
411
  * logic live beside the other durability machinery.
372
412
  */
373
413
  checkpoint(ctx: Context): Promise<void>;
414
+ /**
415
+ * Capture `ctx` behind any capture still in flight for the same execution, and
416
+ * resolve true when this one landed. Every step in the tree checkpoints its root,
417
+ * and concurrent paths would otherwise race their writes: on a networked adapter an
418
+ * older snapshot could land last and win.
419
+ */
420
+ private saveCheckpoint;
374
421
  /**
375
422
  * Rebuild a `Context` from what a previous run of `executionId` recorded: its
376
423
  * checkpoint snapshot, its step-completion ledger, or both. Without a snapshot the