@namzu/sdk 20.3.0 → 21.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.
- package/CHANGELOG.md +321 -0
- package/dist/bridge/sse/mapper.d.ts +19 -0
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +9 -1
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/contracts/schemas.d.ts +10 -10
- package/dist/manager/run/persistence.d.ts +26 -0
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +40 -0
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/public-runtime.d.ts +5 -0
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +21 -0
- package/dist/public-runtime.js.map +1 -1
- package/dist/run/drain.d.ts +194 -0
- package/dist/run/drain.d.ts.map +1 -0
- package/dist/run/drain.js +228 -0
- package/dist/run/drain.js.map +1 -0
- package/dist/run/index.d.ts +2 -0
- package/dist/run/index.d.ts.map +1 -1
- package/dist/run/index.js +1 -0
- package/dist/run/index.js.map +1 -1
- package/dist/runtime/query/checkpoint.d.ts +27 -1
- package/dist/runtime/query/checkpoint.d.ts.map +1 -1
- package/dist/runtime/query/checkpoint.js +34 -4
- package/dist/runtime/query/checkpoint.js.map +1 -1
- package/dist/runtime/query/events.d.ts +12 -0
- package/dist/runtime/query/events.d.ts.map +1 -1
- package/dist/runtime/query/events.js +61 -3
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/index.d.ts +57 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +36 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/resume-run.d.ts +34 -1
- package/dist/runtime/query/resume-run.d.ts.map +1 -1
- package/dist/runtime/query/resume-run.js +16 -3
- package/dist/runtime/query/resume-run.js.map +1 -1
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +2 -2
- package/dist/store/index.js.map +1 -1
- package/dist/store/run/checkpoint-disk.d.ts +18 -2
- package/dist/store/run/checkpoint-disk.d.ts.map +1 -1
- package/dist/store/run/checkpoint-disk.js +50 -5
- package/dist/store/run/checkpoint-disk.js.map +1 -1
- package/dist/store/run/checkpoint-memory.d.ts +22 -2
- package/dist/store/run/checkpoint-memory.d.ts.map +1 -1
- package/dist/store/run/checkpoint-memory.js +99 -4
- package/dist/store/run/checkpoint-memory.js.map +1 -1
- package/dist/store/run/claim-disk.d.ts +130 -0
- package/dist/store/run/claim-disk.d.ts.map +1 -0
- package/dist/store/run/claim-disk.js +550 -0
- package/dist/store/run/claim-disk.js.map +1 -0
- package/dist/store/run/conformance.d.ts +159 -0
- package/dist/store/run/conformance.d.ts.map +1 -0
- package/dist/store/run/conformance.js +451 -0
- package/dist/store/run/conformance.js.map +1 -0
- package/dist/store/run/disk.d.ts +30 -2
- package/dist/store/run/disk.d.ts.map +1 -1
- package/dist/store/run/disk.js +101 -0
- package/dist/store/run/disk.js.map +1 -1
- package/dist/store/run/listing.d.ts +44 -1
- package/dist/store/run/listing.d.ts.map +1 -1
- package/dist/store/run/listing.js +92 -1
- package/dist/store/run/listing.js.map +1 -1
- package/dist/store/run/memory.d.ts +5 -4
- package/dist/store/run/memory.d.ts.map +1 -1
- package/dist/store/run/memory.js +30 -1
- package/dist/store/run/memory.js.map +1 -1
- package/dist/types/doctor/check.d.ts +28 -2
- package/dist/types/doctor/check.d.ts.map +1 -1
- package/dist/types/run/checkpoint-store.d.ts +178 -2
- package/dist/types/run/checkpoint-store.d.ts.map +1 -1
- package/dist/types/run/event-cursor.d.ts +90 -0
- package/dist/types/run/event-cursor.d.ts.map +1 -0
- package/dist/types/run/event-cursor.js +47 -0
- package/dist/types/run/event-cursor.js.map +1 -0
- package/dist/types/run/events.d.ts +71 -1
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/events.js.map +1 -1
- package/dist/types/run/index.d.ts +1 -0
- package/dist/types/run/index.d.ts.map +1 -1
- package/dist/types/run/index.js +1 -0
- package/dist/types/run/index.js.map +1 -1
- package/dist/types/run/store.d.ts +41 -1
- package/dist/types/run/store.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/bridge/sse/mapper.ts +28 -1
- package/src/manager/run/persistence.ts +43 -0
- package/src/public-runtime.ts +27 -0
- package/src/run/drain.ts +393 -0
- package/src/run/index.ts +3 -0
- package/src/runtime/query/checkpoint.ts +42 -5
- package/src/runtime/query/events.ts +68 -4
- package/src/runtime/query/index.ts +113 -1
- package/src/runtime/query/resume-run.ts +77 -12
- package/src/store/index.ts +5 -1
- package/src/store/run/checkpoint-disk.ts +70 -5
- package/src/store/run/checkpoint-memory.ts +118 -3
- package/src/store/run/claim-disk.ts +593 -0
- package/src/store/run/conformance.ts +705 -0
- package/src/store/run/disk.ts +106 -2
- package/src/store/run/listing.ts +116 -1
- package/src/store/run/memory.ts +35 -5
- package/src/types/doctor/check.ts +28 -2
- package/src/types/run/checkpoint-store.ts +189 -2
- package/src/types/run/event-cursor.ts +118 -0
- package/src/types/run/events.ts +80 -3
- package/src/types/run/index.ts +1 -0
- package/src/types/run/store.ts +43 -1
package/dist/run/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { RunPersistence } from '../manager/run/persistence.js';
|
|
|
2
2
|
export { RunDiskStore } from '../store/run/disk.js';
|
|
3
3
|
export { createRunReporter } from './reporter.js';
|
|
4
4
|
export type { RunReporter } from './reporter.js';
|
|
5
|
+
export { DEFAULT_DRAIN_PAGE_SIZE, drainRuns } from './drain.js';
|
|
6
|
+
export type { DrainFailure, DrainRun, DrainRunsParams, DrainRunsResult } from './drain.js';
|
|
5
7
|
export { checkLimitsDetailed, buildLimitConfig } from './LimitChecker.js';
|
|
6
8
|
export type { LimitCheckerState, LimitCheckResult } from './LimitChecker.js';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/run/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/run/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACzE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/run/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC/D,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE1F,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACzE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/run/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { RunPersistence } from '../manager/run/persistence.js';
|
|
2
2
|
export { RunDiskStore } from '../store/run/disk.js';
|
|
3
3
|
export { createRunReporter } from './reporter.js';
|
|
4
|
+
export { DEFAULT_DRAIN_PAGE_SIZE, drainRuns } from './drain.js';
|
|
4
5
|
export { checkLimitsDetailed, buildLimitConfig } from './LimitChecker.js';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/run/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/run/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGjD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/run/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGjD,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAG/D,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -2,7 +2,7 @@ import type { WorkingStateSnapshot } from '../../compaction/wire.js';
|
|
|
2
2
|
import type { RunPersistence } from '../../manager/run/persistence.js';
|
|
3
3
|
import type { SerializedSpanContext } from '../../telemetry/attributes.js';
|
|
4
4
|
import type { CheckpointId, CheckpointSummary, HITLDecisionRequest, HITLResumeDecision, IterationCheckpoint, PendingDecision } from '../../types/hitl/index.js';
|
|
5
|
-
import type { CheckpointRunScope, CheckpointStore } from '../../types/run/checkpoint-store.js';
|
|
5
|
+
import type { CheckpointRunScope, CheckpointStore, ClaimFence } from '../../types/run/checkpoint-store.js';
|
|
6
6
|
import type { EmergencySaveData } from '../../types/run/emergency.js';
|
|
7
7
|
import type { CheckpointListEntry } from '../../types/run/replay.js';
|
|
8
8
|
/**
|
|
@@ -75,6 +75,21 @@ export declare class CheckpointManager {
|
|
|
75
75
|
private traceSource?;
|
|
76
76
|
/** See {@link setParkTtl}. */
|
|
77
77
|
private parkTtlMs?;
|
|
78
|
+
/**
|
|
79
|
+
* The claim this run holds, presented on every checkpoint write.
|
|
80
|
+
*
|
|
81
|
+
* Unset means unfenced, which is correct for a single-writer deployment
|
|
82
|
+
* and is what every run did before claims existed. Set it and a write from
|
|
83
|
+
* a superseded holding is refused by the store.
|
|
84
|
+
*
|
|
85
|
+
* This existed nowhere for one release, and the omission was invisible in
|
|
86
|
+
* the worst way: the claim, the fence and the refusal were all built and
|
|
87
|
+
* tested, and no code path between a run and its store carried the number,
|
|
88
|
+
* so every checkpoint a RUN wrote went out unfenced. A capability that is
|
|
89
|
+
* complete except for the wire between its halves reads exactly like a
|
|
90
|
+
* working one.
|
|
91
|
+
*/
|
|
92
|
+
private claimFence?;
|
|
78
93
|
/**
|
|
79
94
|
* The run's attribution instant, stamped onto every checkpoint this
|
|
80
95
|
* manager writes.
|
|
@@ -153,6 +168,17 @@ export declare class CheckpointManager {
|
|
|
153
168
|
park(checkpoint: IterationCheckpoint, request: HITLDecisionRequest, options?: {
|
|
154
169
|
readonly ttlMs?: number;
|
|
155
170
|
}): Promise<IterationCheckpoint>;
|
|
171
|
+
/**
|
|
172
|
+
* Present this claim on every subsequent write. See {@link claimFence}.
|
|
173
|
+
*
|
|
174
|
+
* A setter rather than a constructor argument because a run is claimed at
|
|
175
|
+
* a different moment than it is constructed — a worker draining a queue
|
|
176
|
+
* takes the run, then builds the pipeline around it — and because a
|
|
177
|
+
* renewal mints a NEW fence mid-run that has to replace the old one.
|
|
178
|
+
*/
|
|
179
|
+
setClaimFence(fence: ClaimFence | undefined): void;
|
|
180
|
+
/** The claim currently presented on writes, if any. */
|
|
181
|
+
get presentedFence(): ClaimFence | undefined;
|
|
156
182
|
/** Default time-to-live applied to every park this manager records. */
|
|
157
183
|
setParkTtl(ttlMs: number | undefined): void;
|
|
158
184
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAE1E,OAAO,KAAK,EACX,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,MAAM,2BAA2B,CAAA;AAElC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAE1E,OAAO,KAAK,EACX,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,MAAM,2BAA2B,CAAA;AAElC,OAAO,KAAK,EACX,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,MAAM,qCAAqC,CAAA;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAKpE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,mBAAmB,GAAG,mBAAmB,CAQlF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,iBAAiB,GAAG,mBAAmB,CAq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lD,OAAO,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA4BjE,IAAI,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAI5C;;;;;OAKG;IACG,WAAW,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAK7C,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5C,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB;CAajF"}
|
|
@@ -121,6 +121,21 @@ export class CheckpointManager {
|
|
|
121
121
|
traceSource;
|
|
122
122
|
/** See {@link setParkTtl}. */
|
|
123
123
|
parkTtlMs;
|
|
124
|
+
/**
|
|
125
|
+
* The claim this run holds, presented on every checkpoint write.
|
|
126
|
+
*
|
|
127
|
+
* Unset means unfenced, which is correct for a single-writer deployment
|
|
128
|
+
* and is what every run did before claims existed. Set it and a write from
|
|
129
|
+
* a superseded holding is refused by the store.
|
|
130
|
+
*
|
|
131
|
+
* This existed nowhere for one release, and the omission was invisible in
|
|
132
|
+
* the worst way: the claim, the fence and the refusal were all built and
|
|
133
|
+
* tested, and no code path between a run and its store carried the number,
|
|
134
|
+
* so every checkpoint a RUN wrote went out unfenced. A capability that is
|
|
135
|
+
* complete except for the wire between its halves reads exactly like a
|
|
136
|
+
* working one.
|
|
137
|
+
*/
|
|
138
|
+
claimFence;
|
|
124
139
|
/**
|
|
125
140
|
* The run's attribution instant, stamped onto every checkpoint this
|
|
126
141
|
* manager writes.
|
|
@@ -188,7 +203,7 @@ export class CheckpointManager {
|
|
|
188
203
|
workingState: extra?.workingState ?? this.workingStateSource?.(),
|
|
189
204
|
traceContext: this.traceSource?.(),
|
|
190
205
|
};
|
|
191
|
-
await this.store.writeCheckpoint(this.scope, checkpoint);
|
|
206
|
+
await this.store.writeCheckpoint(this.scope, checkpoint, this.claimFence);
|
|
192
207
|
this.lastCreatedId = checkpoint.id;
|
|
193
208
|
return checkpoint;
|
|
194
209
|
}
|
|
@@ -246,9 +261,24 @@ export class CheckpointManager {
|
|
|
246
261
|
...(ttl !== undefined && ttl > 0 ? { deadlineAt: parkedAt + ttl } : {}),
|
|
247
262
|
},
|
|
248
263
|
};
|
|
249
|
-
await this.store.writeCheckpoint(this.scope, parked);
|
|
264
|
+
await this.store.writeCheckpoint(this.scope, parked, this.claimFence);
|
|
250
265
|
return parked;
|
|
251
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Present this claim on every subsequent write. See {@link claimFence}.
|
|
269
|
+
*
|
|
270
|
+
* A setter rather than a constructor argument because a run is claimed at
|
|
271
|
+
* a different moment than it is constructed — a worker draining a queue
|
|
272
|
+
* takes the run, then builds the pipeline around it — and because a
|
|
273
|
+
* renewal mints a NEW fence mid-run that has to replace the old one.
|
|
274
|
+
*/
|
|
275
|
+
setClaimFence(fence) {
|
|
276
|
+
this.claimFence = fence;
|
|
277
|
+
}
|
|
278
|
+
/** The claim currently presented on writes, if any. */
|
|
279
|
+
get presentedFence() {
|
|
280
|
+
return this.claimFence;
|
|
281
|
+
}
|
|
252
282
|
/** Default time-to-live applied to every park this manager records. */
|
|
253
283
|
setParkTtl(ttlMs) {
|
|
254
284
|
this.parkTtlMs = ttlMs;
|
|
@@ -275,7 +305,7 @@ export class CheckpointManager {
|
|
|
275
305
|
decision: { action: 'pause', reason: 'The approval request expired without an answer.' },
|
|
276
306
|
},
|
|
277
307
|
};
|
|
278
|
-
await this.store.writeCheckpoint(this.scope, expired);
|
|
308
|
+
await this.store.writeCheckpoint(this.scope, expired, this.claimFence);
|
|
279
309
|
return expired;
|
|
280
310
|
}
|
|
281
311
|
/**
|
|
@@ -294,7 +324,7 @@ export class CheckpointManager {
|
|
|
294
324
|
...checkpoint,
|
|
295
325
|
pending: { ...checkpoint.pending, resolvedAt: Date.now(), decision },
|
|
296
326
|
};
|
|
297
|
-
await this.store.writeCheckpoint(this.scope, resolved);
|
|
327
|
+
await this.store.writeCheckpoint(this.scope, resolved, this.claimFence);
|
|
298
328
|
return resolved;
|
|
299
329
|
}
|
|
300
330
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../../../src/runtime/query/checkpoint.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../../../src/runtime/query/checkpoint.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAiBxD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAExD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAAuB;IAC5D,OAAO;QACN,EAAE,EAAE,EAAE,CAAC,EAAE;QACT,KAAK,EAAE,EAAE,CAAC,KAAK;QACf,SAAS,EAAE,EAAE,CAAC,SAAS;QACvB,SAAS,EAAE,EAAE,CAAC,SAAS;QACvB,YAAY,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM;KAChC,CAAA;AACF,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,4BAA4B,CAAC,IAAuB;IACnE,MAAM,eAAe,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;IACtD,OAAO;QACN,EAAE,EAAE,gBAAgB,eAAe,EAAkB;QACrD,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,mEAAmE;QACnE,oEAAoE;QACpE,8DAA8D;QAC9D,sEAAsE;QACtE,yCAAyC;QACzC,YAAY,EAAE,IAAI,CAAC,SAAS;QAC5B,SAAS,EAAE,IAAI,CAAC,gBAAgB;QAChC,QAAQ,EA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B,IAAI,GAAG,CAAC,MAAM,IAAI,QAAQ;YAAE,OAAM;QAElC,MAAM,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAA;QAE9F,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;QACrD,CAAC;IACF,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,MAAsB,EAAE,SAAiB;QAC5D,MAAM,aAAa,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;aACxC,OAAO,EAAE;aACT,IAAI,CAAC,CAAC,CAAC,EAAyB,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC,CAAA;QAElF,OAAO;YACN,SAAS;YACT,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YACpC,UAAU,EAAE,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE;YACpC,QAAQ,EAAE,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE;YAChC,oBAAoB,EAAE,aAAa,EAAE,OAAO,IAAI,SAAS;SACzD,CAAA;IACF,CAAC;CACD"}
|
|
@@ -3,6 +3,7 @@ import type { RunPersistence } from '../../manager/run/persistence.js';
|
|
|
3
3
|
import { type ProbeRegistry } from '../../probe/registry.js';
|
|
4
4
|
import type { ActivityStore } from '../../store/activity/memory.js';
|
|
5
5
|
import type { RunId } from '../../types/ids/index.js';
|
|
6
|
+
import type { ClaimFence } from '../../types/run/checkpoint-store.js';
|
|
6
7
|
import type { RunEvent } from '../../types/run/index.js';
|
|
7
8
|
import type { TaskStore } from '../../types/task/index.js';
|
|
8
9
|
export type EmitEvent = (event: RunEvent) => Promise<void>;
|
|
@@ -13,6 +14,17 @@ export declare class EventTranslator {
|
|
|
13
14
|
private droppedDeltaCount;
|
|
14
15
|
private readonly log;
|
|
15
16
|
constructor(runMgr: RunPersistence, probeRegistry?: ProbeRegistry);
|
|
17
|
+
/**
|
|
18
|
+
* The claim this run is being written under, when it holds one.
|
|
19
|
+
*
|
|
20
|
+
* Stamped on every durable event as its `generation`, so a consumer whose
|
|
21
|
+
* cursor predates a takeover is told its sequence space changed instead of
|
|
22
|
+
* being handed a splice from a different writer's log.
|
|
23
|
+
*/
|
|
24
|
+
private generation;
|
|
25
|
+
/** Serializes sequence assignment against the append. See {@link emitEvent}. */
|
|
26
|
+
private appendChain;
|
|
27
|
+
setGeneration(fence: ClaimFence | undefined): void;
|
|
16
28
|
readonly emitEvent: EmitEvent;
|
|
17
29
|
drainPending(): Generator<RunEvent>;
|
|
18
30
|
wireActivityStore(activityStore: ActivityStore, runId: RunId): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AAEtE,OAAO,EAAE,KAAK,aAAa,EAAiC,MAAM,yBAAyB,CAAA;AAC3F,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAClF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAk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this.runMgr = runMgr;
|
|
26
26
|
this.probes = probeRegistry;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The claim this run is being written under, when it holds one.
|
|
30
|
+
*
|
|
31
|
+
* Stamped on every durable event as its `generation`, so a consumer whose
|
|
32
|
+
* cursor predates a takeover is told its sequence space changed instead of
|
|
33
|
+
* being handed a splice from a different writer's log.
|
|
34
|
+
*/
|
|
35
|
+
generation;
|
|
36
|
+
/** Serializes sequence assignment against the append. See {@link emitEvent}. */
|
|
37
|
+
appendChain = Promise.resolve();
|
|
38
|
+
setGeneration(fence) {
|
|
39
|
+
this.generation = fence;
|
|
40
|
+
}
|
|
28
41
|
emitEvent = async (event) => {
|
|
29
42
|
this.probes.dispatch(event, buildProbeContext({ runId: event.runId }));
|
|
30
43
|
// D2: bound the queue. Drop oldest ephemeral events under
|
|
@@ -50,14 +63,59 @@ export class EventTranslator {
|
|
|
50
63
|
// and rely on consumer drain catching up. Better to grow
|
|
51
64
|
// briefly than to drop a state transition.
|
|
52
65
|
}
|
|
53
|
-
this.pendingEvents.push(event);
|
|
54
66
|
// D1 middle path: ephemeral events never enter `transcript.jsonl`.
|
|
55
67
|
// They live only on the in-memory bus for live UI rendering.
|
|
56
68
|
// Replay (`runtime/query/replay/prepare.ts`) reads checkpoints
|
|
57
69
|
// not transcripts, so this preserves replay fidelity while
|
|
58
70
|
// eliminating the durable bloat review flagged.
|
|
59
|
-
if (
|
|
60
|
-
|
|
71
|
+
if (isEphemeralEvent(event)) {
|
|
72
|
+
// No number, and that is the honest statement: nothing will
|
|
73
|
+
// persist this, so a consumer must never advance a cursor to it.
|
|
74
|
+
this.pendingEvents.push(event);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// One appender at a time, and this is not a precaution — it is the fix
|
|
78
|
+
// for a measured defect. Taking the number, awaiting the write and then
|
|
79
|
+
// committing is a read-modify-write, and emits genuinely interleave:
|
|
80
|
+
// the task store, the plan manager and a batch of parallel tools all
|
|
81
|
+
// emit into this one funnel. Measured on a two-tool run, three events
|
|
82
|
+
// took the number 15 and two took 12. A duplicated sequence is worse
|
|
83
|
+
// than a missing one — a consumer asking for everything above 15 is
|
|
84
|
+
// handed part of the run it already had, spliced in as if it were new.
|
|
85
|
+
const previous = this.appendChain;
|
|
86
|
+
let release;
|
|
87
|
+
this.appendChain = new Promise((resolve) => {
|
|
88
|
+
release = resolve;
|
|
89
|
+
});
|
|
90
|
+
try {
|
|
91
|
+
await previous;
|
|
92
|
+
// The number is a claim that the event is IN the log, so it is taken
|
|
93
|
+
// against the append and not before it. The candidate goes to the
|
|
94
|
+
// store first; only a write that landed advances the counter and
|
|
95
|
+
// reaches the live stream carrying it.
|
|
96
|
+
//
|
|
97
|
+
// The failure path still delivers the event — unstamped. A store
|
|
98
|
+
// that cannot record a `run_failed` must not also swallow it, and an
|
|
99
|
+
// unstamped event says exactly what is true of it: it happened, and
|
|
100
|
+
// it is not recoverable.
|
|
101
|
+
const seq = this.runMgr.nextEventSeq();
|
|
102
|
+
const stamped = {
|
|
103
|
+
...event,
|
|
104
|
+
seq,
|
|
105
|
+
...(this.generation !== undefined ? { generation: this.generation } : {}),
|
|
106
|
+
};
|
|
107
|
+
try {
|
|
108
|
+
await this.runMgr.getRunStore().appendEvent(stamped);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
this.pendingEvents.push(event);
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
this.runMgr.commitEventSeq(seq);
|
|
115
|
+
this.pendingEvents.push(stamped);
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
release();
|
|
61
119
|
}
|
|
62
120
|
};
|
|
63
121
|
*drainPending() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/runtime/query/events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAsB,KAAK,I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AAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC7D,CAAC,CAAA;oBACF,MAAK;gBACN,gEAAgE;gBAChE,8DAA8D;gBAC9D,4DAA4D;gBAC5D,gEAAgE;gBAChE,wDAAwD;gBACxD,KAAK,iBAAiB,CAAC;gBACvB,KAAK,gBAAgB;oBACpB,MAAK;gBACN,OAAO,CAAC,CAAC,CAAC;oBACT,iEAAiE;oBACjE,kEAAkE;oBAClE,mEAAmE;oBACnE,QAAQ;oBACR,MAAM,WAAW,GAAU,KAAK,CAAC,IAAI,CAAA;oBACrC,MAAM,IAAI,KAAK,CAAC,8BAA8B,WAAW,EAAE,CAAC,CAAA;gBAC7D,CAAC;YACF,CAAC;QACF,CAAC,CAAC,CAAA;IACH,CAAC;CACD"}
|
|
@@ -16,7 +16,8 @@ import type { AgentPersona } from '../../types/persona/index.js';
|
|
|
16
16
|
import type { LLMProvider } from '../../types/provider/index.js';
|
|
17
17
|
import type { TaskRouterConfig } from '../../types/router/index.js';
|
|
18
18
|
import type { ReviewAnswer } from '../../types/run/answer-review.js';
|
|
19
|
-
import type { CheckpointStore } from '../../types/run/checkpoint-store.js';
|
|
19
|
+
import type { CheckpointStore, ClaimFence } from '../../types/run/checkpoint-store.js';
|
|
20
|
+
import type { RunEventCursor, RunEventReplay } from '../../types/run/event-cursor.js';
|
|
20
21
|
import type { AgentRunConfig, PrepareStepChain, Run, RunEvent, RunEventListener, StepResult, StopCondition } from '../../types/run/index.js';
|
|
21
22
|
import type { PromoteMemory } from '../../types/run/memory-promotion.js';
|
|
22
23
|
import type { RunStore } from '../../types/run/store.js';
|
|
@@ -307,6 +308,26 @@ export interface QueryParams {
|
|
|
307
308
|
* survives machines that lose their local disk.
|
|
308
309
|
*/
|
|
309
310
|
checkpointStore?: CheckpointStore;
|
|
311
|
+
/**
|
|
312
|
+
* The fence of the claim this worker holds on the run, from `claimRun`.
|
|
313
|
+
*
|
|
314
|
+
* Presented on every checkpoint the run writes, so a worker that stalled
|
|
315
|
+
* past its lease is refused rather than writing into a run somebody else
|
|
316
|
+
* has taken over. Omit it for single-writer deployments, which is what
|
|
317
|
+
* every run did before claims existed.
|
|
318
|
+
*
|
|
319
|
+
* This hop did not exist for a release. The claim, the fence and the
|
|
320
|
+
* store-side refusal were all built and tested, and no path between a run
|
|
321
|
+
* and its store carried the number — so every checkpoint a RUN wrote went
|
|
322
|
+
* out unfenced while the tests, which called the store directly, all
|
|
323
|
+
* passed. A capability complete except for the wire between its halves
|
|
324
|
+
* reads exactly like a working one.
|
|
325
|
+
*
|
|
326
|
+
* It fences checkpoints and nothing else. {@link QueryParams.runStore}
|
|
327
|
+
* takes no fence, so two workers that both took one run still overwrite
|
|
328
|
+
* each other's run record, transcript and report — see the changeset.
|
|
329
|
+
*/
|
|
330
|
+
claimFence?: ClaimFence;
|
|
310
331
|
/**
|
|
311
332
|
* Where this run records its own evidence — the run record, its messages,
|
|
312
333
|
* its transcript and its report. Defaults to the disk layout under the
|
|
@@ -317,6 +338,41 @@ export interface QueryParams {
|
|
|
317
338
|
* evidence could not.
|
|
318
339
|
*/
|
|
319
340
|
runStore?: RunStore;
|
|
341
|
+
/**
|
|
342
|
+
* Where a reconnecting consumer left off, so this run's stream can start by
|
|
343
|
+
* handing back what it missed.
|
|
344
|
+
*
|
|
345
|
+
* The case this serves is the one that exists without a network hop: the
|
|
346
|
+
* process holding the run died, and the consumer watching it is coming back
|
|
347
|
+
* to a run that has to be resumed. Pair it with `resumeFromCheckpoint` — or
|
|
348
|
+
* reach it through {@link import('./resume-run.js').resumeRun}, which is the
|
|
349
|
+
* surface that does both — and the missed durable events are yielded, in
|
|
350
|
+
* order, before the resumed run emits anything of its own.
|
|
351
|
+
*
|
|
352
|
+
* On a run with no log to catch up on the cursor is answered honestly rather
|
|
353
|
+
* than ignored: a `sinceSeq` above what exists is `cursor_ahead`, not
|
|
354
|
+
* silence.
|
|
355
|
+
*
|
|
356
|
+
* What comes back is message-granular. Streaming deltas are never persisted
|
|
357
|
+
* — see {@link import('../../types/run/store.js').RunStore.appendEvent} —
|
|
358
|
+
* so a late subscriber recovers the assistant text, the tool results and the
|
|
359
|
+
* lifecycle, not the keystroke cadence that produced them.
|
|
360
|
+
*/
|
|
361
|
+
eventCursor?: RunEventCursor;
|
|
362
|
+
/**
|
|
363
|
+
* What became of {@link QueryParams.eventCursor}.
|
|
364
|
+
*
|
|
365
|
+
* A callback rather than an event on the stream, because the answer is about
|
|
366
|
+
* the SUBSCRIPTION and not about the run — and rather than a throw, because
|
|
367
|
+
* a stale cursor is a client's problem and must not be able to stop a run
|
|
368
|
+
* from continuing. A host that receives `unavailable` re-derives from the
|
|
369
|
+
* transcript; one that receives nothing at all would splice a hole into its
|
|
370
|
+
* state and never know.
|
|
371
|
+
*
|
|
372
|
+
* Called once, before the run's first event, and only when a cursor was
|
|
373
|
+
* supplied.
|
|
374
|
+
*/
|
|
375
|
+
onEventReplay?: (replay: RunEventReplay) => void;
|
|
320
376
|
runId?: RunId;
|
|
321
377
|
parentRunId?: RunId;
|
|
322
378
|
depth?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAGjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAGjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAK/D,OAAO,EACN,KAAK,mBAAmB,EAGxB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,KAAK,mBAAm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-20,6 +20,7 @@ import { buildTaskTools } from '../../tools/task/index.js';
|
|
|
20
20
|
import { NamzuError } from '../../types/errors/index.js';
|
|
21
21
|
import { autoApproveHandler, } from '../../types/hitl/index.js';
|
|
22
22
|
import { createSystemMessage } from '../../types/message/index.js';
|
|
23
|
+
import { resolveRunEventReplay } from '../../types/run/event-cursor.js';
|
|
23
24
|
import { memoryCandidateFor } from '../../types/run/memory-promotion.js';
|
|
24
25
|
import { getRootLogger } from '../../utils/logger.js';
|
|
25
26
|
import { VerificationGate } from '../../verification/gate.js';
|
|
@@ -481,6 +482,14 @@ export async function* query(params) {
|
|
|
481
482
|
// And every park it records carries an absolute deadline, so an
|
|
482
483
|
// unanswered approval cannot outlive the worker that asked for it.
|
|
483
484
|
checkpointMgr.setParkTtl(params.runConfig.hitlParkTtlMs);
|
|
485
|
+
// The claim this worker holds, if it took one. Without this hop the
|
|
486
|
+
// fence exists, the refusal exists, and no checkpoint a RUN writes ever
|
|
487
|
+
// carries a number — so a stalled worker is refused nowhere.
|
|
488
|
+
checkpointMgr.setClaimFence(params.claimFence);
|
|
489
|
+
// And every EVENT it records carries the same fence as its generation,
|
|
490
|
+
// so a consumer whose cursor was minted under an older holding is told
|
|
491
|
+
// the sequence space changed rather than handed a splice from it.
|
|
492
|
+
eventTranslator.setGeneration(params.claimFence);
|
|
484
493
|
// A question raised from inside a tool becomes a real checkpoint
|
|
485
494
|
// here. It used to park under a synthetic id nothing ever wrote, so
|
|
486
495
|
// the checkpoint did not exist: nothing on disk said a human owed
|
|
@@ -555,6 +564,14 @@ export async function* query(params) {
|
|
|
555
564
|
let emergencyManager;
|
|
556
565
|
try {
|
|
557
566
|
await ctx.runMgr.init();
|
|
567
|
+
// A consumer coming back gets what it missed BEFORE the run says
|
|
568
|
+
// anything new, which is the only order that lets it fold one
|
|
569
|
+
// stream into one state. It has to follow `init()` — that is what
|
|
570
|
+
// binds the store and reads the log's head — and precede every
|
|
571
|
+
// emit below.
|
|
572
|
+
if (params.eventCursor) {
|
|
573
|
+
yield* catchUpFromCursor(ctx.runMgr, params.eventCursor, params.onEventReplay, params.claimFence);
|
|
574
|
+
}
|
|
558
575
|
// Handed over here, and the position is load-bearing in BOTH
|
|
559
576
|
// directions. It has to follow `wirePlanManager`, or a host that
|
|
560
577
|
// builds its plan in this callback — which is what the callback is
|
|
@@ -976,6 +993,25 @@ export async function* query(params) {
|
|
|
976
993
|
return await resultAssembler.finalize();
|
|
977
994
|
})();
|
|
978
995
|
}
|
|
996
|
+
/**
|
|
997
|
+
* Hand a returning consumer what it missed, or tell it why it cannot have it.
|
|
998
|
+
*
|
|
999
|
+
* Yields NOTHING on a refusal. A partial catch-up is the failure this exists to
|
|
1000
|
+
* prevent: a consumer that receives some of the gap folds it into its state and
|
|
1001
|
+
* cannot tell the state is wrong, where one that receives an explicit
|
|
1002
|
+
* `unavailable` re-derives from the transcript and is right. The run continues
|
|
1003
|
+
* either way — a stale cursor belongs to the client, and must not be able to
|
|
1004
|
+
* stop the work.
|
|
1005
|
+
*/
|
|
1006
|
+
async function* catchUpFromCursor(runMgr, cursor, onEventReplay, generation) {
|
|
1007
|
+
const missed = await runMgr.getRunStore().readEvents({ sinceSeq: cursor.sinceSeq });
|
|
1008
|
+
const replay = resolveRunEventReplay(cursor, { lastSeq: runMgr.lastEventSeq, ...(generation !== undefined ? { generation } : {}) }, missed);
|
|
1009
|
+
onEventReplay?.(replay);
|
|
1010
|
+
if (replay.status !== 'replayed')
|
|
1011
|
+
return;
|
|
1012
|
+
for (const event of replay.events)
|
|
1013
|
+
yield event;
|
|
1014
|
+
}
|
|
979
1015
|
export async function drainQuery(params, listener) {
|
|
980
1016
|
const fullParams = {
|
|
981
1017
|
...params,
|