@earendil-works/pi-durable 1.4.0 → 1.5.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 +186 -0
- package/README.md +181 -84
- package/dist/codemode/codemode.d.ts +4 -4
- package/dist/codemode/codemode.d.ts.map +1 -1
- package/dist/codemode/codemode.js +9 -12
- package/dist/codemode/codemode.js.map +1 -1
- package/dist/codemode/models.js +4 -4
- package/dist/codemode/models.js.map +1 -1
- package/dist/env/index.d.ts +12 -10
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js.map +1 -1
- package/dist/env/node-watch.d.ts +3 -3
- package/dist/env/node-watch.d.ts.map +1 -1
- package/dist/env/node-watch.js +18 -16
- package/dist/env/node-watch.js.map +1 -1
- package/dist/env/node.d.ts +2 -2
- package/dist/env/node.d.ts.map +1 -1
- package/dist/env/node.js +1 -1
- package/dist/env/node.js.map +1 -1
- package/dist/errors.d.ts +18 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +26 -3
- package/dist/errors.js.map +1 -1
- package/dist/harness/agent.d.ts.map +1 -1
- package/dist/harness/agent.js +10 -2
- package/dist/harness/agent.js.map +1 -1
- package/dist/harness/compaction.d.ts.map +1 -1
- package/dist/harness/compaction.js +19 -2
- package/dist/harness/compaction.js.map +1 -1
- package/dist/harness/context.d.ts +23 -7
- package/dist/harness/context.d.ts.map +1 -1
- package/dist/harness/context.js +71 -25
- package/dist/harness/context.js.map +1 -1
- package/dist/harness/define.d.ts +7 -3
- package/dist/harness/define.d.ts.map +1 -1
- package/dist/harness/define.js +4 -0
- package/dist/harness/define.js.map +1 -1
- package/dist/harness/generation.d.ts +38 -5
- package/dist/harness/generation.d.ts.map +1 -1
- package/dist/harness/generation.js +445 -96
- package/dist/harness/generation.js.map +1 -1
- package/dist/harness/harness.d.ts +2 -0
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/harness.js +87 -62
- package/dist/harness/harness.js.map +1 -1
- package/dist/harness/inbox.d.ts +5 -1
- package/dist/harness/inbox.d.ts.map +1 -1
- package/dist/harness/inbox.js +4 -1
- package/dist/harness/inbox.js.map +1 -1
- package/dist/harness/json.d.ts +20 -4
- package/dist/harness/json.d.ts.map +1 -1
- package/dist/harness/json.js +23 -5
- package/dist/harness/json.js.map +1 -1
- package/dist/harness/live.d.ts +122 -16
- package/dist/harness/live.d.ts.map +1 -1
- package/dist/harness/live.js +93 -12
- package/dist/harness/live.js.map +1 -1
- package/dist/harness/partial-changes.d.ts +54 -0
- package/dist/harness/partial-changes.d.ts.map +1 -0
- package/dist/harness/partial-changes.js +162 -0
- package/dist/harness/partial-changes.js.map +1 -0
- package/dist/harness/registry-reader.d.ts +11 -0
- package/dist/harness/registry-reader.d.ts.map +1 -0
- package/dist/harness/registry-reader.js +25 -0
- package/dist/harness/registry-reader.js.map +1 -0
- package/dist/harness/scheduler.d.ts +46 -19
- package/dist/harness/scheduler.d.ts.map +1 -1
- package/dist/harness/scheduler.js +973 -376
- package/dist/harness/scheduler.js.map +1 -1
- package/dist/harness/submissions.d.ts +17 -10
- package/dist/harness/submissions.d.ts.map +1 -1
- package/dist/harness/submissions.js +62 -25
- package/dist/harness/submissions.js.map +1 -1
- package/dist/harness/task-graph.d.ts +12 -9
- package/dist/harness/task-graph.d.ts.map +1 -1
- package/dist/harness/task-graph.js +38 -28
- package/dist/harness/task-graph.js.map +1 -1
- package/dist/harness/telemetry.d.ts +11 -11
- package/dist/harness/telemetry.d.ts.map +1 -1
- package/dist/harness/telemetry.js +7 -7
- package/dist/harness/telemetry.js.map +1 -1
- package/dist/harness/tool.d.ts +2 -0
- package/dist/harness/tool.d.ts.map +1 -1
- package/dist/harness/tool.js +171 -55
- package/dist/harness/tool.js.map +1 -1
- package/dist/harness/transcript.d.ts +72 -0
- package/dist/harness/transcript.d.ts.map +1 -0
- package/dist/harness/transcript.js +264 -0
- package/dist/harness/transcript.js.map +1 -0
- package/dist/harness/types.d.ts +218 -59
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/util.d.ts +3 -1
- package/dist/harness/util.d.ts.map +1 -1
- package/dist/harness/util.js +9 -0
- package/dist/harness/util.js.map +1 -1
- package/dist/harness/view.d.ts +43 -22
- package/dist/harness/view.d.ts.map +1 -1
- package/dist/harness/view.js +130 -71
- package/dist/harness/view.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/search.d.ts +19 -3
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +107 -44
- package/dist/search.js.map +1 -1
- package/dist/session/cached-storage.d.ts +71 -0
- package/dist/session/cached-storage.d.ts.map +1 -0
- package/dist/session/cached-storage.js +269 -0
- package/dist/session/cached-storage.js.map +1 -0
- package/dist/session/conversation-tails.d.ts +33 -0
- package/dist/session/conversation-tails.d.ts.map +1 -0
- package/dist/session/conversation-tails.js +101 -0
- package/dist/session/conversation-tails.js.map +1 -0
- package/dist/session/keys.d.ts +68 -0
- package/dist/session/keys.d.ts.map +1 -0
- package/dist/session/keys.js +161 -0
- package/dist/session/keys.js.map +1 -0
- package/dist/session/session.d.ts +167 -26
- package/dist/session/session.d.ts.map +1 -1
- package/dist/session/session.js +1029 -171
- package/dist/session/session.js.map +1 -1
- package/dist/session/transaction.d.ts +81 -3
- package/dist/session/transaction.d.ts.map +1 -1
- package/dist/session/transaction.js +224 -37
- package/dist/session/transaction.js.map +1 -1
- package/dist/session/writer.d.ts +74 -0
- package/dist/session/writer.d.ts.map +1 -0
- package/dist/session/writer.js +294 -0
- package/dist/session/writer.js.map +1 -0
- package/dist/storage/indexeddb.d.ts +10 -2
- package/dist/storage/indexeddb.d.ts.map +1 -1
- package/dist/storage/indexeddb.js +91 -41
- package/dist/storage/indexeddb.js.map +1 -1
- package/dist/storage/jsonl/storage.d.ts +14 -2
- package/dist/storage/jsonl/storage.d.ts.map +1 -1
- package/dist/storage/jsonl/storage.js +88 -24
- package/dist/storage/jsonl/storage.js.map +1 -1
- package/dist/storage/memory.d.ts +7 -2
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/storage/memory.js +28 -2
- package/dist/storage/memory.js.map +1 -1
- package/dist/storage/sqlite/storage.d.ts +14 -2
- package/dist/storage/sqlite/storage.d.ts.map +1 -1
- package/dist/storage/sqlite/storage.js +110 -36
- package/dist/storage/sqlite/storage.js.map +1 -1
- package/dist/storage/store/commit.d.ts +33 -0
- package/dist/storage/store/commit.d.ts.map +1 -0
- package/dist/storage/store/commit.js +286 -0
- package/dist/storage/store/commit.js.map +1 -0
- package/dist/storage/store/documents.d.ts +43 -0
- package/dist/storage/store/documents.d.ts.map +1 -0
- package/dist/storage/store/documents.js +102 -0
- package/dist/storage/store/documents.js.map +1 -0
- package/dist/storage/store/index.d.ts +2 -0
- package/dist/storage/store/index.d.ts.map +1 -0
- package/dist/storage/store/index.js +2 -0
- package/dist/storage/store/index.js.map +1 -0
- package/dist/storage/store/queries.d.ts +49 -0
- package/dist/storage/store/queries.d.ts.map +1 -0
- package/dist/storage/store/queries.js +93 -0
- package/dist/storage/store/queries.js.map +1 -0
- package/dist/storage/store/storage.d.ts +59 -0
- package/dist/storage/store/storage.d.ts.map +1 -0
- package/dist/storage/store/storage.js +438 -0
- package/dist/storage/store/storage.js.map +1 -0
- package/dist/storage/store/tables.d.ts +54 -0
- package/dist/storage/store/tables.d.ts.map +1 -0
- package/dist/storage/store/tables.js +108 -0
- package/dist/storage/store/tables.js.map +1 -0
- package/dist/testing/commit-writes.d.ts +5 -0
- package/dist/testing/commit-writes.d.ts.map +1 -0
- package/dist/testing/commit-writes.js +12 -0
- package/dist/testing/commit-writes.js.map +1 -0
- package/dist/testing/env-conformance.js +7 -7
- package/dist/testing/env-conformance.js.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/storage-benchmark.d.ts.map +1 -1
- package/dist/testing/storage-benchmark.js +18 -17
- package/dist/testing/storage-benchmark.js.map +1 -1
- package/dist/testing/storage-conformance.d.ts.map +1 -1
- package/dist/testing/storage-conformance.js +354 -69
- package/dist/testing/storage-conformance.js.map +1 -1
- package/dist/tool-search/tool-search.d.ts +6 -12
- package/dist/tool-search/tool-search.d.ts.map +1 -1
- package/dist/tool-search/tool-search.js +7 -7
- package/dist/tool-search/tool-search.js.map +1 -1
- package/dist/tools/bash.d.ts +12 -12
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +16 -15
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/edit.d.ts +7 -7
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +9 -9
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/index.d.ts +32 -32
- package/dist/tools/read.d.ts +6 -6
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +19 -8
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/write.d.ts +4 -4
- package/dist/tools/write.d.ts.map +1 -1
- package/dist/tools/write.js +5 -5
- package/dist/tools/write.js.map +1 -1
- package/dist/types.d.ts +223 -77
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +19 -12
- package/dist/harness/events.d.ts +0 -186
- package/dist/harness/events.d.ts.map +0 -1
- package/dist/harness/events.js +0 -373
- package/dist/harness/events.js.map +0 -1
- package/dist/session/observation.d.ts +0 -42
- package/dist/session/observation.d.ts.map +0 -1
- package/dist/session/observation.js +0 -281
- package/dist/session/observation.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Context } from "@earendil-works/chord";
|
|
2
2
|
import { type TelemetryContext, type TelemetrySpan } from "@earendil-works/pi-telemetry";
|
|
3
3
|
import type { SessionImpl } from "../session/session.ts";
|
|
4
|
-
import type { ConversationId,
|
|
4
|
+
import type { ConversationId, SubmissionId, SubmissionRecord, Tx } from "../types.ts";
|
|
5
5
|
import { type QueueModes } from "./inbox.ts";
|
|
6
6
|
import type { SettledSubmissionRecord, Submission, SubmissionDraft } from "./types.ts";
|
|
7
7
|
type AbortResult = "aborted" | "already_placed" | "settled";
|
|
@@ -12,9 +12,14 @@ type Admission = {
|
|
|
12
12
|
/** Admission, waits, and withdrawal of the durable submissions of one Harness. */
|
|
13
13
|
export declare class Submissions {
|
|
14
14
|
#private;
|
|
15
|
-
constructor(session: SessionImpl,
|
|
15
|
+
constructor(session: SessionImpl, now: () => number, queueModes: () => QueueModes, resume: () => void, telemetry?: TelemetryContext);
|
|
16
16
|
/** Admit a submission in one commit; see `admitSubmission()`. */
|
|
17
17
|
submit(conversationId: ConversationId, draft: SubmissionDraft, context: Context): Promise<Submission>;
|
|
18
|
+
/**
|
|
19
|
+
* Admit a submission inside the caller's commit `tx`, with the rules of `submit()`. The admission is stored or lost
|
|
20
|
+
* with that commit. It must come before the commit's first table write, another admission's included.
|
|
21
|
+
*/
|
|
22
|
+
admit(tx: Tx, conversationId: ConversationId, draft: SubmissionDraft): Promise<SubmissionId>;
|
|
18
23
|
/** Handle for an existing submission, or `undefined`. */
|
|
19
24
|
get(id: SubmissionId, context: Context): Promise<Submission | undefined>;
|
|
20
25
|
status(id: SubmissionId, context: Context): Promise<SubmissionRecord>;
|
|
@@ -23,14 +28,16 @@ export declare class Submissions {
|
|
|
23
28
|
abort(id: SubmissionId, context: Context, conversationId?: ConversationId): Promise<AbortResult | "not_found">;
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
|
-
* Admit a submission inside a commit (spec §6); `Conversation.submit()` and conversation-owned compactions
|
|
27
|
-
* known request ID returns its existing submission without writing. A display-only write (only `kind` and
|
|
28
|
-
* appended and settled `done` at once, busy or not, as it changes nothing the model sees; only behind a
|
|
29
|
-
* queues, so it lands after the reset instead of before it in the context the reset ends. A busy
|
|
30
|
-
* `pi.inbox`, or rejects `whenBusy: "reject"` input
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* Admit a submission inside a commit (spec §6); both `Conversation.submit()` forms and conversation-owned compactions
|
|
32
|
+
* share it. A known request ID returns its existing submission without writing. A display-only write (only `kind` and
|
|
33
|
+
* `data`) is appended and settled `done` at once, busy or not, as it changes nothing the model sees; only behind a
|
|
34
|
+
* queued reset it queues, so it lands after the reset instead of before it in the context the reset ends. A busy
|
|
35
|
+
* conversation queues anything else in `pi.inbox`, or rejects `whenBusy: "reject"` input and any continue with
|
|
36
|
+
* `ConversationBusy`; an idle one rejects `whenIdle: "reject"` input with `ConversationIdle`. An idle continue places
|
|
37
|
+
* queued items and starts a run with them and itself, placing no entry of its own. An idle conversation with queued
|
|
38
|
+
* items queues it behind them and runs a final boundary. Otherwise idle input places its entry (`pi.user`, or the
|
|
39
|
+
* input's own) and starts a run, and an idle write appends its entry and settles `done`, or `stale` when its head
|
|
40
|
+
* reaches before the active range.
|
|
34
41
|
*/
|
|
35
42
|
export declare function admitSubmission(tx: Tx, conversationId: ConversationId, draft: SubmissionDraft, now: number, queueModes: QueueModes, span?: TelemetrySpan): Promise<Admission>;
|
|
36
43
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submissions.d.ts","sourceRoot":"","sources":["../../src/harness/submissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAqC,MAAM,uBAAuB,CAAC;AAExF,OAAO,EAGN,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"submissions.d.ts","sourceRoot":"","sources":["../../src/harness/submissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAqC,MAAM,uBAAuB,CAAC;AAExF,OAAO,EAGN,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAkB,WAAW,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,uBAAuB,CAAC,CAY/E;IAED,kHAAkH;IAClH,KAAK,CAAC,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC,CAa7G;CAUD;AAwCD;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACpC,EAAE,EAAE,EAAE,EACN,cAAc,EAAE,cAAc,EAC9B,KAAK,EAAE,eAAe,EACtB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,UAAU,EACtB,IAAI,CAAC,EAAE,aAAa,GAClB,OAAO,CAAC,SAAS,CAAC,CAuFpB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { copyJson } from "@earendil-works/chord";
|
|
2
2
|
import { withTelemetry } from "@earendil-works/chord/context";
|
|
3
3
|
import { createTypedSpanStarter, NOOP_TELEMETRY_CONTEXT, } from "@earendil-works/pi-telemetry";
|
|
4
|
-
import { ConversationBusy } from "../errors.js";
|
|
4
|
+
import { ConversationBusy, ConversationIdle, ReadAfterWrite } from "../errors.js";
|
|
5
5
|
import { startRun } from "./generation.js";
|
|
6
6
|
import { appendInput, applyBoundary, hasQueuedReset, InboxDoc, isDisplayOnly, isStale, pickInputEntry, prepareBoundary, removeInboxItem, } from "./inbox.js";
|
|
7
7
|
import { LiveDoc } from "./live.js";
|
|
@@ -11,7 +11,6 @@ import { closedError, Waiters } from "./util.js";
|
|
|
11
11
|
export class Submissions {
|
|
12
12
|
#telemetry;
|
|
13
13
|
#session;
|
|
14
|
-
#storage;
|
|
15
14
|
#now;
|
|
16
15
|
/** Read at each admission, on the Session line. */
|
|
17
16
|
#queueModes;
|
|
@@ -19,14 +18,13 @@ export class Submissions {
|
|
|
19
18
|
#resume;
|
|
20
19
|
#waiters = new Waiters();
|
|
21
20
|
#closed = false;
|
|
22
|
-
constructor(session,
|
|
21
|
+
constructor(session, now, queueModes, resume, telemetry = NOOP_TELEMETRY_CONTEXT) {
|
|
23
22
|
this.#telemetry = telemetry;
|
|
24
23
|
this.#session = session;
|
|
25
|
-
this.#storage = storage;
|
|
26
24
|
this.#now = now;
|
|
27
25
|
this.#queueModes = queueModes;
|
|
28
26
|
this.#resume = resume;
|
|
29
|
-
session.
|
|
27
|
+
session.followCommits((publication) => this.#observe(publication));
|
|
30
28
|
session.subscribeClose(() => {
|
|
31
29
|
this.#closed = true;
|
|
32
30
|
this.#waiters.rejectAll(closedError(this.#session));
|
|
@@ -34,18 +32,38 @@ export class Submissions {
|
|
|
34
32
|
}
|
|
35
33
|
/** Admit a submission in one commit; see `admitSubmission()`. */
|
|
36
34
|
async submit(conversationId, draft, context) {
|
|
35
|
+
const { id } = await this.#traced(conversationId, draft, context, (span) => this.#session.commitWith((tx) => admitSubmission(tx, conversationId, draft, this.#now(), this.#queueModes(), span), withTelemetry(span, context)));
|
|
36
|
+
return new SubmissionHandle(id, this);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Admit a submission inside the caller's commit `tx`, with the rules of `submit()`. The admission is stored or lost
|
|
40
|
+
* with that commit. It must come before the commit's first table write, another admission's included.
|
|
41
|
+
*/
|
|
42
|
+
async admit(tx, conversationId, draft) {
|
|
43
|
+
if (!this.#session.ownsTransaction(tx))
|
|
44
|
+
throw new Error("The transaction belongs to another Session");
|
|
45
|
+
// Enforced on every path: admission reads tables only on some (request IDs, an idle boundary, a steer's trace).
|
|
46
|
+
if (tx.hasTableWrite)
|
|
47
|
+
throw new ReadAfterWrite("submit(tx, draft)");
|
|
48
|
+
const admission = await this.#traced(conversationId, draft, tx.context, (span) => admitSubmission(tx, conversationId, draft, this.#now(), this.#queueModes(), span));
|
|
49
|
+
return admission.id;
|
|
50
|
+
}
|
|
51
|
+
/** Run one admission in its `pi.durable.submit` span, asking for progress first, as the run it starts needs it. */
|
|
52
|
+
#traced(conversationId, draft, context, admit) {
|
|
37
53
|
this.#resume();
|
|
38
|
-
|
|
54
|
+
// Inputs and continues start runs: root traces linked to their callers.
|
|
55
|
+
const startsRun = draft.type !== "write";
|
|
56
|
+
const parent = startsRun ? this.#telemetry : context.telemetry;
|
|
39
57
|
return createTypedSpanStarter(parent, [DURABLE_TELEMETRY_SCHEMA])("pi.durable.submit", {
|
|
40
58
|
"submission.type": draft.type,
|
|
41
59
|
"conversation.id": conversationId,
|
|
42
60
|
}, async (span) => {
|
|
43
|
-
if (
|
|
61
|
+
if (startsRun)
|
|
44
62
|
span.addLink({ context: context.telemetry });
|
|
45
63
|
try {
|
|
46
|
-
const
|
|
47
|
-
span.setAttributes({ "submission.id": id, result: status });
|
|
48
|
-
return
|
|
64
|
+
const admission = await admit(span);
|
|
65
|
+
span.setAttributes({ "submission.id": admission.id, result: admission.status });
|
|
66
|
+
return admission;
|
|
49
67
|
}
|
|
50
68
|
catch (error) {
|
|
51
69
|
// Error text may contain caller content. Record only the status.
|
|
@@ -56,11 +74,11 @@ export class Submissions {
|
|
|
56
74
|
}
|
|
57
75
|
/** Handle for an existing submission, or `undefined`. */
|
|
58
76
|
async get(id, context) {
|
|
59
|
-
const record = await this.#session.readOnLine(() =>
|
|
77
|
+
const record = await this.#session.readOnLine((storage) => storage.submission(id, context));
|
|
60
78
|
return record === undefined ? undefined : new SubmissionHandle(record.id, this);
|
|
61
79
|
}
|
|
62
80
|
async status(id, context) {
|
|
63
|
-
const record = await this.#session.readOnLine(() =>
|
|
81
|
+
const record = await this.#session.readOnLine((storage) => storage.submission(id, context));
|
|
64
82
|
if (record === undefined)
|
|
65
83
|
throw new Error(`Submission ${id} does not exist`);
|
|
66
84
|
return record;
|
|
@@ -68,8 +86,8 @@ export class Submissions {
|
|
|
68
86
|
async wait(id, context) {
|
|
69
87
|
this.#resume();
|
|
70
88
|
// Check and register on the line so no settling publication falls between them.
|
|
71
|
-
const found = await this.#session.readOnLine(async () => {
|
|
72
|
-
const record = await
|
|
89
|
+
const found = await this.#session.readOnLine(async (storage) => {
|
|
90
|
+
const record = await storage.submission(id, context);
|
|
73
91
|
if (record === undefined)
|
|
74
92
|
throw new Error(`Submission ${id} does not exist`);
|
|
75
93
|
if (isSettled(record))
|
|
@@ -97,6 +115,9 @@ export class Submissions {
|
|
|
97
115
|
}, context);
|
|
98
116
|
}
|
|
99
117
|
#observe(publication) {
|
|
118
|
+
// A commit held in memory changes documents only.
|
|
119
|
+
if (publication.kind === "memory")
|
|
120
|
+
return;
|
|
100
121
|
for (const change of publication.changes) {
|
|
101
122
|
if (change.type !== "submission" || !isSettled(change.value))
|
|
102
123
|
continue;
|
|
@@ -135,14 +156,16 @@ function checkInputEntry(entry) {
|
|
|
135
156
|
}
|
|
136
157
|
}
|
|
137
158
|
/**
|
|
138
|
-
* Admit a submission inside a commit (spec §6); `Conversation.submit()` and conversation-owned compactions
|
|
139
|
-
* known request ID returns its existing submission without writing. A display-only write (only `kind` and
|
|
140
|
-
* appended and settled `done` at once, busy or not, as it changes nothing the model sees; only behind a
|
|
141
|
-
* queues, so it lands after the reset instead of before it in the context the reset ends. A busy
|
|
142
|
-
* `pi.inbox`, or rejects `whenBusy: "reject"` input
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
159
|
+
* Admit a submission inside a commit (spec §6); both `Conversation.submit()` forms and conversation-owned compactions
|
|
160
|
+
* share it. A known request ID returns its existing submission without writing. A display-only write (only `kind` and
|
|
161
|
+
* `data`) is appended and settled `done` at once, busy or not, as it changes nothing the model sees; only behind a
|
|
162
|
+
* queued reset it queues, so it lands after the reset instead of before it in the context the reset ends. A busy
|
|
163
|
+
* conversation queues anything else in `pi.inbox`, or rejects `whenBusy: "reject"` input and any continue with
|
|
164
|
+
* `ConversationBusy`; an idle one rejects `whenIdle: "reject"` input with `ConversationIdle`. An idle continue places
|
|
165
|
+
* queued items and starts a run with them and itself, placing no entry of its own. An idle conversation with queued
|
|
166
|
+
* items queues it behind them and runs a final boundary. Otherwise idle input places its entry (`pi.user`, or the
|
|
167
|
+
* input's own) and starts a run, and an idle write appends its entry and settles `done`, or `stale` when its head
|
|
168
|
+
* reaches before the active range.
|
|
146
169
|
*/
|
|
147
170
|
export async function admitSubmission(tx, conversationId, draft, now, queueModes, span) {
|
|
148
171
|
if (draft.type === "input" && draft.entry !== undefined)
|
|
@@ -176,6 +199,20 @@ export async function admitSubmission(tx, conversationId, draft, now, queueModes
|
|
|
176
199
|
}
|
|
177
200
|
if (busy && draft.type === "input" && draft.whenBusy === "reject")
|
|
178
201
|
throw new ConversationBusy(conversationId);
|
|
202
|
+
if (!busy && draft.type === "input" && draft.whenIdle === "reject")
|
|
203
|
+
throw new ConversationIdle(conversationId);
|
|
204
|
+
if (draft.type === "continue") {
|
|
205
|
+
// Never queued: whether a run can continue depends on how the current one ends. Rejected before any write.
|
|
206
|
+
if (busy)
|
|
207
|
+
throw new ConversationBusy(conversationId);
|
|
208
|
+
const boundary = await prepareBoundary(tx, conversationId, queueModes);
|
|
209
|
+
const { id } = await tx.createSubmission({ ...fields, type: "continue", status: "placed" });
|
|
210
|
+
// Items an earlier failed run left queued (`afterFailedRun: "keep"`) are placed first and join the run. Its history
|
|
211
|
+
// starts with the failed run's, so `afterRun` hooks see what that run did.
|
|
212
|
+
const { users, first } = await applyBoundary(tx, boundary, "final", now);
|
|
213
|
+
await startRun(tx, conversationId, live, { inputs: [...users, id], first: live.runFailure?.first ?? first });
|
|
214
|
+
return { id, status: "placed" };
|
|
215
|
+
}
|
|
179
216
|
// A boundary reads the table, so it is prepared before the first table write; a busy one needs none.
|
|
180
217
|
const boundary = busy ? undefined : await prepareBoundary(tx, conversationId, queueModes);
|
|
181
218
|
if (boundary === undefined || boundary.inbox.items.length > 0) {
|
|
@@ -199,9 +236,9 @@ export async function admitSubmission(tx, conversationId, draft, now, queueModes
|
|
|
199
236
|
}
|
|
200
237
|
if (boundary === undefined)
|
|
201
238
|
return { id, status: "queued" };
|
|
202
|
-
const { users } = await applyBoundary(tx, boundary, "final", now);
|
|
239
|
+
const { users, first } = await applyBoundary(tx, boundary, "final", now);
|
|
203
240
|
if (users.length > 0)
|
|
204
|
-
await startRun(tx, conversationId, live, users);
|
|
241
|
+
await startRun(tx, conversationId, live, { inputs: users, first });
|
|
205
242
|
return { id, status: draft.type === "write" ? "done" : users.at(-1) === id ? "placed" : "queued" };
|
|
206
243
|
}
|
|
207
244
|
if (draft.type === "write") {
|
|
@@ -219,7 +256,7 @@ export async function admitSubmission(tx, conversationId, draft, now, queueModes
|
|
|
219
256
|
const entry = await appendInput(tx, conversationId, draft.content, draft.entry, now);
|
|
220
257
|
const input = { ...fields, type: "input", status: "placed", entry: entry.id };
|
|
221
258
|
const { id } = await tx.createSubmission(input);
|
|
222
|
-
await startRun(tx, conversationId, live, [id]);
|
|
259
|
+
await startRun(tx, conversationId, live, { inputs: [id], first: entry.id });
|
|
223
260
|
return { id, status: "placed" };
|
|
224
261
|
}
|
|
225
262
|
//# sourceMappingURL=submissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submissions.js","sourceRoot":"","sources":["../../src/harness/submissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAA2B,MAAM,uBAAuB,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EACN,sBAAsB,EACtB,sBAAsB,GAGtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAWhD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACN,WAAW,EACX,aAAa,EACb,cAAc,EACd,QAAQ,EACR,aAAa,EACb,OAAO,EACP,cAAc,EACd,eAAe,EAEf,eAAe,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKjD,kFAAk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AE,GAAG,CAAC,CAAC;IACrF,MAAM,KAAK,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,EAAW,CAAC;IACvF,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,QAAQ,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/C,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import { type Context, copyJson, type JsonRepresentation } from \"@earendil-works/chord\";\nimport { withTelemetry } from \"@earendil-works/chord/context\";\nimport {\n\tcreateTypedSpanStarter,\n\tNOOP_TELEMETRY_CONTEXT,\n\ttype TelemetryContext,\n\ttype TelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\nimport { ConversationBusy } from \"../errors.ts\";\nimport type { SessionImpl } from \"../session/session.ts\";\nimport type {\n\tCommitPublication,\n\tConversationId,\n\tJsonObject,\n\tStorage,\n\tSubmissionId,\n\tSubmissionRecord,\n\tTx,\n} from \"../types.ts\";\nimport { startRun } from \"./generation.ts\";\nimport {\n\tappendInput,\n\tapplyBoundary,\n\thasQueuedReset,\n\tInboxDoc,\n\tisDisplayOnly,\n\tisStale,\n\tpickInputEntry,\n\tprepareBoundary,\n\ttype QueueModes,\n\tremoveInboxItem,\n} from \"./inbox.ts\";\nimport { LiveDoc } from \"./live.ts\";\nimport { DURABLE_TELEMETRY_SCHEMA } from \"./telemetry.ts\";\nimport type { InputEntry, SettledSubmissionRecord, Submission, SubmissionDraft, UserInput } from \"./types.ts\";\nimport { closedError, Waiters } from \"./util.ts\";\n\ntype AbortResult = \"aborted\" | \"already_placed\" | \"settled\";\ntype Admission = { readonly id: SubmissionId; readonly status: \"queued\" | \"placed\" | \"done\" };\n\n/** Admission, waits, and withdrawal of the durable submissions of one Harness. */\nexport class Submissions {\n\treadonly #telemetry: TelemetryContext;\n\treadonly #session: SessionImpl;\n\treadonly #storage: Storage;\n\treadonly #now: () => number;\n\t/** Read at each admission, on the Session line. */\n\treadonly #queueModes: () => QueueModes;\n\t/** Enable task scheduling; submitting or waiting asks for progress. */\n\treadonly #resume: () => void;\n\treadonly #waiters = new Waiters<SubmissionId, SettledSubmissionRecord>();\n\t#closed = false;\n\n\tconstructor(\n\t\tsession: SessionImpl,\n\t\tstorage: Storage,\n\t\tnow: () => number,\n\t\tqueueModes: () => QueueModes,\n\t\tresume: () => void,\n\t\ttelemetry: TelemetryContext = NOOP_TELEMETRY_CONTEXT,\n\t) {\n\t\tthis.#telemetry = telemetry;\n\t\tthis.#session = session;\n\t\tthis.#storage = storage;\n\t\tthis.#now = now;\n\t\tthis.#queueModes = queueModes;\n\t\tthis.#resume = resume;\n\t\tsession.observeCommits((publication) => this.#observe(publication));\n\t\tsession.subscribeClose(() => {\n\t\t\tthis.#closed = true;\n\t\t\tthis.#waiters.rejectAll(closedError(this.#session));\n\t\t});\n\t}\n\n\t/** Admit a submission in one commit; see `admitSubmission()`. */\n\tasync submit(conversationId: ConversationId, draft: SubmissionDraft, context: Context): Promise<Submission> {\n\t\tthis.#resume();\n\t\tconst parent = draft.type === \"input\" ? this.#telemetry : context.telemetry;\n\t\treturn createTypedSpanStarter(parent, [DURABLE_TELEMETRY_SCHEMA])(\n\t\t\t\"pi.durable.submit\",\n\t\t\t{\n\t\t\t\t\"submission.type\": draft.type,\n\t\t\t\t\"conversation.id\": conversationId,\n\t\t\t},\n\t\t\tasync (span) => {\n\t\t\t\tif (draft.type === \"input\") span.addLink({ context: context.telemetry });\n\t\t\t\ttry {\n\t\t\t\t\tconst { id, status } = await this.#session.commitWith(\n\t\t\t\t\t\t(tx) => admitSubmission(tx, conversationId, draft, this.#now(), this.#queueModes(), span),\n\t\t\t\t\t\twithTelemetry(span, context),\n\t\t\t\t\t);\n\t\t\t\t\tspan.setAttributes({ \"submission.id\": id, result: status });\n\t\t\t\t\treturn new SubmissionHandle(id, this);\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Error text may contain caller content. Record only the status.\n\t\t\t\t\tspan.setStatus({ status: \"error\" });\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Handle for an existing submission, or `undefined`. */\n\tasync get(id: SubmissionId, context: Context): Promise<Submission | undefined> {\n\t\tconst record = await this.#session.readOnLine(() => this.#storage.submission(id, context));\n\t\treturn record === undefined ? undefined : new SubmissionHandle(record.id, this);\n\t}\n\n\tasync status(id: SubmissionId, context: Context): Promise<SubmissionRecord> {\n\t\tconst record = await this.#session.readOnLine(() => this.#storage.submission(id, context));\n\t\tif (record === undefined) throw new Error(`Submission ${id} does not exist`);\n\t\treturn record;\n\t}\n\n\tasync wait(id: SubmissionId, context: Context): Promise<SettledSubmissionRecord> {\n\t\tthis.#resume();\n\t\t// Check and register on the line so no settling publication falls between them.\n\t\tconst found = await this.#session.readOnLine(async () => {\n\t\t\tconst record = await this.#storage.submission(id, context);\n\t\t\tif (record === undefined) throw new Error(`Submission ${id} does not exist`);\n\t\t\tif (isSettled(record)) return { promise: Promise.resolve(record) };\n\t\t\t// Close rejects registered waiters synchronously and may begin during the read.\n\t\t\tif (this.#closed) throw closedError(this.#session);\n\t\t\treturn { promise: this.#waiters.add(id, context) };\n\t\t});\n\t\treturn found.promise;\n\t}\n\n\t/** Withdraw a queued submission and remove its inbox item; placed inputs and settled submissions are reported. */\n\tabort(id: SubmissionId, context: Context, conversationId?: ConversationId): Promise<AbortResult | \"not_found\"> {\n\t\treturn this.#session.commitWith(async (tx) => {\n\t\t\tconst record = await tx.submission(id);\n\t\t\tif (record === undefined || (conversationId !== undefined && record.conversationId !== conversationId)) {\n\t\t\t\treturn \"not_found\";\n\t\t\t}\n\t\t\tif (record.status === \"queued\") {\n\t\t\t\ttx.settleSubmission(id, { status: \"unanswered\", reason: \"aborted\" });\n\t\t\t\tawait removeInboxItem(tx, record.conversationId, id);\n\t\t\t\treturn \"aborted\";\n\t\t\t}\n\t\t\treturn record.status === \"placed\" ? \"already_placed\" : \"settled\";\n\t\t}, context);\n\t}\n\n\t#observe(publication: CommitPublication): void {\n\t\tfor (const change of publication.changes) {\n\t\t\tif (change.type !== \"submission\" || !isSettled(change.value)) continue;\n\t\t\tthis.#waiters.resolve(change.value.id, change.value);\n\t\t}\n\t}\n}\n\nclass SubmissionHandle implements Submission {\n\treadonly id: SubmissionId;\n\treadonly #submissions: Submissions;\n\n\tconstructor(id: SubmissionId, submissions: Submissions) {\n\t\tthis.id = id;\n\t\tthis.#submissions = submissions;\n\t}\n\n\tstatus(context: Context): Promise<SubmissionRecord> {\n\t\treturn this.#submissions.status(this.id, context);\n\t}\n\n\twait(context: Context): Promise<SettledSubmissionRecord> {\n\t\treturn this.#submissions.wait(this.id, context);\n\t}\n\n\tasync abort(context: Context): Promise<AbortResult> {\n\t\tconst result = await this.#submissions.abort(this.id, context);\n\t\tif (result === \"not_found\") throw new Error(`Submission ${this.id} does not exist`);\n\t\treturn result;\n\t}\n}\n\nfunction isSettled(record: SubmissionRecord): record is SettledSubmissionRecord {\n\treturn record.status === \"done\" || record.status === \"unanswered\";\n}\n\n/** Reject an input entry an untyped caller got wrong: its kind must be a non-empty string outside the `pi.` prefix. */\nfunction checkInputEntry(entry: InputEntry): void {\n\tconst { kind } = entry;\n\tif (typeof kind !== \"string\" || kind.length === 0 || kind.startsWith(\"pi.\")) {\n\t\tthrow new TypeError(\n\t\t\t`An input entry's kind must be a non-empty string not starting with \"pi.\", got ${String(kind)}`,\n\t\t);\n\t}\n}\n\n/**\n * Admit a submission inside a commit (spec §6); `Conversation.submit()` and conversation-owned compactions share it. A\n * known request ID returns its existing submission without writing. A display-only write (only `kind` and `data`) is\n * appended and settled `done` at once, busy or not, as it changes nothing the model sees; only behind a queued reset it\n * queues, so it lands after the reset instead of before it in the context the reset ends. A busy conversation queues anything else in\n * `pi.inbox`, or rejects `whenBusy: \"reject\"` input with `ConversationBusy`. An idle conversation with queued items\n * queues it behind them and runs a final boundary. Otherwise idle input places its entry (`pi.user`, or the input's\n * own) and starts a run, and an idle write appends its entry and settles `done`, or `stale` when its head reaches\n * before the active range.\n */\nexport async function admitSubmission(\n\ttx: Tx,\n\tconversationId: ConversationId,\n\tdraft: SubmissionDraft,\n\tnow: number,\n\tqueueModes: QueueModes,\n\tspan?: TelemetrySpan,\n): Promise<Admission> {\n\tif (draft.type === \"input\" && draft.entry !== undefined) checkInputEntry(draft.entry);\n\tif (draft.requestId !== undefined) {\n\t\tconst existing = await tx.submissionByRequest(conversationId, draft.requestId);\n\t\tif (existing !== undefined) {\n\t\t\tif (existing.type !== draft.type) {\n\t\t\t\tthrow new Error(`Request ${draft.requestId} already identifies a submission of type ${existing.type}`);\n\t\t\t}\n\t\t\treturn { id: existing.id, status: existing.status === \"unanswered\" ? \"done\" : existing.status };\n\t\t}\n\t}\n\tconst fields = { conversationId, requestId: draft.requestId, trace: span?.propagation?.inject(span) };\n\tif (\n\t\tdraft.type === \"write\" &&\n\t\tisDisplayOnly(draft.entry) &&\n\t\t!hasQueuedReset((await tx.doc(InboxDoc, conversationId)).items)\n\t) {\n\t\tconst entry = await tx.appendEntry(conversationId, draft.entry);\n\t\tconst write = { ...fields, type: \"write\", status: \"done\", entry: entry.id } as const;\n\t\treturn { id: (await tx.createSubmission(write)).id, status: \"done\" };\n\t}\n\tconst live = await tx.doc(LiveDoc, conversationId);\n\tconst busy = live.run !== undefined;\n\tif (\n\t\tdraft.type === \"input\" &&\n\t\tdraft.whenBusy === \"steer\" &&\n\t\tlive.run !== undefined &&\n\t\tspan?.propagation !== undefined\n\t) {\n\t\tconst run = await tx.task(live.run.taskId);\n\t\tif (run?.trace !== undefined) span.addLink({ context: span.propagation.extract(run.trace) });\n\t}\n\tif (busy && draft.type === \"input\" && draft.whenBusy === \"reject\") throw new ConversationBusy(conversationId);\n\t// A boundary reads the table, so it is prepared before the first table write; a busy one needs none.\n\tconst boundary = busy ? undefined : await prepareBoundary(tx, conversationId, queueModes);\n\tif (boundary === undefined || boundary.inbox.items.length > 0) {\n\t\tconst { id } = await tx.createSubmission({\n\t\t\t...fields,\n\t\t\ttype: draft.type,\n\t\t\tstatus: \"queued\",\n\t\t});\n\t\t// Hosts may leave optional fields `undefined`; drafts take strict JSON.\n\t\tconst value = copyJson(draft.type === \"write\" ? draft.entry : draft.content, {\n\t\t\tomitUndefinedProperties: true,\n\t\t});\n\t\tconst items = (boundary?.inbox ?? (await tx.doc(InboxDoc, conversationId))).items;\n\t\tif (draft.type === \"write\") items.push({ id, mode: \"write\", entry: value as JsonObject });\n\t\telse {\n\t\t\tconst mode = draft.whenBusy === \"steer\" ? \"steer\" : \"followUp\";\n\t\t\tconst content = value as JsonRepresentation<UserInput>;\n\t\t\tconst entry = draft.entry === undefined ? {} : { entry: pickInputEntry(draft.entry) };\n\t\t\titems.push({ id, mode, content, ...entry });\n\t\t}\n\t\tif (boundary === undefined) return { id, status: \"queued\" };\n\t\tconst { users } = await applyBoundary(tx, boundary, \"final\", now);\n\t\tif (users.length > 0) await startRun(tx, conversationId, live, users);\n\t\treturn { id, status: draft.type === \"write\" ? \"done\" : users.at(-1) === id ? \"placed\" : \"queued\" };\n\t}\n\tif (draft.type === \"write\") {\n\t\tif (isStale(boundary, draft.entry)) {\n\t\t\tconst stale = { status: \"unanswered\", reason: \"stale\" } as const;\n\t\t\treturn {\n\t\t\t\tid: (await tx.createSubmission({ ...fields, type: \"write\", ...stale })).id,\n\t\t\t\tstatus: \"done\",\n\t\t\t};\n\t\t}\n\t\tconst entry = await tx.appendEntry(conversationId, draft.entry);\n\t\tconst write = { ...fields, type: \"write\", status: \"done\", entry: entry.id } as const;\n\t\treturn { id: (await tx.createSubmission(write)).id, status: \"done\" };\n\t}\n\tconst entry = await appendInput(tx, conversationId, draft.content, draft.entry, now);\n\tconst input = { ...fields, type: \"input\", status: \"placed\", entry: entry.id } as const;\n\tconst { id } = await tx.createSubmission(input);\n\tawait startRun(tx, conversationId, live, [id]);\n\treturn { id, status: \"placed\" };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"submissions.js","sourceRoot":"","sources":["../../src/harness/submissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAA2B,MAAM,uBAAuB,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EACN,sBAAsB,EACtB,sBAAsB,GAGtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGlF,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACN,WAAW,EACX,aAAa,EACb,cAAc,EACd,QAAQ,EACR,aAAa,EACb,OAAO,EACP,cAAc,EACd,eAAe,EAEf,eAAe,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKjD,kFAAkF;AAClF,MAAM,OAAO,WAAW;IACd,UAAU,CAAmB;IAC7B,QAAQ,CAAc;IACtB,IAAI,CAAe;IAC5B,mDAAmD;IAC1C,WAAW,CAAmB;IACvC,uEAAuE;IAC9D,OAAO,CAAa;IACpB,QAAQ,GAAG,IAAI,OAAO,EAAyC,CAAC;IACzE,OAAO,GAAG,KAAK,CAAC;IAEhB,YACC,OAAoB,EACpB,GAAiB,EACjB,UAA4B,EAC5B,MAAkB,EAClB,SAAS,GAAqB,sBAAsB;QAEpD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG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AAE,EAAE,CAAC,MAAM,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IACtE,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,EAAE,EAAE,cAAc,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACrF,MAAM,KAAK,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,EAAW,CAAC;IACvF,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,QAAQ,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5E,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import { type Context, copyJson, type JsonRepresentation } from \"@earendil-works/chord\";\nimport { withTelemetry } from \"@earendil-works/chord/context\";\nimport {\n\tcreateTypedSpanStarter,\n\tNOOP_TELEMETRY_CONTEXT,\n\ttype TelemetryContext,\n\ttype TelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\nimport { ConversationBusy, ConversationIdle, ReadAfterWrite } from \"../errors.ts\";\nimport type { ObservedCommit, SessionImpl } from \"../session/session.ts\";\nimport type { ConversationId, JsonObject, SubmissionId, SubmissionRecord, Tx } from \"../types.ts\";\nimport { startRun } from \"./generation.ts\";\nimport {\n\tappendInput,\n\tapplyBoundary,\n\thasQueuedReset,\n\tInboxDoc,\n\tisDisplayOnly,\n\tisStale,\n\tpickInputEntry,\n\tprepareBoundary,\n\ttype QueueModes,\n\tremoveInboxItem,\n} from \"./inbox.ts\";\nimport { LiveDoc } from \"./live.ts\";\nimport { DURABLE_TELEMETRY_SCHEMA } from \"./telemetry.ts\";\nimport type { InputEntry, SettledSubmissionRecord, Submission, SubmissionDraft, UserInput } from \"./types.ts\";\nimport { closedError, Waiters } from \"./util.ts\";\n\ntype AbortResult = \"aborted\" | \"already_placed\" | \"settled\";\ntype Admission = { readonly id: SubmissionId; readonly status: \"queued\" | \"placed\" | \"done\" };\n\n/** Admission, waits, and withdrawal of the durable submissions of one Harness. */\nexport class Submissions {\n\treadonly #telemetry: TelemetryContext;\n\treadonly #session: SessionImpl;\n\treadonly #now: () => number;\n\t/** Read at each admission, on the Session line. */\n\treadonly #queueModes: () => QueueModes;\n\t/** Enable task scheduling; submitting or waiting asks for progress. */\n\treadonly #resume: () => void;\n\treadonly #waiters = new Waiters<SubmissionId, SettledSubmissionRecord>();\n\t#closed = false;\n\n\tconstructor(\n\t\tsession: SessionImpl,\n\t\tnow: () => number,\n\t\tqueueModes: () => QueueModes,\n\t\tresume: () => void,\n\t\ttelemetry: TelemetryContext = NOOP_TELEMETRY_CONTEXT,\n\t) {\n\t\tthis.#telemetry = telemetry;\n\t\tthis.#session = session;\n\t\tthis.#now = now;\n\t\tthis.#queueModes = queueModes;\n\t\tthis.#resume = resume;\n\t\tsession.followCommits((publication) => this.#observe(publication));\n\t\tsession.subscribeClose(() => {\n\t\t\tthis.#closed = true;\n\t\t\tthis.#waiters.rejectAll(closedError(this.#session));\n\t\t});\n\t}\n\n\t/** Admit a submission in one commit; see `admitSubmission()`. */\n\tasync submit(conversationId: ConversationId, draft: SubmissionDraft, context: Context): Promise<Submission> {\n\t\tconst { id } = await this.#traced(conversationId, draft, context, (span) =>\n\t\t\tthis.#session.commitWith(\n\t\t\t\t(tx) => admitSubmission(tx, conversationId, draft, this.#now(), this.#queueModes(), span),\n\t\t\t\twithTelemetry(span, context),\n\t\t\t),\n\t\t);\n\t\treturn new SubmissionHandle(id, this);\n\t}\n\n\t/**\n\t * Admit a submission inside the caller's commit `tx`, with the rules of `submit()`. The admission is stored or lost\n\t * with that commit. It must come before the commit's first table write, another admission's included.\n\t */\n\tasync admit(tx: Tx, conversationId: ConversationId, draft: SubmissionDraft): Promise<SubmissionId> {\n\t\tif (!this.#session.ownsTransaction(tx)) throw new Error(\"The transaction belongs to another Session\");\n\t\t// Enforced on every path: admission reads tables only on some (request IDs, an idle boundary, a steer's trace).\n\t\tif (tx.hasTableWrite) throw new ReadAfterWrite(\"submit(tx, draft)\");\n\t\tconst admission = await this.#traced(conversationId, draft, tx.context, (span) =>\n\t\t\tadmitSubmission(tx, conversationId, draft, this.#now(), this.#queueModes(), span),\n\t\t);\n\t\treturn admission.id;\n\t}\n\n\t/** Run one admission in its `pi.durable.submit` span, asking for progress first, as the run it starts needs it. */\n\t#traced(\n\t\tconversationId: ConversationId,\n\t\tdraft: SubmissionDraft,\n\t\tcontext: Context,\n\t\tadmit: (span: TelemetrySpan) => Promise<Admission>,\n\t): Promise<Admission> {\n\t\tthis.#resume();\n\t\t// Inputs and continues start runs: root traces linked to their callers.\n\t\tconst startsRun = draft.type !== \"write\";\n\t\tconst parent = startsRun ? this.#telemetry : context.telemetry;\n\t\treturn createTypedSpanStarter(parent, [DURABLE_TELEMETRY_SCHEMA])(\n\t\t\t\"pi.durable.submit\",\n\t\t\t{\n\t\t\t\t\"submission.type\": draft.type,\n\t\t\t\t\"conversation.id\": conversationId,\n\t\t\t},\n\t\t\tasync (span) => {\n\t\t\t\tif (startsRun) span.addLink({ context: context.telemetry });\n\t\t\t\ttry {\n\t\t\t\t\tconst admission = await admit(span);\n\t\t\t\t\tspan.setAttributes({ \"submission.id\": admission.id, result: admission.status });\n\t\t\t\t\treturn admission;\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Error text may contain caller content. Record only the status.\n\t\t\t\t\tspan.setStatus({ status: \"error\" });\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\t/** Handle for an existing submission, or `undefined`. */\n\tasync get(id: SubmissionId, context: Context): Promise<Submission | undefined> {\n\t\tconst record = await this.#session.readOnLine((storage) => storage.submission(id, context));\n\t\treturn record === undefined ? undefined : new SubmissionHandle(record.id, this);\n\t}\n\n\tasync status(id: SubmissionId, context: Context): Promise<SubmissionRecord> {\n\t\tconst record = await this.#session.readOnLine((storage) => storage.submission(id, context));\n\t\tif (record === undefined) throw new Error(`Submission ${id} does not exist`);\n\t\treturn record;\n\t}\n\n\tasync wait(id: SubmissionId, context: Context): Promise<SettledSubmissionRecord> {\n\t\tthis.#resume();\n\t\t// Check and register on the line so no settling publication falls between them.\n\t\tconst found = await this.#session.readOnLine(async (storage) => {\n\t\t\tconst record = await storage.submission(id, context);\n\t\t\tif (record === undefined) throw new Error(`Submission ${id} does not exist`);\n\t\t\tif (isSettled(record)) return { promise: Promise.resolve(record) };\n\t\t\t// Close rejects registered waiters synchronously and may begin during the read.\n\t\t\tif (this.#closed) throw closedError(this.#session);\n\t\t\treturn { promise: this.#waiters.add(id, context) };\n\t\t});\n\t\treturn found.promise;\n\t}\n\n\t/** Withdraw a queued submission and remove its inbox item; placed inputs and settled submissions are reported. */\n\tabort(id: SubmissionId, context: Context, conversationId?: ConversationId): Promise<AbortResult | \"not_found\"> {\n\t\treturn this.#session.commitWith(async (tx) => {\n\t\t\tconst record = await tx.submission(id);\n\t\t\tif (record === undefined || (conversationId !== undefined && record.conversationId !== conversationId)) {\n\t\t\t\treturn \"not_found\";\n\t\t\t}\n\t\t\tif (record.status === \"queued\") {\n\t\t\t\ttx.settleSubmission(id, { status: \"unanswered\", reason: \"aborted\" });\n\t\t\t\tawait removeInboxItem(tx, record.conversationId, id);\n\t\t\t\treturn \"aborted\";\n\t\t\t}\n\t\t\treturn record.status === \"placed\" ? \"already_placed\" : \"settled\";\n\t\t}, context);\n\t}\n\n\t#observe(publication: ObservedCommit): void {\n\t\t// A commit held in memory changes documents only.\n\t\tif (publication.kind === \"memory\") return;\n\t\tfor (const change of publication.changes) {\n\t\t\tif (change.type !== \"submission\" || !isSettled(change.value)) continue;\n\t\t\tthis.#waiters.resolve(change.value.id, change.value);\n\t\t}\n\t}\n}\n\nclass SubmissionHandle implements Submission {\n\treadonly id: SubmissionId;\n\treadonly #submissions: Submissions;\n\n\tconstructor(id: SubmissionId, submissions: Submissions) {\n\t\tthis.id = id;\n\t\tthis.#submissions = submissions;\n\t}\n\n\tstatus(context: Context): Promise<SubmissionRecord> {\n\t\treturn this.#submissions.status(this.id, context);\n\t}\n\n\twait(context: Context): Promise<SettledSubmissionRecord> {\n\t\treturn this.#submissions.wait(this.id, context);\n\t}\n\n\tasync abort(context: Context): Promise<AbortResult> {\n\t\tconst result = await this.#submissions.abort(this.id, context);\n\t\tif (result === \"not_found\") throw new Error(`Submission ${this.id} does not exist`);\n\t\treturn result;\n\t}\n}\n\nfunction isSettled(record: SubmissionRecord): record is SettledSubmissionRecord {\n\treturn record.status === \"done\" || record.status === \"unanswered\";\n}\n\n/** Reject an input entry an untyped caller got wrong: its kind must be a non-empty string outside the `pi.` prefix. */\nfunction checkInputEntry(entry: InputEntry): void {\n\tconst { kind } = entry;\n\tif (typeof kind !== \"string\" || kind.length === 0 || kind.startsWith(\"pi.\")) {\n\t\tthrow new TypeError(\n\t\t\t`An input entry's kind must be a non-empty string not starting with \"pi.\", got ${String(kind)}`,\n\t\t);\n\t}\n}\n\n/**\n * Admit a submission inside a commit (spec §6); both `Conversation.submit()` forms and conversation-owned compactions\n * share it. A known request ID returns its existing submission without writing. A display-only write (only `kind` and\n * `data`) is appended and settled `done` at once, busy or not, as it changes nothing the model sees; only behind a\n * queued reset it queues, so it lands after the reset instead of before it in the context the reset ends. A busy\n * conversation queues anything else in `pi.inbox`, or rejects `whenBusy: \"reject\"` input and any continue with\n * `ConversationBusy`; an idle one rejects `whenIdle: \"reject\"` input with `ConversationIdle`. An idle continue places\n * queued items and starts a run with them and itself, placing no entry of its own. An idle conversation with queued\n * items queues it behind them and runs a final boundary. Otherwise idle input places its entry (`pi.user`, or the\n * input's own) and starts a run, and an idle write appends its entry and settles `done`, or `stale` when its head\n * reaches before the active range.\n */\nexport async function admitSubmission(\n\ttx: Tx,\n\tconversationId: ConversationId,\n\tdraft: SubmissionDraft,\n\tnow: number,\n\tqueueModes: QueueModes,\n\tspan?: TelemetrySpan,\n): Promise<Admission> {\n\tif (draft.type === \"input\" && draft.entry !== undefined) checkInputEntry(draft.entry);\n\tif (draft.requestId !== undefined) {\n\t\tconst existing = await tx.submissionByRequest(conversationId, draft.requestId);\n\t\tif (existing !== undefined) {\n\t\t\tif (existing.type !== draft.type) {\n\t\t\t\tthrow new Error(`Request ${draft.requestId} already identifies a submission of type ${existing.type}`);\n\t\t\t}\n\t\t\treturn { id: existing.id, status: existing.status === \"unanswered\" ? \"done\" : existing.status };\n\t\t}\n\t}\n\tconst fields = { conversationId, requestId: draft.requestId, trace: span?.propagation?.inject(span) };\n\tif (\n\t\tdraft.type === \"write\" &&\n\t\tisDisplayOnly(draft.entry) &&\n\t\t!hasQueuedReset((await tx.doc(InboxDoc, conversationId)).items)\n\t) {\n\t\tconst entry = await tx.appendEntry(conversationId, draft.entry);\n\t\tconst write = { ...fields, type: \"write\", status: \"done\", entry: entry.id } as const;\n\t\treturn { id: (await tx.createSubmission(write)).id, status: \"done\" };\n\t}\n\tconst live = await tx.doc(LiveDoc, conversationId);\n\tconst busy = live.run !== undefined;\n\tif (\n\t\tdraft.type === \"input\" &&\n\t\tdraft.whenBusy === \"steer\" &&\n\t\tlive.run !== undefined &&\n\t\tspan?.propagation !== undefined\n\t) {\n\t\tconst run = await tx.task(live.run.taskId);\n\t\tif (run?.trace !== undefined) span.addLink({ context: span.propagation.extract(run.trace) });\n\t}\n\tif (busy && draft.type === \"input\" && draft.whenBusy === \"reject\") throw new ConversationBusy(conversationId);\n\tif (!busy && draft.type === \"input\" && draft.whenIdle === \"reject\") throw new ConversationIdle(conversationId);\n\tif (draft.type === \"continue\") {\n\t\t// Never queued: whether a run can continue depends on how the current one ends. Rejected before any write.\n\t\tif (busy) throw new ConversationBusy(conversationId);\n\t\tconst boundary = await prepareBoundary(tx, conversationId, queueModes);\n\t\tconst { id } = await tx.createSubmission({ ...fields, type: \"continue\", status: \"placed\" });\n\t\t// Items an earlier failed run left queued (`afterFailedRun: \"keep\"`) are placed first and join the run. Its history\n\t\t// starts with the failed run's, so `afterRun` hooks see what that run did.\n\t\tconst { users, first } = await applyBoundary(tx, boundary, \"final\", now);\n\t\tawait startRun(tx, conversationId, live, { inputs: [...users, id], first: live.runFailure?.first ?? first });\n\t\treturn { id, status: \"placed\" };\n\t}\n\t// A boundary reads the table, so it is prepared before the first table write; a busy one needs none.\n\tconst boundary = busy ? undefined : await prepareBoundary(tx, conversationId, queueModes);\n\tif (boundary === undefined || boundary.inbox.items.length > 0) {\n\t\tconst { id } = await tx.createSubmission({\n\t\t\t...fields,\n\t\t\ttype: draft.type,\n\t\t\tstatus: \"queued\",\n\t\t});\n\t\t// Hosts may leave optional fields `undefined`; drafts take strict JSON.\n\t\tconst value = copyJson(draft.type === \"write\" ? draft.entry : draft.content, {\n\t\t\tomitUndefinedProperties: true,\n\t\t});\n\t\tconst items = (boundary?.inbox ?? (await tx.doc(InboxDoc, conversationId))).items;\n\t\tif (draft.type === \"write\") items.push({ id, mode: \"write\", entry: value as JsonObject });\n\t\telse {\n\t\t\tconst mode = draft.whenBusy === \"steer\" ? \"steer\" : \"followUp\";\n\t\t\tconst content = value as JsonRepresentation<UserInput>;\n\t\t\tconst entry = draft.entry === undefined ? {} : { entry: pickInputEntry(draft.entry) };\n\t\t\titems.push({ id, mode, content, ...entry });\n\t\t}\n\t\tif (boundary === undefined) return { id, status: \"queued\" };\n\t\tconst { users, first } = await applyBoundary(tx, boundary, \"final\", now);\n\t\tif (users.length > 0) await startRun(tx, conversationId, live, { inputs: users, first });\n\t\treturn { id, status: draft.type === \"write\" ? \"done\" : users.at(-1) === id ? \"placed\" : \"queued\" };\n\t}\n\tif (draft.type === \"write\") {\n\t\tif (isStale(boundary, draft.entry)) {\n\t\t\tconst stale = { status: \"unanswered\", reason: \"stale\" } as const;\n\t\t\treturn {\n\t\t\t\tid: (await tx.createSubmission({ ...fields, type: \"write\", ...stale })).id,\n\t\t\t\tstatus: \"done\",\n\t\t\t};\n\t\t}\n\t\tconst entry = await tx.appendEntry(conversationId, draft.entry);\n\t\tconst write = { ...fields, type: \"write\", status: \"done\", entry: entry.id } as const;\n\t\treturn { id: (await tx.createSubmission(write)).id, status: \"done\" };\n\t}\n\tconst entry = await appendInput(tx, conversationId, draft.content, draft.entry, now);\n\tconst input = { ...fields, type: \"input\", status: \"placed\", entry: entry.id } as const;\n\tconst { id } = await tx.createSubmission(input);\n\tawait startRun(tx, conversationId, live, { inputs: [id], first: entry.id });\n\treturn { id, status: \"placed\" };\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Context, type JsonValue, type WatchHandle } from "@earendil-works/chord";
|
|
2
2
|
import { type SessionImpl } from "../session/session.ts";
|
|
3
|
-
import type { ConversationId, JoinPolicy,
|
|
3
|
+
import type { ConversationId, JoinPolicy, Observation, Observer, TaskId, TaskOutcome } from "../types.ts";
|
|
4
4
|
import { type BlockedReason, type BlockedSubject } from "./scheduler.ts";
|
|
5
|
-
/** A live task's durable status without its checkpoint and outcome payloads (spec §9.
|
|
5
|
+
/** A live task's durable status without its checkpoint and outcome payloads (spec §9.4). */
|
|
6
6
|
export type TaskGraphState = {
|
|
7
7
|
readonly status: "pending" | "running";
|
|
8
8
|
readonly phase: string;
|
|
@@ -34,13 +34,13 @@ export type TaskGraphNode = {
|
|
|
34
34
|
readonly state: TaskGraphState;
|
|
35
35
|
/**
|
|
36
36
|
* Why it cannot run here, when it cannot: no registered definition takes it (`missing_task`, `task_too_old`,
|
|
37
|
-
* `migration_failed`)
|
|
37
|
+
* `migration_failed`). Follows registry changes.
|
|
38
38
|
*/
|
|
39
39
|
readonly blocked?: BlockedReason;
|
|
40
40
|
/** Conversations this task owns, in ID order. */
|
|
41
41
|
readonly conversations: readonly ConversationId[];
|
|
42
42
|
};
|
|
43
|
-
/** Every live task of the Session (spec §9.
|
|
43
|
+
/** Every live task of the Session (spec §9.4). */
|
|
44
44
|
export type TaskGraph = {
|
|
45
45
|
/** Every live task, keyed by its decimal ID. */
|
|
46
46
|
readonly tasks: Readonly<Record<string, TaskGraphNode>>;
|
|
@@ -57,10 +57,13 @@ export type TaskGraphBlocking = {
|
|
|
57
57
|
*/
|
|
58
58
|
export declare class TaskGraphView {
|
|
59
59
|
#private;
|
|
60
|
-
constructor(session: SessionImpl,
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
constructor(session: SessionImpl, blocking: TaskGraphBlocking);
|
|
61
|
+
/**
|
|
62
|
+
* Attach a synchronous observer of the graph (`Harness.observeTaskGraph()`), behind `guardObserver()`; `context`
|
|
63
|
+
* governs only the attachment.
|
|
64
|
+
*/
|
|
65
|
+
observe(observer: Observer<TaskGraph>, context: Context): Promise<Observation<TaskGraph>>;
|
|
66
|
+
/** A serialized watch of the graph, an observer of its mount; aborting `context` ends it `aborted`. */
|
|
64
67
|
watch(context: Context): Promise<TaskGraphWatch>;
|
|
65
68
|
}
|
|
66
69
|
//# sourceMappingURL=task-graph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-graph.d.ts","sourceRoot":"","sources":["../../src/harness/task-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"task-graph.d.ts","sourceRoot":"","sources":["../../src/harness/task-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAyB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG9G,OAAO,EAON,KAAK,WAAW,EAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACX,cAAc,EACd,UAAU,EACV,WAAW,EACX,QAA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AQ,CAAC,aAAa,EAAE,SAAS,cAAc,EAAE,CAAC;CAClD,CAAC;AAEF,kDAAkD;AAClD,MAAM,MAAM,SAAS,GAAG;IACvB,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;AAWpD,gHAAgH;AAChH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,aAAa,GAAG,SAAS,CAAC;IACxE,QAAQ,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CAChE,CAAC;AAKF;;;GAGG;AACH,qBAAa,aAAa;;IAMzB,YAAY,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,iBAAiB,EAoB5D;IAED;;;OAGG;IACG,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAY9F;IAED,uGAAuG;IACjG,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAYrD;CAmED"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Watch } from "@earendil-works/chord";
|
|
2
2
|
import { BACKGROUND_CONTEXT, withoutAbortSignal } from "@earendil-works/chord/context";
|
|
3
3
|
import { applyImmutable } from "@earendil-works/chord/delta";
|
|
4
|
-
import {
|
|
5
|
-
import { contained } from "../session/session.js";
|
|
4
|
+
import { closeEndOf, closeEnds, contained, guardObserver, observation, } from "../session/session.js";
|
|
6
5
|
import { blockedSubject } from "./scheduler.js";
|
|
7
6
|
import { closedError, scanAll } from "./util.js";
|
|
8
7
|
const LIVE_STATUSES = ["pending", "running", "waiting", "sleeping", "completing"];
|
|
@@ -13,55 +12,64 @@ const SCAN_PAGE_SIZE = 256;
|
|
|
13
12
|
*/
|
|
14
13
|
export class TaskGraphView {
|
|
15
14
|
#session;
|
|
16
|
-
#storage;
|
|
17
15
|
#blocking;
|
|
18
16
|
#mount;
|
|
19
17
|
#closed = false;
|
|
20
|
-
constructor(session,
|
|
18
|
+
constructor(session, blocking) {
|
|
21
19
|
this.#session = session;
|
|
22
|
-
this.#storage = storage;
|
|
23
20
|
this.#blocking = blocking;
|
|
24
|
-
session.
|
|
25
|
-
|
|
21
|
+
session.followCommits((publication, context) => {
|
|
22
|
+
// A commit held in memory changes documents only, which the graph does not show.
|
|
23
|
+
if (this.#mount === undefined || publication.kind === "memory")
|
|
26
24
|
return;
|
|
27
25
|
advance(this.#mount, publication, context, blocking.blocked, (error) => session.report(error));
|
|
28
26
|
});
|
|
29
27
|
blocking.subscribeBlocked(() => this.#refreshBlocked());
|
|
30
28
|
session.subscribeClose(() => {
|
|
31
29
|
this.#closed = true;
|
|
30
|
+
const ends = closeEnds(this.#session.failure);
|
|
32
31
|
for (const observer of [...(this.#mount?.observers ?? [])]) {
|
|
33
|
-
contained(() => observer.
|
|
32
|
+
contained(() => observer.end(closeEndOf(observer, ends)), (error) => session.report(error));
|
|
34
33
|
}
|
|
35
34
|
this.#mount = undefined;
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Attach a synchronous observer of the graph (`Harness.observeTaskGraph()`), behind `guardObserver()`; `context`
|
|
39
|
+
* governs only the attachment.
|
|
40
|
+
*/
|
|
41
|
+
async observe(observer, context) {
|
|
42
|
+
let value;
|
|
43
|
+
const attached = await this.#attach((current, release) => {
|
|
44
|
+
value = current;
|
|
45
|
+
return guardObserver(observer, release, (error) => this.#session.report(error));
|
|
46
|
+
}, context);
|
|
47
|
+
const signal = context.abortSignal;
|
|
48
|
+
if (signal?.aborted) {
|
|
49
|
+
attached.detach();
|
|
50
|
+
throw signal.reason;
|
|
47
51
|
}
|
|
52
|
+
return observation(value, attached.observer);
|
|
48
53
|
}
|
|
49
|
-
/** A serialized
|
|
54
|
+
/** A serialized watch of the graph, an observer of its mount; aborting `context` ends it `aborted`. */
|
|
50
55
|
async watch(context) {
|
|
51
|
-
const { observer } = await this.#attach((value, release) => new
|
|
56
|
+
const { observer } = await this.#attach((value, release) => new Watch(value, release, (error) => this.#session.report(error)), context);
|
|
52
57
|
const signal = context.abortSignal;
|
|
53
58
|
if (signal?.aborted) {
|
|
54
|
-
observer.
|
|
59
|
+
observer.abort();
|
|
55
60
|
throw signal.reason;
|
|
56
61
|
}
|
|
57
62
|
if (signal !== undefined)
|
|
58
|
-
observer.
|
|
63
|
+
observer.observeAbort(signal);
|
|
59
64
|
return observer;
|
|
60
65
|
}
|
|
61
66
|
/** Register an observer created from the current revision, atomically on the Session line. */
|
|
62
67
|
#attach(create, context) {
|
|
63
|
-
return this.#session.readOnLine(async () => {
|
|
64
|
-
const mount = this.#mount ?? {
|
|
68
|
+
return this.#session.readOnLine(async (storage) => {
|
|
69
|
+
const mount = this.#mount ?? {
|
|
70
|
+
...(await this.#build(storage, context)),
|
|
71
|
+
observers: new Set(),
|
|
72
|
+
};
|
|
65
73
|
const detach = () => {
|
|
66
74
|
mount.observers.delete(observer);
|
|
67
75
|
if (mount.observers.size === 0 && this.#mount === mount)
|
|
@@ -98,16 +106,17 @@ export class TaskGraphView {
|
|
|
98
106
|
// Rejected only once the Session is closing or failed.
|
|
99
107
|
.catch(() => { });
|
|
100
108
|
}
|
|
101
|
-
|
|
109
|
+
/** Read the graph on the line, through the line's `storage`. */
|
|
110
|
+
async #build(storage, context) {
|
|
102
111
|
const tasks = {};
|
|
103
112
|
const live = new Map();
|
|
104
113
|
const records = [];
|
|
105
114
|
for (const status of LIVE_STATUSES) {
|
|
106
|
-
records.push(...(await scanAll((cursor) =>
|
|
115
|
+
records.push(...(await scanAll((cursor) => storage.scanTasks({ status }, SCAN_PAGE_SIZE, cursor, context))));
|
|
107
116
|
}
|
|
108
117
|
records.sort((a, b) => a.id - b.id);
|
|
109
118
|
for (const record of records) {
|
|
110
|
-
const owned = await scanAll((cursor) =>
|
|
119
|
+
const owned = await scanAll((cursor) => storage.scanConversations({ ownerTaskId: record.id }, SCAN_PAGE_SIZE, cursor, context));
|
|
111
120
|
const conversations = owned.map((conversation) => conversation.id).sort((a, b) => a - b);
|
|
112
121
|
const subject = blockedSubject(record);
|
|
113
122
|
tasks[String(record.id)] = nodeOf(record, conversations, this.#blocking.blocked(subject));
|
|
@@ -169,8 +178,9 @@ function publish(mount, ops, context, report) {
|
|
|
169
178
|
return;
|
|
170
179
|
mount.value = applyImmutable(mount.value, ops);
|
|
171
180
|
const frameContext = withoutAbortSignal(context);
|
|
181
|
+
const call = { kind: "value", value: mount.value, ops, retired: false };
|
|
172
182
|
for (const observer of [...mount.observers])
|
|
173
|
-
contained(() => observer.advance(
|
|
183
|
+
contained(() => observer.advance(call, frameContext), report);
|
|
174
184
|
}
|
|
175
185
|
function nodeOf(record, conversations, blocked) {
|
|
176
186
|
return {
|