@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,+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AQ;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACxD,IAAI,MAAS,CAAC;QACd,2EAA2E;QAC3E,MAAM,IAAI,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC;YACJ,MAAM,GAAG,MAAM,IAAI,CAAC;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,yGAAyG;YACzG,MAAM,MAAM,GACX,IAAI,KAAK,SAAS,IAAI,CAAC,KAAK,YAAY,mBAAmB,IAAI,IAAI,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC,CAAC;YACpG,IAAI,CAAC,MAAM;gBAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrC,MAAM,KAAK,CAAC;QACb,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,OAAO,MAAM,CAAC;IACf,CAAC;IAED,cAAc;QACb,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QACpC,IAAI,OAAO,KAAK,SAAS;YAAE,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC;CACD","sourcesContent":["import { type Context, type JsonValue, replicatedState } from \"@earendil-works/chord\";\nimport { awaitWithContext, BACKGROUND_CONTEXT, withoutAbortSignal } from \"@earendil-works/chord/context\";\nimport { type Op, track } from \"@earendil-works/chord/delta\";\nimport {\n\ttype AnyDocToken,\n\taddressId,\n\tcheckRecordScope,\n\tcheckRecordVersion,\n\tmaterializeDocument,\n\tresolveAddress,\n} from \"../documents.ts\";\nimport { SessionFailed, StorageRequestError } from \"../errors.ts\";\nimport { idFromNumber } from \"../ids.ts\";\nimport { hostTimers, type Timers } from \"../timers.ts\";\nimport type {\n\tCommitChange,\n\tCommitPublication,\n\tConversationDocFamilyToken,\n\tConversationDocToken,\n\tConversationId,\n\tConversationQuery,\n\tConversationRecord,\n\tCursor,\n\tDocumentAddress,\n\tDocumentCommitChange,\n\tDocumentId,\n\tDocumentPoint,\n\tDocumentQuery,\n\tDocumentRecord,\n\tDocumentState,\n\tDocumentWatch,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tId,\n\tJsonObject,\n\tPage,\n\tReportInfo,\n\tRewindableConversationDocFamilyToken,\n\tRewindableConversationDocToken,\n\tSeq,\n\tSession,\n\tSessionDocFamilyToken,\n\tSessionDocToken,\n\tSessionEnd,\n\tSetTimer,\n\tStorage,\n\tStorageWrite,\n\tStoredDocument,\n\tSubmissionId,\n\tSubmissionQuery,\n\tSubmissionRecord,\n\tTaskDocFamilyToken,\n\tTaskDocToken,\n\tTaskId,\n\tTaskQuery,\n\tTaskRecord,\n\tTx,\n} from \"../types.ts\";\nimport {\n\tCommittedStateSource,\n\tCommittedWatch,\n\ttype ObservedDocumentValue,\n\tRETIREMENT_OPERATIONS,\n} from \"./observation.ts\";\nimport { type LoadedDocument, Transaction, type TransactionHost, type TransactionScope } from \"./transaction.ts\";\n\n/** The default source of a report: a listener, which never fails what ran it. */\nconst LISTENER: ReportInfo = { type: \"listener_error\" };\n\n/**\n * Open a Session kernel over one storage backend. `now` is the wall clock for task times; default `Date.now`.\n * `setTimer` arms the timers that evict idle documents; default `setTimeout` (see `HarnessOptions.setTimer`). The first\n * error a Storage method throws fails the Session (`SessionFailed`); see `SessionImpl`.\n */\nexport function createSession(\n\tstorage: Storage,\n\toptions?: { readonly now?: () => number; readonly documentRetentionMs?: number; readonly setTimer?: SetTimer },\n): Session {\n\tconst retention = options?.documentRetentionMs;\n\treturn new SessionImpl(\n\t\tstorage,\n\t\toptions?.now,\n\t\tretention === undefined ? undefined : () => retention,\n\t\toptions?.setTimer,\n\t);\n}\n\n/** Default document retention: ten minutes, as for kept contexts. */\nlet defaultRetention = 600_000;\n\n/** Internal, for tests: the retention of every Session that keeps the default, as a suite run with eviction at once. */\nexport function setDefaultDocumentRetention(ms: number): void {\n\tdefaultRetention = ms;\n}\n\n/**\n * A retention as given, when it is a number of milliseconds, `0` or more (`Infinity` keeps documents); otherwise the\n * default.\n */\nexport function documentRetention(ms: number | undefined): number {\n\treturn typeof ms === \"number\" && ms >= 0 ? ms : defaultRetention;\n}\n\n/**\n * Session kernel: one mutation line, the loaded document tracker cache, and committed publication.\n *\n * The cache is bounded by use: a document with no watch or document state attached leaves it once it was not read or\n * written for the retention period, and the next access loads it from Storage. Eviction runs as a job on the mutation\n * line, so no transaction ever holds a tracker that leaves.\n *\n * Only committed state is observable. Every commit callback, preparation, Storage settlement, adoption, and\n * publication enqueue runs while the line is held; listeners run later.\n *\n * Storage failures are final. Every Storage call goes through one guard: the first error a Storage method throws, other\n * than for a cancelled caller, fails the Session, as does a commit it cannot adopt. That call gets the error; every later\n * call and every Storage call still underway gets `SessionFailed`; close listeners run at once with the error, and the\n * Session then closes itself, Storage included, and `closed` settles. Nothing retries: transient errors are the\n * Storage's to retry. Reopening recovers from what was committed.\n */\nexport class SessionImpl implements Session {\n\treadonly #storage: Storage;\n\treadonly #documents = new Map<string, LoadedDocument>();\n\t/** Cached documents with no observer attached, by address, oldest use first, with the time of that use. */\n\treadonly #idleDocuments = new Map<string, number>();\n\t/** Observers attached per document incarnation (record ID); a cached incarnation with any is never evicted. */\n\treadonly #attachedDocuments = new Map<DocumentId, number>();\n\treadonly #clock: () => number;\n\treadonly #documentRetentionMs: () => number;\n\treadonly #timers: Timers;\n\t/** The pending eviction: a timer for the oldest idle document, or a line job when the retention is 0. */\n\t#documentSweep: { readonly at: number; disarm: (() => void) | undefined } | undefined;\n\t#sweepJobs = 0;\n\t/** Set once the host declined a background timer: then none is kept, and the end of each commit evicts what expired. */\n\t#documentTimersUnavailable = false;\n\treadonly #commitListeners = new Set<(publication: CommitPublication, context: Context) => void>();\n\t/** The Session's own listeners, such as its scheduler's: they keep memory in step with storage, so a throw fails it. */\n\treadonly #internalListeners = new Set<(publication: CommitPublication, context: Context) => void>();\n\treadonly #closeListeners = new Set<() => void>();\n\treadonly #host: TransactionHost;\n\t#tail: Promise<void> = Promise.resolve();\n\t#closing: Promise<void> | undefined;\n\t#failure: { readonly error: unknown } | undefined;\n\t/** Set when close reaches the backend: calls that fail from then on fail because it closes. */\n\treadonly #failed = Promise.withResolvers<never>();\n\treadonly #closed = Promise.withResolvers<SessionEnd>();\n\n\tget closed(): Promise<SessionEnd> {\n\t\treturn this.#closed.promise;\n\t}\n\n\t/** Internal: the error that failed the Session, if one did. */\n\tget failure(): { readonly error: unknown } | undefined {\n\t\treturn this.#failure;\n\t}\n\n\t/** Internal: rejects with `SessionFailed` the moment the Session fails, before work underway has ended; never resolves. */\n\tget failed(): Promise<never> {\n\t\treturn this.#failed.promise;\n\t}\n\n\tconstructor(\n\t\tstorage: Storage,\n\t\tnow: () => number = Date.now,\n\t\tdocumentRetentionMs: () => number | undefined = () => undefined,\n\t\tsetTimer?: SetTimer,\n\t) {\n\t\t// Waits race it; none has to.\n\t\tthis.#failed.promise.catch(() => {});\n\t\tthis.#storage = new GuardedStorage(storage, this);\n\t\tthis.#timers = hostTimers(setTimer, (error) => this.report(error, { type: \"host_error\", callback: \"setTimer\" }));\n\t\t// Cache bookkeeping must never change the outcome of the operation it follows: a clock or a retention setting\n\t\t// that throws counts as now, and as the default.\n\t\tthis.#clock = () => {\n\t\t\ttry {\n\t\t\t\treturn now();\n\t\t\t} catch {\n\t\t\t\treturn Date.now();\n\t\t\t}\n\t\t};\n\t\tthis.#documentRetentionMs = () => {\n\t\t\ttry {\n\t\t\t\treturn documentRetention(documentRetentionMs());\n\t\t\t} catch {\n\t\t\t\treturn documentRetention(undefined);\n\t\t\t}\n\t\t};\n\t\tthis.#host = {\n\t\t\tstorage: this.#storage,\n\t\t\tnow,\n\t\t\tcached: (id) => {\n\t\t\t\tconst cached = this.#documents.get(id);\n\t\t\t\tif (cached !== undefined) this.#touchDocument(id);\n\t\t\t\treturn cached;\n\t\t\t},\n\t\t\tload: (definition, addressId, address, context) => this.#loadDocument(definition, addressId, address, context),\n\t\t\tinstall: (document) => {\n\t\t\t\tthis.#documents.set(document.addressId, document);\n\t\t\t\tthis.#touchDocument(document.addressId);\n\t\t\t},\n\t\t\tevict: (id, recordId) => {\n\t\t\t\tif (this.#documents.get(id)?.record.id === recordId) this.#dropDocument(id);\n\t\t\t},\n\t\t\tconversationCreated: (tx, record) => this.conversationCreated(tx, record),\n\t\t};\n\t}\n\n\t/** The Storage behind the failure guard; every component reads and writes through it. */\n\tprotected get storage(): Storage {\n\t\treturn this.#storage;\n\t}\n\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T> {\n\t\treturn this.commitWith(change, context);\n\t}\n\n\t/**\n\t * Internal: fail the Session with `error`, the first wins, and report it once. Admission ends, and close listeners run\n\t * now; they read the error from `failure`. The Storage guard calls this; the Harness also calls it for a throw in its\n\t * scheduler's own commits.\n\t */\n\tfail(error: unknown, context?: Context): void {\n\t\tif (this.#failure !== undefined) return;\n\t\tthis.#failure = { error };\n\t\tthis.#failed.reject(new SessionFailed(error));\n\t\t// Seal first, so a report handler that calls back finds the Session failed. Closing runs the close listeners\n\t\t// synchronously; a failing backend close is the caller's to see, and here nobody waits.\n\t\tthis.close(BACKGROUND_CONTEXT).catch(() => {});\n\t\tthis.report(error, { type: \"session_failed\" }, context);\n\t}\n\n\t/**\n\t * Internal commit exposing the concrete transaction and its internal operations, such as the reserved-ID root\n\t * bootstrap and task replacement. `scope` sets the default `tx.createTask()` conversation and the task attributed to\n\t * appended entries.\n\t */\n\tcommitWith<T>(change: (tx: Transaction) => T | Promise<T>, context: Context, scope?: TransactionScope): Promise<T> {\n\t\ttry {\n\t\t\tthis.assertUsable();\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn this.#enqueue(() => this.#runCommit(change, context, scope));\n\t}\n\n\t/** Internal: run a read-only job on the mutation line so multi-read derivations observe one committed state. */\n\treadOnLine<T>(job: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.assertUsable();\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn this.#enqueue(async () => {\n\t\t\tthis.#assertHealthy();\n\t\t\treturn job();\n\t\t});\n\t}\n\n\t/**\n\t * Internal: a conversation document's current incarnation and value, for a job already running on the line (see\n\t * `readOnLine()`). Absent documents are `undefined`.\n\t */\n\tasync conversationDocumentOnLine(\n\t\ttoken: ConversationDocToken<JsonObject>,\n\t\tconversationId: ConversationId,\n\t\tcontext: Context,\n\t): Promise<{ readonly record: DocumentRecord; readonly version: number; readonly value: JsonObject } | undefined> {\n\t\tconst definition = token.definition;\n\t\tconst resolved = resolveAddress(definition, [conversationId, context]);\n\t\tconst loaded = await this.#loadDocument(definition, resolved.id, resolved.address, context);\n\t\tif (loaded === undefined) return undefined;\n\t\tcheckRecordScope(definition, loaded.record);\n\t\tcheckRecordVersion(definition, loaded.record, loaded.storedVersion);\n\t\treturn { record: loaded.record, version: loaded.valueVersion, value: loaded.tracker.value };\n\t}\n\n\tsnapshot<T extends JsonObject>(token: SessionDocToken<T>, context: Context): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject>(\n\t\ttoken: ConversationDocToken<T>,\n\t\tconversationId: ConversationId,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject>(\n\t\ttoken: TaskDocToken<T>,\n\t\ttaskId: TaskId,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: SessionDocFamilyToken<T, I>,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: ConversationDocFamilyToken<T, I>,\n\t\tconversationId: ConversationId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: TaskDocFamilyToken<T, I>,\n\t\ttaskId: TaskId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tasync snapshot(token: AnyDocToken, ...args: readonly unknown[]): Promise<JsonObject | undefined> {\n\t\tthis.assertUsable();\n\t\tconst definition = token.definition;\n\t\tconst resolved = resolveAddress(definition, args);\n\t\tconst context = args[resolved.nextArgument] as Context;\n\t\tconst cached = this.#documents.get(resolved.id);\n\t\tif (cached?.valueVersion === definition.version) this.#touchDocument(resolved.id);\n\t\tconst loaded =\n\t\t\tcached?.valueVersion === definition.version\n\t\t\t\t? cached\n\t\t\t\t: await this.#enqueue(async () => {\n\t\t\t\t\t\tthis.#assertHealthy();\n\t\t\t\t\t\treturn this.#loadDocument(definition, resolved.id, resolved.address, context);\n\t\t\t\t\t});\n\t\tif (loaded === undefined) return undefined;\n\t\tcheckRecordScope(definition, loaded.record);\n\t\tcheckRecordVersion(definition, loaded.record, loaded.storedVersion);\n\t\treturn loaded.tracker.value;\n\t}\n\n\tdocumentState<T extends JsonObject>(\n\t\ttoken: SessionDocToken<T>,\n\t\tcontext: Context,\n\t): Promise<DocumentState<T> | undefined>;\n\tdocumentState<T extends JsonObject>(\n\t\ttoken: ConversationDocToken<T>,\n\t\tconversationId: ConversationId,\n\t\tcontext: Context,\n\t): Promise<DocumentState<T> | undefined>;\n\tdocumentState<T extends JsonObject>(\n\t\ttoken: TaskDocToken<T>,\n\t\ttaskId: TaskId,\n\t\tcontext: Context,\n\t): Promise<DocumentState<T> | undefined>;\n\tdocumentState<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: SessionDocFamilyToken<T, I>,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<DocumentState<T> | undefined>;\n\tdocumentState<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: ConversationDocFamilyToken<T, I>,\n\t\tconversationId: ConversationId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<DocumentState<T> | undefined>;\n\tdocumentState<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: TaskDocFamilyToken<T, I>,\n\t\ttaskId: TaskId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<DocumentState<T> | undefined>;\n\tdocumentState(token: AnyDocToken, ...args: readonly unknown[]): Promise<DocumentState<JsonObject> | undefined> {\n\t\ttry {\n\t\t\tthis.assertUsable();\n\t\t\tconst definition = token.definition;\n\t\t\tconst resolved = resolveAddress(definition, args);\n\t\t\tconst context = args[resolved.nextArgument] as Context;\n\t\t\treturn this.#enqueue(async () => {\n\t\t\t\tthis.#assertHealthy();\n\t\t\t\tconst loaded = await this.#loadDocument(definition, resolved.id, resolved.address, context);\n\t\t\t\tif (loaded === undefined) return undefined;\n\t\t\t\tconst { observer: source, detach } = this.#attachDocument(\n\t\t\t\t\tdefinition,\n\t\t\t\t\tloaded,\n\t\t\t\t\t(value, release) => new CommittedStateSource<ObservedDocumentValue>(value, release),\n\t\t\t\t);\n\t\t\t\ttry {\n\t\t\t\t\treturn replicatedState(source, { onError: (error) => this.report(error) }) as DocumentState<JsonObject>;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tdetach();\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t}\n\n\twatchDoc<T extends JsonObject>(token: SessionDocToken<T>, context: Context): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject>(\n\t\ttoken: ConversationDocToken<T>,\n\t\tconversationId: ConversationId,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject>(\n\t\ttoken: TaskDocToken<T>,\n\t\ttaskId: TaskId,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: SessionDocFamilyToken<T, I>,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: ConversationDocFamilyToken<T, I>,\n\t\tconversationId: ConversationId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: TaskDocFamilyToken<T, I>,\n\t\ttaskId: TaskId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\tasync watchDoc(token: AnyDocToken, ...args: readonly unknown[]): Promise<DocumentWatch<JsonObject> | undefined> {\n\t\tthis.assertUsable();\n\t\tconst definition = token.definition;\n\t\tconst resolved = resolveAddress(definition, args);\n\t\tconst context = args[resolved.nextArgument] as Context;\n\t\tconst signal = context.abortSignal;\n\t\tlet cancelled = signal?.aborted ?? false;\n\t\tconst markCancelled = (): void => {\n\t\t\tcancelled = true;\n\t\t};\n\t\tsignal?.addEventListener(\"abort\", markCancelled, { once: true });\n\t\ttry {\n\t\t\tconst watch = await this.#enqueue(async () => {\n\t\t\t\tthis.#assertHealthy();\n\t\t\t\tif (cancelled) throw cancellationError(signal!);\n\t\t\t\tconst loaded = await this.#loadDocument(definition, resolved.id, resolved.address, context);\n\t\t\t\tif (cancelled) throw cancellationError(signal!);\n\t\t\t\tif (loaded === undefined) return undefined;\n\t\t\t\treturn this.#attachDocument(\n\t\t\t\t\tdefinition,\n\t\t\t\t\tloaded,\n\t\t\t\t\t(value, release) =>\n\t\t\t\t\t\tnew CommittedWatch<ObservedDocumentValue>(value, release, (error) => this.report(error)),\n\t\t\t\t).observer;\n\t\t\t});\n\t\t\tif (watch === undefined) return undefined;\n\t\t\tif (cancelled) {\n\t\t\t\twatch.cancel();\n\t\t\t\tthrow cancellationError(signal!);\n\t\t\t}\n\t\t\tif (signal !== undefined) watch.observeCancellation(signal);\n\t\t\treturn watch as DocumentWatch<JsonObject>;\n\t\t} finally {\n\t\t\tsignal?.removeEventListener(\"abort\", markCancelled);\n\t\t}\n\t}\n\n\tsnapshotAsOf<T extends JsonObject>(\n\t\ttoken: RewindableConversationDocToken<T>,\n\t\tconversationId: ConversationId,\n\t\tat: EntryId,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshotAsOf<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: RewindableConversationDocFamilyToken<T, I>,\n\t\tconversationId: ConversationId,\n\t\tkey: string,\n\t\tat: EntryId,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tasync snapshotAsOf(token: AnyDocToken, ...args: readonly unknown[]): Promise<JsonObject | undefined> {\n\t\tthis.assertUsable();\n\t\tconst definition = token.definition;\n\t\tconst resolved = resolveAddress(definition, args);\n\t\tif (resolved.address.scope.kind !== \"conversation\") {\n\t\t\tthrow new TypeError(\"Session.snapshotAsOf() requires a conversation document\");\n\t\t}\n\t\tconst conversationId = resolved.address.scope.conversationId;\n\t\tconst atValue = args[resolved.nextArgument];\n\t\tif (typeof atValue !== \"number\" || !Number.isSafeInteger(atValue)) {\n\t\t\tthrow new TypeError(\"Session.snapshotAsOf() requires an entry ID\");\n\t\t}\n\t\tconst at = idFromNumber<EntryId>(atValue);\n\t\tconst context = args[resolved.nextArgument + 1] as Context;\n\t\treturn this.#enqueue(async () => {\n\t\t\tthis.#assertHealthy();\n\t\t\tconst storedEntry = await this.#storage.entry(conversationId, at, context);\n\t\t\tif (storedEntry === undefined) {\n\t\t\t\tthrow new Error(`Entry ${at} is not visible from conversation ${conversationId}`);\n\t\t\t}\n\t\t\tconst address: DocumentAddress = {\n\t\t\t\t...resolved.address,\n\t\t\t\tscope: { kind: \"conversation\", conversationId: storedEntry.entry.conversationId },\n\t\t\t};\n\t\t\tconst record = await this.#storage.findDocument(address, storedEntry.commitSeq, context);\n\t\t\tif (record === undefined) return undefined;\n\t\t\tconst stored = await this.#storage.document(record.id, storedEntry.commitSeq, context);\n\t\t\tif (stored === undefined) {\n\t\t\t\tthrow new Error(`Historical document ${record.id} (${record.kind}) cannot be read`);\n\t\t\t}\n\t\t\treturn materializeDocument(definition, stored);\n\t\t});\n\t}\n\n\tclose(context: Context): Promise<void> {\n\t\tif (this.#closing === undefined) {\n\t\t\tconst cleanup = withoutAbortSignal(context);\n\t\t\t// Seal admission before anything else runs, then stop observers; admitted work settles before Storage closes.\n\t\t\tthis.#closing = Promise.resolve()\n\t\t\t\t.then(() => this.beforeClose())\n\t\t\t\t.then(() =>\n\t\t\t\t\tthis.#enqueue(async () => {\n\t\t\t\t\t\tthis.#commitListeners.clear();\n\t\t\t\t\t\tthis.#internalListeners.clear();\n\t\t\t\t\t\tthis.#documents.clear();\n\t\t\t\t\t\tthis.#idleDocuments.clear();\n\t\t\t\t\t\tthis.#attachedDocuments.clear();\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this.#storage.close(cleanup);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// A Storage that cannot close is a failed one; an earlier failure stays the cause.\n\t\t\t\t\t\t\tif (this.#failure === undefined) {\n\t\t\t\t\t\t\t\tthis.#failure = { error };\n\t\t\t\t\t\t\t\tthis.report(error, { type: \"session_failed\" });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tconst failure = this.#failure;\n\t\t\t\t\tthis.#closed.resolve(\n\t\t\t\t\t\tfailure === undefined ? { reason: \"closed\" } : { reason: \"failed\", error: failure.error },\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\tthis.#notifyClose();\n\t\t}\n\t\treturn awaitWithContext(this.#closing, context);\n\t}\n\n\t/** Run the close listeners once, each on its own: one that fails is reported, and the rest still run. */\n\t#notifyClose(): void {\n\t\tthis.#documentSweep?.disarm?.();\n\t\tthis.#documentSweep = undefined;\n\t\tconst listeners = [...this.#closeListeners];\n\t\tthis.#closeListeners.clear();\n\t\tfor (const listener of listeners) contained(listener, (error) => this.report(error));\n\t}\n\n\t/**\n\t * Internal: the Session's failure, and errors of listeners, which never fail what ran them; `info` defaults to a\n\t * listener. A plain Session drops them.\n\t */\n\treport(_error: unknown, _info: ReportInfo = LISTENER, _context?: Context): void {}\n\n\t/**\n\t * Runs inside every transaction that creates or forks a conversation, after the conversation record is staged. A\n\t * plain Session stages nothing; a Harness stages its built-in documents.\n\t */\n\tprotected conversationCreated(_tx: Transaction, _record: ConversationRecord): Promise<void> {\n\t\treturn Promise.resolve();\n\t}\n\n\t/**\n\t * Internal, for `beforeClose()`: on the line, after every commit admitted before the seal has settled, write what\n\t * `writes()` returns then straight to Storage. Nothing is published, since the Session is closing; a failed Session\n\t * writes nothing.\n\t */\n\tprotected writeAtClose(writes: () => readonly StorageWrite[]): Promise<void> {\n\t\treturn this.#enqueue(async () => {\n\t\t\tif (this.#failure !== undefined) return;\n\t\t\tconst batch = writes();\n\t\t\tif (batch.length > 0) await this.#storage.commit(batch, BACKGROUND_CONTEXT);\n\t\t});\n\t}\n\n\t/** Runs after close seals admission and before the line closes Storage; must not reject. */\n\tprotected beforeClose(): Promise<void> {\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Register a synchronous post-adoption listener. It must not block or call Session operations; a throw is reported. */\n\tsubscribeCommits(listener: (publication: CommitPublication, context: Context) => void): () => void {\n\t\tthis.assertUsable();\n\t\tthis.#commitListeners.add(listener);\n\t\treturn () => this.#commitListeners.delete(listener);\n\t}\n\n\t/**\n\t * Internal: `subscribeCommits()` for the Session's own components, whose state follows each commit. A throw leaves\n\t * that state behind storage, so it fails the Session instead of being reported. They run before host listeners.\n\t */\n\tobserveCommits(listener: (publication: CommitPublication, context: Context) => void): () => void {\n\t\tthis.assertUsable();\n\t\tthis.#internalListeners.add(listener);\n\t\treturn () => this.#internalListeners.delete(listener);\n\t}\n\n\t/**\n\t * Register a listener called synchronously when close begins, also when a failure closes the Session (`failure` is\n\t * then set). It must not block or call Session operations; a throw is reported.\n\t */\n\tsubscribeClose(listener: () => void): () => void {\n\t\tthis.assertUsable();\n\t\tthis.#closeListeners.add(listener);\n\t\treturn () => this.#closeListeners.delete(listener);\n\t}\n\n\t/** Drop every loaded tracker on the mutation line; later access cold-loads from Storage. */\n\tunloadDocuments(): Promise<void> {\n\t\treturn this.#enqueue(async () => {\n\t\t\tthis.#documents.clear();\n\t\t\tthis.#idleDocuments.clear();\n\t\t});\n\t}\n\n\t/**\n\t * Internal, for tests: how many documents the cache holds, how many are idle, how many incarnations are pinned, and how\n\t * many sweep jobs were queued on the line so far.\n\t */\n\tget documentCacheSizes(): {\n\t\treadonly cached: number;\n\t\treadonly idle: number;\n\t\treadonly attached: number;\n\t\treadonly sweeps: number;\n\t} {\n\t\treturn {\n\t\t\tcached: this.#documents.size,\n\t\t\tidle: this.#idleDocuments.size,\n\t\t\tattached: this.#attachedDocuments.size,\n\t\t\tsweeps: this.#sweepJobs,\n\t\t};\n\t}\n\n\t/** Note a use of a cached document: an unattached one becomes the newest idle one, and an eviction is scheduled. */\n\t#touchDocument(addressId: string): void {\n\t\tconst cached = this.#documents.get(addressId);\n\t\tif (cached === undefined || this.#attachedDocuments.has(cached.record.id)) return;\n\t\tconst now = this.#clock();\n\t\tconst since = this.#idleDocuments.get(addressId);\n\t\t// A hot document moves to the back at most once per granule, a tenth of the retention up to 1 s: it may then leave\n\t\t// up to a granule early, which costs a reload, while a commit-heavy workload skips the reordering.\n\t\tif (since !== undefined && now - since < Math.min(1_000, this.#documentRetentionMs() / 10)) return;\n\t\tthis.#idleDocuments.delete(addressId);\n\t\tthis.#idleDocuments.set(addressId, now);\n\t\t// A pending sweep for the oldest document comes first unless the retention was shortened since; then it moves up.\n\t\tif (this.#documentSweep === undefined || this.#documentSweep.at > now + this.#documentRetentionMs()) {\n\t\t\tthis.#scheduleDocumentSweep();\n\t\t}\n\t}\n\n\t#dropDocument(addressId: string): void {\n\t\tthis.#documents.delete(addressId);\n\t\tthis.#idleDocuments.delete(addressId);\n\t}\n\n\t/**\n\t * Schedule the eviction of the oldest idle document: on the line at once when the retention is 0, otherwise when it\n\t * expires, by a background timer (`HarnessOptions.setTimer`), which never keeps the process alive. Where the host\n\t * declines it, as the default does in Cloudflare Workers, none is kept: the end of each commit evicts what expired.\n\t */\n\t#scheduleDocumentSweep(): void {\n\t\tif (this.#closing !== undefined) return;\n\t\tconst oldest = this.#idleDocuments.values().next();\n\t\tif (oldest.done === true) return;\n\t\tconst at = oldest.value + this.#documentRetentionMs();\n\t\tif (this.#documentSweep !== undefined && this.#documentSweep.at <= at) return;\n\t\tthis.#documentSweep?.disarm?.();\n\t\t// The pending sweep stays set until its job runs, so touches while the line is busy queue no more.\n\t\tconst sweep: { readonly at: number; disarm: (() => void) | undefined } = { at, disarm: undefined };\n\t\tconst run = (): void => {\n\t\t\tthis.#sweepJobs++;\n\t\t\tthis.#enqueue(async () => {\n\t\t\t\tif (this.#documentSweep === sweep) this.#documentSweep = undefined;\n\t\t\t\tif (this.#closing === undefined) this.#sweepDocuments();\n\t\t\t}).catch(() => {});\n\t\t};\n\t\tconst delay = at - this.#clock();\n\t\tthis.#documentSweep = sweep;\n\t\tif (delay <= 0) {\n\t\t\tqueueMicrotask(run);\n\t\t\treturn;\n\t\t}\n\t\tif (this.#documentTimersUnavailable) {\n\t\t\tthis.#documentSweep = undefined;\n\t\t\treturn;\n\t\t}\n\t\t// A timer that fires early sweeps nothing and arms the next one.\n\t\tconst disarm = this.#timers.background(run, delay);\n\t\tif (disarm === undefined) {\n\t\t\tthis.#documentTimersUnavailable = true;\n\t\t\tthis.#documentSweep = undefined;\n\t\t\treturn;\n\t\t}\n\t\tsweep.disarm = disarm;\n\t}\n\n\t/** On the line: evict the idle documents whose retention passed, oldest first, then schedule the next eviction. */\n\t#sweepDocuments(): void {\n\t\tconst expired = this.#clock() - this.#documentRetentionMs();\n\t\tfor (const [addressId, since] of this.#idleDocuments) {\n\t\t\tif (since > expired) break;\n\t\t\tthis.#dropDocument(addressId);\n\t\t}\n\t\tthis.#scheduleDocumentSweep();\n\t}\n\n\t/** Pin a cached incarnation for one observer; the returned release unpins it once, idle again after the last. */\n\t#pinDocument(addressId: string, recordId: DocumentId): () => void {\n\t\tthis.#attachedDocuments.set(recordId, (this.#attachedDocuments.get(recordId) ?? 0) + 1);\n\t\tthis.#idleDocuments.delete(addressId);\n\t\tlet pinned = true;\n\t\treturn () => {\n\t\t\tif (!pinned) return;\n\t\t\tpinned = false;\n\t\t\tconst count = (this.#attachedDocuments.get(recordId) ?? 1) - 1;\n\t\t\tif (count > 0) {\n\t\t\t\tthis.#attachedDocuments.set(recordId, count);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.#attachedDocuments.delete(recordId);\n\t\t\tif (this.#documents.get(addressId)?.record.id === recordId) this.#touchDocument(addressId);\n\t\t};\n\t}\n\n\tasync #runCommit<T>(\n\t\tchange: (tx: Transaction) => T | Promise<T>,\n\t\tcontext: Context,\n\t\tscope?: TransactionScope,\n\t): Promise<T> {\n\t\tthis.#assertHealthy();\n\t\tcontext.abortSignal?.throwIfAborted();\n\t\tconst tx = new Transaction(this.#host, context, scope);\n\t\tlet result: T;\n\t\ttry {\n\t\t\tresult = await change(tx);\n\t\t\t// A callback that caught a failed read must not commit, nor succeed as if it had.\n\t\t\tthis.#assertHealthy();\n\t\t} catch (error) {\n\t\t\tawait tx.settleFailure();\n\t\t\tthis.#sweepDocuments();\n\t\t\tthrow error;\n\t\t}\n\t\tlet writes: readonly StorageWrite[];\n\t\ttry {\n\t\t\twrites = await tx.settleSuccess();\n\t\t} catch (error) {\n\t\t\t// Settlement aborted every change already.\n\t\t\tthis.#sweepDocuments();\n\t\t\tthrow error;\n\t\t}\n\t\tif (writes.length === 0) {\n\t\t\ttx.discard();\n\t\t\tthis.#sweepDocuments();\n\t\t\treturn result;\n\t\t}\n\t\tlet seq: Seq;\n\t\ttry {\n\t\t\t// Once admitted, caller cancellation does not interrupt Storage settlement.\n\t\t\tseq = await this.#storage.commit(writes, withoutAbortSignal(context));\n\t\t} catch (error) {\n\t\t\t// The guard has failed the Session.\n\t\t\ttx.discard();\n\t\t\tthrow error;\n\t\t}\n\t\tlet documents: DocumentCommitChange[];\n\t\ttry {\n\t\t\tdocuments = tx.adopt(seq);\n\t\t} catch (error) {\n\t\t\t// Storage already committed; a failed adoption leaves memory behind durable state.\n\t\t\tthis.fail(error);\n\t\t\tthrow error;\n\t\t}\n\t\tfor (const document of documents) this.#touchDocument(addressId(document.record));\n\t\tthis.#publish(seq, writes, documents, context);\n\t\tthis.#sweepDocuments();\n\t\treturn result;\n\t}\n\n\t#publish(\n\t\tseq: Seq,\n\t\twrites: readonly StorageWrite[],\n\t\tdocuments: readonly DocumentCommitChange[],\n\t\tcontext: Context,\n\t): void {\n\t\tconst changes: CommitChange[] | undefined =\n\t\t\tthis.#commitListeners.size > 0 || this.#internalListeners.size > 0 ? [] : undefined;\n\t\tfor (const write of writes) {\n\t\t\tswitch (write.type) {\n\t\t\t\tcase \"entry\":\n\t\t\t\t\tcontext.telemetry.addEvent(\"pi.durable.entry\", {\n\t\t\t\t\t\t\"entry.id\": write.value.id,\n\t\t\t\t\t\t\"entry.kind\": write.value.kind,\n\t\t\t\t\t});\n\t\t\t\t\tchanges?.push(write);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"submission\":\n\t\t\t\t\tif (write.value.status === \"done\" || write.value.status === \"unanswered\") {\n\t\t\t\t\t\tcontext.telemetry.addEvent(\"pi.durable.submission\", {\n\t\t\t\t\t\t\t\"submission.id\": write.value.id,\n\t\t\t\t\t\t\tstatus: write.value.status,\n\t\t\t\t\t\t\t\"answer.entry_id\": write.value.answer,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tchanges?.push(write);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"conversation\":\n\t\t\t\tcase \"task\":\n\t\t\t\t\tchanges?.push(write);\n\t\t\t}\n\t\t}\n\t\tif (changes === undefined) return;\n\t\tfor (const document of documents) changes.push(document);\n\t\tconst publication: CommitPublication = { seq, changes };\n\t\t// The commit is durable: a failing listener neither fails the commit nor skips the others.\n\t\tfor (const listener of [...this.#internalListeners]) {\n\t\t\tcontained(\n\t\t\t\t() => listener(publication, context),\n\t\t\t\t(error) => this.fail(error, context),\n\t\t\t);\n\t\t}\n\t\tfor (const listener of [...this.#commitListeners]) {\n\t\t\tcontained(\n\t\t\t\t() => listener(publication, context),\n\t\t\t\t(error) => this.report(error, LISTENER, context),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Attach an observer to one committed incarnation: check the definition, then forward this incarnation's committed\n\t * changes and close. `detach` removes both subscriptions.\n\t */\n\t#attachDocument<O extends CommittedStateSource | CommittedWatch>(\n\t\tdefinition: AnyDocToken[\"definition\"],\n\t\tloaded: LoadedDocument,\n\t\tcreate: (value: JsonObject, detach: () => void) => O,\n\t): { observer: O; detach: () => void } {\n\t\tcheckRecordScope(definition, loaded.record);\n\t\tcheckRecordVersion(definition, loaded.record, loaded.storedVersion);\n\t\tlet unsubscribeCommit = (): void => {};\n\t\tlet unsubscribeClose = (): void => {};\n\t\t// Attached, the incarnation stays cached; once its last observer detaches, or it retires, it is idle again.\n\t\tconst unpin = this.#pinDocument(loaded.addressId, loaded.record.id);\n\t\tconst detach = (): void => {\n\t\t\tunsubscribeCommit();\n\t\t\tunsubscribeClose();\n\t\t\tunpin();\n\t\t};\n\t\tlet observer: O;\n\t\ttry {\n\t\t\tobserver = create(loaded.tracker.value, detach);\n\t\t} catch (error) {\n\t\t\tunpin();\n\t\t\tthrow error;\n\t\t}\n\t\tconst observed = { version: loaded.valueVersion };\n\t\tunsubscribeCommit = this.observeCommits((publication, context) => {\n\t\t\tfor (const change of publication.changes) {\n\t\t\t\tif (change.type !== \"document\" || change.record.id !== loaded.record.id) continue;\n\t\t\t\t// A document state's frames carry no caller cancellation; a watch observes its own cancellation.\n\t\t\t\tconst frameContext = observer instanceof CommittedStateSource ? withoutAbortSignal(context) : context;\n\t\t\t\tconst ops = observedOperations(observed, change);\n\t\t\t\t// A migration-only base changes nothing for an observer of the new version.\n\t\t\t\tif (ops.length === 0) continue;\n\t\t\t\t// A retired incarnation never changes again: its observers keep their last value but pin nothing.\n\t\t\t\tif (change.value === null) unpin();\n\t\t\t\tobserver.advance(change.value, ops, frameContext);\n\t\t\t}\n\t\t});\n\t\tunsubscribeClose = this.subscribeClose(() => observer.closeSession(this.#failure));\n\t\treturn { observer, detach };\n\t}\n\n\tasync #loadDocument(\n\t\tdefinition: AnyDocToken[\"definition\"],\n\t\taddressId: string,\n\t\taddress: DocumentAddress,\n\t\tcontext: Context,\n\t): Promise<LoadedDocument | undefined> {\n\t\tconst cached = this.#documents.get(addressId);\n\t\t// A tracker serves only tokens of the version its value was materialized for; others reload from Storage.\n\t\tif (cached?.valueVersion === definition.version) {\n\t\t\tthis.#touchDocument(addressId);\n\t\t\treturn cached;\n\t\t}\n\t\tif (cached !== undefined) this.#dropDocument(addressId);\n\t\tconst record = await this.#storage.findDocument(address, \"current\", context);\n\t\tif (record === undefined) return undefined;\n\t\tconst stored = await this.#storage.document(record.id, \"current\", context);\n\t\tif (stored === undefined) throw new Error(`Current document ${record.id} (${record.kind}) cannot be read`);\n\t\tconst value = materializeDocument(definition, stored);\n\t\tconst loaded: LoadedDocument = {\n\t\t\taddressId,\n\t\t\trecord: stored.record,\n\t\t\tstoredVersion: stored.version,\n\t\t\tvalueVersion: definition.version,\n\t\t\tdeltasSinceBase: stored.deltasSinceBase,\n\t\t\ttracker: track(value),\n\t\t};\n\t\tthis.#documents.set(addressId, loaded);\n\t\tthis.#touchDocument(addressId);\n\t\treturn loaded;\n\t}\n\n\t#enqueue<T>(job: () => Promise<T>): Promise<T> {\n\t\tconst run = this.#tail.then(job);\n\t\tthis.#tail = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\t/** Internal: throw `SessionFailed` when failed, else an error when closing. */\n\tassertUsable(): void {\n\t\tthis.#assertHealthy();\n\t\tif (this.#closing !== undefined) throw new Error(\"Session is closed\");\n\t}\n\n\t#assertHealthy(): void {\n\t\tif (this.#failure !== undefined) throw new SessionFailed(this.#failure.error);\n\t}\n}\n\n/**\n * Run a host callback that must not fail its caller: a throw, or a promise it returns that rejects, goes to `onError`,\n * which is not awaited.\n */\nexport function contained(callback: () => unknown, onError: (error: unknown) => void): void {\n\ttry {\n\t\tconst result = callback();\n\t\t// Any thenable, also a promise from another realm; `Promise.resolve` adopts it with handlers of its own.\n\t\tif (typeof (result as { then?: unknown } | null)?.then === \"function\") Promise.resolve(result).catch(onError);\n\t} catch (error) {\n\t\tonError(error);\n\t}\n}\n\n/**\n * Operations an observer applies for one committed change. An observer hydrated under another definition version holds\n * a differently shaped value, so it receives the new value as a root replacement instead of operations for that shape.\n */\nfunction observedOperations(\n\tobserved: { version: number },\n\tchange: Extract<DocumentCommitChange, { readonly type: \"document\" }>,\n): readonly Op[] {\n\tif (change.value === null) return RETIREMENT_OPERATIONS;\n\tif (change.version === observed.version) return change.ops;\n\tobserved.version = change.version!;\n\treturn [[\"r\", change.value]];\n}\n\nfunction cancellationError(signal: AbortSignal): Error {\n\treturn signal.reason instanceof Error ? signal.reason : new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n\n/** What the guard needs of its Session: the failure so far, and how to fail it. */\ntype FailureLatch = {\n\treadonly failure: { readonly error: unknown } | undefined;\n\tfail(error: unknown): void;\n};\n\n/**\n * The Session's Storage behind its failure guard; every component of the Session reads and writes through it. Before a\n * call, a failed Session gets `SessionFailed` without reaching the backend. A call that throws fails the Session and\n * rethrows the backend's error, unless it is a `StorageRequestError` or a read whose caller's context was aborted:\n * neither says the Storage is broken.\n * `close()` always reaches the backend, so a failed Session still closes it.\n */\nclass GuardedStorage implements Storage {\n\treadonly #storage: Storage;\n\treadonly #latch: FailureLatch;\n\t/** Backend calls underway, also those off the Session line, which close waits for before it closes the backend. */\n\treadonly #underway = new Set<Promise<unknown>>();\n\t#closing = false;\n\n\tconstructor(storage: Storage, latch: FailureLatch) {\n\t\tthis.#storage = storage;\n\t\tthis.#latch = latch;\n\t}\n\n\t/** Never exempt, whatever it throws: once admitted, whether a failed batch committed is unknown. */\n\tcommit(writes: readonly StorageWrite[], context: Context): Promise<Seq> {\n\t\treturn this.#call(undefined, () => this.#storage.commit(writes, context));\n\t}\n\n\tmintId<I extends Id<string>>(): Promise<I> {\n\t\treturn this.#call(undefined, () => this.#storage.mintId<I>());\n\t}\n\n\tconversation(id: ConversationId, context: Context): Promise<ConversationRecord | undefined> {\n\t\treturn this.#call(context, () => this.#storage.conversation(id, context));\n\t}\n\n\tscanConversations(\n\t\tquery: ConversationQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<ConversationRecord, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanConversations(query, limit, cursor, context));\n\t}\n\n\tentry(id: EntryId, context: Context): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined>;\n\tentry(\n\t\tconversationId: ConversationId,\n\t\tid: EntryId,\n\t\tcontext: Context,\n\t): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined>;\n\tentry(\n\t\tfirst: EntryId | ConversationId,\n\t\tsecond: EntryId | Context,\n\t\tthird?: Context,\n\t): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined> {\n\t\tif (third === undefined) {\n\t\t\tconst context = second as Context;\n\t\t\treturn this.#call(context, () => this.#storage.entry(first as EntryId, context));\n\t\t}\n\t\treturn this.#call(third, () => this.#storage.entry(first as ConversationId, second as EntryId, third));\n\t}\n\n\tfindLatestHeadMarker(\n\t\tconversationId: ConversationId,\n\t\tatOrBeforeEntryId: EntryId | undefined,\n\t\tcontext: Context,\n\t): Promise<(EntryRecord & { readonly head: EntryId }) | undefined> {\n\t\treturn this.#call(context, () => this.#storage.findLatestHeadMarker(conversationId, atOrBeforeEntryId, context));\n\t}\n\n\tscanEntries(\n\t\tquery: EntryQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanEntries(query, limit, cursor, context));\n\t}\n\n\ttask(id: TaskId, context: Context): Promise<TaskRecord<JsonValue, JsonValue, JsonValue> | undefined> {\n\t\treturn this.#call(context, () => this.#storage.task(id, context));\n\t}\n\n\tscanTasks(\n\t\tquery: TaskQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<TaskRecord<JsonValue, JsonValue, JsonValue>, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanTasks(query, limit, cursor, context));\n\t}\n\n\tsubmission(id: SubmissionId, context: Context): Promise<SubmissionRecord | undefined> {\n\t\treturn this.#call(context, () => this.#storage.submission(id, context));\n\t}\n\n\tscanSubmissions(\n\t\tquery: SubmissionQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<SubmissionRecord, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanSubmissions(query, limit, cursor, context));\n\t}\n\n\tsubmissionByRequest(\n\t\tconversationId: ConversationId,\n\t\trequestId: string,\n\t\tcontext: Context,\n\t): Promise<SubmissionRecord | undefined> {\n\t\treturn this.#call(context, () => this.#storage.submissionByRequest(conversationId, requestId, context));\n\t}\n\n\tfindDocument(address: DocumentAddress, at: DocumentPoint, context: Context): Promise<DocumentRecord | undefined> {\n\t\treturn this.#call(context, () => this.#storage.findDocument(address, at, context));\n\t}\n\n\tdocument(id: DocumentId, at: DocumentPoint, context: Context): Promise<StoredDocument | undefined> {\n\t\treturn this.#call(context, () => this.#storage.document(id, at, context));\n\t}\n\n\tscanDocuments(\n\t\tquery: DocumentQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<DocumentRecord, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanDocuments(query, limit, cursor, context));\n\t}\n\n\t/**\n\t * Close the backend once every call underway has settled, so none outlives it or fails after `closed` settles. New\n\t * calls are refused from here on: a paged read must not start its next page while the backend closes.\n\t */\n\tasync close(context: Context): Promise<void> {\n\t\tthis.#closing = true;\n\t\tawait Promise.allSettled([...this.#underway]);\n\t\treturn this.#storage.close(context);\n\t}\n\n\t/**\n\t * Run one backend call under the guard. `read` is a read's context; `commit()` and `mintId()` pass none, so nothing\n\t * exempts their errors: once a batch is admitted, whether it committed is unknown. A call still underway when another\n\t * fails the Session ends with `SessionFailed` too, whatever it returns: nothing it read or wrote is used.\n\t */\n\tasync #call<T>(read: Context | undefined, run: () => Promise<T>): Promise<T> {\n\t\tthis.#assertHealthy();\n\t\tif (this.#closing) throw new Error(\"Session is closed\");\n\t\tlet result: T;\n\t\t// An async wrapper, so a backend that throws synchronously is guarded too.\n\t\tconst call = (async () => run())();\n\t\tthis.#underway.add(call);\n\t\ttry {\n\t\t\tresult = await call;\n\t\t} catch (error) {\n\t\t\tthis.#assertHealthy();\n\t\t\t// An invalid read, or one its caller cancelled, says nothing about the Storage; it fails that call only.\n\t\t\tconst exempt =\n\t\t\t\tread !== undefined && (error instanceof StorageRequestError || read.abortSignal?.aborted === true);\n\t\t\tif (!exempt) this.#latch.fail(error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tthis.#underway.delete(call);\n\t\t}\n\t\tthis.#assertHealthy();\n\t\treturn result;\n\t}\n\n\t#assertHealthy(): void {\n\t\tconst failure = this.#latch.failure;\n\t\tif (failure !== undefined) throw new SessionFailed(failure.error);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file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AC,CAAC;QACzB,IAAI,CAAC;YACJ,MAAM,GAAG,MAAM,IAAI,CAAC;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,yGAAyG;YACzG,MAAM,MAAM,GACX,IAAI,KAAK,SAAS,IAAI,CAAC,KAAK,YAAY,mBAAmB,IAAI,IAAI,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC,CAAC;YACpG,IAAI,CAAC,MAAM;gBAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrC,MAAM,KAAK,CAAC;QACb,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,OAAO,MAAM,CAAC;IACf,CAAC;IAED,cAAc;QACb,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QACpC,IAAI,OAAO,KAAK,SAAS;YAAE,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC;CACD","sourcesContent":["import { type Context, type JsonValue, Watch, type WatchEnd } from \"@earendil-works/chord\";\nimport { awaitWithContext, BACKGROUND_CONTEXT, withoutAbortSignal } from \"@earendil-works/chord/context\";\nimport { type Op, PendingOps, track } from \"@earendil-works/chord/delta\";\nimport type { SpanAttributes } from \"@earendil-works/pi-telemetry\";\nimport {\n\ttype AnyDocToken,\n\taddressId,\n\tcheckRecordScope,\n\tcheckRecordVersion,\n\tmaterializeDocument,\n\tresolveAddress,\n} from \"../documents.ts\";\nimport { ReadOnlySession, SessionFailed, StorageRequestError } from \"../errors.ts\";\nimport { idFromNumber } from \"../ids.ts\";\nimport { hostTimers, type Timers } from \"../timers.ts\";\nimport type {\n\tCommitChange,\n\tCommitObservation,\n\tCommitObserver,\n\tCommitOptions,\n\tCommitPersistence,\n\tCommitPublication,\n\tCommitResult,\n\tConversationDocFamilyToken,\n\tConversationDocToken,\n\tConversationId,\n\tConversationQuery,\n\tConversationRecord,\n\tCursor,\n\tDocumentAddress,\n\tDocumentCommitChange,\n\tDocumentId,\n\tDocumentPoint,\n\tDocumentQuery,\n\tDocumentRecord,\n\tDocumentWatch,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tId,\n\tJsonObject,\n\tObservation,\n\tObserver,\n\tPage,\n\tReportInfo,\n\tRewindableConversationDocFamilyToken,\n\tRewindableConversationDocToken,\n\tSeq,\n\tSession,\n\tSessionDocFamilyToken,\n\tSessionDocToken,\n\tSessionEnd,\n\tSetTimer,\n\tStorage,\n\tStorageWrite,\n\tStoredDocument,\n\tSubmissionId,\n\tSubmissionQuery,\n\tSubmissionRecord,\n\tTaskDocFamilyToken,\n\tTaskDocToken,\n\tTaskId,\n\tTaskQuery,\n\tTaskRecord,\n\tTx,\n} from \"../types.ts\";\nimport { CachedStorage, scopeOf } from \"./cached-storage.ts\";\nimport { ConversationTails, type HeadMarker } from \"./conversation-tails.ts\";\nimport { ALL_KEYS, appendKey, conversationKey, documentKey, GatedStorage, incarnationKey } from \"./keys.ts\";\nimport {\n\ttype AdoptedDocuments,\n\ttype HeldDocument,\n\ttype LoadedDocument,\n\tstoreHeld,\n\tTransaction,\n\ttype TransactionHost,\n\ttype TransactionScope,\n} from \"./transaction.ts\";\nimport { type PublishFailure, Writer } from \"./writer.ts\";\n\n/**\n * What the Session's own components observe of one commit (`followCommits()`): a stored commit with its own changes, or\n * a deferred one adopted in memory only (`CommitPersistence`), which changes documents only. Memory is never behind:\n * a later store of held changes is not observed again.\n */\nexport type ObservedCommit =\n\t| { readonly kind: \"stored\"; readonly seq: Seq; readonly changes: readonly CommitChange[] }\n\t| { readonly kind: \"memory\"; readonly changes: readonly DocumentCommitChange[] };\n\n/** A held document (`HeldDocument`) as the Session keeps it: pinned in the cache until stored. */\ntype Hold = HeldDocument & {\n\t/** When the earliest of its held commits must be stored, on the Session clock. */\n\tdeadline: number;\n\treadonly unpin: () => void;\n};\n\n/** The armed store of held documents: a foreground timer for the earliest deadline, `fired` once its job is queued. */\ntype HoldTimer = { readonly at: number; disarm: () => void; fired: boolean };\n\nconst NO_HOLDS: readonly Hold[] = [];\n\nconst NO_OPERATIONS: readonly Op[] = [];\n\n/** A line job's result: its value, delivered once `after`, the publication of its commit, settles, if it has one. */\ntype Ran<T> = { readonly value: T; readonly after?: Promise<void> };\n\n/** A job on the line: its index in line order, and whether a touch of it waited for an unpublished writer. */\ntype Job = {\n\treadonly index: number;\n\thit: boolean;\n\t/** Called once its outcome settles: its commit published, or never to be (`onJobEnd()`). */\n\tends?: (() => void)[];\n};\n\nconst NO_KEYS: readonly string[] = [];\n\n/**\n * Jobs admitted to the line whose outcome is not delivered yet, beyond which the line waits. A count, not bytes: what\n * waits is bounded by what one commit can hold (tool output by its output limits), times the count.\n */\nconst MAX_OUTSTANDING = 256;\n\nconst ignore = (): void => {};\n\n/**\n * Queues a commit's host dispatch as one microtask through `then`: in the same queue as `queueMicrotask()`, which Node\n * wraps in an async resource that costs about twice the memory and three times the time per stored commit.\n */\nconst SETTLED: Promise<void> = Promise.resolve();\n\n/** The default source of a report: a listener, which never fails what ran it. */\nconst LISTENER: ReportInfo = { kind: \"listener_error\" };\n\n/** A telemetry adapter that threw on a commit's event, which must not fail the durable commit. */\nconst TELEMETRY: ReportInfo = { kind: \"host_error\", callback: \"telemetry\" };\n\n/**\n * Open a Session kernel over one storage backend. `now` is the wall clock for task times; default `Date.now`.\n * `setTimer` arms the timers that evict idle documents; default `setTimeout` (see `HarnessOptions.setTimer`). The first\n * error a Storage method throws fails the Session (`SessionFailed`); see `SessionImpl`.\n */\nexport function createSession(\n\tstorage: Storage,\n\toptions?: {\n\t\treadonly now?: () => number;\n\t\treadonly documentRetentionMs?: number;\n\t\treadonly setTimer?: SetTimer;\n\t\t/** Default `withinMs` of a deferred commit (`CommitPersistence`); default 1,000. */\n\t\treadonly persistWithinMs?: number;\n\t},\n): Session {\n\tconst retention = options?.documentRetentionMs;\n\tconst within = options?.persistWithinMs;\n\treturn new SessionImpl(\n\t\tstorage,\n\t\toptions?.now,\n\t\tretention === undefined ? undefined : () => retention,\n\t\toptions?.setTimer,\n\t\tfalse,\n\t\t() => within,\n\t);\n}\n\n/** Default document retention: ten minutes, as for kept contexts. */\nlet defaultRetention = 600_000;\n\n/** Internal, for tests: the retention of every Session that keeps the default, as a suite run with eviction at once. */\nexport function setDefaultDocumentRetention(ms: number): void {\n\tdefaultRetention = ms;\n}\n\n/**\n * A retention as given, when it is a number of milliseconds, `0` or more (`Infinity` keeps documents); otherwise the\n * default.\n */\nexport function documentRetention(ms: number | undefined): number {\n\treturn typeof ms === \"number\" && ms >= 0 ? ms : defaultRetention;\n}\n\n/** Default `withinMs` of a deferred commit, `settings.progress.persistWithinMs`. */\nconst DEFAULT_PERSIST_WITHIN_MS = 1_000;\n\n/**\n * A deferred commit's default window as given, when it is a number of milliseconds, `0` or more (`Infinity` waits for a\n * reading or writing commit or close); otherwise the default.\n */\nexport function persistWithin(ms: number | undefined): number {\n\treturn typeof ms === \"number\" && ms >= 0 ? ms : DEFAULT_PERSIST_WITHIN_MS;\n}\n\n/**\n * Session kernel: one mutation line, the loaded document tracker cache, and committed publication.\n *\n * The cache is bounded by use: a document with no watch attached leaves it once it was not read or\n * written for the retention period, and the next access loads it from Storage. Eviction runs as a job on the mutation\n * line, so no transaction ever holds a tracker that leaves.\n *\n * Only committed state is observable. A deferred commit (`CommitPersistence`) is committed in memory first: it is\n * adopted and shown to the Session's own observers, and its changes wait, folded per document and pinned in the cache,\n * for the first commit that reads or writes the document, the document's deadline, a drop of its tracker, or close,\n * which store them.\n *\n * Group commit: the line runs one job at a time, a commit's callback and settlement; a commit with writes then joins\n * the writer's pending batch (logical admission, `Writer`) and the line goes on. The writer stores every commit admitted\n * while no call is in flight in one `commit()` call, off the line, and publishes them one by one, in line order, a\n * macrotask apart: the read caches, adoption, telemetry events, the Session's own observers, and one microtask later\n * `observeCommits()` observers, before every wait the commit resolves and every abort it queues. Host listeners and\n * watch listeners have no order. A deferred commit is published when the commits before it are. A job's every read\n * touches its key (`touch()`); while an unpublished commit writes that key, the job waits for its publication, so no\n * job observes state that is not stored. Outcomes are delivered in line order (`#enqueue()`).\n *\n * Storage failures are final. Every Storage call goes through one guard: the first error a Storage method throws, other\n * than for a cancelled caller, fails the Session, as does a commit it cannot adopt. That call gets the error; every later\n * call and every Storage call still underway gets `SessionFailed`; close listeners run at once with the error, and the\n * Session then closes itself, Storage included, and `closed` settles. Nothing retries: transient errors are the\n * Storage's to retry. Reopening recovers from what was committed.\n */\nexport class SessionImpl implements Session {\n\treadonly #storage: GuardedStorage;\n\t/** Newest entry and head marker per conversation; none for a read-only Session, whose Storage another process writes. */\n\treadonly #tails: ConversationTails | undefined;\n\t/**\n\t * The current documents of each live task this Session created, so the commit that ends a task retires them without\n\t * a scan. An entry starts with its task's creation and goes when the task is terminal: bounded by live tasks.\n\t */\n\treadonly #taskDocuments = new Map<TaskId, Map<DocumentId, DocumentRecord>>();\n\treadonly #documents = new Map<string, LoadedDocument>();\n\t/** Cached documents with no observer attached, by address, oldest use first, with the time of that use. */\n\treadonly #idleDocuments = new Map<string, number>();\n\t/** Observers attached per document incarnation (record ID); a cached incarnation with any is never evicted. */\n\treadonly #attachedDocuments = new Map<DocumentId, number>();\n\treadonly #clock: () => number;\n\treadonly #documentRetentionMs: () => number;\n\treadonly #persistWithinMs: () => number;\n\t/** Documents with held changes, by incarnation (record ID); each is pinned in the cache until they are stored. */\n\treadonly #holds = new Map<DocumentId, Hold>();\n\t#holdTimer: HoldTimer | undefined;\n\t/** Refuse every commit with writes (`HarnessOptions.readOnly`). */\n\treadonly #readOnly: boolean;\n\treadonly #timers: Timers;\n\t/** The pending eviction: a timer for the oldest idle document, or a line job when the retention is 0. */\n\t#documentSweep: { readonly at: number; disarm: (() => void) | undefined } | undefined;\n\t#sweepJobs = 0;\n\t/** Set once the host declined a background timer: then none is kept, and the end of each commit evicts what expired. */\n\t#documentTimersUnavailable = false;\n\t/** Host commit observers (`observeCommits()`), each behind `guardObserver()`. */\n\treadonly #commitListeners = new Set<GuardedObserver<CommitPublication>>();\n\t/** The Session's own listeners, such as its scheduler's: they keep memory in step with storage, so a throw fails it. */\n\treadonly #internalListeners = new Set<(publication: ObservedCommit, context: Context) => void>();\n\treadonly #closeListeners = new Set<() => void>();\n\treadonly #host: TransactionHost;\n\t/** The record cache under the guard, which the writer applies each batch to at its publication. */\n\treadonly #cached: CachedStorage | undefined;\n\treadonly #writer: Writer;\n\t/** The Storage jobs on the line read through: each read waits while its key has an unpublished writer. */\n\treadonly #gated: GatedStorage;\n\t/** The end of the last line job: the line runs one job at a time. */\n\t#tail: Promise<void> = Promise.resolve();\n\t/** Line index of the next job; outcomes are delivered in this order. */\n\t#nextIndex = 0;\n\t/** The job on the line, while one runs: its index, and whether it waited at a gate. */\n\t#current: Job | undefined;\n\t/** Settles once every job so far has its outcome delivered. */\n\t#fence: Promise<void> = Promise.resolve();\n\t#lastDelivered = -1;\n\t/** Jobs that started on the line and have no outcome delivered yet (`MAX_OUTSTANDING`). */\n\t#outstanding = 0;\n\t#room: PromiseWithResolvers<void> | undefined;\n\t/** The line index whose outcome the failure is: every later job's outcome is `SessionFailed`, except `#ownOutcomes`. */\n\t#failAt: number | undefined;\n\t/** Later jobs whose outcome is their own error all the same: the other parts of a storage call that rejected. */\n\treadonly #ownOutcomes = new Set<number>();\n\t#closing: Promise<void> | undefined;\n\t#failure: { readonly error: unknown } | undefined;\n\t/** Set when close reaches the backend: calls that fail from then on fail because it closes. */\n\treadonly #failed = Promise.withResolvers<never>();\n\treadonly #closed = Promise.withResolvers<SessionEnd>();\n\n\tget closed(): Promise<SessionEnd> {\n\t\treturn this.#closed.promise;\n\t}\n\n\t/** Internal: the error that failed the Session, if one did. */\n\tget failure(): { readonly error: unknown } | undefined {\n\t\treturn this.#failure;\n\t}\n\n\t/** Internal: rejects with `SessionFailed` the moment the Session fails, before work underway has ended; never resolves. */\n\tget failed(): Promise<never> {\n\t\treturn this.#failed.promise;\n\t}\n\n\tconstructor(\n\t\tstorage: Storage,\n\t\tnow: () => number = Date.now,\n\t\tdocumentRetentionMs: () => number | undefined = () => undefined,\n\t\tsetTimer?: SetTimer,\n\t\treadOnly = false,\n\t\tpersistWithinMs: () => number | undefined = () => undefined,\n\t) {\n\t\t// Waits race it; none has to.\n\t\tthis.#failed.promise.catch(() => {});\n\t\tthis.#readOnly = readOnly;\n\t\t// A read-only Session shows a Storage another process writes, so nothing it reads stays current.\n\t\tthis.#cached = readOnly ? undefined : new CachedStorage(storage);\n\t\tthis.#storage = new GuardedStorage(this.#cached ?? storage, this);\n\t\tthis.#gated = new GatedStorage(this.#storage, (key) => this.touch(key));\n\t\tthis.#writer = new Writer({\n\t\t\tcommit: (batches, receive, context) => this.#storage.commit(batches, receive, context),\n\t\t\tstored: (writes) => {\n\t\t\t\tthis.#cached?.published(writes);\n\t\t\t\tthis.#tails?.apply(writes);\n\t\t\t},\n\t\t\tpublishing: (publish, context) => this.#publishing(publish, context),\n\t\t\tfailure: () => this.#failure,\n\t\t\tfail: (error, at, own) => this.fail(error, undefined, at, own),\n\t\t\treport: (error, context) => this.report(error, LISTENER, context),\n\t\t});\n\t\tthis.#tails = readOnly ? undefined : new ConversationTails();\n\t\tthis.#timers = hostTimers(setTimer, (error) => this.report(error, { kind: \"host_error\", callback: \"setTimer\" }));\n\t\t// Cache bookkeeping must never change the outcome of the operation it follows: a clock or a retention setting\n\t\t// that throws counts as now, and as the default.\n\t\tthis.#clock = () => {\n\t\t\ttry {\n\t\t\t\treturn now();\n\t\t\t} catch {\n\t\t\t\treturn Date.now();\n\t\t\t}\n\t\t};\n\t\tthis.#documentRetentionMs = () => {\n\t\t\ttry {\n\t\t\t\treturn documentRetention(documentRetentionMs());\n\t\t\t} catch {\n\t\t\t\treturn documentRetention(undefined);\n\t\t\t}\n\t\t};\n\t\tthis.#persistWithinMs = () => {\n\t\t\ttry {\n\t\t\t\treturn persistWithin(persistWithinMs());\n\t\t\t} catch {\n\t\t\t\treturn persistWithin(undefined);\n\t\t\t}\n\t\t};\n\t\tthis.#host = {\n\t\t\tstorage: this.#gated,\n\t\t\ttouch: (key) => this.touch(key),\n\t\t\tnow,\n\t\t\tcached: (id) => {\n\t\t\t\tconst cached = this.#documents.get(id);\n\t\t\t\tif (cached !== undefined) this.#touchDocument(id);\n\t\t\t\treturn cached;\n\t\t\t},\n\t\t\tload: (definition, addressId, address, context) => this.#loadDocument(definition, addressId, address, context),\n\t\t\tinstall: (document) => {\n\t\t\t\tthis.#documents.set(document.addressId, document);\n\t\t\t\tthis.#touchDocument(document.addressId);\n\t\t\t},\n\t\t\tevict: (id, recordId) => {\n\t\t\t\tif (this.#documents.get(id)?.record.id === recordId) this.#dropDocument(id);\n\t\t\t},\n\t\t\tconversationCreated: (tx, record) => this.conversationCreated(tx, record),\n\t\t\ttaskDocuments: (taskId) => this.#taskDocuments.get(taskId)?.values(),\n\t\t\tlatestEntryId: (conversationId, context) => this.latestEntryId(conversationId, context),\n\t\t\tlatestHeadMarker: (conversationId, context) => this.latestHeadMarker(conversationId, undefined, context),\n\t\t};\n\t}\n\n\t/** The Storage behind the failure guard; every component reads and writes through it. */\n\tprotected get storage(): Storage {\n\t\treturn this.#storage;\n\t}\n\n\t/**\n\t * Internal, on the Session line: the newest entry ID visible from `conversationId`. Known from the Session's own\n\t * commits when it owns its Storage, so it costs no Storage read after the first.\n\t */\n\tlatestEntryId(conversationId: ConversationId, context: Context): Promise<EntryId | undefined> {\n\t\tconst gate = this.#touchEntries(conversationId);\n\t\tconst latest = (): Promise<EntryId | undefined> => {\n\t\t\tconst read = async () =>\n\t\t\t\t(await this.#storage.scanEntries({ conversationId }, 1, undefined, context)).items[0]?.id;\n\t\t\treturn this.#tails === undefined ? read() : this.#tails.latest(conversationId, read);\n\t\t};\n\t\treturn gate === undefined ? latest() : gate.then(latest);\n\t}\n\n\t/**\n\t * Internal: the newest entry ID of `conversationId` as known from the Session's commits right now, without reading;\n\t * `undefined` when not known (and always for a read-only Session).\n\t */\n\tknownLatestEntryId(conversationId: ConversationId): EntryId | null | undefined {\n\t\treturn this.#tails?.peek(conversationId);\n\t}\n\n\t/**\n\t * Internal, on the Session line: the newest visible head marker of `conversationId` at or before `atOrBefore`, any\n\t * when `undefined`; known from the Session's own commits as `latestEntryId()` is.\n\t */\n\tlatestHeadMarker(\n\t\tconversationId: ConversationId,\n\t\tatOrBefore: EntryId | undefined,\n\t\tcontext: Context,\n\t): Promise<HeadMarker | undefined> {\n\t\tconst gate = this.#touchEntries(conversationId);\n\t\tconst marker = (): Promise<HeadMarker | undefined> => {\n\t\t\tconst read = () => this.#storage.findLatestHeadMarker(conversationId, atOrBefore, context);\n\t\t\treturn this.#tails === undefined ? read() : this.#tails.marker(conversationId, atOrBefore, read);\n\t\t};\n\t\treturn gate === undefined ? marker() : gate.then(marker);\n\t}\n\n\t/**\n\t * On the line: wait for what an unpublished commit wrote of a conversation's entries, its appends and its creation,\n\t * as reading them from Storage fails for a conversation not stored yet.\n\t */\n\t#touchEntries(conversationId: ConversationId): Promise<void> | undefined {\n\t\tconst created = this.touch(conversationKey(conversationId));\n\t\tconst appended = this.touch(appendKey(conversationId));\n\t\tif (created === undefined) return appended;\n\t\treturn appended === undefined ? created : Promise.all([created, appended]).then(ignore);\n\t}\n\n\t/**\n\t * Internal, on the line: wait, while `key` has an unpublished writer (for `ALL_KEYS`, while anything is unpublished),\n\t * until it is published, then check that the Session is healthy; `undefined` when there is nothing to wait for. A\n\t * job's every read touches its key first, so it never observes state an earlier job admitted and the writer has not\n\t * published.\n\t */\n\ttouch(key: string): Promise<void> | undefined {\n\t\tconst gate = key === ALL_KEYS ? this.#writer.drained() : this.#writer.gate(key);\n\t\tif (gate === undefined) return undefined;\n\t\tif (this.#current !== undefined) this.#current.hit = true;\n\t\treturn gate.then(() => this.#assertHealthy());\n\t}\n\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context, options?: CommitOptions): Promise<T> {\n\t\treturn this.commitWith(change, context, undefined, options);\n\t}\n\n\t/**\n\t * Internal: fail the Session with `error`, the first wins, and report it once. Admission ends, and close listeners run\n\t * now; they read the error from `failure`. The Storage guard calls this; the Harness also calls it for a throw in its\n\t * scheduler's own commits. `at` is the line index of the job whose outcome the failure is, by default the job on the\n\t * line: later jobs' outcomes become `SessionFailed`.\n\t */\n\tfail(error: unknown, context?: Context, at?: number, own?: readonly number[]): void {\n\t\tif (this.#failure !== undefined) return;\n\t\tthis.#failure = { error };\n\t\t// The job that caused it keeps its own outcome; without one, every outcome not delivered yet is `SessionFailed`.\n\t\tthis.#failAt = at ?? this.#current?.index ?? this.#lastDelivered;\n\t\tif (own !== undefined) for (const index of own) this.#ownOutcomes.add(index);\n\t\tthis.#failed.reject(new SessionFailed(error));\n\t\t// Seal first, so a report handler that calls back finds the Session failed. Closing runs the close listeners\n\t\t// synchronously; a failing backend close is the caller's to see, and here nobody waits.\n\t\tthis.close(BACKGROUND_CONTEXT).catch(() => {});\n\t\tthis.report(error, { kind: \"storage_failed\" }, context);\n\t}\n\n\t/**\n\t * Internal commit exposing the concrete transaction and its internal operations, such as the reserved-ID root\n\t * bootstrap and task replacement. `scope` sets the default `tx.createTask()` conversation and the task attributed to\n\t * appended entries.\n\t */\n\tcommitWith<T>(\n\t\tchange: (tx: Transaction) => T | Promise<T>,\n\t\tcontext: Context,\n\t\tscope?: TransactionScope,\n\t\toptions?: CommitOptions,\n\t): Promise<T> {\n\t\tlet withinMs: number | undefined;\n\t\ttry {\n\t\t\tthis.assertUsable();\n\t\t\twithinMs = this.#deferral(options?.persistence);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn this.#enqueue((index) => this.#runCommit(change, context, scope, withinMs, index));\n\t}\n\n\t/**\n\t * Internal: `commitWith()` for a commit of the scheduler's own whose outcome goes only to scheduler code. When it\n\t * writes nothing and waited at no gate, it is equivalent to having run before every unpublished commit, so its\n\t * outcome is delivered at once, ahead of theirs. One that writes is never exempt: its outcome waits for its own\n\t * publication and every earlier outcome, so no invocation starts on a reservation that is not durable.\n\t */\n\tcommitInternal<T>(change: (tx: Transaction) => T | Promise<T>, context: Context): Promise<T> {\n\t\ttry {\n\t\t\tthis.assertUsable();\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn this.#enqueue((index) => this.#runCommit(change, context, undefined, undefined, index), true);\n\t}\n\n\t/**\n\t * Internal, on the line: call `end` once the outcome of the job on the line settles, its commit published or never to\n\t * be; at once off the line.\n\t */\n\tonJobEnd(end: () => void): void {\n\t\tconst job = this.#current;\n\t\tif (job === undefined) {\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tif (job.ends === undefined) job.ends = [end];\n\t\telse job.ends.push(end);\n\t}\n\n\t/** Internal: the Storage jobs on the line read through (`touch()`); off the line, use the plain one. */\n\tget lineStorage(): Storage {\n\t\treturn this.#gated;\n\t}\n\n\t/** How long a commit may stay in memory before it is stored; `undefined` when it is immediate. */\n\t#deferral(persistence: CommitPersistence | undefined): number | undefined {\n\t\tif (persistence?.kind !== \"deferred\") return undefined;\n\t\tconst ms = persistence.withinMs;\n\t\tif (ms === undefined) return this.#persistWithinMs();\n\t\t// Public options: checked here, as the types cannot.\n\t\tif (typeof ms !== \"number\" || !(ms >= 0)) {\n\t\t\tthrow new TypeError(\"CommitPersistence.withinMs must be a number of milliseconds, 0 or more\");\n\t\t}\n\t\treturn ms;\n\t}\n\n\t/** Internal: whether `tx` is the transaction of one of this Session's commits. */\n\townsTransaction(tx: Tx): tx is Transaction {\n\t\treturn Transaction.ownedBy(tx, this.#host);\n\t}\n\n\t/**\n\t * Internal: run a read-only job on the mutation line so multi-read derivations observe one committed state. It reads\n\t * through `storage`, whose reads wait for the publication of what the line admitted before; its outcome comes after\n\t * theirs.\n\t */\n\treadOnLine<T>(job: (storage: Storage) => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.assertUsable();\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn this.#enqueue(async () => {\n\t\t\tthis.#assertHealthy();\n\t\t\treturn { value: await job(this.#gated) };\n\t\t});\n\t}\n\n\t/**\n\t * Internal: a conversation document's current incarnation and value, for a job already running on the line (see\n\t * `readOnLine()`). Absent documents are `undefined`.\n\t */\n\tasync conversationDocumentOnLine(\n\t\ttoken: ConversationDocToken<JsonObject>,\n\t\tconversationId: ConversationId,\n\t\tcontext: Context,\n\t): Promise<{ readonly record: DocumentRecord; readonly version: number; readonly value: JsonObject } | undefined> {\n\t\tconst definition = token.definition;\n\t\tconst resolved = resolveAddress(definition, [conversationId, context]);\n\t\tconst loaded = await this.#loadDocument(definition, resolved.id, resolved.address, context);\n\t\tif (loaded === undefined) return undefined;\n\t\tcheckRecordScope(definition, loaded.record);\n\t\tcheckRecordVersion(definition, loaded.record, loaded.storedVersion);\n\t\treturn { record: loaded.record, version: loaded.valueVersion, value: loaded.tracker.value };\n\t}\n\n\tsnapshot<T extends JsonObject>(token: SessionDocToken<T>, context: Context): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject>(\n\t\ttoken: ConversationDocToken<T>,\n\t\tconversationId: ConversationId,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject>(\n\t\ttoken: TaskDocToken<T>,\n\t\ttaskId: TaskId,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: SessionDocFamilyToken<T, I>,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: ConversationDocFamilyToken<T, I>,\n\t\tconversationId: ConversationId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshot<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: TaskDocFamilyToken<T, I>,\n\t\ttaskId: TaskId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tasync snapshot(token: AnyDocToken, ...args: readonly unknown[]): Promise<JsonObject | undefined> {\n\t\tthis.assertUsable();\n\t\tconst definition = token.definition;\n\t\tconst resolved = resolveAddress(definition, args);\n\t\tconst context = args[resolved.nextArgument] as Context;\n\t\tconst cached = this.#documents.get(resolved.id);\n\t\tif (cached?.valueVersion === definition.version) this.#touchDocument(resolved.id);\n\t\tconst loaded =\n\t\t\tcached?.valueVersion === definition.version\n\t\t\t\t? cached\n\t\t\t\t: await this.#enqueue(async () => {\n\t\t\t\t\t\tthis.#assertHealthy();\n\t\t\t\t\t\treturn { value: await this.#loadDocument(definition, resolved.id, resolved.address, context) };\n\t\t\t\t\t});\n\t\tif (loaded === undefined) return undefined;\n\t\tcheckRecordScope(definition, loaded.record);\n\t\tcheckRecordVersion(definition, loaded.record, loaded.storedVersion);\n\t\treturn loaded.tracker.value;\n\t}\n\n\twatchDoc<T extends JsonObject>(token: SessionDocToken<T>, context: Context): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject>(\n\t\ttoken: ConversationDocToken<T>,\n\t\tconversationId: ConversationId,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject>(\n\t\ttoken: TaskDocToken<T>,\n\t\ttaskId: TaskId,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: SessionDocFamilyToken<T, I>,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: ConversationDocFamilyToken<T, I>,\n\t\tconversationId: ConversationId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: TaskDocFamilyToken<T, I>,\n\t\ttaskId: TaskId,\n\t\tkey: string,\n\t\tcontext: Context,\n\t): Promise<DocumentWatch<T> | undefined>;\n\twatchDoc(token: AnyDocToken, ...args: readonly unknown[]): Promise<DocumentWatch<JsonObject> | undefined> {\n\t\t// Not async, so an attachment costs one async frame, `#attachDocument`'s; a throw here still rejects.\n\t\ttry {\n\t\t\tthis.assertUsable();\n\t\t\tconst definition = token.definition;\n\t\t\tconst resolved = resolveAddress(definition, args);\n\t\t\tconst context = args[resolved.nextArgument] as Context;\n\t\t\tconst signal = context.abortSignal;\n\t\t\treturn this.#attachDocument(\n\t\t\t\tdefinition,\n\t\t\t\tresolved,\n\t\t\t\tcontext,\n\t\t\t\t(loaded) => {\n\t\t\t\t\tconst watch = this.#observeDocument(definition, loaded, createWatch, endWatch);\n\t\t\t\t\tif (signal !== undefined) watch.observeAbort(signal);\n\t\t\t\t\treturn watch;\n\t\t\t\t},\n\t\t\t\tabortWatch,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t}\n\n\tobserveDoc<T extends JsonObject>(\n\t\ttoken: SessionDocToken<T>,\n\t\tobserver: Observer<Readonly<T>>,\n\t\tcontext: Context,\n\t): Promise<Observation<Readonly<T>> | undefined>;\n\tobserveDoc<T extends JsonObject>(\n\t\ttoken: ConversationDocToken<T>,\n\t\tconversationId: ConversationId,\n\t\tobserver: Observer<Readonly<T>>,\n\t\tcontext: Context,\n\t): Promise<Observation<Readonly<T>> | undefined>;\n\tobserveDoc<T extends JsonObject>(\n\t\ttoken: TaskDocToken<T>,\n\t\ttaskId: TaskId,\n\t\tobserver: Observer<Readonly<T>>,\n\t\tcontext: Context,\n\t): Promise<Observation<Readonly<T>> | undefined>;\n\tobserveDoc<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: SessionDocFamilyToken<T, I>,\n\t\tkey: string,\n\t\tobserver: Observer<Readonly<T>>,\n\t\tcontext: Context,\n\t): Promise<Observation<Readonly<T>> | undefined>;\n\tobserveDoc<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: ConversationDocFamilyToken<T, I>,\n\t\tconversationId: ConversationId,\n\t\tkey: string,\n\t\tobserver: Observer<Readonly<T>>,\n\t\tcontext: Context,\n\t): Promise<Observation<Readonly<T>> | undefined>;\n\tobserveDoc<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: TaskDocFamilyToken<T, I>,\n\t\ttaskId: TaskId,\n\t\tkey: string,\n\t\tobserver: Observer<Readonly<T>>,\n\t\tcontext: Context,\n\t): Promise<Observation<Readonly<T>> | undefined>;\n\tobserveDoc(token: AnyDocToken, ...args: readonly unknown[]): Promise<Observation<Readonly<JsonObject>> | undefined> {\n\t\t// Not async, as `watchDoc()`; a throw here still rejects.\n\t\ttry {\n\t\t\tthis.assertUsable();\n\t\t\tconst definition = token.definition;\n\t\t\tconst resolved = resolveAddress(definition, args);\n\t\t\tconst observer = args[resolved.nextArgument] as Observer<Readonly<JsonObject>>;\n\t\t\tconst context = args[resolved.nextArgument + 1] as Context;\n\t\t\treturn this.#attachDocument(\n\t\t\t\tdefinition,\n\t\t\t\tresolved,\n\t\t\t\tcontext,\n\t\t\t\t(loaded) => {\n\t\t\t\t\tconst guarded = this.#observeDocument(\n\t\t\t\t\t\tdefinition,\n\t\t\t\t\t\tloaded,\n\t\t\t\t\t\t(_value, detach, report) => guardObserver(observer, detach, report),\n\t\t\t\t\t\tendGuarded,\n\t\t\t\t\t);\n\t\t\t\t\treturn observation(loaded.tracker.value, guarded);\n\t\t\t\t},\n\t\t\t\tdetachObservation,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t}\n\n\tsnapshotAsOf<T extends JsonObject>(\n\t\ttoken: RewindableConversationDocToken<T>,\n\t\tconversationId: ConversationId,\n\t\tat: EntryId,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tsnapshotAsOf<T extends JsonObject, I extends JsonValue>(\n\t\ttoken: RewindableConversationDocFamilyToken<T, I>,\n\t\tconversationId: ConversationId,\n\t\tkey: string,\n\t\tat: EntryId,\n\t\tcontext: Context,\n\t): Promise<Readonly<T> | undefined>;\n\tasync snapshotAsOf(token: AnyDocToken, ...args: readonly unknown[]): Promise<JsonObject | undefined> {\n\t\tthis.assertUsable();\n\t\tconst definition = token.definition;\n\t\tconst resolved = resolveAddress(definition, args);\n\t\tif (resolved.address.scope.kind !== \"conversation\") {\n\t\t\tthrow new TypeError(\"Session.snapshotAsOf() requires a conversation document\");\n\t\t}\n\t\tconst conversationId = resolved.address.scope.conversationId;\n\t\tconst atValue = args[resolved.nextArgument];\n\t\tif (typeof atValue !== \"number\" || !Number.isSafeInteger(atValue)) {\n\t\t\tthrow new TypeError(\"Session.snapshotAsOf() requires an entry ID\");\n\t\t}\n\t\tconst at = idFromNumber<EntryId>(atValue);\n\t\tconst context = args[resolved.nextArgument + 1] as Context;\n\t\treturn this.#enqueue(async () => {\n\t\t\tthis.#assertHealthy();\n\t\t\tconst storedEntry = await this.#gated.entry(conversationId, at, context);\n\t\t\tif (storedEntry === undefined) {\n\t\t\t\tthrow new Error(`Entry ${at} is not visible from conversation ${conversationId}`);\n\t\t\t}\n\t\t\tconst address: DocumentAddress = {\n\t\t\t\t...resolved.address,\n\t\t\t\tscope: { kind: \"conversation\", conversationId: storedEntry.entry.conversationId },\n\t\t\t};\n\t\t\tconst record = await this.#gated.findDocument(address, storedEntry.commitSeq, context);\n\t\t\tif (record === undefined) return { value: undefined };\n\t\t\tconst stored = await this.#gated.document(record.id, storedEntry.commitSeq, context);\n\t\t\tif (stored === undefined) {\n\t\t\t\tthrow new Error(`Historical document ${record.id} (${record.kind}) cannot be read`);\n\t\t\t}\n\t\t\treturn { value: materializeDocument(definition, stored) };\n\t\t});\n\t}\n\n\tclose(context: Context): Promise<void> {\n\t\tif (this.#closing === undefined) {\n\t\t\tconst cleanup = withoutAbortSignal(context);\n\t\t\t// Seal admission before anything else runs, then stop observers; admitted work settles before Storage closes.\n\t\t\tthis.#closing = Promise.resolve()\n\t\t\t\t.then(() => this.beforeClose())\n\t\t\t\t.then(() =>\n\t\t\t\t\tthis.#maintain(async () => {\n\t\t\t\t\t\tawait this.#drained();\n\t\t\t\t\t\t// Last, after the writes at close (`writeAtClose()`), while the trackers are still here. A failed Session\n\t\t\t\t\t\t// writes nothing; a failing store fails it, and the backend still closes.\n\t\t\t\t\t\tlet unstored: { readonly error: unknown } | undefined;\n\t\t\t\t\t\t// Only with something to store: otherwise the backend's close begins in this very job.\n\t\t\t\t\t\tif (this.#failure === undefined && this.#holds.size > 0) {\n\t\t\t\t\t\t\tawait this.#storeHolds(() => [...this.#holds.values()], cleanup).catch((error: unknown) => {\n\t\t\t\t\t\t\t\tunstored = { error };\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst observers = [...this.#commitListeners];\n\t\t\t\t\t\tthis.#commitListeners.clear();\n\t\t\t\t\t\t// After the last publication: the commits admitted before the seal have settled, held changes are stored.\n\t\t\t\t\t\t// Commit observers are synchronous observers, all of them.\n\t\t\t\t\t\tconst end = closeEnds(this.#failure).observer;\n\t\t\t\t\t\tfor (const observer of observers) observer.end(end);\n\t\t\t\t\t\tthis.#internalListeners.clear();\n\t\t\t\t\t\tthis.#documents.clear();\n\t\t\t\t\t\tthis.#idleDocuments.clear();\n\t\t\t\t\t\tthis.#attachedDocuments.clear();\n\t\t\t\t\t\tthis.#holds.clear();\n\t\t\t\t\t\tthis.#taskDocuments.clear();\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this.#storage.close(cleanup);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// A Storage that cannot close is a failed one; an earlier failure stays the cause.\n\t\t\t\t\t\t\tif (this.#failure === undefined) {\n\t\t\t\t\t\t\t\tthis.#failure = { error };\n\t\t\t\t\t\t\t\tthis.report(error, { kind: \"storage_failed\" });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (unstored !== undefined) throw unstored.error;\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tconst failure = this.#failure;\n\t\t\t\t\tthis.#closed.resolve(\n\t\t\t\t\t\tfailure === undefined ? { kind: \"closed\" } : { kind: \"failed\", error: failure.error },\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\tthis.#notifyClose();\n\t\t}\n\t\treturn awaitWithContext(this.#closing, context);\n\t}\n\n\t/** Run the close listeners once, each on its own: one that fails is reported, and the rest still run. */\n\t#notifyClose(): void {\n\t\tthis.#documentSweep?.disarm?.();\n\t\tthis.#documentSweep = undefined;\n\t\tthis.#holdTimer?.disarm();\n\t\tthis.#holdTimer = undefined;\n\t\tconst listeners = [...this.#closeListeners];\n\t\tthis.#closeListeners.clear();\n\t\tfor (const listener of listeners) contained(listener, (error) => this.report(error));\n\t}\n\n\t/**\n\t * Internal: the Session's failure, and errors of listeners, which never fail what ran them; `info` defaults to a\n\t * listener. A plain Session drops them.\n\t */\n\treport(_error: unknown, _info: ReportInfo = LISTENER, _context?: Context): void {}\n\n\t/**\n\t * Runs inside every transaction that creates or forks a conversation, after the conversation record is staged. A\n\t * plain Session stages nothing; a Harness stages its built-in documents.\n\t */\n\tprotected conversationCreated(_tx: Transaction, _record: ConversationRecord): Promise<void> {\n\t\treturn Promise.resolve();\n\t}\n\n\t/**\n\t * Internal, for `beforeClose()`: on the line, after every commit admitted before the seal has settled, write what\n\t * `writes()` returns then straight to Storage. Nothing is published, since the Session is closing; a failed Session\n\t * writes nothing.\n\t */\n\tprotected writeAtClose(writes: () => readonly StorageWrite[]): Promise<void> {\n\t\treturn this.#maintain(async (index) => {\n\t\t\tawait this.#drained();\n\t\t\tif (this.#failure !== undefined) return;\n\t\t\tconst batch = writes();\n\t\t\tif (batch.length === 0) return;\n\t\t\tconst context = BACKGROUND_CONTEXT;\n\t\t\tawait this.#writer.admit({\n\t\t\t\tindex,\n\t\t\t\twrites: batch,\n\t\t\t\tkeys: [],\n\t\t\t\tcontext,\n\t\t\t\tpublish: () => undefined,\n\t\t\t\tdiscard: ignore,\n\t\t\t}).outcome;\n\t\t});\n\t}\n\n\t/**\n\t * Keys a commit writes besides its records' (`Transaction.writeKeys()`), at its admission, on the line: a Harness\n\t * adds the ownership memberships its task changes write. A plain Session adds none.\n\t */\n\tprotected membershipKeys(_tx: Transaction): readonly string[] | Promise<readonly string[]> {\n\t\treturn NO_KEYS;\n\t}\n\n\t/** Runs after close seals admission and before the line closes Storage; must not reject. */\n\tprotected beforeClose(): Promise<void> {\n\t\treturn Promise.resolve();\n\t}\n\n\t/**\n\t * Attach a synchronous observer of every stored commit, with exactly what it stored (`CommitPublication`). Its\n\t * `advance` runs one microtask after the commit's publication, which follows its storage call, in line order, before\n\t * every wait the commit resolves and every abort it queues (in no order with watch listeners); it must not block or\n\t * call Session operations. A throw is reported, detaches it, and ends it `listener_error`; `end` gets the Session's\n\t * close after its last publication.\n\t */\n\tobserveCommits(observer: CommitObserver): CommitObservation {\n\t\tthis.assertUsable();\n\t\tconst guarded = guardObserver(\n\t\t\tobserver,\n\t\t\t() => this.#commitListeners.delete(guarded),\n\t\t\t(error, context) => this.report(error, LISTENER, context),\n\t\t);\n\t\tthis.#commitListeners.add(guarded);\n\t\treturn { detach: () => guarded.detach() };\n\t}\n\n\t/**\n\t * Internal: follow every commit as memory adopts it (`ObservedCommit`), for the Session's own components, whose state\n\t * follows memory. A throw leaves that state behind, so it fails the Session instead of being reported. They run at\n\t * the commit's publication, synchronously, so they call no Storage method, run no task code, and contain every host\n\t * callback; the waits they resolve and the aborts they queue run after host observers.\n\t */\n\tfollowCommits(listener: (publication: ObservedCommit, context: Context) => void): () => void {\n\t\tthis.assertUsable();\n\t\tthis.#internalListeners.add(listener);\n\t\treturn () => this.#internalListeners.delete(listener);\n\t}\n\n\t/**\n\t * Register a listener called synchronously when close begins, also when a failure closes the Session (`failure` is\n\t * then set). It must not block or call Session operations; a throw is reported.\n\t */\n\tsubscribeClose(listener: () => void): () => void {\n\t\tthis.assertUsable();\n\t\tthis.#closeListeners.add(listener);\n\t\treturn () => this.#closeListeners.delete(listener);\n\t}\n\n\t/** Drop every loaded tracker on the mutation line, held changes stored first; later access cold-loads from Storage. */\n\tunloadDocuments(): Promise<void> {\n\t\treturn this.#maintain(async () => {\n\t\t\tif (this.#failure === undefined) await this.#storeHolds(() => [...this.#holds.values()], BACKGROUND_CONTEXT);\n\t\t\tthis.#documents.clear();\n\t\t\tthis.#idleDocuments.clear();\n\t\t});\n\t}\n\n\t/**\n\t * Internal, for tests: how many documents the cache holds, how many are idle, how many incarnations are pinned, how\n\t * many sweep jobs were queued on the line so far, how many documents have held changes, how many live tasks have\n\t * their documents indexed, and how many conversations have their newest entry kept.\n\t */\n\tget documentCacheSizes(): {\n\t\treadonly cached: number;\n\t\treadonly idle: number;\n\t\treadonly attached: number;\n\t\treadonly sweeps: number;\n\t\treadonly held: number;\n\t\treadonly taskDocuments: number;\n\t\treadonly tails: number;\n\t} {\n\t\treturn {\n\t\t\tcached: this.#documents.size,\n\t\t\tidle: this.#idleDocuments.size,\n\t\t\tattached: this.#attachedDocuments.size,\n\t\t\tsweeps: this.#sweepJobs,\n\t\t\theld: this.#holds.size,\n\t\t\ttaskDocuments: this.#taskDocuments.size,\n\t\t\ttails: this.#tails?.size ?? 0,\n\t\t};\n\t}\n\n\t/**\n\t * Internal, for tests that bound memory: jobs whose outcome is not delivered yet, keys with an unpublished writer,\n\t * and record reads in flight in the cache. All three are 0 once the line is idle.\n\t */\n\tget lineSizes(): { readonly outstanding: number; readonly unpublished: number; readonly reads: number } {\n\t\treturn {\n\t\t\toutstanding: this.#outstanding,\n\t\t\tunpublished: this.#writer.unpublished,\n\t\t\treads: this.#cached?.readsInFlight ?? 0,\n\t\t};\n\t}\n\n\t/** Note a use of a cached document: an unattached one becomes the newest idle one, and an eviction is scheduled. */\n\t#touchDocument(addressId: string): void {\n\t\tconst cached = this.#documents.get(addressId);\n\t\tif (cached === undefined || this.#attachedDocuments.has(cached.record.id)) return;\n\t\tconst now = this.#clock();\n\t\tconst since = this.#idleDocuments.get(addressId);\n\t\t// A hot document moves to the back at most once per granule, a tenth of the retention up to 1 s: it may then leave\n\t\t// up to a granule early, which costs a reload, while a commit-heavy workload skips the reordering.\n\t\tif (since !== undefined && now - since < Math.min(1_000, this.#documentRetentionMs() / 10)) return;\n\t\tthis.#idleDocuments.delete(addressId);\n\t\tthis.#idleDocuments.set(addressId, now);\n\t\t// A pending sweep for the oldest document comes first unless the retention was shortened since; then it moves up.\n\t\tif (this.#documentSweep === undefined || this.#documentSweep.at > now + this.#documentRetentionMs()) {\n\t\t\tthis.#scheduleDocumentSweep();\n\t\t}\n\t}\n\n\t#dropDocument(addressId: string): void {\n\t\tthis.#documents.delete(addressId);\n\t\tthis.#idleDocuments.delete(addressId);\n\t}\n\n\t/**\n\t * Schedule the eviction of the oldest idle document: on the line at once when the retention is 0, otherwise when it\n\t * expires, by a background timer (`HarnessOptions.setTimer`), which never keeps the process alive. Where the host\n\t * declines it, as the default does in Cloudflare Workers, none is kept: the end of each commit evicts what expired.\n\t */\n\t#scheduleDocumentSweep(): void {\n\t\tif (this.#closing !== undefined) return;\n\t\t// Documents with unpublished changes are not swept: their publication touches them again.\n\t\tlet oldest: number | undefined;\n\t\tfor (const [addressId, since] of this.#idleDocuments) {\n\t\t\tif (this.#writer.gate(documentKey(addressId)) !== undefined) continue;\n\t\t\toldest = since;\n\t\t\tbreak;\n\t\t}\n\t\tif (oldest === undefined) return;\n\t\tconst at = oldest + this.#documentRetentionMs();\n\t\tif (this.#documentSweep !== undefined && this.#documentSweep.at <= at) return;\n\t\tthis.#documentSweep?.disarm?.();\n\t\t// The pending sweep stays set until its job runs, so touches while the line is busy queue no more.\n\t\tconst sweep: { readonly at: number; disarm: (() => void) | undefined } = { at, disarm: undefined };\n\t\tconst run = (): void => {\n\t\t\tthis.#sweepJobs++;\n\t\t\tthis.#maintain(async () => {\n\t\t\t\tif (this.#documentSweep === sweep) this.#documentSweep = undefined;\n\t\t\t\tif (this.#closing === undefined) this.#sweepDocuments();\n\t\t\t}).catch(() => {});\n\t\t};\n\t\tconst delay = at - this.#clock();\n\t\tthis.#documentSweep = sweep;\n\t\tif (delay <= 0) {\n\t\t\tqueueMicrotask(run);\n\t\t\treturn;\n\t\t}\n\t\tif (this.#documentTimersUnavailable) {\n\t\t\tthis.#documentSweep = undefined;\n\t\t\treturn;\n\t\t}\n\t\t// A timer that fires early sweeps nothing and arms the next one.\n\t\tconst disarm = this.#timers.background(run, delay);\n\t\tif (disarm === undefined) {\n\t\t\tthis.#documentTimersUnavailable = true;\n\t\t\tthis.#documentSweep = undefined;\n\t\t\treturn;\n\t\t}\n\t\tsweep.disarm = disarm;\n\t}\n\n\t/** On the line: evict the idle documents whose retention passed, oldest first, then schedule the next eviction. */\n\t#sweepDocuments(): void {\n\t\tconst expired = this.#clock() - this.#documentRetentionMs();\n\t\tfor (const [addressId, since] of this.#idleDocuments) {\n\t\t\tif (since > expired) break;\n\t\t\t// A document with an unpublished change stays until its publication touches it.\n\t\t\tif (this.#writer.gate(documentKey(addressId)) !== undefined) continue;\n\t\t\tthis.#dropDocument(addressId);\n\t\t}\n\t\tthis.#scheduleDocumentSweep();\n\t}\n\n\t/** Pin a cached incarnation for one observer; the returned release unpins it once, idle again after the last. */\n\t#pinDocument(addressId: string, recordId: DocumentId): () => void {\n\t\tthis.#attachedDocuments.set(recordId, (this.#attachedDocuments.get(recordId) ?? 0) + 1);\n\t\tthis.#idleDocuments.delete(addressId);\n\t\tlet pinned = true;\n\t\treturn () => {\n\t\t\tif (!pinned) return;\n\t\t\tpinned = false;\n\t\t\tconst count = (this.#attachedDocuments.get(recordId) ?? 1) - 1;\n\t\t\tif (count > 0) {\n\t\t\t\tthis.#attachedDocuments.set(recordId, count);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.#attachedDocuments.delete(recordId);\n\t\t\tif (this.#documents.get(addressId)?.record.id === recordId) this.#touchDocument(addressId);\n\t\t};\n\t}\n\n\tasync #runCommit<T>(\n\t\tchange: (tx: Transaction) => T | Promise<T>,\n\t\tcontext: Context,\n\t\tscope: TransactionScope | undefined,\n\t\twithinMs: number | undefined,\n\t\tindex: number,\n\t): Promise<Ran<T>> {\n\t\tthis.#assertHealthy();\n\t\tcontext.abortSignal?.throwIfAborted();\n\t\tconst tx = new Transaction(this.#host, context, scope);\n\t\tlet result: T;\n\t\ttry {\n\t\t\tresult = await change(tx);\n\t\t\t// A callback that caught a failed read must not commit, nor succeed as if it had.\n\t\t\tthis.#assertHealthy();\n\t\t} catch (error) {\n\t\t\tawait tx.settleFailure();\n\t\t\tthis.#sweepDocuments();\n\t\t\tthrow error;\n\t\t}\n\t\tlet writes: readonly StorageWrite[];\n\t\ttry {\n\t\t\twrites = await tx.settleSuccess();\n\t\t} catch (error) {\n\t\t\t// Settlement aborted every change already.\n\t\t\tthis.#sweepDocuments();\n\t\t\tthrow error;\n\t\t}\n\t\tif (writes.length === 0) {\n\t\t\ttx.discard();\n\t\t\tthis.#sweepDocuments();\n\t\t\treturn { value: result };\n\t\t}\n\t\tif (this.#readOnly) {\n\t\t\t// Refused before Storage: the Session stays healthy, and the caller sees why.\n\t\t\ttx.discard();\n\t\t\tthis.#sweepDocuments();\n\t\t\tthrow new ReadOnlySession(\"a commit with writes\");\n\t\t}\n\t\tconst discard = (): void => tx.discard();\n\t\tif (withinMs !== undefined) {\n\t\t\tconst held = tx.holdable();\n\t\t\tif (held !== undefined) {\n\t\t\t\t// Adopted in memory when the commits before it are published, as a part of no storage call.\n\t\t\t\tconst part = this.#writer.admit({\n\t\t\t\t\tindex,\n\t\t\t\t\twrites: undefined,\n\t\t\t\t\tkeys: tx.writeKeys(),\n\t\t\t\t\tcontext,\n\t\t\t\t\tpublish: () => this.#hold(tx, held, withinMs, context),\n\t\t\t\t\tdiscard,\n\t\t\t\t});\n\t\t\t\tthis.#sweepDocuments();\n\t\t\t\treturn { value: result, after: part.outcome };\n\t\t\t}\n\t\t}\n\t\tlet membership = this.membershipKeys(tx);\n\t\tif (!Array.isArray(membership)) {\n\t\t\ttry {\n\t\t\t\tmembership = await membership;\n\t\t\t} catch (error) {\n\t\t\t\ttx.discard();\n\t\t\t\tthis.#sweepDocuments();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\t// Logical admission. Held changes leave their queue only here, once nothing but Storage can fail; a commit never\n\t\t// stores a hold adopted after it in line order. Taken before the keys, so the documents it stores held changes of\n\t\t// are its writes too: a later job that reads one waits for it instead of storing them again.\n\t\tconst taken = this.#holds.size === 0 ? NO_HOLDS : tx.takeHeld((id) => this.#holds.get(id));\n\t\tconst keys = tx.writeKeys();\n\t\tfor (const key of membership as readonly string[]) keys.push(key);\n\t\tconst part = this.#writer.admit({\n\t\t\tindex,\n\t\t\twrites,\n\t\t\tkeys,\n\t\t\tcontext,\n\t\t\tpublish: (seq) => this.#adopt(tx, writes, taken, seq!, context),\n\t\t\tdiscard,\n\t\t});\n\t\tthis.#sweepDocuments();\n\t\treturn { value: result, after: part.outcome };\n\t}\n\n\t/**\n\t * Publish a stored commit (`Writer`), after the read caches took its writes: adopt it in memory and run its\n\t * publication. A throw of the adoption leaves memory behind durable state; the writer fails the Session with it.\n\t */\n\t#adopt(\n\t\ttx: Transaction,\n\t\twrites: readonly StorageWrite[],\n\t\ttaken: readonly Hold[],\n\t\tseq: Seq,\n\t\tcontext: Context,\n\t): PublishFailure | undefined {\n\t\tlet documents: AdoptedDocuments;\n\t\ttry {\n\t\t\tdocuments = tx.adopt(seq);\n\t\t} catch (error) {\n\t\t\treturn { kind: \"adoption\", error };\n\t\t}\n\t\tthis.#indexTaskDocuments(tx, writes, documents, seq);\n\t\tconst failure = this.#publish(seq, writes, documents, context);\n\t\tif (taken.length > 0) this.#release(taken);\n\t\tfor (const document of documents.stored) this.#touchDocument(addressId(document.record));\n\t\treturn failure === undefined ? undefined : { kind: \"listener\", error: failure.error };\n\t}\n\n\t/**\n\t * At publication: keep `#taskDocuments` in step with a stored commit: the tasks it creates start with no documents,\n\t * task documents it creates join their task, ones it retires leave, and tasks it ends leave the index.\n\t */\n\t#indexTaskDocuments(tx: Transaction, writes: readonly StorageWrite[], documents: AdoptedDocuments, seq: Seq): void {\n\t\tfor (const id of tx.createdTaskIds()) this.#taskDocuments.set(id, new Map());\n\t\tif (this.#taskDocuments.size === 0) return;\n\t\tfor (const change of documents.stored) {\n\t\t\tif (change.type !== \"document\" || change.record.scope.kind !== \"task\") continue;\n\t\t\tconst known = this.#taskDocuments.get(change.record.scope.taskId);\n\t\t\tif (known === undefined) continue;\n\t\t\tif (change.kind === \"retire\") known.delete(change.record.id);\n\t\t\telse if (change.record.createdAt === seq) known.set(change.record.id, change.record);\n\t\t}\n\t\tfor (const write of writes) {\n\t\t\tif (write.type === \"task\" && write.value.state.status === \"terminal\")\n\t\t\t\tthis.#taskDocuments.delete(write.value.id);\n\t\t}\n\t}\n\n\t/**\n\t * Hold a deferred commit (`Transaction.holdable()`): adopt it in memory, queue its changes per document, pinned, by\n\t * the earliest deadline of the document's held commits, and show it to the Session's own observers.\n\t */\n\t#hold(\n\t\ttx: Transaction,\n\t\theld: NonNullable<ReturnType<Transaction[\"holdable\"]>>,\n\t\twithinMs: number,\n\t\tcontext: Context,\n\t): PublishFailure | undefined {\n\t\tlet documents: DocumentCommitChange[];\n\t\ttry {\n\t\t\tdocuments = tx.adoptHeld();\n\t\t} catch (error) {\n\t\t\t// As a stored commit's: memory could not adopt it; the writer fails the Session.\n\t\t\treturn { kind: \"adoption\", error };\n\t\t}\n\t\tconst deadline = this.#clock() + withinMs;\n\t\tfor (const { loaded, ops, base } of held) {\n\t\t\tconst id = loaded.record.id;\n\t\t\tlet hold = this.#holds.get(id);\n\t\t\tif (hold === undefined) {\n\t\t\t\tconst unpin = this.#pinDocument(loaded.addressId, id);\n\t\t\t\thold = { loaded, pending: new PendingOps(), base: false, deadline, unpin };\n\t\t\t\tthis.#holds.set(id, hold);\n\t\t\t}\n\t\t\thold.pending.push(ops);\n\t\t\tif (base) hold.base = true;\n\t\t\tif (deadline < hold.deadline) hold.deadline = deadline;\n\t\t}\n\t\tthis.#armHoldTimer();\n\t\tconst publication: ObservedCommit = { kind: \"memory\", changes: documents };\n\t\tlet failure: PublishFailure | undefined;\n\t\tfor (const listener of [...this.#internalListeners]) {\n\t\t\t// Our own observers are synchronous.\n\t\t\ttry {\n\t\t\t\tlistener(publication, context);\n\t\t\t} catch (error) {\n\t\t\t\tfailure ??= { kind: \"listener\", error };\n\t\t\t}\n\t\t}\n\t\treturn failure;\n\t}\n\n\t/**\n\t * Store the held changes `select` returns in one storage transaction, through the writer, from a job on the line. A\n\t * barrier: they are selected once every commit admitted before is published. Memory already has them, so only\n\t * `observeCommits()` observers see it, published as the writer publishes it. A failure fails the Session, as every\n\t * Storage failure does.\n\t */\n\tasync #storeHolds(select: () => readonly Hold[], context: Context): Promise<void> {\n\t\tawait this.#drained();\n\t\tconst holds = select();\n\t\tif (holds.length === 0) return;\n\t\tconst writes: Extract<StorageWrite, { readonly type: \"document.change\" }>[] = [];\n\t\tconst changes: DocumentCommitChange[] = [];\n\t\tconst keys: string[] = [];\n\t\tfor (const hold of holds) {\n\t\t\tconst { record, tracker, valueVersion: version } = hold.loaded;\n\t\t\tconst value = tracker.value;\n\t\t\tconst stored = storeHeld(hold, NO_OPERATIONS, value, version);\n\t\t\twrites.push({ type: \"document.change\", id: record.id, content: stored.content });\n\t\t\tkeys.push(documentKey(hold.loaded.addressId), incarnationKey(record.id));\n\t\t\t// Held documents are conversation documents.\n\t\t\tconst conversationId = record.scope.kind === \"conversation\" ? record.scope.conversationId : undefined;\n\t\t\tchanges.push({ type: \"document\", kind: \"change\", record, conversationId, version, value, ops: stored.ops });\n\t\t}\n\t\tconst publish = (seq: Seq | undefined): undefined => {\n\t\t\tfor (const [index, hold] of holds.entries()) {\n\t\t\t\tif (writes[index]!.content.kind === \"base\") hold.loaded.deltasSinceBase = 0;\n\t\t\t\telse hold.loaded.deltasSinceBase++;\n\t\t\t}\n\t\t\tif (this.#commitListeners.size > 0) this.#notifyHosts({ seq: seq!, changes }, context);\n\t\t\tthis.#release(holds);\n\t\t\treturn undefined;\n\t\t};\n\t\t// Run from a job on the line, which a failure it causes is the outcome of.\n\t\tconst index = this.#current!.index;\n\t\tawait this.#writer.admit({ index, writes, keys, context, publish, discard: ignore }).outcome;\n\t}\n\n\t/** After their store: forget `holds`, unpin their documents, and move the timer to the next deadline. */\n\t#release(holds: readonly Hold[]): void {\n\t\tfor (const hold of holds) {\n\t\t\tthis.#holds.delete(hold.loaded.record.id);\n\t\t\thold.unpin();\n\t\t}\n\t\tthis.#armHoldTimer();\n\t}\n\n\t/**\n\t * Keep a foreground timer (Workers refuse background ones) for the earliest deadline of the held documents. When it\n\t * fires, every held document is stored, in one storage transaction: a deadline is the latest time, and the others\n\t * cost little more in the same transaction. Once fired, it stays until its job ran.\n\t */\n\t#armHoldTimer(): void {\n\t\tif (this.#closing !== undefined) return;\n\t\tlet at = Infinity;\n\t\tfor (const hold of this.#holds.values()) if (hold.deadline < at) at = hold.deadline;\n\t\tconst armed = this.#holdTimer;\n\t\tif (armed !== undefined && (armed.fired || armed.at === at)) return;\n\t\tarmed?.disarm();\n\t\tthis.#holdTimer = undefined;\n\t\tif (at === Infinity) return;\n\t\tconst timer: HoldTimer = { at, disarm: () => {}, fired: false };\n\t\tconst run = (): void => {\n\t\t\ttimer.fired = true;\n\t\t\tthis.#maintain(async () => {\n\t\t\t\tif (this.#holdTimer === timer) this.#holdTimer = undefined;\n\t\t\t\t// Close stores what is held itself.\n\t\t\t\tif (this.#closing !== undefined || this.#failure !== undefined) return;\n\t\t\t\tawait this.#storeHolds(() => [...this.#holds.values()], BACKGROUND_CONTEXT);\n\t\t\t}).catch(() => {});\n\t\t};\n\t\tthis.#holdTimer = timer;\n\t\ttimer.disarm = this.#timers.foreground(run, Math.max(0, at - this.#clock()));\n\t}\n\n\t/**\n\t * At publication: publish a stored commit. Its telemetry events first, then the dispatch to `observeCommits()`\n\t * observers, queued before the waits and aborts the observers wake, then the Session's own observers. Never throws:\n\t * returns the first error of an own observer, which fails the Session once its storage call settled.\n\t */\n\t#publish(\n\t\tseq: Seq,\n\t\twrites: readonly StorageWrite[],\n\t\tdocuments: AdoptedDocuments,\n\t\tcontext: Context,\n\t): { readonly error: unknown } | undefined {\n\t\tconst changes: CommitChange[] | undefined =\n\t\t\tthis.#commitListeners.size > 0 || this.#internalListeners.size > 0 ? [] : undefined;\n\t\tfor (const write of writes) {\n\t\t\tswitch (write.type) {\n\t\t\t\tcase \"entry\":\n\t\t\t\t\tthis.#event(\"pi.durable.entry\", { \"entry.id\": write.value.id, \"entry.kind\": write.value.kind }, context);\n\t\t\t\t\tchanges?.push(write);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"submission\":\n\t\t\t\t\tif (write.value.status === \"done\" || write.value.status === \"unanswered\") {\n\t\t\t\t\t\tthis.#event(\n\t\t\t\t\t\t\t\"pi.durable.submission\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\"submission.id\": write.value.id,\n\t\t\t\t\t\t\t\tstatus: write.value.status,\n\t\t\t\t\t\t\t\t\"answer.entry_id\": write.value.answer,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tchanges?.push(write);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"conversation\":\n\t\t\t\tcase \"task\":\n\t\t\t\t\tchanges?.push(write);\n\t\t\t}\n\t\t}\n\t\tif (changes === undefined) return undefined;\n\t\tconst tables = changes.length;\n\t\tfor (const document of documents.observed) changes.push(document);\n\t\tconst observed: ObservedCommit = { kind: \"stored\", seq, changes };\n\t\tif (this.#commitListeners.size > 0) {\n\t\t\t// One publication for both, unless the commit also stored held changes, which only host listeners get.\n\t\t\tconst stored: CommitPublication =\n\t\t\t\tdocuments.stored === documents.observed\n\t\t\t\t\t? observed\n\t\t\t\t\t: { seq, changes: [...changes.slice(0, tables), ...documents.stored] };\n\t\t\tthis.#notifyHosts(stored, context);\n\t\t}\n\t\t// The commit is durable: a failing observer neither fails the commit nor skips the others.\n\t\tlet failure: { readonly error: unknown } | undefined;\n\t\tfor (const listener of [...this.#internalListeners]) {\n\t\t\t// Our own observers are synchronous.\n\t\t\ttry {\n\t\t\t\tlistener(observed, context);\n\t\t\t} catch (error) {\n\t\t\t\tfailure ??= { error };\n\t\t\t}\n\t\t}\n\t\treturn failure;\n\t}\n\n\t/** At publication: record a commit's telemetry event. A throwing adapter is reported, as publication must not throw. */\n\t#event(name: string, attributes: SpanAttributes, context: Context): void {\n\t\ttry {\n\t\t\tcontext.telemetry.addEvent(name, attributes);\n\t\t} catch (error) {\n\t\t\tthis.report(error, TELEMETRY, context);\n\t\t}\n\t}\n\n\t/**\n\t * At publication: call the `observeCommits()` observers with `publication` one microtask from now, and, queued\n\t * before the Session's own observers run, before the waits they resolve and the aborts they queue. The observers are\n\t * those attached when it runs; their guards report a throw.\n\t */\n\t#notifyHosts(publication: CommitPublication, context: Context): void {\n\t\tvoid SETTLED.then(() => {\n\t\t\tfor (const observer of [...this.#commitListeners]) observer.advance(publication, context);\n\t\t});\n\t}\n\n\t/**\n\t * On the line, as one job: load the document at `resolved` and `attach` to it, so the attachment sees every commit\n\t * after the value it starts from; `undefined` when absent. Cancelling `context` meanwhile rejects, after `cancel`\n\t * undid an attachment made.\n\t */\n\tasync #attachDocument<A extends object>(\n\t\tdefinition: AnyDocToken[\"definition\"],\n\t\tresolved: { readonly id: string; readonly address: DocumentAddress },\n\t\tcontext: Context,\n\t\tattach: (loaded: LoadedDocument) => A,\n\t\tcancel: (attached: A) => void,\n\t): Promise<A | undefined> {\n\t\tconst signal = context.abortSignal;\n\t\tlet cancelled = signal?.aborted ?? false;\n\t\tconst markCancelled = (): void => {\n\t\t\tcancelled = true;\n\t\t};\n\t\tsignal?.addEventListener(\"abort\", markCancelled, { once: true });\n\t\ttry {\n\t\t\tconst attached = await this.#enqueue(async () => {\n\t\t\t\tthis.#assertHealthy();\n\t\t\t\tif (cancelled) throw cancellationError(signal!);\n\t\t\t\tconst loaded = await this.#loadDocument(definition, resolved.id, resolved.address, context);\n\t\t\t\tif (cancelled) throw cancellationError(signal!);\n\t\t\t\treturn { value: loaded === undefined ? undefined : attach(loaded) };\n\t\t\t});\n\t\t\tif (attached === undefined) return undefined;\n\t\t\tif (cancelled) {\n\t\t\t\tcancel(attached);\n\t\t\t\tthrow cancellationError(signal!);\n\t\t\t}\n\t\t\treturn attached;\n\t\t} finally {\n\t\t\tsignal?.removeEventListener(\"abort\", markCancelled);\n\t\t}\n\t}\n\n\t/**\n\t * Follow the address of the incarnation `loaded`, after checking the definition, with the observer `create` makes\n\t * from its value, the idempotent detach, and the report of a listener error; returns that observer. It gets each\n\t * committed change there, a retirement as a `retired` change with the last value it was given and no ops (a change\n\t * in the retiring commit is not published), and a later incarnation as a root replacement. When the commit makes the\n\t * owner task of a task document terminal, no later commit can change the address: after its changes the commit\n\t * subscription and the pin go, and `ownerEnded` tells the observer, which stays subscribed to the Session's close\n\t * until it ends (its detach drops that). `end` gets the Session's close. The current incarnation is pinned in the\n\t * cache. The detach runs before `end`; once it ran, nothing more of the commit underway reaches the observer or pins\n\t * anything for it. `create` and `ownerEnded` are module functions where they can be, so a watch keeps no closure of\n\t * its caller.\n\t */\n\t#observeDocument<O extends Observer<Readonly<JsonObject>>>(\n\t\tdefinition: AnyDocToken[\"definition\"],\n\t\tloaded: LoadedDocument,\n\t\tcreate: (value: Readonly<JsonObject>, detach: () => void, report: (error: unknown) => void) => O,\n\t\townerEnded: (observer: O) => void,\n\t): O {\n\t\tcheckRecordScope(definition, loaded.record);\n\t\tcheckRecordVersion(definition, loaded.record, loaded.storedVersion);\n\t\t// The closures below keep only the address, as the cache's ID and first record, which the cache shares while the\n\t\t// document is cached: `loaded` holds its incarnation's tracker, which a retirement frees.\n\t\tconst addressId = loaded.addressId;\n\t\tconst address: DocumentAddress = loaded.record;\n\t\tlet incarnation: DocumentId | undefined = loaded.record.id;\n\t\t// The value of the incarnation followed; none while the address is absent, so the Session keeps no retired value.\n\t\tlet value: Readonly<JsonObject> | undefined = loaded.tracker.value;\n\t\t// The definition version the observer's value has: a change of another version replaces it whole.\n\t\tlet version = loaded.valueVersion;\n\t\t// The incarnation observed stays cached; once it retires or the observer detaches, it is idle again.\n\t\tlet unpin = this.#pinDocument(addressId, incarnation);\n\t\tlet unsubscribeCommit = (): void => {};\n\t\tlet unsubscribeClose = (): void => {};\n\t\tlet attached = true;\n\t\tconst detach = (): void => {\n\t\t\tif (!attached) return;\n\t\t\tattached = false;\n\t\t\tunsubscribeCommit();\n\t\t\tunsubscribeClose();\n\t\t\tunpin();\n\t\t};\n\t\tconst observer = create(loaded.tracker.value, detach, (error) => this.report(error));\n\t\tunsubscribeCommit = this.followCommits((publication, context) => {\n\t\t\t// Listeners run from a copy of the set: another observer's call may have detached this one.\n\t\t\tif (!attached) return;\n\t\t\tlet ownerEnds = false;\n\t\t\tfor (const change of publication.changes) {\n\t\t\t\tif (change.type === \"task\") {\n\t\t\t\t\tconst scope = address.scope;\n\t\t\t\t\tif (\n\t\t\t\t\t\tscope.kind === \"task\" &&\n\t\t\t\t\t\tchange.value.id === scope.taskId &&\n\t\t\t\t\t\tchange.value.state.status === \"terminal\"\n\t\t\t\t\t) {\n\t\t\t\t\t\townerEnds = true;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// The incarnation followed is at the address by definition; only another record needs the address compared.\n\t\t\t\tif (change.type !== \"document\") continue;\n\t\t\t\tif (change.record.id !== incarnation && !atAddress(change.record, address)) continue;\n\t\t\t\tif (change.kind === \"retire\") {\n\t\t\t\t\tif (change.record.id !== incarnation) continue;\n\t\t\t\t\t// Set with every incarnation.\n\t\t\t\t\tconst last = value!;\n\t\t\t\t\tincarnation = undefined;\n\t\t\t\t\tvalue = undefined;\n\t\t\t\t\tunpin();\n\t\t\t\t\tobserver.advance({ kind: \"value\", value: last, ops: NO_OPERATIONS, retired: true }, context);\n\t\t\t\t} else if (change.record.id !== incarnation || change.version !== version) {\n\t\t\t\t\t// A new incarnation at the address, or a value of another definition version, whose shape the observer's\n\t\t\t\t\t// value does not have: shown whole.\n\t\t\t\t\tif (change.record.id !== incarnation) {\n\t\t\t\t\t\tincarnation = change.record.id;\n\t\t\t\t\t\tunpin();\n\t\t\t\t\t\tunpin = this.#pinDocument(addressId, incarnation);\n\t\t\t\t\t}\n\t\t\t\t\tversion = change.version;\n\t\t\t\t\tvalue = change.value;\n\t\t\t\t\tobserver.advance({ kind: \"value\", value, ops: [[\"r\", value]], retired: false }, context);\n\t\t\t\t} else {\n\t\t\t\t\t// A migration-only base changes nothing for an observer of the new version.\n\t\t\t\t\tif (change.ops.length === 0) continue;\n\t\t\t\t\tvalue = change.value;\n\t\t\t\t\tobserver.advance({ kind: \"value\", value, ops: change.ops, retired: false }, context);\n\t\t\t\t}\n\t\t\t\t// The observer may detach in its call, or throw and be detached: the rest of the commit is not its.\n\t\t\t\tif (!attached) return;\n\t\t\t}\n\t\t\tif (!ownerEnds) return;\n\t\t\tunsubscribeCommit();\n\t\t\tunpin();\n\t\t\townerEnded(observer);\n\t\t});\n\t\tunsubscribeClose = this.subscribeClose(() => {\n\t\t\tdetach();\n\t\t\tobserver.end(closeEndOf(observer, closeEnds(this.#failure)));\n\t\t});\n\t\treturn observer;\n\t}\n\n\tasync #loadDocument(\n\t\tdefinition: AnyDocToken[\"definition\"],\n\t\taddressId: string,\n\t\taddress: DocumentAddress,\n\t\tcontext: Context,\n\t): Promise<LoadedDocument | undefined> {\n\t\t// What an unpublished commit wrote at the address is in neither the cache nor what Storage shows yet.\n\t\tconst gate = this.touch(documentKey(addressId));\n\t\tif (gate !== undefined) await gate;\n\t\tconst cached = this.#documents.get(addressId);\n\t\t// A tracker serves only tokens of the version its value was materialized for; others reload from Storage.\n\t\tif (cached?.valueVersion === definition.version) {\n\t\t\tthis.#touchDocument(addressId);\n\t\t\treturn cached;\n\t\t}\n\t\tif (cached !== undefined) {\n\t\t\t// The reload must find what memory holds: held changes are stored before their tracker goes, after a barrier.\n\t\t\tconst id = cached.record.id;\n\t\t\tawait this.#storeHolds(() => {\n\t\t\t\tconst hold = this.#holds.get(id);\n\t\t\t\treturn hold === undefined ? NO_HOLDS : [hold];\n\t\t\t}, context);\n\t\t\tthis.#dropDocument(addressId);\n\t\t}\n\t\tconst record = await this.#storage.findDocument(address, \"current\", context);\n\t\tif (record === undefined) return undefined;\n\t\tconst stored = await this.#storage.document(record.id, \"current\", context);\n\t\tif (stored === undefined) throw new Error(`Current document ${record.id} (${record.kind}) cannot be read`);\n\t\tconst value = materializeDocument(definition, stored);\n\t\tconst loaded: LoadedDocument = {\n\t\t\taddressId,\n\t\t\trecord: stored.record,\n\t\t\tstoredVersion: stored.version,\n\t\t\tvalueVersion: definition.version,\n\t\t\tdeltasSinceBase: stored.deltasSinceBase,\n\t\t\ttracker: track(value),\n\t\t};\n\t\tthis.#documents.set(addressId, loaded);\n\t\tthis.#touchDocument(addressId);\n\t\treturn loaded;\n\t}\n\n\t/**\n\t * Run `job` on the line, after the jobs before it, and deliver its outcome in line order: once the jobs before it\n\t * have theirs, and once its commit, if it admitted one, is published. With `exempt`, a job that admitted no commit and\n\t * waited at no gate is delivered as soon as it has its outcome: it is equivalent to having run before every\n\t * unpublished commit. A job\n\t * whose outcome comes after the one a failure is gets `SessionFailed` instead. At most `MAX_OUTSTANDING` jobs wait\n\t * for their delivery; beyond it the line waits.\n\t */\n\t#enqueue<T>(work: (index: number) => Promise<Ran<T>>, exempt = false): Promise<T> {\n\t\tconst job: Job = { index: this.#nextIndex++, hit: false };\n\t\tconst ran = this.#tail.then(async () => {\n\t\t\twhile (this.#outstanding >= MAX_OUTSTANDING) {\n\t\t\t\tthis.#room ??= Promise.withResolvers();\n\t\t\t\tawait this.#room.promise;\n\t\t\t}\n\t\t\tthis.#outstanding++;\n\t\t\treturn this.#onLine(job, work);\n\t\t});\n\t\tthis.#tail = ran.then(ignore, ignore);\n\t\tconst outcome = ran.then(\n\t\t\t(result) => {\n\t\t\t\tif (result.after === undefined) {\n\t\t\t\t\tthis.#ended(job);\n\t\t\t\t\treturn result.value;\n\t\t\t\t}\n\t\t\t\treturn result.after.then(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.#ended(job);\n\t\t\t\t\t\treturn result.value;\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tthis.#ended(job);\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tthis.#ended(job);\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\t// Delivered later, after the outcomes before it: handled now, so an early rejection is not reported unhandled.\n\t\toutcome.catch(ignore);\n\t\tconst fence = this.#fence;\n\t\tthis.#fence = fence.then(() => outcome).then(ignore, ignore);\n\t\tconst index = job.index;\n\t\tconst deliver = (fenced: boolean) =>\n\t\t\t(fenced ? fence.then(() => outcome) : outcome).then(\n\t\t\t\t(value) => {\n\t\t\t\t\tthis.#delivered(index, fenced);\n\t\t\t\t\tif (this.#poisoned(index)) throw new SessionFailed(this.#failure!.error);\n\t\t\t\t\treturn value;\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tthis.#delivered(index, fenced);\n\t\t\t\t\tthrow this.#poisoned(index) ? new SessionFailed(this.#failure!.error) : error;\n\t\t\t\t},\n\t\t\t);\n\t\t// Only a job without writes is exempt: one with writes waits for its own publication and the outcomes before it.\n\t\treturn exempt\n\t\t\t? ran.then(\n\t\t\t\t\t(result) => deliver(job.hit || result.after !== undefined),\n\t\t\t\t\t() => deliver(job.hit),\n\t\t\t\t)\n\t\t\t: deliver(true);\n\t}\n\n\t/** Whether job `index` comes after the failure's boundary without an outcome of its own: it gets `SessionFailed`. */\n\t#poisoned(index: number): boolean {\n\t\treturn this.#failAt !== undefined && index > this.#failAt && !this.#ownOutcomes.has(index);\n\t}\n\n\t/** The job's outcome settled: run what waited for it (`onJobEnd()`). */\n\t#ended(job: Job): void {\n\t\tconst ends = job.ends;\n\t\tif (ends === undefined) return;\n\t\tjob.ends = undefined;\n\t\tfor (const end of ends) end();\n\t}\n\n\t/** Run a job of the Session's own upkeep on the line: no outcome to deliver, so no fence and no `SessionFailed`. */\n\t#maintain<T>(work: (index: number) => Promise<T>): Promise<T> {\n\t\tconst job: Job = { index: this.#nextIndex++, hit: false };\n\t\tconst ran = this.#tail.then(() => this.#onLine(job, work));\n\t\tthis.#tail = ran.then(ignore, ignore);\n\t\treturn ran;\n\t}\n\n\t/** Hold the line for job `index` until its line part, through admission, is done. Gates are its touches' own. */\n\tasync #onLine<R>(job: Job, work: (index: number) => Promise<R>): Promise<R> {\n\t\tthis.#current = job;\n\t\ttry {\n\t\t\treturn await work(job.index);\n\t\t} finally {\n\t\t\tthis.#current = undefined;\n\t\t}\n\t}\n\n\t/** A `*` barrier: once every part admitted so far is published, or never will be. */\n\tasync #drained(): Promise<void> {\n\t\tconst drained = this.#writer.drained();\n\t\tif (drained !== undefined) await drained;\n\t}\n\n\t/**\n\t * Run one commit's publication inside the Storage's own scope (`Storage.publishing`), such as a store host's batch;\n\t * directly without one. `undefined` when it ran at once, else settles once it ran. A Storage that throws instead of\n\t * running it is reported, and the publication runs directly: the commit is stored, so it must be published.\n\t */\n\t#publishing(publish: () => void, context: Context): Promise<void> | undefined {\n\t\tconst publishing = this.#storage.publishing;\n\t\tif (publishing === undefined) {\n\t\t\tpublish();\n\t\t\treturn undefined;\n\t\t}\n\t\tconst done = Promise.withResolvers<void>();\n\t\tlet ran = false;\n\t\tconst once = (): void => {\n\t\t\tif (ran) return;\n\t\t\tran = true;\n\t\t\ttry {\n\t\t\t\tpublish();\n\t\t\t} finally {\n\t\t\t\tdone.resolve();\n\t\t\t}\n\t\t};\n\t\ttry {\n\t\t\tpublishing(once, context);\n\t\t} catch (error) {\n\t\t\tthis.report(error, LISTENER, context);\n\t\t\tonce();\n\t\t}\n\t\treturn done.promise;\n\t}\n\n\t/** Job `index` has its outcome: let the line go on past `MAX_OUTSTANDING`. */\n\t#delivered(index: number, fenced: boolean): void {\n\t\tif (fenced) this.#lastDelivered = index;\n\t\tthis.#outstanding--;\n\t\tconst room = this.#room;\n\t\tif (room !== undefined && this.#outstanding < MAX_OUTSTANDING) {\n\t\t\tthis.#room = undefined;\n\t\t\troom.resolve();\n\t\t}\n\t}\n\n\t/** Internal: throw `SessionFailed` when failed, else an error when closing. */\n\tassertUsable(): void {\n\t\tthis.#assertHealthy();\n\t\tif (this.#closing !== undefined) throw new Error(\"Session is closed\");\n\t}\n\n\t#assertHealthy(): void {\n\t\tif (this.#failure !== undefined) throw new SessionFailed(this.#failure.error);\n\t}\n}\n\n/**\n * Run a host callback that must not fail its caller: a throw, or a promise it returns that rejects, goes to `onError`,\n * which is not awaited.\n */\nexport function contained(callback: () => unknown, onError: (error: unknown) => void): void {\n\ttry {\n\t\tconst result = callback();\n\t\t// Any thenable, also a promise from another realm; `Promise.resolve` adopts it with handlers of its own.\n\t\tif (typeof (result as { then?: unknown } | null)?.then === \"function\") Promise.resolve(result).catch(onError);\n\t} catch (error) {\n\t\tonError(error);\n\t}\n}\n\n/** A synchronous observer as Durable attaches it: `Observer` (`advance` gets a `WatchCall`) or `CommitObserver`. */\ntype SyncObserver<A> = { advance(call: A, context: Context): void; end(end: WatchEnd): void };\n\n/** A guarded observer (`guardObserver()`) with its observation's detach. */\nexport type GuardedObserver<A> = SyncObserver<A> & { detach(): void };\n\n/**\n * `observer`, a host's, behind the rule for observers that run at a commit's publication: one that throws, or whose\n * `advance` returns a promise that rejects, is reported through `report`, detached, and ended `listener_error`, so the\n * throw never reaches `adopt`; nothing reaches it after its detach or end, and from then on the guard references\n * neither it nor its source. `detach` is the source's; the returned `detach()` is the observation's.\n */\nexport function guardObserver<A>(\n\tobserver: SyncObserver<A>,\n\tdetach: () => void,\n\treport: (error: unknown, context?: Context) => void,\n): GuardedObserver<A> {\n\ttype Attached = {\n\t\treadonly observer: SyncObserver<A>;\n\t\treadonly detach: () => void;\n\t\treadonly report: (error: unknown, context?: Context) => void;\n\t};\n\tlet attached: Attached | undefined = { observer, detach, report };\n\t/** Detach from the source once, and hand back what it was attached with. */\n\tconst release = (): Attached | undefined => {\n\t\tconst released = attached;\n\t\tattached = undefined;\n\t\treleased?.detach();\n\t\treturn released;\n\t};\n\t/** Report a throw of `current`'s `advance`, then detach and end it, unless that happened meanwhile. */\n\tconst fault = (current: Attached, error: unknown, context: Context): void => {\n\t\tcurrent.report(error, context);\n\t\tif (release() !== undefined) {\n\t\t\tconst end: WatchEnd = { kind: \"listener_error\", error: toError(error) };\n\t\t\tcontained(() => current.observer.end(end), current.report);\n\t\t}\n\t};\n\treturn {\n\t\tadvance: (call, context) => {\n\t\t\tconst current = attached;\n\t\t\tif (current === undefined) return;\n\t\t\ttry {\n\t\t\t\tconst result: unknown = current.observer.advance(call, context);\n\t\t\t\t// Any thenable, as `contained()` takes it: a rejection is the observer's throw, after the fact.\n\t\t\t\tif (typeof (result as { then?: unknown } | null)?.then === \"function\") {\n\t\t\t\t\tPromise.resolve(result).catch((error: unknown) => fault(current, error, context));\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tfault(current, error, context);\n\t\t\t}\n\t\t},\n\t\tend: (end) => {\n\t\t\tconst ending = release();\n\t\t\tif (ending !== undefined) contained(() => ending.observer.end(end), ending.report);\n\t\t},\n\t\tdetach: () => {\n\t\t\trelease();\n\t\t},\n\t};\n}\n\n/** A listener's throw as the `Error` a `listener_error` end carries, as Chord's watch makes it. */\nfunction toError(error: unknown): Error {\n\tif (error instanceof Error) return error;\n\ttry {\n\t\treturn new Error(String(error));\n\t} catch {\n\t\treturn new Error(Object.prototype.toString.call(error));\n\t}\n}\n\n/** The end of an observer whose source closed. */\nexport const ENDED: WatchEnd = { kind: \"ended\" };\n\n/**\n * How a Session's close ends what follows it (decision \"Slice 8 S1\"), made once per close: an app's watch `ended`; a\n * synchronous observer (an adapter following the Session, which may open it again) `failed` with \"session closed\", so\n * it follows the next Session; `ended` stays for an observed owner that ended (a task document's task). A failed\n * Session ends both `failed` with its error.\n */\nexport function closeEnds(failure: { readonly error: unknown } | undefined): {\n\treadonly watch: WatchEnd;\n\treadonly observer: WatchEnd;\n} {\n\tif (failure !== undefined) {\n\t\tconst failed: WatchEnd = { kind: \"failed\", error: failure.error };\n\t\treturn { watch: failed, observer: failed };\n\t}\n\treturn { watch: ENDED, observer: { kind: \"failed\", error: new Error(\"session closed\") } };\n}\n\n/** The end `ends` give `follower`: a watch's, or an observer's. */\nexport function closeEndOf(follower: unknown, ends: ReturnType<typeof closeEnds>): WatchEnd {\n\treturn follower instanceof Watch ? ends.watch : ends.observer;\n}\n\n/**\n * The `Observation` of a guarded observer attached at `value`. Built outside the attaching closure, so a detached\n * observation keeps nothing but `value` and the spent guard alive.\n */\nexport function observation<T>(value: T, guarded: { detach(): void }): Observation<T> {\n\treturn { value, detach: () => guarded.detach() };\n}\n\n/** A document watch over its source's detach and report. */\nfunction createWatch(\n\tvalue: Readonly<JsonObject>,\n\tdetach: () => void,\n\treport: (error: unknown) => void,\n): Watch<Readonly<JsonObject>> {\n\treturn new Watch<Readonly<JsonObject>>(value, detach, report);\n}\n\n/** Undo a watch attached while its acquisition was aborted. */\nfunction abortWatch(watch: Watch<Readonly<JsonObject>>): void {\n\twatch.abort();\n}\n\n/** Undo an observation attached while its attachment was cancelled. */\nfunction detachObservation(attached: Observation<Readonly<JsonObject>>): void {\n\tattached.detach();\n}\n\n/** A task document's watch delivers the retirement that ends its task, then ends. */\nfunction endWatch(watch: Watch<Readonly<JsonObject>>): void {\n\twatch.endAfterDelivery();\n}\n\n/** A task document's observer ends right after the retirement that ends its task. */\nfunction endGuarded(guarded: Observer<Readonly<JsonObject>>): void {\n\tguarded.end(ENDED);\n}\n\n/** Whether `record` is an incarnation at `address`. */\nfunction atAddress(record: DocumentRecord, address: DocumentAddress): boolean {\n\tif (record.kind !== address.kind || record.key !== address.key) return false;\n\tswitch (record.scope.kind) {\n\t\tcase \"session\":\n\t\t\treturn address.scope.kind === \"session\";\n\t\tcase \"conversation\":\n\t\t\treturn address.scope.kind === \"conversation\" && address.scope.conversationId === record.scope.conversationId;\n\t\tcase \"task\":\n\t\t\treturn address.scope.kind === \"task\" && address.scope.taskId === record.scope.taskId;\n\t}\n}\n\nfunction cancellationError(signal: AbortSignal): Error {\n\treturn signal.reason instanceof Error ? signal.reason : new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n\n/** What the guard needs of its Session: the failure so far, and how to fail it. */\ntype FailureLatch = {\n\treadonly failure: { readonly error: unknown } | undefined;\n\tfail(error: unknown): void;\n};\n\n/**\n * The Session's Storage behind its failure guard; every component of the Session reads and writes through it. Before a\n * call, a failed Session gets `SessionFailed` without reaching the backend. A call that throws fails the Session and\n * rethrows the backend's error, unless it is a `StorageRequestError` or a read whose caller's context was aborted:\n * neither says the Storage is broken.\n * `close()` always reaches the backend, so a failed Session still closes it.\n */\nclass GuardedStorage implements Storage {\n\treadonly #storage: Storage;\n\treadonly #latch: FailureLatch;\n\t/** Backend calls underway, also those off the Session line, which close waits for before it closes the backend. */\n\treadonly #underway = new Set<Promise<unknown>>();\n\t#closing = false;\n\n\tconstructor(storage: Storage, latch: FailureLatch) {\n\t\tthis.#storage = storage;\n\t\tthis.#latch = latch;\n\t}\n\n\t/** The backend's own scope for a publication (`Storage.publishing`), when it has one; not a call to guard. */\n\tget publishing(): Storage[\"publishing\"] {\n\t\treturn scopeOf(this.#storage);\n\t}\n\n\t/**\n\t * Guarded like every call, but its outcome is the Session writer's to judge: it publishes the batches received first,\n\t * then fails the Session for a refusal or a rejection, and for a Session that failed meanwhile.\n\t */\n\tasync commit(\n\t\tbatches: readonly (readonly StorageWrite[])[],\n\t\treceive: (index: number, seq: Seq) => void,\n\t\tcontext: Context,\n\t): Promise<CommitResult> {\n\t\tthis.#assertHealthy();\n\t\tif (this.#closing) throw new Error(\"Session is closed\");\n\t\tconst call = (async () => this.#storage.commit(batches, receive, context))();\n\t\tthis.#underway.add(call);\n\t\ttry {\n\t\t\treturn await call;\n\t\t} finally {\n\t\t\tthis.#underway.delete(call);\n\t\t}\n\t}\n\n\tmintId<I extends Id<string>>(): Promise<I> {\n\t\treturn this.#call(undefined, () => this.#storage.mintId<I>());\n\t}\n\n\tconversation(id: ConversationId, context: Context): Promise<ConversationRecord | undefined> {\n\t\treturn this.#call(context, () => this.#storage.conversation(id, context));\n\t}\n\n\tscanConversations(\n\t\tquery: ConversationQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<ConversationRecord, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanConversations(query, limit, cursor, context));\n\t}\n\n\tentry(id: EntryId, context: Context): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined>;\n\tentry(\n\t\tconversationId: ConversationId,\n\t\tid: EntryId,\n\t\tcontext: Context,\n\t): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined>;\n\tentry(\n\t\tfirst: EntryId | ConversationId,\n\t\tsecond: EntryId | Context,\n\t\tthird?: Context,\n\t): Promise<{ readonly entry: EntryRecord; readonly commitSeq: Seq } | undefined> {\n\t\tif (third === undefined) {\n\t\t\tconst context = second as Context;\n\t\t\treturn this.#call(context, () => this.#storage.entry(first as EntryId, context));\n\t\t}\n\t\treturn this.#call(third, () => this.#storage.entry(first as ConversationId, second as EntryId, third));\n\t}\n\n\tfindLatestHeadMarker(\n\t\tconversationId: ConversationId,\n\t\tatOrBeforeEntryId: EntryId | undefined,\n\t\tcontext: Context,\n\t): Promise<(EntryRecord & { readonly head: EntryId }) | undefined> {\n\t\treturn this.#call(context, () => this.#storage.findLatestHeadMarker(conversationId, atOrBeforeEntryId, context));\n\t}\n\n\tscanEntries(\n\t\tquery: EntryQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanEntries(query, limit, cursor, context));\n\t}\n\n\ttask(id: TaskId, context: Context): Promise<TaskRecord<JsonValue, JsonValue, JsonValue> | undefined> {\n\t\treturn this.#call(context, () => this.#storage.task(id, context));\n\t}\n\n\tscanTasks(\n\t\tquery: TaskQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<TaskRecord<JsonValue, JsonValue, JsonValue>, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanTasks(query, limit, cursor, context));\n\t}\n\n\tsubmission(id: SubmissionId, context: Context): Promise<SubmissionRecord | undefined> {\n\t\treturn this.#call(context, () => this.#storage.submission(id, context));\n\t}\n\n\tscanSubmissions(\n\t\tquery: SubmissionQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<SubmissionRecord, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanSubmissions(query, limit, cursor, context));\n\t}\n\n\tsubmissionByRequest(\n\t\tconversationId: ConversationId,\n\t\trequestId: string,\n\t\tcontext: Context,\n\t): Promise<SubmissionRecord | undefined> {\n\t\treturn this.#call(context, () => this.#storage.submissionByRequest(conversationId, requestId, context));\n\t}\n\n\tfindDocument(address: DocumentAddress, at: DocumentPoint, context: Context): Promise<DocumentRecord | undefined> {\n\t\treturn this.#call(context, () => this.#storage.findDocument(address, at, context));\n\t}\n\n\tdocument(id: DocumentId, at: DocumentPoint, context: Context): Promise<StoredDocument | undefined> {\n\t\treturn this.#call(context, () => this.#storage.document(id, at, context));\n\t}\n\n\tscanDocuments(\n\t\tquery: DocumentQuery,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<DocumentRecord, Cursor>> {\n\t\treturn this.#call(context, () => this.#storage.scanDocuments(query, limit, cursor, context));\n\t}\n\n\t/**\n\t * Close the backend once every call underway has settled, so none outlives it or fails after `closed` settles. New\n\t * calls are refused from here on: a paged read must not start its next page while the backend closes.\n\t */\n\tasync close(context: Context): Promise<void> {\n\t\tthis.#closing = true;\n\t\tawait Promise.allSettled([...this.#underway]);\n\t\treturn this.#storage.close(context);\n\t}\n\n\t/**\n\t * Run one backend call under the guard. `read` is a read's context; `commit()` and `mintId()` pass none, so nothing\n\t * exempts their errors: once a batch is admitted, whether it committed is unknown. A call still underway when another\n\t * fails the Session ends with `SessionFailed` too, whatever it returns: nothing it read or wrote is used.\n\t */\n\tasync #call<T>(read: Context | undefined, run: () => Promise<T>): Promise<T> {\n\t\tthis.#assertHealthy();\n\t\tif (this.#closing) throw new Error(\"Session is closed\");\n\t\tlet result: T;\n\t\t// An async wrapper, so a backend that throws synchronously is guarded too.\n\t\tconst call = (async () => run())();\n\t\tthis.#underway.add(call);\n\t\ttry {\n\t\t\tresult = await call;\n\t\t} catch (error) {\n\t\t\tthis.#assertHealthy();\n\t\t\t// An invalid read, or one its caller cancelled, says nothing about the Storage; it fails that call only.\n\t\t\tconst exempt =\n\t\t\t\tread !== undefined && (error instanceof StorageRequestError || read.abortSignal?.aborted === true);\n\t\t\tif (!exempt) this.#latch.fail(error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tthis.#underway.delete(call);\n\t\t}\n\t\tthis.#assertHealthy();\n\t\treturn result;\n\t}\n\n\t#assertHealthy(): void {\n\t\tconst failure = this.#latch.failure;\n\t\tif (failure !== undefined) throw new SessionFailed(failure.error);\n\t}\n}\n"]}
|