@ny4n/durable 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +41 -5
  3. package/dist/codemode/codemode.d.ts +132 -0
  4. package/dist/codemode/codemode.d.ts.map +1 -0
  5. package/dist/codemode/codemode.js +791 -0
  6. package/dist/codemode/codemode.js.map +1 -0
  7. package/dist/codemode/describe.d.ts +38 -0
  8. package/dist/codemode/describe.d.ts.map +1 -0
  9. package/dist/codemode/describe.js +117 -0
  10. package/dist/codemode/describe.js.map +1 -0
  11. package/dist/codemode/index.d.ts +3 -0
  12. package/dist/codemode/index.d.ts.map +1 -0
  13. package/dist/codemode/index.js +3 -0
  14. package/dist/codemode/index.js.map +1 -0
  15. package/dist/codemode/output.d.ts +39 -0
  16. package/dist/codemode/output.d.ts.map +1 -0
  17. package/dist/codemode/output.js +160 -0
  18. package/dist/codemode/output.js.map +1 -0
  19. package/dist/harness/agent.d.ts +4 -2
  20. package/dist/harness/agent.d.ts.map +1 -1
  21. package/dist/harness/agent.js +56 -26
  22. package/dist/harness/agent.js.map +1 -1
  23. package/dist/harness/compaction.d.ts +6 -1
  24. package/dist/harness/compaction.d.ts.map +1 -1
  25. package/dist/harness/compaction.js +10 -7
  26. package/dist/harness/compaction.js.map +1 -1
  27. package/dist/harness/events.d.ts +8 -2
  28. package/dist/harness/events.d.ts.map +1 -1
  29. package/dist/harness/events.js +4 -1
  30. package/dist/harness/events.js.map +1 -1
  31. package/dist/harness/generation.d.ts +2 -0
  32. package/dist/harness/generation.d.ts.map +1 -1
  33. package/dist/harness/generation.js +25 -4
  34. package/dist/harness/generation.js.map +1 -1
  35. package/dist/harness/inbox.d.ts +16 -4
  36. package/dist/harness/inbox.d.ts.map +1 -1
  37. package/dist/harness/inbox.js +26 -3
  38. package/dist/harness/inbox.js.map +1 -1
  39. package/dist/harness/live.d.ts +15 -1
  40. package/dist/harness/live.d.ts.map +1 -1
  41. package/dist/harness/live.js +10 -2
  42. package/dist/harness/live.js.map +1 -1
  43. package/dist/harness/scheduler.d.ts.map +1 -1
  44. package/dist/harness/scheduler.js +72 -10
  45. package/dist/harness/scheduler.js.map +1 -1
  46. package/dist/harness/submissions.d.ts +7 -4
  47. package/dist/harness/submissions.d.ts.map +1 -1
  48. package/dist/harness/submissions.js +29 -10
  49. package/dist/harness/submissions.js.map +1 -1
  50. package/dist/harness/tool.d.ts.map +1 -1
  51. package/dist/harness/tool.js +13 -1
  52. package/dist/harness/tool.js.map +1 -1
  53. package/dist/harness/types.d.ts +38 -11
  54. package/dist/harness/types.d.ts.map +1 -1
  55. package/dist/harness/types.js.map +1 -1
  56. package/dist/index.d.ts +2 -2
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js.map +1 -1
  59. package/dist/tool-search/index.d.ts +2 -0
  60. package/dist/tool-search/index.d.ts.map +1 -0
  61. package/dist/tool-search/index.js +2 -0
  62. package/dist/tool-search/index.js.map +1 -0
  63. package/dist/tool-search/tool-search.d.ts +18 -0
  64. package/dist/tool-search/tool-search.d.ts.map +1 -0
  65. package/dist/tool-search/tool-search.js +62 -0
  66. package/dist/tool-search/tool-search.js.map +1 -0
  67. package/package.json +16 -3
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/harness/scheduler.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,QAAQ,EAAkB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAqB5C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAqB,eAAe,EAAE,MAAM,cAAc,CAAC;AAYlE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAa1D,MAAM,cAA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E,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC3G,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAChG,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC5D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import type { ModelRuntime } from \"@ny4n/ai/contracts\";\nimport { type Context, copyJson, type JsonValue } from \"@ny4n/chord\";\nimport { awaitWithContext, withAbortSignal } from \"@ny4n/chord/context\";\nimport type { ExecutionEnv } from \"../env/index.ts\";\nimport { errorMessage } from \"../errors.ts\";\nimport type { SessionImpl } from \"../session/session.ts\";\nimport type { Transaction } from \"../session/transaction.ts\";\nimport type {\n\tCommitPublication,\n\tConversationId,\n\tDocumentWatch,\n\tEntryId,\n\tEntryRecord,\n\tHookRunner,\n\tJsonObject,\n\tNextTaskState,\n\tRunningTask,\n\tStorage,\n\tTaskDefinition,\n\tTaskId,\n\tTaskOutcome,\n\tTaskRecord,\n\tTaskRuntime,\n\tTaskState,\n} from \"../types.ts\";\nimport { agentHooks } from \"./agent.ts\";\nimport { type ContextRange, readContextFrom } from \"./context.ts\";\nimport type {\n\tAgent,\n\tAnyTask,\n\tConversationHandle,\n\tHarnessInspection,\n\tRegistryReader,\n\tRegistrySnapshot,\n\tSettings,\n\tSettledTask,\n\tTaskInspection,\n} from \"./types.ts\";\nimport { closedError, scanAll, Waiters } from \"./util.ts\";\n\ntype AnyTaskRecord = TaskRecord<JsonValue, JsonValue, JsonValue>;\n/** A record that can still run code: pending, running, or waiting. */\ntype RunnableTaskRecord = Extract<\n\tAnyTaskRecord,\n\t{ readonly state: { readonly status: \"pending\" | \"running\" | \"waiting\" } }\n>;\ntype Checkpoint = { readonly phase: string };\ntype ErasedDefinition = TaskDefinition<JsonValue, Checkpoint, JsonValue, object>;\ntype ErasedRuntime = TaskRuntime<JsonValue, Checkpoint, JsonValue, object>;\ntype ErasedRunningTask = RunningTask<JsonValue, Checkpoint, JsonValue>;\n\nconst SCAN_PAGE_SIZE = 256;\n/** Longest delay `setTimeout` supports; longer sleeps wait in several steps. */\nconst MAX_TIMER_DELAY = 2_147_483_647;\nconst LIVE_STATUSES = [\"pending\", \"running\", \"waiting\", \"completing\"] as const;\n\n/** Why a pending task cannot be reserved under a registry snapshot. Derived, never persisted. */\ntype BlockedReason = \"missing_task\" | \"task_too_old\" | \"migration_failed\";\n\ntype Resolution =\n\t| { readonly kind: \"ready\"; readonly task: AnyTask; readonly record: RunnableTaskRecord }\n\t| { readonly kind: \"blocked\"; readonly reason: BlockedReason };\n\n/** A definition that can take a record, or why none can; deciding it runs no task code. */\ntype Fit =\n\t| { readonly task: AnyTask; readonly migrates: boolean }\n\t| { readonly reason: BlockedReason; readonly error?: unknown };\n\n/** One in-memory execution of a task in run or abort mode. */\ntype Invocation = {\n\treadonly taskId: TaskId;\n\treadonly conversationId: ConversationId;\n\treadonly mode: \"run\" | \"abort\";\n\treadonly controller: AbortController;\n\t/** Context passed to handlers; cancelled by `controller`. */\n\treadonly context: Context;\n\t/** Watches acquired through the runtime; stopped at invocation end. */\n\treadonly watches: Set<DocumentWatch<JsonObject>>;\n\tended: boolean;\n\treadonly done: Promise<void>;\n\treadonly finish: () => void;\n};\n\n/** What a runtime reads for the phase handler it serves: the phase's snapshot and task, and its lazily resolved agent. */\ntype Phase = {\n\treadonly snapshot: () => RegistrySnapshot;\n\treadonly task: () => AnyTask;\n\tagent: Promise<Agent> | undefined;\n};\n\ntype Reservation = {\n\treadonly invocation: Invocation;\n\treadonly task: AnyTask;\n\treadonly snapshot: RegistrySnapshot;\n};\n\n/** Replacement definition already reported as unable to take over, per invocation. */\ntype ReportedTask = { readonly task: AnyTask | undefined } | undefined;\n\n/** Outcome of the phase that just returned, judged by the next step. */\ntype PhaseResult = { readonly checkpoint: Checkpoint; readonly failure?: { readonly error: unknown } };\n\n/** Step decision: continue with the next phase, end the invocation, or end it by writing `faulted`. */\ntype Decision = boolean | { readonly fault: unknown };\n\n/** Terminal outcomes the scheduler writes without running task code. */\nexport type SchedulerOutcome = Extract<TaskOutcome<JsonValue>, { readonly status: \"faulted\" | \"orphaned\" }>;\n\n/** An invocation a conversation handle is bound to: its signal, and a check that throws once it ended. */\nexport type InvocationBinding = { readonly signal: AbortSignal; check(): void };\n\n/** The immutable ownership fields of a task. */\ntype TaskNode = Pick<AnyTaskRecord, \"conversationId\" | \"owner\" | \"background\">;\n\n/** Where a walk up the ownership tree continues: an owner task, or a conversation. */\ntype Up = { readonly task: TaskId } | { readonly conversation: ConversationId };\n\n/** One step of a walk up: an owner task with its node, a conversation, or an owner edge that is not loaded yet. */\ntype Step =\n\t| { readonly task: TaskId; readonly node: TaskNode }\n\t| { readonly conversation: ConversationId }\n\t| { readonly unknown: true };\n\n/** Candidate records a commit staged; they override committed records in ownership walks. */\ntype Overlay = {\n\treadonly tasks: ReadonlyMap<TaskId, AnyTaskRecord>;\n\treadonly edges: ReadonlyMap<ConversationId, TaskId | null>;\n\t/** Links to the staged tasks `#below` does not list, by parent node, for walks down; built at first use. */\n\tlinks?: ReadonlyMap<Node, ReadonlySet<Node>>;\n};\n\n/** A node of the downward index: a task, or a conversation as `c<id>`. */\ntype Node = TaskId | `c${number}`;\n\nfunction conversationNode(id: ConversationId): Node {\n\treturn `c${id}`;\n}\n\nfunction conversationOf(node: `c${number}`): ConversationId {\n\treturn Number(node.slice(1)) as ConversationId;\n}\n\n/** The node a task hangs from: its owner task, or its conversation. */\nfunction parentNode(node: TaskNode): Node {\n\treturn node.owner ?? conversationNode(node.conversationId);\n}\n\n/** Where ordinary ownership traversal starts: one conversation, or every ownerless conversation. */\ntype Scope = { readonly conversation: ConversationId } | { readonly roots: true };\n\nexport type TaskSchedulerOptions = {\n\treadonly session: SessionImpl;\n\treadonly storage: Storage;\n\treadonly registry: RegistryReader;\n\treadonly models: ModelRuntime;\n\t/** Resolve a conversation's agent against a snapshot; the runtime calls it at most once per phase. */\n\treadonly agent: (conversationId: ConversationId, snapshot: RegistrySnapshot, context: Context) => Promise<Agent>;\n\t/** Resolve the settings; read at each access. */\n\treadonly settings: () => Settings;\n\t/** Build a conversation's environment with `HarnessOptions.env`. */\n\treadonly env: (conversationId: ConversationId, context: Context) => Promise<ExecutionEnv | undefined>;\n\treadonly now: () => number;\n\treadonly report: (error: unknown) => void;\n\t/** Harness cleanup staged in the commit that makes an outcome the scheduler wrote itself terminal. */\n\treadonly settleOutcome: (tx: Transaction, record: AnyTaskRecord, outcome: SchedulerOutcome) => Promise<void>;\n\t/** Withdraw a conversation's queued inputs, for conversation abort and abort cascades. */\n\treadonly withdrawInputs: (tx: Transaction, conversationId: ConversationId) => Promise<void>;\n\t/** Invocation-bound handle of an existing conversation, for task runtimes and tools. */\n\treadonly conversation: (\n\t\tid: ConversationId,\n\t\tbinding: InvocationBinding,\n\t\tcontext: Context,\n\t) => Promise<ConversationHandle | undefined>;\n\t/** Context for scheduler commits and invocations; carries no caller cancellation. */\n\treadonly context: Context;\n};\n\n/**\n * Durable task scheduler of one Harness.\n *\n * `#live` mirrors every committed non-terminal task record: pending, running, waiting, and completing. The synchronous\n * commit listener updates it on the Session line, so code running on the line reads exactly the committed state from it.\n *\n * Tasks and conversations form one ownership tree (spec §5.5): a task's parent is its owner task, or its conversation;\n * a conversation's parent is its owner task, if any. Walks up that tree decide what reaches one task: a cancelling\n * owner, a scope. `#below` lists the tree downward around live work, so what lies below one node is a walk down from\n * it: a task's live ordinary owned work, which holds its outcome as `completing` and delays its abort handler, a\n * scope's tasks, a cascade's reach. No pass visits every live task; the sets below hold each pass's candidates.\n *\n * The ownership indexes are bounded by live work: an owner edge and an ended task's ownership fields are kept only while\n * something is listed below them in `#below`, so only the chains above live tasks are known, whole. Work that appears\n * later below a dropped node finds it unknown and loads its chain from storage again.\n *\n * Invariant: every task transition is decided and written by one callback serialized on the Session line. That covers\n * reservation, marks, runtime commits, finalization, and the synchronous step before each phase, which applies the\n * precedence rules and writes a fault or handover. Handlers and joins run off the line. An invocation ends inside the\n * step that decides its end, so a runtime commit it queued either lands before that decision or is rejected.\n */\nexport class TaskScheduler {\n\treadonly #session: SessionImpl;\n\treadonly #storage: Storage;\n\treadonly #registry: RegistryReader;\n\treadonly #models: ModelRuntime;\n\treadonly #agent: TaskSchedulerOptions[\"agent\"];\n\treadonly #settings: TaskSchedulerOptions[\"settings\"];\n\treadonly #env: TaskSchedulerOptions[\"env\"];\n\treadonly #now: () => number;\n\treadonly #report: (error: unknown) => void;\n\treadonly #settleOutcome: TaskSchedulerOptions[\"settleOutcome\"];\n\treadonly #withdrawInputs: TaskSchedulerOptions[\"withdrawInputs\"];\n\treadonly #conversation: TaskSchedulerOptions[\"conversation\"];\n\treadonly #context: Context;\n\treadonly #live = new Map<TaskId, AnyTaskRecord>();\n\t/**\n\t * Context range last read through a task runtime, per conversation: a later read, by any of its tasks, scans only\n\t * newer entries. `idleSince` is the Harness time it was first seen idle. Derived and never persisted; dropped at the\n\t * first idle check after `settings.contextRetentionMs` of idleness, and at close.\n\t */\n\treadonly #contexts = new Map<ConversationId, { range: ContextRange; idleSince: number | undefined }>();\n\t/** Timer for the earliest expiry of an idle context, only where timers can be unreferenced (see `#scheduleExpiry`). */\n\t#expiry: { readonly at: number; readonly timer: ReturnType<typeof setTimeout> } | undefined;\n\treadonly #invocations = new Map<TaskId, Invocation>();\n\treadonly #taskWaiters = new Waiters<TaskId, SettledTask<JsonValue>>();\n\t/** Idle waiters by conversation; `undefined` waits for the whole Harness. */\n\treadonly #idleWaiters = new Waiters<ConversationId | undefined, void>();\n\t/** Definition whose migration failed per task; retried only once the registry resolves another definition. */\n\treadonly #failedMigrations = new Map<TaskId, { readonly task: AnyTask; readonly error: unknown }>();\n\t/** Owner task of each known conversation, `null` when ownerless. */\n\treadonly #edges = new Map<ConversationId, TaskId | null>();\n\t/** Ownership fields of the known terminal tasks, which walks pass through. */\n\treadonly #settled = new Map<TaskId, TaskNode>();\n\t/**\n\t * Ended tasks and conversations found unneeded, dropped by `#sweep()` at the end of the commit's publication unless\n\t * needed again by then: a chain load installs nodes before the work below them is listed.\n\t */\n\treadonly #dropQueue = new Set<Node>();\n\t/**\n\t * The tree downward around live work: each node's child nodes that are live tasks or have nodes listed below them.\n\t * A conversation's parent is its owner task; ownerless ones with work are in `#roots`.\n\t */\n\treadonly #below = new Map<Node, Set<Node>>();\n\treadonly #roots = new Set<ConversationId>();\n\t/** Known tasks whose chain may not be loaded; every other known task's chain is, and stays, loaded. */\n\treadonly #unloaded = new Set<TaskId>();\n\t/** Live tasks with cancellation intent, the sources of abort cascades (spec §5.4). */\n\treadonly #intent = new Set<TaskId>();\n\t/** Live tasks that are not `completing`, the candidates of a reservation pass; ones found waiting leave it. */\n\treadonly #runnable = new Set<TaskId>();\n\t/** `completing` tasks the next finalize pass checks: those that started holding, and holders of ended work. */\n\treadonly #finalizeChecks = new Set<TaskId>();\n\t/** Live waiting tasks by each task in their `on`. */\n\treadonly #waiters = new Map<TaskId, Set<TaskId>>();\n\t/**\n\t * `failFast` waiters the next reconcile checks for a failed task in `on`: at open, when they start waiting, and when\n\t * one of their tasks fails.\n\t */\n\treadonly #failFastChecks = new Set<TaskId>();\n\t/**\n\t * Live tasks with `abandonOnRestart` found at open, from an earlier Harness. The first reservation pass abort-marks\n\t * them with reason `restart`, so nothing of them or below them runs a phase again.\n\t */\n\treadonly #abandoned = new Set<TaskId>();\n\t#reconcileScheduled = false;\n\t#sweepScheduled = false;\n\t#cascadePending = false;\n\t#unsubscribeRegistry: () => void = () => {};\n\t#enabled = false;\n\t#closing = false;\n\t#dirty = false;\n\t#draining = false;\n\n\tconstructor(options: TaskSchedulerOptions) {\n\t\tthis.#session = options.session;\n\t\tthis.#storage = options.storage;\n\t\tthis.#registry = options.registry;\n\t\tthis.#models = options.models;\n\t\tthis.#agent = options.agent;\n\t\tthis.#settings = options.settings;\n\t\tthis.#env = options.env;\n\t\tthis.#now = options.now;\n\t\tthis.#report = options.report;\n\t\tthis.#settleOutcome = options.settleOutcome;\n\t\tthis.#withdrawInputs = options.withdrawInputs;\n\t\tthis.#conversation = options.conversation;\n\t\tthis.#context = options.context;\n\t}\n\n\t/** Load live tasks and change surviving `running` tasks back to `pending`. Dispatches nothing. */\n\tasync open(context: Context): Promise<void> {\n\t\tthis.#session.observeCommits((publication) => this.#observe(publication));\n\t\tthis.#session.subscribeClose(() => this.#seal());\n\t\tthis.#unsubscribeRegistry = this.#registry.subscribe(() => this.#kick());\n\t\tawait this.#session.commitWith(async (tx) => {\n\t\t\t// Every table read before the first write.\n\t\t\tconst scans = [];\n\t\t\tfor (const status of LIVE_STATUSES) {\n\t\t\t\tscans.push(await scanAll((cursor) => tx.scanTasks({ status }, SCAN_PAGE_SIZE, cursor)));\n\t\t\t}\n\t\t\tfor (const records of scans) {\n\t\t\t\tfor (const record of records) {\n\t\t\t\t\tthis.#track(undefined, record);\n\t\t\t\t\tif (record.abandonOnRestart === true) this.#abandoned.add(record.id);\n\t\t\t\t\tif (record.state.status === \"running\") {\n\t\t\t\t\t\ttx.setTask(withState(record, { status: \"pending\", checkpoint: record.state.checkpoint }));\n\t\t\t\t\t}\n\t\t\t\t\tif (record.state.status === \"waiting\" && record.state.policy === \"failFast\") {\n\t\t\t\t\t\tthis.#failFastChecks.add(record.id);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}, context);\n\t\t// Derive abort marks a crash left unapplied below cancelled owners, and finalize held outcomes.\n\t\tthis.#cascadePending = true;\n\t\tthis.#scheduleReconcile();\n\t}\n\n\t/** Enable scheduling. Idempotent; the kick does nothing once closing. */\n\tresume(): void {\n\t\tthis.#enabled = true;\n\t\tthis.#kick();\n\t}\n\n\t/**\n\t * Signal every invocation and wait for them; writes nothing. Close calls this after every close listener has run, so\n\t * waits, watches, and streams a task holds end with the Session's reason, not as cancelled by its signal.\n\t */\n\tasync join(): Promise<void> {\n\t\tfor (const invocation of this.#invocations.values()) invocation.controller.abort();\n\t\tawait Promise.allSettled([...this.#invocations.values()].map((invocation) => invocation.done));\n\t}\n\n\t/**\n\t * Commit the abort mark, or settle a task that no registered definition can take as `orphaned` when nothing it owns\n\t * is live, then join the run invocation seen on the line; the commit listener signalled it. The abort invocation\n\t * starts once the task's ordinary owned work is gone. A `completing` task is only marked. A request replaces a\n\t * `restart` mark, so a task abandoned after a restart that waits for its definition is orphaned; with `keepRestart`,\n\t * as for an owner's own cleanup, such a task keeps its mark and waits on.\n\t */\n\tasync abort(id: TaskId, context: Context, keepRestart = false): Promise<\"marked\" | \"terminal\"> {\n\t\tconst marked = await this.#session.commitWith(async (tx) => {\n\t\t\tconst current = await tx.task(id);\n\t\t\tif (current === undefined) throw new Error(`Task ${id} does not exist`);\n\t\t\tif (current.state.status === \"terminal\") return { result: \"terminal\" as const };\n\t\t\tconst invocation = this.#invocations.get(id);\n\t\t\t// A restart-marked task has no run invocation; it only waits for its abort.\n\t\t\tif (keepRestart && current.abortReason === \"restart\") return { result: \"marked\" as const };\n\t\t\tif (invocation === undefined && current.state.status !== \"completing\") {\n\t\t\t\tawait this.#loadScopes(false);\n\t\t\t\tif (!this.#hasOwnedLive(id)) {\n\t\t\t\t\tconst resolution = this.#resolve(current as RunnableTaskRecord, this.#registry.snapshot());\n\t\t\t\t\tif (resolution.kind === \"blocked\") {\n\t\t\t\t\t\tawait this.#terminate(tx, current, { status: \"orphaned\", reason: resolution.reason });\n\t\t\t\t\t\treturn { result: \"marked\" as const };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!current.abortRequested || current.abortReason !== undefined) tx.setTask(withAbortMark(current));\n\t\t\treturn { result: \"marked\" as const, run: invocation?.mode === \"run\" ? invocation : undefined };\n\t\t}, context);\n\t\t// The commit listener signalled the run; join it. A run that ignores its signal can outlive a failed Session,\n\t\t// which ends the wait instead.\n\t\tif (marked.run !== undefined) {\n\t\t\tawait awaitWithContext(Promise.race([marked.run.done, this.#session.failed]), context);\n\t\t}\n\t\treturn marked.result;\n\t}\n\n\tasync waitForTask(id: TaskId, context: Context): Promise<SettledTask<JsonValue>> {\n\t\t// Check and register on the line so no terminal publication falls between them.\n\t\tconst found = await this.#session.readOnLine(async () => {\n\t\t\tif (this.#closing) throw closedError(this.#session);\n\t\t\tif (this.#live.has(id)) return { promise: this.#taskWaiters.add(id, context) };\n\t\t\tconst record = await this.#storage.task(id, context);\n\t\t\tif (record === undefined) throw new Error(`Task ${id} does not exist`);\n\t\t\treturn { promise: Promise.resolve(record as SettledTask<JsonValue>) };\n\t\t});\n\t\treturn found.promise;\n\t}\n\n\t/**\n\t * Resolve when ordinary traversal from the conversation, or from every ownerless conversation, reaches no live\n\t * non-background task.\n\t */\n\twaitForIdle(conversationId: ConversationId | undefined, context: Context): Promise<void> {\n\t\tif (this.#closing) return Promise.reject(closedError(this.#session));\n\t\tif (this.#idle(conversationId)) return Promise.resolve();\n\t\tthis.#scheduleReconcile();\n\t\treturn this.#idleWaiters.add(conversationId, context);\n\t}\n\n\t/**\n\t * `Conversation.abort()`: in one commit, withdraw the queued inputs and mark every live non-background task that\n\t * ordinary traversal from the conversation reaches; resolves once the scope is idle. With `background`, traversal\n\t * crosses background boundaries, and the wait also covers every task it reached.\n\t */\n\tasync abortConversation(conversationId: ConversationId, background: boolean, context: Context): Promise<void> {\n\t\tconst reached = await this.#session.commitWith(async (tx) => {\n\t\t\tconst queued = await this.#loadScopes(true);\n\t\t\tconst scope = { conversation: conversationId };\n\t\t\tconst reached: TaskId[] = [];\n\t\t\tconst walk = this.#walkDown(conversationNode(conversationId), { crossBackground: background });\n\t\t\tfor (const { node, live } of walk) {\n\t\t\t\tif (live === undefined || (node.background && !background)) continue;\n\t\t\t\treached.push(live.id);\n\t\t\t\tif (!live.abortRequested || live.abortReason !== undefined) tx.setTask(withAbortMark(live));\n\t\t\t}\n\t\t\tfor (const id of queued) {\n\t\t\t\tif (this.#inScope({ conversation: id }, scope, background) === true) await this.#withdrawInputs(tx, id);\n\t\t\t}\n\t\t\treturn reached;\n\t\t}, context);\n\t\tif (background) for (const id of reached) await this.waitForTask(id, context);\n\t\tawait this.waitForIdle(conversationId, context);\n\t}\n\n\t// ─── Scheduling ────────────────────────────────────────────────────────\n\n\t#observe(publication: CommitPublication): void {\n\t\tconst updated: AnyTaskRecord[] = [];\n\t\tconst failed: TaskId[] = [];\n\t\tlet changed = false;\n\t\t// Edges first, so the tasks a commit creates in a new conversation hang from it.\n\t\tfor (const change of publication.changes) {\n\t\t\tif (change.type === \"conversation\" && !this.#edges.has(change.value.id)) {\n\t\t\t\tthis.#setEdge(change.value.id, change.value.owner?.taskId ?? null);\n\t\t\t}\n\t\t}\n\t\tfor (const change of publication.changes) {\n\t\t\tif (change.type !== \"task\") continue;\n\t\t\tchanged = true;\n\t\t\tconst record = change.value;\n\t\t\tconst previous = this.#live.get(record.id);\n\t\t\tif (failedOutcome(record) && (previous === undefined || !failedOutcome(previous))) failed.push(record.id);\n\t\t\tthis.#track(previous, record);\n\t\t\tif (record.state.status === \"terminal\") {\n\t\t\t\tthis.#failedMigrations.delete(record.id);\n\t\t\t\tthis.#failFastChecks.delete(record.id);\n\t\t\t\tthis.#taskWaiters.resolve(record.id, record as SettledTask<JsonValue>);\n\t\t\t\t// Its owner may finalize now.\n\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (record.abortRequested && previous?.abortRequested !== true) {\n\t\t\t\tthis.#cascadePending = true;\n\t\t\t\t// Signal a run invocation of the newly marked task; its next step ends it.\n\t\t\t\tconst invocation = this.#invocations.get(record.id);\n\t\t\t\tif (invocation?.mode === \"run\") invocation.controller.abort();\n\t\t\t}\n\t\t\t// A request replacing a `restart` mark upgrades the marks of the work below.\n\t\t\tif (previous?.abortReason !== undefined && record.abortReason === undefined) this.#cascadePending = true;\n\t\t\tconst status = record.state.status;\n\t\t\tif (status === \"completing\" && previous?.state.status !== \"completing\") {\n\t\t\t\tif (cancellationIntent(record)) this.#cascadePending = true;\n\t\t\t\tthis.#scheduleReconcile();\n\t\t\t}\n\t\t\tif (status === \"waiting\" && record.state.policy === \"failFast\" && previous?.state.status !== \"waiting\") {\n\t\t\t\tthis.#failFastChecks.add(record.id);\n\t\t\t\tthis.#scheduleReconcile();\n\t\t\t}\n\t\t\t// Its owners and place never change: what is above it is checked once, when it becomes live.\n\t\t\tif (previous === undefined) updated.push(record);\n\t\t}\n\t\tfor (const id of failed) {\n\t\t\tfor (const waiter of this.#waiters.get(id) ?? []) {\n\t\t\t\tconst state = this.#live.get(waiter)?.state;\n\t\t\t\tif (state?.status === \"waiting\" && state.policy === \"failFast\") {\n\t\t\t\t\tthis.#failFastChecks.add(waiter);\n\t\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const change of publication.changes) {\n\t\t\t// A queued input below a cancelled owner is withdrawn, even after its cascade.\n\t\t\tif (change.type !== \"submission\" || change.value.status !== \"queued\" || change.value.type !== \"input\")\n\t\t\t\tcontinue;\n\t\t\t// Only an owner with cancellation intent withdraws it; a later intent's mark runs the cascade then.\n\t\t\tif (this.#intent.size === 0) continue;\n\t\t\tconst conversation = change.value.conversationId;\n\t\t\tif (!this.#known(conversationNode(conversation)) || this.#belowCancelled({ conversation })) {\n\t\t\t\tthis.#cascadePending = true;\n\t\t\t}\n\t\t}\n\t\tfor (const record of updated) {\n\t\t\t// Work created below a cancelled owner, even after its cascade, is aborted too.\n\t\t\tif (this.#unloaded.has(record.id)) this.#scheduleReconcile();\n\t\t\telse if (!record.background && !record.abortRequested && this.#belowCancelled(parentOf(record))) {\n\t\t\t\tthis.#cascadePending = true;\n\t\t\t}\n\t\t}\n\t\t// A cascade that a reservation or step found pending runs with the next commit of any kind.\n\t\tif (this.#cascadePending) this.#scheduleReconcile();\n\t\tthis.#sweep();\n\t\tif (!changed) return;\n\t\tthis.#settleIdle();\n\t\tthis.#kick();\n\t}\n\n\t/**\n\t * `settings.contextRetentionMs`, or 0 when the host's settings throw. Kept contexts are only a cache, so dropping them\n\t * is safe, while a throw here would escape commit listeners, reconciliation, and the expiry timer.\n\t */\n\t#contextRetentionMs(): number {\n\t\ttry {\n\t\t\treturn this.#settings().contextRetentionMs;\n\t\t} catch (error) {\n\t\t\tthis.#report(error);\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\t/** Resolve idle waiters, and drop each kept context whose conversation has been idle for the retention period. */\n\t#settleIdle(): void {\n\t\tfor (const conversationId of this.#idleWaiters.keys()) {\n\t\t\tif (this.#idle(conversationId)) this.#idleWaiters.resolve(conversationId);\n\t\t}\n\t\tconst now = this.#now();\n\t\tconst retention = this.#contextRetentionMs();\n\t\tfor (const [conversationId, kept] of this.#contexts) {\n\t\t\tif (kept.idleSince !== undefined && now - kept.idleSince >= retention) {\n\t\t\t\tthis.#contexts.delete(conversationId);\n\t\t\t} else if (!this.#idle(conversationId)) {\n\t\t\t\tkept.idleSince = undefined;\n\t\t\t} else if (retention > 0) {\n\t\t\t\tkept.idleSince ??= now;\n\t\t\t} else {\n\t\t\t\tthis.#contexts.delete(conversationId);\n\t\t\t}\n\t\t}\n\t\tthis.#scheduleExpiry();\n\t}\n\n\t/**\n\t * Run `#settleIdle()` when the earliest idle context expires. The timer is unreferenced, so it never keeps the process\n\t * alive. Where timers cannot be unreferenced, as in Cloudflare Workers, none is kept: a pending timer could keep a\n\t * Durable Object from being evicted, and eviction frees the contexts. There, task changes alone check expiry.\n\t */\n\t#scheduleExpiry(): void {\n\t\tconst retention = this.#contextRetentionMs();\n\t\tlet at: number | undefined;\n\t\tfor (const kept of this.#contexts.values()) {\n\t\t\tif (kept.idleSince !== undefined && (at === undefined || kept.idleSince + retention < at)) {\n\t\t\t\tat = kept.idleSince + retention;\n\t\t\t}\n\t\t}\n\t\tif (this.#expiry !== undefined && this.#expiry.at === at) return;\n\t\tif (this.#expiry !== undefined) clearTimeout(this.#expiry.timer);\n\t\tthis.#expiry = undefined;\n\t\tif (at === undefined || this.#closing) return;\n\t\tconst timer = setTimeout(\n\t\t\t() => {\n\t\t\t\tthis.#expiry = undefined;\n\t\t\t\tthis.#settleIdle();\n\t\t\t},\n\t\t\tMath.min(Math.max(0, at - this.#now()), MAX_TIMER_DELAY),\n\t\t);\n\t\tconst unref = (timer as { unref?: unknown }).unref;\n\t\tif (typeof unref !== \"function\") {\n\t\t\tclearTimeout(timer);\n\t\t\treturn;\n\t\t}\n\t\tunref.call(timer);\n\t\tthis.#expiry = { at, timer };\n\t}\n\n\t// ─── Ownership ───────────────────────────────────────────────────────────\n\n\t#scheduleReconcile(): void {\n\t\tif (this.#reconcileScheduled || this.#closing) return;\n\t\tthis.#reconcileScheduled = true;\n\t\tqueueMicrotask(() => void this.#reconcile());\n\t}\n\n\t/**\n\t * One commit that applies what committed records imply: abort marks below live owners with cancellation intent\n\t * (spec §5.4), `failFast` marks (spec §5.5), withdrawn queued inputs below cancelled owners, and the final terminal\n\t * record of every `completing` task whose ordinary owned work is gone. The durable records are the intent, so this\n\t * also repairs whatever a crash left unapplied. Resolves idle waiters that the loaded edges decide.\n\t */\n\tasync #reconcile(): Promise<void> {\n\t\tthis.#reconcileScheduled = false;\n\t\tconst cascade = this.#cascadePending;\n\t\tthis.#cascadePending = false;\n\t\tconst checks = [...this.#failFastChecks];\n\t\tthis.#failFastChecks.clear();\n\t\ttry {\n\t\t\tawait this.#session.commitWith(async (tx) => {\n\t\t\t\tif (this.#closing) return;\n\t\t\t\tconst queued = await this.#loadScopes(cascade);\n\t\t\t\t// A cascade from an abandoned owner passes its `restart` reason on; any other intent marks, or upgrades a\n\t\t\t\t// `restart` mark, as a request. Collected first, so a request wins over a `restart` mark of the same pass.\n\t\t\t\tconst marks = new Map<TaskId, { readonly record: AnyTaskRecord; readonly reason: \"restart\" | undefined }>();\n\t\t\t\tconst mark = (record: AnyTaskRecord, reason: \"restart\" | undefined): void => {\n\t\t\t\t\tconst staged = marks.get(record.id);\n\t\t\t\t\tif (staged !== undefined && staged.reason === undefined) return;\n\t\t\t\t\tif (record.abortRequested && (record.abortReason === undefined || reason !== undefined)) return;\n\t\t\t\t\tmarks.set(record.id, { record, reason });\n\t\t\t\t};\n\t\t\t\t// Every live foreground task below a live owner with cancellation intent, which is its nearest one: a walk down\n\t\t\t\t// from each owner with intent does not enter another, whose own walk covers what is below it. Derived again on\n\t\t\t\t// every pass, as loading edges can reveal a cancelled owner.\n\t\t\t\tfor (const id of this.#intent) {\n\t\t\t\t\tconst owner = this.#live.get(id)!;\n\t\t\t\t\t// Only an owner abandoned after a restart, and nothing else, passes its reason on.\n\t\t\t\t\tconst restart = owner.abortReason === \"restart\" && !failedOutcome(owner);\n\t\t\t\t\tfor (const { node, live } of this.#walkDown(id, { enter: (below) => !this.#intent.has(below) })) {\n\t\t\t\t\t\tif (live !== undefined && !node.background) mark(live, restart ? \"restart\" : undefined);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const id of checks) {\n\t\t\t\t\tconst waiter = this.#live.get(id);\n\t\t\t\t\tif (waiter?.state.status !== \"waiting\" || !(await this.#anyFailed(waiter.state.on))) continue;\n\t\t\t\t\t// Every other live task: the failed one keeps its own outcome.\n\t\t\t\t\tfor (const member of waiter.state.on) {\n\t\t\t\t\t\tconst record = this.#live.get(member);\n\t\t\t\t\t\tif (record !== undefined && !failedOutcome(record)) mark(record, undefined);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const { record, reason } of marks.values()) tx.setTask(withAbortMark(record, reason));\n\t\t\t\tfor (const id of queued) if (this.#belowCancelled({ conversation: id })) await this.#withdrawInputs(tx, id);\n\t\t\t\tawait this.#finalize(tx);\n\t\t\t}, this.#context);\n\t\t} catch (error) {\n\t\t\t// No extension code runs in this commit: a throw is a storage failure, a host callback, or a bug. None is fixed by\n\t\t\t// running the pass again, so it fails the Session, which reports it.\n\t\t\tthis.#failSession(error);\n\t\t}\n\t\tthis.#settleIdle();\n\t}\n\n\t/** Whether any of `ids` holds or ended with an outcome other than `completed`. */\n\tasync #anyFailed(ids: readonly TaskId[]): Promise<boolean> {\n\t\tfor (const id of ids) {\n\t\t\tconst record = this.#live.get(id) ?? (await this.#storage.task(id, this.#context));\n\t\t\tif (record !== undefined && failedOutcome(record)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Write the terminal record of every `completing` task without live ordinary owned work. Finalizing one can free its\n\t * owner, so this repeats over the commit's candidates until nothing changes. A held scheduler outcome gets its\n\t * Harness cleanup here.\n\t */\n\tasync #finalize(tx: Transaction): Promise<void> {\n\t\t// A worklist: the tasks that started holding, and the holders of work that ended. Finalizing one can free the\n\t\t// nearest live task above it, which goes on the list. Tasks finalized here have no live work below them, so walks\n\t\t// down skip them.\n\t\t// In rounds: the holders the tasks of one round free are checked once, in the next, so a holder of many tasks that\n\t\t// end together is walked once, not once per task.\n\t\tlet round = [...this.#finalizeChecks];\n\t\tthis.#finalizeChecks.clear();\n\t\tconst done = new Set<TaskId>();\n\t\tconst overlay = overlayOf(tx);\n\t\twhile (round.length > 0) {\n\t\t\tconst next = new Set<TaskId>();\n\t\t\tfor (const id of round) {\n\t\t\t\tconst record = overlay.tasks.get(id) ?? this.#live.get(id);\n\t\t\t\tif (record?.state.status !== \"completing\" || done.has(id)) continue;\n\t\t\t\tif (this.#hasOwnedLive(id, overlay, done)) continue;\n\t\t\t\tconst outcome = record.state.outcome;\n\t\t\t\tconst terminal = withState(record, { status: \"terminal\", outcome });\n\t\t\t\ttx.setTask(terminal);\n\t\t\t\t(overlay.tasks as Map<TaskId, AnyTaskRecord>).set(id, terminal);\n\t\t\t\tdone.add(id);\n\t\t\t\t// REMINDER: only the scheduler writes `faulted` and `orphaned` (spec §5.4); their cleanup waits for this commit.\n\t\t\t\tif (outcome.status === \"faulted\" || outcome.status === \"orphaned\") {\n\t\t\t\t\tawait this.#settleOutcome(tx, record, outcome);\n\t\t\t\t}\n\t\t\t\tconst above = this.#nearestLiveAbove(record, overlay);\n\t\t\t\tif (above?.state.status === \"completing\") next.add(above.id);\n\t\t\t}\n\t\t\tround = [...next];\n\t\t}\n\t}\n\n\t/**\n\t * Load the owner chains of the tasks in `#unloaded` and, with `queued`, of every conversation with queued inputs,\n\t * on the Session line; returns the latter. Reads committed Storage directly, so it may run inside a commit callback.\n\t */\n\tasync #loadScopes(queued: boolean): Promise<ConversationId[]> {\n\t\tfor (const id of [...this.#unloaded]) {\n\t\t\t// An earlier load in this loop may have passed it.\n\t\t\tif (this.#unloaded.has(id)) await this.#loadChain({ task: id });\n\t\t}\n\t\tif (!queued) return [];\n\t\tconst submissions = await scanAll((cursor) =>\n\t\t\tthis.#storage.scanSubmissions({ status: \"queued\" }, SCAN_PAGE_SIZE, cursor, this.#context),\n\t\t);\n\t\tconst inputs = submissions.filter((submission) => submission.type === \"input\");\n\t\tconst conversations = [...new Set(inputs.map((submission) => submission.conversationId))];\n\t\tfor (const id of conversations) await this.#loadChain({ conversation: id });\n\t\treturn conversations;\n\t}\n\n\t/**\n\t * Load the owner edges and task nodes from `start` up to its ownerless root. A known task outside `#unloaded` ends the\n\t * walk, as its chain is loaded; the `#unloaded` tasks passed have a loaded chain afterwards. Loading a node can reveal\n\t * a cancelled owner, so it makes the next reconcile derive cascade marks.\n\t */\n\tasync #loadChain(start: Up, overlay?: Overlay): Promise<void> {\n\t\tconst passed: TaskId[] = [];\n\t\tlet at: Up | undefined = start;\n\t\twhile (at !== undefined) {\n\t\t\tif (\"task\" in at) {\n\t\t\t\tconst id: TaskId = at.task;\n\t\t\t\tlet node: TaskNode | undefined = this.#live.get(id) ?? this.#settled.get(id);\n\t\t\t\t// Created in this commit: the load from its own record covers what is above it.\n\t\t\t\tif (node === undefined && overlay?.tasks.has(id) === true) break;\n\t\t\t\tif (node !== undefined && !this.#unloaded.has(id)) break;\n\t\t\t\tif (node === undefined) {\n\t\t\t\t\tconst record = await this.#storage.task(id, this.#context);\n\t\t\t\t\tif (record === undefined) return;\n\t\t\t\t\tnode = nodeOf(record);\n\t\t\t\t\tif (record.state.status === \"terminal\") this.#settle(id, node);\n\t\t\t\t\t// A loaded node can reveal a cancelling owner: the next reconcile derives marks again.\n\t\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\t}\n\t\t\t\tpassed.push(id);\n\t\t\t\tat = parentOf(node);\n\t\t\t} else {\n\t\t\t\tlet edge = this.#edge(at.conversation, overlay);\n\t\t\t\tif (edge === undefined) {\n\t\t\t\t\tconst record = await this.#storage.conversation(at.conversation, this.#context);\n\t\t\t\t\tedge = record?.owner?.taskId ?? null;\n\t\t\t\t\tthis.#setEdge(at.conversation, edge);\n\t\t\t\t\t// A loaded node can reveal a cancelling owner: the next reconcile derives marks again.\n\t\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\t}\n\t\t\t\tat = edge === null ? undefined : { task: edge };\n\t\t\t}\n\t\t}\n\t\tfor (const id of passed) this.#unloaded.delete(id);\n\t}\n\n\t#setEdge(conversationId: ConversationId, owner: TaskId | null): void {\n\t\tthis.#edges.set(conversationId, owner);\n\t\t// The conversation now hangs from its owner, or is a root; with nothing below it, it waits for the sweep.\n\t\tthis.#relist(conversationNode(conversationId));\n\t\tthis.#dropIfUnneeded(conversationNode(conversationId));\n\t}\n\n\t/** Know a terminal task a chain load read, so walks pass through it; its own chain is not loaded yet. */\n\t#settle(id: TaskId, node: TaskNode): void {\n\t\tthis.#settled.set(id, node);\n\t\tthis.#unloaded.add(id);\n\t\tthis.#relist(id);\n\t\tthis.#dropIfUnneeded(id);\n\t}\n\n\t/** Queue an ended task or a conversation for the sweep when nothing is listed below it. */\n\t#dropIfUnneeded(node: Node): void {\n\t\tif (typeof node !== \"string\" && this.#live.has(node)) return;\n\t\tif (this.#below.has(node)) return;\n\t\tthis.#dropQueue.add(node);\n\t\tthis.#scheduleSweep();\n\t}\n\n\t/**\n\t * Sweep in a job of its own on the Session line, after the operation underway: a rejected commit, one with nothing to\n\t * write, and a read publish nothing, so the sweep at the end of `#observe` would not run for what they loaded.\n\t */\n\t#scheduleSweep(): void {\n\t\tif (this.#sweepScheduled || this.#closing) return;\n\t\tthis.#sweepScheduled = true;\n\t\tthis.#session\n\t\t\t.readOnLine(async () => {\n\t\t\t\tthis.#sweepScheduled = false;\n\t\t\t\tthis.#sweep();\n\t\t\t})\n\t\t\t// Rejected only once the Session is closing or failed, when nothing is kept anyway.\n\t\t\t.catch(() => {});\n\t}\n\n\t/**\n\t * Drop the queued nodes that are still unneeded: not live, nothing listed below. Runs once a publication is fully\n\t * tracked, and as a job of its own on the line, never inside an operation: work a commit creates below a chain its\n\t * own callback loaded keeps that chain. A flat loop: unlisting already queued every node on the way up that lost its\n\t * last listed node.\n\t */\n\t#sweep(): void {\n\t\tfor (const node of this.#dropQueue) {\n\t\t\tif (this.#below.has(node)) continue;\n\t\t\tif (typeof node === \"string\") {\n\t\t\t\tthis.#edges.delete(conversationOf(node));\n\t\t\t\tthis.#roots.delete(conversationOf(node));\n\t\t\t} else if (!this.#live.has(node)) {\n\t\t\t\tthis.#settled.delete(node);\n\t\t\t\tthis.#unloaded.delete(node);\n\t\t\t}\n\t\t}\n\t\tthis.#dropQueue.clear();\n\t}\n\n\t/**\n\t * Bring the scheduler's sets in line with a task's committed record. A task that ended may free the nearest live task\n\t * above it: one holding its outcome finalizes, an abort-marked one runs its abort handler; its waiters may run.\n\t */\n\t#track(previous: AnyTaskRecord | undefined, record: AnyTaskRecord): void {\n\t\tconst id = record.id;\n\t\tif (previous?.state.status === \"waiting\") for (const on of previous.state.on) deleteFrom(this.#waiters, on, id);\n\t\tif (record.state.status === \"terminal\") {\n\t\t\tconst node = nodeOf(record);\n\t\t\tthis.#live.delete(id);\n\t\t\tthis.#intent.delete(id);\n\t\t\tthis.#runnable.delete(id);\n\t\t\tthis.#finalizeChecks.delete(id);\n\t\t\tthis.#settled.set(id, node);\n\t\t\t// Before anything is forgotten: the walk up to the task it held passes the ended tasks between them. Its chain is\n\t\t\t// loaded, as every commit that ends a task loads the chains of `#unloaded` first.\n\t\t\tthis.#release(node);\n\t\t\tfor (const waiter of this.#waiters.get(id) ?? []) this.#runnable.add(waiter);\n\t\t\tthis.#relist(id);\n\t\t\tthis.#dropIfUnneeded(id);\n\t\t\treturn;\n\t\t}\n\t\tthis.#live.set(id, record);\n\t\tif (previous === undefined) {\n\t\t\tif (!this.#known(parentNode(record))) this.#unloaded.add(id);\n\t\t\tthis.#relist(id);\n\t\t}\n\t\tif (cancellationIntent(record)) this.#intent.add(id);\n\t\telse this.#intent.delete(id);\n\t\tif (record.state.status === \"completing\") {\n\t\t\tthis.#runnable.delete(id);\n\t\t\tthis.#finalizeChecks.add(id);\n\t\t} else {\n\t\t\tthis.#runnable.add(id);\n\t\t}\n\t\tif (record.state.status === \"waiting\") for (const on of record.state.on) addTo(this.#waiters, on, id);\n\t}\n\n\t/** The nearest live task above ended ordinary work may be free now: one holding its outcome, or an aborting one. */\n\t#release(node: TaskNode, overlay?: Overlay): AnyTaskRecord | undefined {\n\t\tconst above = this.#nearestLiveAbove(node, overlay);\n\t\tif (above?.state.status === \"completing\") this.#finalizeChecks.add(above.id);\n\t\telse if (above?.abortRequested === true) this.#runnable.add(above.id);\n\t\treturn above;\n\t}\n\n\t/**\n\t * List `start` under its parent node in `#below` while it is a live task or has nodes listed below it, and unlist it\n\t * otherwise; then its parent, as far up as that changes. So `#below` holds exactly the tree around live work; a\n\t * parent that loses its last listed node is queued for the sweep. A loop, as ownership chains can be deeper than the\n\t * call stack.\n\t */\n\t#relist(start: Node): void {\n\t\tlet node: Node = start;\n\t\tfor (;;) {\n\t\t\tconst needed = (typeof node !== \"string\" && this.#live.has(node)) || this.#below.has(node);\n\t\t\tlet parent: Node | null | undefined;\n\t\t\tif (typeof node === \"string\") {\n\t\t\t\tparent = this.#edges.get(conversationOf(node));\n\t\t\t} else {\n\t\t\t\tconst known = this.#live.get(node) ?? this.#settled.get(node);\n\t\t\t\tif (known === undefined) return;\n\t\t\t\tparent = parentNode(known);\n\t\t\t}\n\t\t\tif (parent === undefined) return;\n\t\t\tif (parent === null) {\n\t\t\t\tconst root = conversationOf(node as `c${number}`);\n\t\t\t\tif (needed) this.#roots.add(root);\n\t\t\t\telse this.#roots.delete(root);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ((this.#below.get(parent)?.has(node) === true) === needed) return;\n\t\t\tif (needed) {\n\t\t\t\tconst first = !this.#below.has(parent);\n\t\t\t\taddTo(this.#below, parent, node);\n\t\t\t\tif (!first) return;\n\t\t\t} else {\n\t\t\t\tdeleteFrom(this.#below, parent, node);\n\t\t\t\tif (this.#below.has(parent)) return;\n\t\t\t\tthis.#dropIfUnneeded(parent);\n\t\t\t}\n\t\t\tnode = parent;\n\t\t}\n\t}\n\n\t/**\n\t * The nearest live task above ended ordinary work `node`, in the overlay's view: the one that work held, if any. Work\n\t * at or below a background task holds nothing above it.\n\t */\n\t#nearestLiveAbove(node: TaskNode, overlay?: Overlay): AnyTaskRecord | undefined {\n\t\tfor (let current = node; !current.background; ) {\n\t\t\tconst owner = current.owner ?? this.#edge(current.conversationId, overlay);\n\t\t\tif (owner === undefined || owner === null) return undefined;\n\t\t\tconst record = overlay?.tasks.get(owner) ?? this.#live.get(owner);\n\t\t\tif (record !== undefined && record.state.status !== \"terminal\") return record;\n\t\t\tconst above = record ?? this.#settled.get(owner);\n\t\t\tif (above === undefined) return undefined;\n\t\t\tcurrent = above;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Whether the chain above `node` is loaded, without walking: known tasks outside `#unloaded` have a loaded chain. */\n\t#known(node: Node): boolean {\n\t\tif (typeof node !== \"string\") {\n\t\t\treturn (this.#live.has(node) || this.#settled.has(node)) && !this.#unloaded.has(node);\n\t\t}\n\t\tconst owner = this.#edges.get(conversationOf(node));\n\t\treturn owner === null || (owner !== undefined && this.#known(owner));\n\t}\n\n\t/** Owner task of a conversation, `null` when ownerless, `undefined` while not loaded. */\n\t#edge(id: ConversationId, overlay?: Overlay): TaskId | null | undefined {\n\t\treturn overlay?.edges.has(id) === true ? overlay.edges.get(id) : this.#edges.get(id);\n\t}\n\n\t#node(id: TaskId, overlay?: Overlay): TaskNode | undefined {\n\t\treturn overlay?.tasks.get(id) ?? this.#live.get(id) ?? this.#settled.get(id);\n\t}\n\n\t/** Walk up from `start`: owner tasks and conversations, ending at an ownerless root or an edge not loaded yet. */\n\t*#above(start: Up, overlay?: Overlay): Generator<Step> {\n\t\tlet at: Up | undefined = start;\n\t\twhile (at !== undefined) {\n\t\t\tif (\"task\" in at) {\n\t\t\t\tconst node = this.#node(at.task, overlay);\n\t\t\t\tif (node === undefined) {\n\t\t\t\t\tyield { unknown: true };\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tyield { task: at.task, node };\n\t\t\t\tat = parentOf(node);\n\t\t\t} else {\n\t\t\t\tyield { conversation: at.conversation };\n\t\t\t\tconst edge = this.#edge(at.conversation, overlay);\n\t\t\t\tif (edge === undefined) {\n\t\t\t\t\tyield { unknown: true };\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tat = edge === null ? undefined : { task: edge };\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The tasks below `start` that a walk down reaches: those `#below` lists and, under an overlay, the commit's new tasks,\n\t * with its candidates in place of committed records. Background tasks are reached but not entered, unless\n\t * `crossBackground`, and neither are the tasks `enter` rejects. A loop, as chains can be deeper than the call stack.\n\t */\n\t*#walkDown(\n\t\tstart: Node,\n\t\toptions: {\n\t\t\treadonly overlay?: Overlay;\n\t\t\treadonly crossBackground?: boolean;\n\t\t\treadonly enter?: (id: TaskId) => boolean;\n\t\t} = {},\n\t): Generator<{ readonly id: TaskId; readonly node: TaskNode; readonly live: AnyTaskRecord | undefined }> {\n\t\tconst { overlay, crossBackground = false, enter } = options;\n\t\tconst links = overlay === undefined ? undefined : this.#links(overlay);\n\t\tconst pending: Node[] = [start];\n\t\tfor (let at = pending.pop(); at !== undefined; at = pending.pop()) {\n\t\t\tfor (const children of [this.#below.get(at), links?.get(at)]) {\n\t\t\t\tfor (const child of children ?? []) {\n\t\t\t\t\tif (typeof child === \"string\") {\n\t\t\t\t\t\tpending.push(child);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst record = overlay?.tasks.get(child) ?? this.#live.get(child);\n\t\t\t\t\tconst node = record ?? this.#settled.get(child);\n\t\t\t\t\tif (node === undefined) continue;\n\t\t\t\t\tconst live = record !== undefined && record.state.status !== \"terminal\" ? record : undefined;\n\t\t\t\t\tyield { id: child, node, live };\n\t\t\t\t\tif ((crossBackground || !node.background) && (enter === undefined || enter(child))) pending.push(child);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The links walks down need for the commit's new tasks: each one under its parent node, then each node above it that\n\t * `#below` does not list yet, until one it lists, a live task (always listed), or the chain's end.\n\t */\n\t#links(overlay: Overlay): ReadonlyMap<Node, ReadonlySet<Node>> {\n\t\tif (overlay.links !== undefined) return overlay.links;\n\t\tconst links = new Map<Node, Set<Node>>();\n\t\tfor (const record of overlay.tasks.values()) {\n\t\t\tif (this.#live.has(record.id) || this.#settled.has(record.id)) continue;\n\t\t\tlet child: Node = record.id;\n\t\t\tlet parent: Node | null | undefined = parentNode(record);\n\t\t\twhile (parent !== undefined && parent !== null && links.get(parent)?.has(child) !== true) {\n\t\t\t\taddTo(links, parent, child);\n\t\t\t\tif (typeof parent !== \"string\" && (this.#live.has(parent) || overlay.tasks.has(parent))) break;\n\t\t\t\tlet above: Node | null | undefined;\n\t\t\t\tif (typeof parent === \"string\") {\n\t\t\t\t\tabove = this.#edge(conversationOf(parent), overlay);\n\t\t\t\t} else {\n\t\t\t\t\tconst fields = this.#settled.get(parent);\n\t\t\t\t\tabove = fields === undefined ? undefined : parentNode(fields);\n\t\t\t\t}\n\t\t\t\tif (above !== undefined && above !== null && this.#below.get(above)?.has(parent) === true) break;\n\t\t\t\tchild = parent;\n\t\t\t\tparent = above;\n\t\t\t}\n\t\t}\n\t\toverlay.links = links;\n\t\treturn links;\n\t}\n\n\t/**\n\t * The live ordinary owned work of `owner` (spec §5.5): the live non-background tasks below it that a walk down reaches\n\t * without entering a background task; with `first`, only the first. Candidates in `overlay` replace committed records;\n\t * the walk does not enter tasks in `done`, which have none. Owner chains must be loaded.\n\t */\n\t#ownedLive(\n\t\towner: TaskId,\n\t\toptions: { readonly overlay?: Overlay; readonly first?: boolean; readonly done?: ReadonlySet<TaskId> } = {},\n\t): TaskId[] {\n\t\tconst { overlay, first = false, done } = options;\n\t\tconst found: TaskId[] = [];\n\t\tconst walk = this.#walkDown(owner, {\n\t\t\t...(overlay === undefined ? {} : { overlay }),\n\t\t\t...(done === undefined ? {} : { enter: (id: TaskId) => !done.has(id) }),\n\t\t});\n\t\tfor (const { id, node, live } of walk) {\n\t\t\tif (live === undefined || node.background) continue;\n\t\t\tfound.push(id);\n\t\t\tif (first) break;\n\t\t}\n\t\treturn found;\n\t}\n\n\t#hasOwnedLive(owner: TaskId, overlay?: Overlay, done?: ReadonlySet<TaskId>): boolean {\n\t\tconst options = {\n\t\t\tfirst: true,\n\t\t\t...(overlay === undefined ? {} : { overlay }),\n\t\t\t...(done === undefined ? {} : { done }),\n\t\t};\n\t\treturn this.#ownedLive(owner, options).length > 0;\n\t}\n\n\t/**\n\t * Whether ordinary traversal from `scope` reaches `start`: walking up reaches the scope's conversation, or an\n\t * ownerless one for `roots`, without crossing a background owner, unless `crossBackground`. `undefined` while an\n\t * edge is not loaded.\n\t */\n\t#inScope(start: Up, scope: Scope, crossBackground = false): boolean | undefined {\n\t\tfor (const step of this.#above(start)) {\n\t\t\tif (\"unknown\" in step) return undefined;\n\t\t\tif (\"conversation\" in step) {\n\t\t\t\tif (\"conversation\" in scope && step.conversation === scope.conversation) return true;\n\t\t\t} else if (step.node.background && !crossBackground) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn \"roots\" in scope;\n\t}\n\n\t/**\n\t * Whether a live owner's cancellation intent reaches `start`: walking up finds an owner with intent before a\n\t * background owner without it. Terminal owners never cascade (spec §5.4).\n\t */\n\t#belowCancelled(start: Up): boolean {\n\t\treturn this.#cancellingOwner(start) !== undefined;\n\t}\n\n\t/** The nearest live owner above `start` whose cancellation intent reaches it, if any; see `#belowCancelled`. */\n\t#cancellingOwner(start: Up): AnyTaskRecord | undefined {\n\t\t// Nothing cancels, the common case: no walk.\n\t\tif (this.#intent.size === 0) return undefined;\n\t\tfor (const step of this.#above(start)) {\n\t\t\tif (\"unknown\" in step) return undefined;\n\t\t\tif (!(\"task\" in step)) continue;\n\t\t\tconst live = this.#live.get(step.task);\n\t\t\tif (live !== undefined && cancellationIntent(live)) return live;\n\t\t\tif (step.node.background) return undefined;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Fail the Session, which reports it, for a throw in one of the scheduler's own commits; ignored once closing. */\n\t#failSession(error: unknown): void {\n\t\tif (!this.#closing) this.#session.fail(error);\n\t}\n\n\t/** Close listener: runs synchronously once admission is sealed, before `join()`, or when the Session fails. */\n\t#seal(): void {\n\t\tthis.#closing = true;\n\t\ttry {\n\t\t\tthis.#unsubscribeRegistry();\n\t\t} catch (error) {\n\t\t\tthis.#report(error);\n\t\t}\n\t\tconst error = closedError(this.#session);\n\t\tthis.#taskWaiters.rejectAll(error);\n\t\tthis.#idleWaiters.rejectAll(error);\n\t\tthis.#contexts.clear();\n\t\tif (this.#expiry !== undefined) clearTimeout(this.#expiry.timer);\n\t\tthis.#expiry = undefined;\n\t}\n\n\t#kick(): void {\n\t\tthis.#dirty = true;\n\t\tif (this.#draining || !this.#enabled || this.#closing) return;\n\t\tthis.#draining = true;\n\t\t// Never commit synchronously from a commit or registry listener.\n\t\tqueueMicrotask(() => void this.#drain());\n\t}\n\n\tasync #drain(): Promise<void> {\n\t\ttry {\n\t\t\twhile (this.#dirty && this.#enabled && !this.#closing) {\n\t\t\t\tthis.#dirty = false;\n\t\t\t\tfor (const reservation of await this.#reserve()) this.#start(reservation);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// As in `#reconcile()`: the reservation commit runs no extension code.\n\t\t\tthis.#failSession(error);\n\t\t} finally {\n\t\t\tthis.#draining = false;\n\t\t\t// A wakeup that arrived after the loop's last check still needs its pass.\n\t\t\tif (this.#dirty) this.#kick();\n\t\t}\n\t}\n\n\t/**\n\t * Reserve every eligible task in one commit; orphan abort-marked tasks no definition can take, unless abandoned after\n\t * a restart. The first pass after open only abort-marks the abandoned tasks, so later passes see the marks.\n\t */\n\tasync #reserve(): Promise<Reservation[]> {\n\t\tconst reservations: Reservation[] = [];\n\t\tlet abandoned: TaskId[] = [];\n\t\ttry {\n\t\t\tawait this.#session.commitWith(async (tx) => {\n\t\t\t\tif (!this.#enabled || this.#closing) return;\n\t\t\t\tfor (const id of this.#abandoned) {\n\t\t\t\t\tconst record = this.#live.get(id);\n\t\t\t\t\tif (record !== undefined && !record.abortRequested) tx.setTask(withAbortMark(record, \"restart\"));\n\t\t\t\t}\n\t\t\t\tif (this.#abandoned.size > 0) {\n\t\t\t\t\tabandoned = [...this.#abandoned];\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait this.#loadScopes(false);\n\t\t\t\t// Taken once per pass, and only when some task is a candidate.\n\t\t\t\tlet snapshot: RegistrySnapshot | undefined;\n\t\t\t\tfor (const id of [...this.#runnable]) {\n\t\t\t\t\tconst record = this.#live.get(id);\n\t\t\t\t\tif (record === undefined || record.state.status === \"completing\" || this.#invocations.has(id)) {\n\t\t\t\t\t\tthis.#runnable.delete(id);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\t// It returns once what it waits for ends, its record changes, or the work below it ends.\n\t\t\t\t\tif (this.#waitingOn(record, true).length > 0) {\n\t\t\t\t\t\tthis.#runnable.delete(id);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst runnable = record as RunnableTaskRecord;\n\t\t\t\t\tconst mode = record.abortRequested ? \"abort\" : \"run\";\n\t\t\t\t\t// Work below an owner with cancellation intent waits for its cascade mark instead of running a phase; schedule\n\t\t\t\t\t// the cascade, which may not have run yet.\n\t\t\t\t\tif (mode === \"run\" && !record.background && this.#belowCancelled(parentOf(record))) {\n\t\t\t\t\t\tthis.#cascadePending = true;\n\t\t\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tsnapshot ??= this.#registry.snapshot();\n\t\t\t\t\tconst resolution = this.#resolve(runnable, snapshot);\n\t\t\t\t\tif (resolution.kind === \"blocked\") {\n\t\t\t\t\t\t// An abandoned task waits for its definition, so its abort handler can clean up.\n\t\t\t\t\t\tif (mode === \"abort\" && record.abortReason === undefined) {\n\t\t\t\t\t\t\tawait this.#terminate(tx, record, { status: \"orphaned\", reason: resolution.reason });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (resolution.record !== runnable || record.state.status !== \"running\") {\n\t\t\t\t\t\ttx.setTask(\n\t\t\t\t\t\t\twithState(resolution.record, {\n\t\t\t\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\t\t\t\tcheckpoint: resolution.record.state.checkpoint,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\t// Registered on the line, so marks and later reservations see it and close joins it; `#end` makes it a\n\t\t\t\t\t// candidate again.\n\t\t\t\t\tthis.#runnable.delete(id);\n\t\t\t\t\tconst invocation = this.#createInvocation(record, mode);\n\t\t\t\t\treservations.push({ invocation, task: resolution.task, snapshot });\n\t\t\t\t}\n\t\t\t}, this.#context);\n\t\t} catch (error) {\n\t\t\tfor (const { invocation } of reservations) {\n\t\t\t\tthis.#invocations.delete(invocation.taskId);\n\t\t\t\tthis.#runnable.add(invocation.taskId);\n\t\t\t\tinvocation.finish();\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\t// Marked, or already marked or gone: done with them. Reserve again, now seeing the marks.\n\t\tfor (const id of abandoned) this.#abandoned.delete(id);\n\t\tif (abandoned.length > 0) this.#dirty = true;\n\t\treturn reservations;\n\t}\n\n\t/**\n\t * Live tasks a task waits for before its next invocation: its live ordinary owned work when abort-marked, since\n\t * abort runs bottom-up, otherwise the live part of the `on` of a wait.\n\t */\n\t#waitingOn(record: AnyTaskRecord, first = false): readonly TaskId[] {\n\t\tif (record.abortRequested) return this.#ownedLive(record.id, { first });\n\t\tif (record.state.status !== \"waiting\") return [];\n\t\tif (!first) return record.state.on.filter((id) => this.#live.has(id));\n\t\tconst live = record.state.on.find((id) => this.#live.has(id));\n\t\treturn live === undefined ? [] : [live];\n\t}\n\n\t/** Resolve the record's definition by kind, migrating an older stored version. */\n\t#resolve(record: RunnableTaskRecord, snapshot: RegistrySnapshot): Resolution {\n\t\tconst fit = this.#fit(record, snapshot.task(record.kind));\n\t\tif (\"reason\" in fit) return { kind: \"blocked\", reason: fit.reason };\n\t\tif (!fit.migrates) return { kind: \"ready\", task: fit.task, record };\n\t\tconst definition = erased(fit.task);\n\t\ttry {\n\t\t\tif (definition.migrate === undefined) throw missingMigration(record, definition);\n\t\t\tconst migrated = definition.migrate(record.input, record.state.checkpoint, record.version);\n\t\t\tconst state = { ...record.state, checkpoint: copyJson(migrated.checkpoint) };\n\t\t\tconst migratedRecord = { ...record, version: definition.version, input: copyJson(migrated.input), state };\n\t\t\treturn { kind: \"ready\", task: fit.task, record: migratedRecord as RunnableTaskRecord };\n\t\t} catch (error) {\n\t\t\tthis.#failedMigrations.set(record.id, { task: fit.task, error });\n\t\t\tthis.#report(error);\n\t\t\treturn { kind: \"blocked\", reason: \"migration_failed\" };\n\t\t}\n\t}\n\n\t#fit(record: AnyTaskRecord, task: AnyTask | undefined): Fit {\n\t\tif (task === undefined) return { reason: \"missing_task\" };\n\t\tconst version = task.definition.version;\n\t\tif (version === record.version) return { task, migrates: false };\n\t\tif (version < record.version) return { reason: \"task_too_old\" };\n\t\tconst failed = this.#failedMigrations.get(record.id);\n\t\tif (failed?.task === task) return { reason: \"migration_failed\", error: failed.error };\n\t\treturn { task, migrates: true };\n\t}\n\n\t/** Sizes of the ownership indexes, for tests that bound the scheduler's memory. */\n\tget indexSizes(): Readonly<\n\t\tRecord<\"live\" | \"settled\" | \"edges\" | \"below\" | \"roots\" | \"unloaded\" | \"dropQueue\", number>\n\t> {\n\t\tlet below = 0;\n\t\tfor (const children of this.#below.values()) below += children.size;\n\t\treturn {\n\t\t\tlive: this.#live.size,\n\t\t\tsettled: this.#settled.size,\n\t\t\tedges: this.#edges.size,\n\t\t\tbelow,\n\t\t\troots: this.#roots.size,\n\t\t\tunloaded: this.#unloaded.size,\n\t\t\tdropQueue: this.#dropQueue.size,\n\t\t};\n\t}\n\n\t/**\n\t * Scheduling state and every live task with its derived state, read on the Session line. Runs no task code: a\n\t * pending migration shows as `ready` with `migrates`, and only a migration the scheduler already tried, or one that\n\t * cannot exist, shows as failed.\n\t */\n\tasync inspect(\n\t\tsnapshot: RegistrySnapshot,\n\t): Promise<{ scheduling: HarnessInspection[\"scheduling\"]; tasks: TaskInspection[] }> {\n\t\tawait this.#loadScopes(false);\n\t\tconst tasks: TaskInspection[] = [];\n\t\tfor (const record of this.#live.values()) tasks.push({ record, state: this.#inspectTask(record, snapshot) });\n\t\tconst scheduling = this.#closing ? \"closing\" : this.#enabled ? \"running\" : \"paused\";\n\t\treturn { scheduling, tasks };\n\t}\n\n\t#inspectTask(record: AnyTaskRecord, snapshot: RegistrySnapshot): TaskInspection[\"state\"] {\n\t\tif (this.#invocations.has(record.id)) return { kind: \"running\" };\n\t\tif (record.state.status === \"completing\") return { kind: \"completing\" };\n\t\tconst on = this.#waitingOn(record);\n\t\tif (on.length > 0) return { kind: \"waiting\", on };\n\t\tconst fit = this.#fit(record, snapshot.task(record.kind));\n\t\tif (\"reason\" in fit) return { kind: \"blocked\", ...fit };\n\t\tif (fit.migrates && fit.task.definition.migrate === undefined) {\n\t\t\treturn { kind: \"blocked\", reason: \"migration_failed\", error: missingMigration(record, erased(fit.task)) };\n\t\t}\n\t\treturn { kind: \"ready\", migrates: fit.migrates };\n\t}\n\n\t#createInvocation(record: AnyTaskRecord, mode: \"run\" | \"abort\"): Invocation {\n\t\tconst controller = new AbortController();\n\t\tconst { promise: done, resolve: finish } = Promise.withResolvers<void>();\n\t\tconst invocation: Invocation = {\n\t\t\ttaskId: record.id,\n\t\t\tconversationId: record.conversationId,\n\t\t\tmode,\n\t\t\tcontroller,\n\t\t\tcontext: withAbortSignal(controller.signal, this.#context),\n\t\t\twatches: new Set(),\n\t\t\tended: false,\n\t\t\tdone,\n\t\t\tfinish: () => finish(),\n\t\t};\n\t\tthis.#invocations.set(record.id, invocation);\n\t\treturn invocation;\n\t}\n\n\t#start(reservation: Reservation): void {\n\t\tconst invocation = reservation.invocation;\n\t\tvoid (async () => {\n\t\t\ttry {\n\t\t\t\tif (invocation.mode === \"run\") await this.#run(reservation);\n\t\t\t\telse await this.#runAbort(reservation);\n\t\t\t} catch (error) {\n\t\t\t\tthis.#report(error);\n\t\t\t} finally {\n\t\t\t\tthis.#end(invocation);\n\t\t\t\tinvocation.finish();\n\t\t\t\tthis.#kick();\n\t\t\t}\n\t\t})();\n\t}\n\n\t/** Run phase handlers, each preceded by a step that decides on the line whether the invocation continues. */\n\tasync #run(reservation: Reservation): Promise<void> {\n\t\tconst invocation = reservation.invocation;\n\t\tconst state = { task: reservation.task, snapshot: reservation.snapshot, reported: undefined as ReportedTask };\n\t\tconst phase: Phase = { snapshot: () => state.snapshot, task: () => state.task, agent: undefined };\n\t\tconst runtime = this.#runtime(invocation, phase);\n\t\tlet previous: PhaseResult | undefined;\n\t\tfor (;;) {\n\t\t\tconst current = await this.#step(invocation, (tx, current) => this.#decide(tx, current, previous, state));\n\t\t\t// Close may seal between the decision and dispatch.\n\t\t\tif (current === undefined || this.#closing) return;\n\t\t\tconst checkpoint = current.state.checkpoint;\n\t\t\t// Each phase handler resolves its agent afresh, at first use.\n\t\t\tphase.agent = undefined;\n\t\t\ttry {\n\t\t\t\tawait erased(state.task).phases[checkpoint.phase]!(current, runtime, invocation.context);\n\t\t\t\tprevious = { checkpoint };\n\t\t\t} catch (error) {\n\t\t\t\tprevious = { checkpoint, failure: { error } };\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Precedence rules for a run invocation, on the line. Rules 1 (terminal, `completing`, or `waiting`) and 2 (closing)\n\t * are applied by `#step`. Returns whether the invocation continues with the next phase.\n\t */\n\t#decide(\n\t\ttx: Transaction,\n\t\tcurrent: ErasedRunningTask,\n\t\tprevious: PhaseResult | undefined,\n\t\tstate: { task: AnyTask; snapshot: RegistrySnapshot; reported: ReportedTask },\n\t): Decision {\n\t\t// 3. abort mark: end; a fresh abort invocation starts once the task's ordinary owned work is gone.\n\t\tif (current.abortRequested) return false;\n\t\t// An owner's cancellation intent ends it too, before its cascade marks it; reservation then holds it back.\n\t\tif (!current.background && this.#belowCancelled(parentOf(current))) {\n\t\t\tthis.#cascadePending = true;\n\t\t\tthis.#scheduleReconcile();\n\t\t\treturn false;\n\t\t}\n\t\tif (previous === undefined) return true;\n\t\t// 4. uncaught error.\n\t\tif (previous.failure !== undefined) return { fault: previous.failure.error };\n\t\t// 6. no durable progress.\n\t\tif (jsonEqual(current.state.checkpoint, previous.checkpoint)) {\n\t\t\tconst message = `Task ${current.kind} phase ${previous.checkpoint.phase} returned without durable progress`;\n\t\t\treturn { fault: new Error(message) };\n\t\t}\n\t\t// 5. progress: refresh the snapshot; hand over to a replacement definition that can take the task.\n\t\tstate.snapshot = this.#registry.snapshot();\n\t\tconst next = state.snapshot.task(current.kind);\n\t\tif (next !== state.task) {\n\t\t\tif (next !== undefined && canReserve(next, current)) {\n\t\t\t\ttx.setTask(withState(current, { status: \"pending\", checkpoint: current.state.checkpoint }));\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (state.reported === undefined || state.reported.task !== next) {\n\t\t\t\tstate.reported = { task: next };\n\t\t\t\tconst cause = next === undefined ? \"missing_task\" : \"incompatible_task\";\n\t\t\t\tthis.#report(\n\t\t\t\t\tnew Error(`Task ${current.id} keeps running under its old ${current.kind} definition`, { cause }),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** Run the abort handler once; rules 1, 2, and 4 apply, and returning without an outcome faults. */\n\tasync #runAbort(reservation: Reservation): Promise<void> {\n\t\tconst invocation = reservation.invocation;\n\t\tconst current = this.#live.get(invocation.taskId) as ErasedRunningTask | undefined;\n\t\tif (current === undefined || this.#closing) return;\n\t\tlet failure: { readonly error: unknown } | undefined;\n\t\ttry {\n\t\t\tconst phase: Phase = { snapshot: () => reservation.snapshot, task: () => reservation.task, agent: undefined };\n\t\t\tconst runtime = this.#runtime(invocation, phase);\n\t\t\tawait erased(reservation.task).abort(current, runtime, invocation.context);\n\t\t} catch (error) {\n\t\t\tfailure = { error };\n\t\t}\n\t\tconst message = `Abort handler of task ${invocation.taskId} returned without a terminal outcome`;\n\t\tawait this.#step(invocation, () => ({ fault: failure?.error ?? new Error(message) }));\n\t}\n\n\t/**\n\t * One synchronous decision on the Session line. A task that is no longer running (rule 1: terminal, `completing`, or\n\t * `waiting`) or a closing Harness (rule 2) ends the invocation without a write; otherwise `decide` may stage a write\n\t * and returns whether the invocation continues. Ending happens inside the callback, before a fault's Harness\n\t * cleanup. A rejected step, such as admission after close, also ends the invocation.\n\t */\n\tasync #step(\n\t\tinvocation: Invocation,\n\t\tdecide: (tx: Transaction, current: ErasedRunningTask) => Decision,\n\t): Promise<ErasedRunningTask | undefined> {\n\t\ttry {\n\t\t\treturn await this.#session.commitWith(async (tx) => {\n\t\t\t\tconst found = this.#live.get(invocation.taskId);\n\t\t\t\tconst current = found?.state.status === \"running\" ? (found as ErasedRunningTask) : undefined;\n\t\t\t\tconst decision = current !== undefined && !this.#closing ? decide(tx, current) : false;\n\t\t\t\tif (decision === true) return current;\n\t\t\t\tthis.#end(invocation);\n\t\t\t\tif (decision !== false) {\n\t\t\t\t\tconst message = errorMessage(decision.fault);\n\t\t\t\t\tawait this.#terminate(tx, current!, { status: \"faulted\", error: { message } });\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t}, this.#context);\n\t\t} catch (error) {\n\t\t\t// The step writes the scheduler's own decision, a fault or a terminal record; a throw there would otherwise\n\t\t\t// leave the task running, to be reserved and run again.\n\t\t\tthis.#end(invocation);\n\t\t\tthis.#failSession(error);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Write an outcome the scheduler decided. While the task's ordinary owned work is live it holds as `completing` and\n\t * its Harness cleanup waits for the final commit (spec §5.5, rule 4); otherwise it is terminal with its cleanup.\n\t */\n\tasync #terminate(tx: Transaction, record: AnyTaskRecord, outcome: SchedulerOutcome): Promise<void> {\n\t\tawait this.#loadScopes(false);\n\t\tif (this.#hasOwnedLive(record.id, overlayOf(tx))) {\n\t\t\ttx.setTask(withState(record, { status: \"completing\", outcome }));\n\t\t\treturn;\n\t\t}\n\t\ttx.setTask(withState(record, { status: \"terminal\", outcome }));\n\t\tawait this.#settleOutcome(tx, record, outcome);\n\t}\n\n\t/**\n\t * Replace a running task's state with what it committed. A terminal state holds as `completing` while ordinary owned\n\t * work is live, judged on the commit's candidates, so work the same commit creates below the task counts. A wait is\n\t * validated first.\n\t */\n\tasync #commitState(\n\t\ttx: Transaction,\n\t\tinvocation: Invocation,\n\t\tcurrent: ErasedRunningTask,\n\t\tnext: NextTaskState<Checkpoint, JsonValue>,\n\t): Promise<void> {\n\t\tif (next.status === \"waiting\") await this.#validateWait(tx, invocation, current, next.on, next.policy);\n\t\tif (next.status === \"terminal\") {\n\t\t\tconst overlay = overlayOf(tx);\n\t\t\tawait this.#loadScopes(false);\n\t\t\tfor (const record of overlay.tasks.values()) await this.#loadChain(parentOf(record), overlay);\n\t\t\tif (this.#hasOwnedLive(current.id, overlay)) {\n\t\t\t\ttx.setTask(withState(current, { status: \"completing\", outcome: next.outcome }));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttx.setTask(withState(current, next));\n\t}\n\n\t/**\n\t * A wait names existing tasks other than the waiter and its owners, which could never finish first; `failFast` only\n\t * tasks the waiter owns. An abort handler cannot wait.\n\t */\n\tasync #validateWait(\n\t\ttx: Transaction,\n\t\tinvocation: Invocation,\n\t\tcurrent: ErasedRunningTask,\n\t\ton: readonly TaskId[],\n\t\tpolicy: string,\n\t): Promise<void> {\n\t\tif (invocation.mode === \"abort\") throw new Error(`Abort handler of task ${current.id} cannot wait`);\n\t\tconst overlay = overlayOf(tx);\n\t\tawait this.#loadChain(parentOf(current));\n\t\tconst owners = new Set<TaskId>();\n\t\tfor (const step of this.#above(parentOf(current))) if (\"task\" in step) owners.add(step.task);\n\t\tfor (const id of on) {\n\t\t\tif (id === current.id || owners.has(id)) {\n\t\t\t\tthrow new Error(`Task ${current.id} cannot wait on itself or its owner ${id}`);\n\t\t\t}\n\t\t\tconst member = overlay.tasks.get(id) ?? this.#live.get(id) ?? (await this.#storage.task(id, this.#context));\n\t\t\tif (member === undefined) throw new Error(`Task ${id} does not exist`);\n\t\t\tif (policy === \"failFast\" && member.owner !== current.id) {\n\t\t\t\tthrow new Error(`Task ${current.id} can wait failFast only on tasks it owns; ${id} is not one`);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** End an invocation: its runtime operations reject from now on, its signal aborts, its watches stop, and its task is free. */\n\t#end(invocation: Invocation): void {\n\t\tif (invocation.ended) return;\n\t\tinvocation.ended = true;\n\t\tif (this.#invocations.get(invocation.taskId) === invocation) {\n\t\t\tthis.#invocations.delete(invocation.taskId);\n\t\t\tif (this.#live.has(invocation.taskId)) this.#runnable.add(invocation.taskId);\n\t\t}\n\t\tfor (const watch of invocation.watches) void watch.stop();\n\t\t// Pending waits bound to the invocation, such as a tool's waitForTask(), reject with it.\n\t\tinvocation.controller.abort(endedError(invocation));\n\t}\n\n\t/** No live non-background task in the scope; a task whose owner edges are not loaded yet counts as inside. */\n\t#idle(conversationId: ConversationId | undefined): boolean {\n\t\tconst scope: Scope = conversationId === undefined ? { roots: true } : { conversation: conversationId };\n\t\t// Tasks whose chain is not loaded are not listed below their scope yet; one counts as inside unless its walk up\n\t\t// decides otherwise.\n\t\tfor (const id of this.#unloaded) {\n\t\t\tconst record = this.#live.get(id);\n\t\t\tif (record !== undefined && !record.background && this.#inScope(parentOf(record), scope) !== false)\n\t\t\t\treturn false;\n\t\t}\n\t\tconst starts = conversationId === undefined ? this.#roots : [conversationId];\n\t\tfor (const start of starts) {\n\t\t\tfor (const { node, live } of this.#walkDown(conversationNode(start))) {\n\t\t\t\tif (live !== undefined && !node.background) return false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ─── Invocation runtime ──────────────────────────────────────────────────\n\n\t#runtime(invocation: Invocation, phase: Phase): ErasedRuntime {\n\t\t// Resolved at most once per phase handler, at first use, with the invocation's context; fixed for the phase.\n\t\tconst agent = (): Promise<Agent> => {\n\t\t\tif (invocation.ended) return Promise.reject(endedError(invocation));\n\t\t\tif (phase.agent === undefined) {\n\t\t\t\tphase.agent = this.#agent(invocation.conversationId, phase.snapshot(), invocation.context);\n\t\t\t\t// A caller that stops waiting must not leave the shared resolution's failure unobserved.\n\t\t\t\tphase.agent.catch(() => {});\n\t\t\t}\n\t\t\treturn phase.agent;\n\t\t};\n\t\tconst hooks: HookRunner<Record<string, unknown>> = {\n\t\t\teach: async (name, invoke) => {\n\t\t\t\tfor (const handlers of agentHooks(await agent(), phase.task().definition.name)) {\n\t\t\t\t\tconst handler = (handlers as Record<string, unknown>)[name];\n\t\t\t\t\tif (typeof handler !== \"function\") continue;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait invoke(handler.bind(handlers));\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (invocation.controller.signal.aborted) throw error;\n\t\t\t\t\t\tthis.#report(error);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\tconst settings = this.#settings;\n\t\treturn {\n\t\t\ttaskId: invocation.taskId as TaskId<JsonValue>,\n\t\t\tconversationId: invocation.conversationId,\n\t\t\tsignal: invocation.controller.signal,\n\t\t\tmodels: this.#models,\n\t\t\tagent: (context) =>\n\t\t\t\tinvocation.ended ? Promise.reject(endedError(invocation)) : awaitWithContext(agent(), context),\n\t\t\tget settings() {\n\t\t\t\treturn settings();\n\t\t\t},\n\t\t\tenv: (context) => this.#read(invocation, () => this.#env(invocation.conversationId, context)),\n\t\t\thooks: hooks as ErasedRuntime[\"hooks\"],\n\t\t\tget registry() {\n\t\t\t\treturn phase.snapshot();\n\t\t\t},\n\t\t\tcommit: (change, context) =>\n\t\t\t\tthis.#gated(\n\t\t\t\t\tinvocation,\n\t\t\t\t\tasync (tx, current) => {\n\t\t\t\t\t\tconst next = await change(tx, current);\n\t\t\t\t\t\tif (next !== undefined) await this.#commitState(tx, invocation, current, next);\n\t\t\t\t\t},\n\t\t\t\t\tcontext,\n\t\t\t\t),\n\t\t\tmemo: ((name: string, ...rest: readonly unknown[]) => {\n\t\t\t\tif (rest.length === 1) {\n\t\t\t\t\treturn this.#read(invocation, async () => memoOf(this.#live.get(invocation.taskId), name));\n\t\t\t\t}\n\t\t\t\tconst candidate = rest[0] as JsonValue;\n\t\t\t\treturn this.#gated(\n\t\t\t\t\tinvocation,\n\t\t\t\t\t(tx, current) => {\n\t\t\t\t\t\tconst winner = memoOf(current, name);\n\t\t\t\t\t\tif (winner !== undefined) return winner;\n\t\t\t\t\t\ttx.setTask({ ...current, memos: { ...current.memos, [name]: candidate } } as AnyTaskRecord);\n\t\t\t\t\t\treturn candidate;\n\t\t\t\t\t},\n\t\t\t\t\trest[1] as Context,\n\t\t\t\t);\n\t\t\t}) as ErasedRuntime[\"memo\"],\n\t\t\tsleep: (until, context) => this.#sleep(invocation, until, context),\n\t\t\twatchDoc: ((...args: readonly unknown[]) => this.#watchDoc(invocation, args)) as ErasedRuntime[\"watchDoc\"],\n\t\t\tsnapshot: ((...args: readonly unknown[]) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tsessionMethod(this.#session, \"snapshot\")(...args),\n\t\t\t\t)) as ErasedRuntime[\"snapshot\"],\n\t\t\tsnapshotAsOf: ((...args: readonly unknown[]) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tsessionMethod(this.#session, \"snapshotAsOf\")(...args),\n\t\t\t\t)) as ErasedRuntime[\"snapshotAsOf\"],\n\t\t\tgetTask: ((id: TaskId, context: Context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.#session.readOnLine(() => this.#storage.task(id, context)),\n\t\t\t\t)) as ErasedRuntime[\"getTask\"],\n\t\t\twaitForTask: ((id: TaskId, context: Context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.waitForTask(id, withAbortSignal(invocation.controller.signal, context)),\n\t\t\t\t)) as ErasedRuntime[\"waitForTask\"],\n\t\t\townedTasks: (context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.#session.readOnLine(async () => {\n\t\t\t\t\t\t// The step that ends the invocation may have run on the line before this.\n\t\t\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\t\t\tcontext.abortSignal?.throwIfAborted();\n\t\t\t\t\t\t// Every live task is listed under its parent node, its owner task when it has one.\n\t\t\t\t\t\tconst owned: AnyTaskRecord[] = [];\n\t\t\t\t\t\tfor (const node of this.#below.get(invocation.taskId) ?? []) {\n\t\t\t\t\t\t\tconst record = typeof node === \"string\" ? undefined : this.#live.get(node);\n\t\t\t\t\t\t\tif (record?.owner === invocation.taskId) owned.push(record);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Copies, as from storage: the scheduler reads its own.\n\t\t\t\t\t\treturn owned\n\t\t\t\t\t\t\t.sort((a, b) => a.id - b.id)\n\t\t\t\t\t\t\t.map((record) => copyJson(record as unknown as JsonValue) as unknown as AnyTaskRecord);\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\tabortOwned: (id, context) =>\n\t\t\t\tthis.#read(invocation, async () => {\n\t\t\t\t\tconst bound = withAbortSignal(invocation.controller.signal, context);\n\t\t\t\t\tconst record = await this.#session.readOnLine(() => this.#storage.task(id, bound));\n\t\t\t\t\tif (record?.owner !== invocation.taskId) {\n\t\t\t\t\t\tthrow new Error(`Task ${id} is not owned by task ${invocation.taskId}`);\n\t\t\t\t\t}\n\t\t\t\t\tif (record.state.status === \"terminal\") return;\n\t\t\t\t\tawait this.abort(id, bound, true);\n\t\t\t\t\tawait this.waitForTask(id, bound);\n\t\t\t\t}),\n\t\t\toutcomes: ((ids: readonly TaskId[], context: Context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.#session.readOnLine(async () => {\n\t\t\t\t\t\tconst outcomes: TaskOutcome<JsonValue>[] = [];\n\t\t\t\t\t\tfor (const id of ids) {\n\t\t\t\t\t\t\tconst state = (await this.#storage.task(id, context))?.state;\n\t\t\t\t\t\t\tif (state?.status !== \"terminal\") throw new Error(`Task ${id} is not terminal`);\n\t\t\t\t\t\t\toutcomes.push(state.outcome);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn outcomes;\n\t\t\t\t\t}),\n\t\t\t\t)) as ErasedRuntime[\"outcomes\"],\n\t\t\tconversation: (id, context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.#conversation(\n\t\t\t\t\t\tid,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsignal: invocation.controller.signal,\n\t\t\t\t\t\t\tcheck: () => {\n\t\t\t\t\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\tentry: ((...args: readonly unknown[]) => {\n\t\t\t\tconst [token, id, context] =\n\t\t\t\t\targs.length === 2\n\t\t\t\t\t\t? [undefined, args[0] as EntryId, args[1] as Context]\n\t\t\t\t\t\t: [args[0] as { readonly kind: string }, args[1] as EntryId, args[2] as Context];\n\t\t\t\treturn this.#read(invocation, async () => {\n\t\t\t\t\tconst found = await this.#session.readOnLine(() =>\n\t\t\t\t\t\tthis.#storage.entry(invocation.conversationId, id, context),\n\t\t\t\t\t);\n\t\t\t\t\tconst entry: EntryRecord | undefined = found?.entry;\n\t\t\t\t\treturn token === undefined || entry?.kind === token.kind ? entry : undefined;\n\t\t\t\t});\n\t\t\t}) as ErasedRuntime[\"entry\"],\n\t\t\tcontext: (conversationId, context, options) =>\n\t\t\t\tthis.#read(invocation, async () => {\n\t\t\t\t\tconst { view, range } = await readContextFrom(\n\t\t\t\t\t\tthis.#session,\n\t\t\t\t\t\tthis.#storage,\n\t\t\t\t\t\tconversationId,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\toptions?.at,\n\t\t\t\t\t\tthis.#contexts.get(conversationId)?.range,\n\t\t\t\t\t);\n\t\t\t\t\t// Keep it unless the invocation ended or a concurrent read already kept a newer range.\n\t\t\t\t\tconst kept = this.#contexts.get(conversationId);\n\t\t\t\t\tif (\n\t\t\t\t\t\trange !== undefined &&\n\t\t\t\t\t\t!this.#closing &&\n\t\t\t\t\t\t!invocation.ended &&\n\t\t\t\t\t\t(kept === undefined || kept.range.bounds.tail <= range.bounds.tail)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// A read of another, idle conversation starts or continues its retention period.\n\t\t\t\t\t\tif (!this.#idle(conversationId)) {\n\t\t\t\t\t\t\tthis.#contexts.set(conversationId, { range, idleSince: undefined });\n\t\t\t\t\t\t} else if (this.#contextRetentionMs() > 0) {\n\t\t\t\t\t\t\tthis.#contexts.set(conversationId, { range, idleSince: kept?.idleSince ?? this.#now() });\n\t\t\t\t\t\t\tthis.#scheduleExpiry();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn view;\n\t\t\t\t}),\n\t\t\tnow: () => {\n\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\treturn this.#now();\n\t\t\t},\n\t\t\treport: (error) => {\n\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\tthis.#report(error);\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Run a committed-state read unless the invocation has ended. */\n\tasync #read<T>(invocation: Invocation, read: () => Promise<T>): Promise<T> {\n\t\tif (invocation.ended) throw endedError(invocation);\n\t\treturn read();\n\t}\n\n\t/** Commit after rereading the task on the line and gating the invocation. */\n\t#gated<T>(\n\t\tinvocation: Invocation,\n\t\tchange: (tx: Transaction, current: ErasedRunningTask) => T | Promise<T>,\n\t\tcontext: Context,\n\t): Promise<T> {\n\t\tif (invocation.ended) return Promise.reject(endedError(invocation));\n\t\treturn this.#session.commitWith(\n\t\t\tasync (tx) => {\n\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\tif (this.#closing) throw closedError(this.#session);\n\t\t\t\tconst found = this.#live.get(invocation.taskId);\n\t\t\t\tif (found === undefined) throw new Error(`Task ${invocation.taskId} is terminal`);\n\t\t\t\tif (found.state.status !== \"running\") throw new Error(`Task ${invocation.taskId} is ${found.state.status}`);\n\t\t\t\tconst current = found as ErasedRunningTask;\n\t\t\t\tif (invocation.mode === \"run\" && current.abortRequested) {\n\t\t\t\t\tthrow new Error(`Task ${invocation.taskId} has a durable abort mark`);\n\t\t\t\t}\n\t\t\t\treturn change(tx, current);\n\t\t\t},\n\t\t\tcontext,\n\t\t\t{ conversationId: invocation.conversationId, taskId: invocation.taskId },\n\t\t);\n\t}\n\n\t/** Wait until the Harness clock reaches `until`, rechecking it after every timer. */\n\tasync #sleep(invocation: Invocation, until: number, context: Context): Promise<void> {\n\t\tif (invocation.ended) throw endedError(invocation);\n\t\tconst signals = [invocation.controller.signal];\n\t\tif (context.abortSignal !== undefined) signals.push(context.abortSignal);\n\t\tconst signal = AbortSignal.any(signals);\n\t\tfor (;;) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tconst remaining = until - this.#now();\n\t\t\tif (remaining <= 0) return;\n\t\t\tawait delay(Math.min(remaining, MAX_TIMER_DELAY), signal);\n\t\t}\n\t}\n\n\tasync #watchDoc(invocation: Invocation, args: readonly unknown[]): Promise<DocumentWatch<JsonObject> | undefined> {\n\t\tif (invocation.ended) throw endedError(invocation);\n\t\tconst watch = (await sessionMethod(this.#session, \"watchDoc\")(...args)) as DocumentWatch<JsonObject> | undefined;\n\t\tif (watch === undefined) return undefined;\n\t\tif (invocation.ended) {\n\t\t\tvoid watch.stop();\n\t\t\tthrow endedError(invocation);\n\t\t}\n\t\tinvocation.watches.add(watch);\n\t\tvoid watch.closed.then(() => invocation.watches.delete(watch));\n\t\treturn watch;\n\t}\n}\n\n/** The record with an abort mark: `restart` for an abandonment; without a reason, a request, which replaces `restart`. */\nfunction withAbortMark(record: AnyTaskRecord, reason?: \"restart\"): AnyTaskRecord {\n\tconst { abortReason: _reason, ...rest } = record;\n\treturn { ...rest, abortRequested: true, ...(reason === undefined ? {} : { abortReason: reason }) } as AnyTaskRecord;\n}\n\n/** A live owner's durable cancellation intent: its abort mark, or a held outcome other than `completed`. */\nfunction cancellationIntent(record: AnyTaskRecord): boolean {\n\treturn record.state.status !== \"terminal\" && (record.abortRequested || failedOutcome(record));\n}\n\n/** Whether the record holds or ends with an outcome other than `completed`. */\nfunction failedOutcome(record: AnyTaskRecord): boolean {\n\tconst state = record.state;\n\treturn (state.status === \"completing\" || state.status === \"terminal\") && state.outcome.status !== \"completed\";\n}\n\nfunction parentOf(node: TaskNode): Up {\n\treturn node.owner !== undefined ? { task: node.owner } : { conversation: node.conversationId };\n}\n\nfunction nodeOf(record: AnyTaskRecord): TaskNode {\n\treturn {\n\t\tconversationId: record.conversationId,\n\t\t...(record.owner === undefined ? {} : { owner: record.owner }),\n\t\tbackground: record.background,\n\t};\n}\n\nfunction overlayOf(tx: Transaction): Overlay {\n\tconst tasks = new Map(tx.stagedTasks().map((record) => [record.id, record]));\n\tconst edges = new Map(tx.stagedConversations().map((record) => [record.id, record.owner?.taskId ?? null]));\n\treturn { tasks, edges };\n}\n\nfunction addTo<K, V>(map: Map<K, Set<V>>, key: K, value: V): void {\n\tconst values = map.get(key);\n\tif (values === undefined) map.set(key, new Set([value]));\n\telse values.add(value);\n}\n\nfunction deleteFrom<K, V>(map: Map<K, Set<V>>, key: K, value: V): void {\n\tconst values = map.get(key);\n\tif (values === undefined) return;\n\tvalues.delete(value);\n\tif (values.size === 0) map.delete(key);\n}\n\n/** Own memo entry only; memo names such as `toString` must not resolve to inherited properties. */\nfunction memoOf(record: AnyTaskRecord | undefined, name: string): JsonValue | undefined {\n\tconst memos = record?.memos;\n\treturn memos !== undefined && Object.hasOwn(memos, name) ? memos[name] : undefined;\n}\n\n/** Overloaded Session method bound for forwarding an argument list unchanged. */\nfunction sessionMethod(\n\tsession: SessionImpl,\n\tname: \"snapshot\" | \"snapshotAsOf\" | \"watchDoc\",\n): (...args: readonly unknown[]) => Promise<unknown> {\n\treturn (session[name] as (...args: readonly unknown[]) => Promise<unknown>).bind(session);\n}\n\nfunction missingMigration(record: AnyTaskRecord, definition: ErasedDefinition): Error {\n\treturn new Error(`Task ${record.kind} version ${definition.version} has no migration from ${record.version}`);\n}\n\nfunction erased(task: AnyTask): ErasedDefinition {\n\treturn task.definition as unknown as ErasedDefinition;\n}\n\nfunction endedError(invocation: Invocation): Error {\n\treturn new Error(`Task ${invocation.taskId} invocation has ended`);\n}\n\n/** Replace a live record's state; memos disappear once an outcome is decided. */\nfunction withState(record: AnyTaskRecord, state: TaskState<JsonValue, JsonValue>): AnyTaskRecord {\n\tif (state.status !== \"terminal\" && state.status !== \"completing\") return { ...record, state } as AnyTaskRecord;\n\tconst { memos: _memos, ...rest } = record;\n\treturn { ...rest, state };\n}\n\n/** Whether a definition can take the task at reservation: same version, or newer with a migration. */\nfunction canReserve(task: AnyTask, record: AnyTaskRecord): boolean {\n\tconst definition = task.definition;\n\treturn (\n\t\tdefinition.version === record.version || (definition.version > record.version && definition.migrate !== undefined)\n\t);\n}\n\nfunction delay(ms: number, signal: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst onAbort = (): void => {\n\t\t\tclearTimeout(timer);\n\t\t\treject(signal.reason);\n\t\t};\n\t\tconst timer = setTimeout(() => {\n\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n}\n\n/** Structural equality of two JSON values; object key order is ignored. */\nfunction jsonEqual(left: JsonValue | undefined, right: JsonValue | undefined): boolean {\n\tif (left === right) return true;\n\tif (typeof left !== \"object\" || typeof right !== \"object\" || left === null || right === null) return false;\n\tif (Array.isArray(left) || Array.isArray(right)) {\n\t\tif (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;\n\t\treturn left.every((value, index) => jsonEqual(value, right[index]));\n\t}\n\tconst keys = Object.keys(left);\n\tif (keys.length !== Object.keys(right).length) return false;\n\treturn keys.every((key) => Object.hasOwn(right, key) && jsonEqual(left[key], right[key]));\n}\n"]}
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/harness/scheduler.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,QAAQ,EAAkB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAqB5C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAqB,eAAe,EAAE,MAAM,cAAc,CAAC;AAYlE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAa1D,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,gFAAgF;AAChF,MAAM,eAAe,GAAG,aAAa,CAAC;AACtC,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,CAAU,CAAC;AAgF/E,SAAS,gBAAgB,CAAC,EAAkB;IAC3C,OAAO,IAAI,EAAE,EAAE,CAAC;AACjB,CAAC;AAED,SAAS,cAAc,CAAC,IAAkB;IACzC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAmB,CAAC;AAChD,CAAC;AAED,uEAAuE;AACvE,SAAS,UAAU,CAAC,IAAc;IACjC,OAAO,IAAI,CAAC,KAAK,IAAI,gBAAgB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAC5D,CAAC;AAgCD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,aAAa;IAChB,QAAQ,CAAc;IACtB,QAAQ,CAAU;IAClB,SAAS,CAAiB;IAC1B,OAAO,CAAe;IACtB,MAAM,CAAgC;IACtC,SAAS,CAAmC;IAC5C,IAAI,CAA8B;IAClC,IAAI,CAAe;IACnB,OAAO,CAA2B;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AAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC5D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import type { ModelRuntime } from \"@ny4n/ai/contracts\";\nimport { type Context, copyJson, type JsonValue } from \"@ny4n/chord\";\nimport { awaitWithContext, withAbortSignal } from \"@ny4n/chord/context\";\nimport type { ExecutionEnv } from \"../env/index.ts\";\nimport { errorMessage } from \"../errors.ts\";\nimport type { SessionImpl } from \"../session/session.ts\";\nimport type { Transaction } from \"../session/transaction.ts\";\nimport type {\n\tCommitPublication,\n\tConversationId,\n\tDocumentWatch,\n\tEntryId,\n\tEntryRecord,\n\tHookRunner,\n\tJsonObject,\n\tNextTaskState,\n\tRunningTask,\n\tStorage,\n\tTaskDefinition,\n\tTaskId,\n\tTaskOutcome,\n\tTaskRecord,\n\tTaskRuntime,\n\tTaskState,\n} from \"../types.ts\";\nimport { agentHooks } from \"./agent.ts\";\nimport { type ContextRange, readContextFrom } from \"./context.ts\";\nimport type {\n\tAgent,\n\tAnyTask,\n\tConversationHandle,\n\tHarnessInspection,\n\tRegistryReader,\n\tRegistrySnapshot,\n\tSettings,\n\tSettledTask,\n\tTaskInspection,\n} from \"./types.ts\";\nimport { closedError, scanAll, Waiters } from \"./util.ts\";\n\ntype AnyTaskRecord = TaskRecord<JsonValue, JsonValue, JsonValue>;\n/** A record that can still run code: pending, running, or waiting. */\ntype RunnableTaskRecord = Extract<\n\tAnyTaskRecord,\n\t{ readonly state: { readonly status: \"pending\" | \"running\" | \"waiting\" } }\n>;\ntype Checkpoint = { readonly phase: string };\ntype ErasedDefinition = TaskDefinition<JsonValue, Checkpoint, JsonValue, object>;\ntype ErasedRuntime = TaskRuntime<JsonValue, Checkpoint, JsonValue, object>;\ntype ErasedRunningTask = RunningTask<JsonValue, Checkpoint, JsonValue>;\n\nconst SCAN_PAGE_SIZE = 256;\n/** Longest delay `setTimeout` supports; longer sleeps wait in several steps. */\nconst MAX_TIMER_DELAY = 2_147_483_647;\nconst LIVE_STATUSES = [\"pending\", \"running\", \"waiting\", \"completing\"] as const;\n\n/** Why a pending task cannot be reserved under a registry snapshot. Derived, never persisted. */\ntype BlockedReason = \"missing_task\" | \"task_too_old\" | \"migration_failed\";\n\ntype Resolution =\n\t| { readonly kind: \"ready\"; readonly task: AnyTask; readonly record: RunnableTaskRecord }\n\t| { readonly kind: \"blocked\"; readonly reason: BlockedReason };\n\n/** A definition that can take a record, or why none can; deciding it runs no task code. */\ntype Fit =\n\t| { readonly task: AnyTask; readonly migrates: boolean }\n\t| { readonly reason: BlockedReason; readonly error?: unknown };\n\n/** One in-memory execution of a task in run or abort mode. */\ntype Invocation = {\n\treadonly taskId: TaskId;\n\treadonly conversationId: ConversationId;\n\treadonly mode: \"run\" | \"abort\";\n\treadonly controller: AbortController;\n\t/** Context passed to handlers; cancelled by `controller`. */\n\treadonly context: Context;\n\t/** Watches acquired through the runtime; stopped at invocation end. */\n\treadonly watches: Set<DocumentWatch<JsonObject>>;\n\tended: boolean;\n\treadonly done: Promise<void>;\n\treadonly finish: () => void;\n};\n\n/** What a runtime reads for the phase handler it serves: the phase's snapshot and task, and its lazily resolved agent. */\ntype Phase = {\n\treadonly snapshot: () => RegistrySnapshot;\n\treadonly task: () => AnyTask;\n\tagent: Promise<Agent> | undefined;\n};\n\ntype Reservation = {\n\treadonly invocation: Invocation;\n\treadonly task: AnyTask;\n\treadonly snapshot: RegistrySnapshot;\n};\n\n/** Replacement definition already reported as unable to take over, per invocation. */\ntype ReportedTask = { readonly task: AnyTask | undefined } | undefined;\n\n/** Outcome of the phase that just returned, judged by the next step. */\ntype PhaseResult = { readonly checkpoint: Checkpoint; readonly failure?: { readonly error: unknown } };\n\n/** Step decision: continue with the next phase, end the invocation, or end it by writing `faulted`. */\ntype Decision = boolean | { readonly fault: unknown };\n\n/** Terminal outcomes the scheduler writes without running task code. */\nexport type SchedulerOutcome = Extract<TaskOutcome<JsonValue>, { readonly status: \"faulted\" | \"orphaned\" }>;\n\n/** An invocation a conversation handle is bound to: its signal, and a check that throws once it ended. */\nexport type InvocationBinding = { readonly signal: AbortSignal; check(): void };\n\n/** The immutable ownership fields of a task. */\ntype TaskNode = Pick<AnyTaskRecord, \"conversationId\" | \"owner\" | \"background\">;\n\n/** Where a walk up the ownership tree continues: an owner task, or a conversation. */\ntype Up = { readonly task: TaskId } | { readonly conversation: ConversationId };\n\n/** One step of a walk up: an owner task with its node, a conversation, or an owner edge that is not loaded yet. */\ntype Step =\n\t| { readonly task: TaskId; readonly node: TaskNode }\n\t| { readonly conversation: ConversationId }\n\t| { readonly unknown: true };\n\n/** Candidate records a commit staged; they override committed records in ownership walks. */\ntype Overlay = {\n\treadonly tasks: ReadonlyMap<TaskId, AnyTaskRecord>;\n\treadonly edges: ReadonlyMap<ConversationId, TaskId | null>;\n\t/** Links to the staged tasks `#below` does not list, by parent node, for walks down; built at first use. */\n\tlinks?: ReadonlyMap<Node, ReadonlySet<Node>>;\n};\n\n/** A node of the downward index: a task, or a conversation as `c<id>`. */\ntype Node = TaskId | `c${number}`;\n\nfunction conversationNode(id: ConversationId): Node {\n\treturn `c${id}`;\n}\n\nfunction conversationOf(node: `c${number}`): ConversationId {\n\treturn Number(node.slice(1)) as ConversationId;\n}\n\n/** The node a task hangs from: its owner task, or its conversation. */\nfunction parentNode(node: TaskNode): Node {\n\treturn node.owner ?? conversationNode(node.conversationId);\n}\n\n/** Where ordinary ownership traversal starts: one conversation, or every ownerless conversation. */\ntype Scope = { readonly conversation: ConversationId } | { readonly roots: true };\n\nexport type TaskSchedulerOptions = {\n\treadonly session: SessionImpl;\n\treadonly storage: Storage;\n\treadonly registry: RegistryReader;\n\treadonly models: ModelRuntime;\n\t/** Resolve a conversation's agent against a snapshot; the runtime calls it at most once per phase. */\n\treadonly agent: (conversationId: ConversationId, snapshot: RegistrySnapshot, context: Context) => Promise<Agent>;\n\t/** Resolve the settings; read at each access. */\n\treadonly settings: () => Settings;\n\t/** Build a conversation's environment with `HarnessOptions.env`. */\n\treadonly env: (conversationId: ConversationId, context: Context) => Promise<ExecutionEnv | undefined>;\n\treadonly now: () => number;\n\treadonly report: (error: unknown) => void;\n\t/** Harness cleanup staged in the commit that makes an outcome the scheduler wrote itself terminal. */\n\treadonly settleOutcome: (tx: Transaction, record: AnyTaskRecord, outcome: SchedulerOutcome) => Promise<void>;\n\t/** Withdraw a conversation's queued inputs, for conversation abort and abort cascades. */\n\treadonly withdrawInputs: (tx: Transaction, conversationId: ConversationId) => Promise<void>;\n\t/** Invocation-bound handle of an existing conversation, for task runtimes and tools. */\n\treadonly conversation: (\n\t\tid: ConversationId,\n\t\tbinding: InvocationBinding,\n\t\tcontext: Context,\n\t) => Promise<ConversationHandle | undefined>;\n\t/** Context for scheduler commits and invocations; carries no caller cancellation. */\n\treadonly context: Context;\n};\n\n/**\n * Durable task scheduler of one Harness.\n *\n * `#live` mirrors every committed non-terminal task record: pending, running, waiting, and completing. The synchronous\n * commit listener updates it on the Session line, so code running on the line reads exactly the committed state from it.\n *\n * Tasks and conversations form one ownership tree (spec §5.5): a task's parent is its owner task, or its conversation;\n * a conversation's parent is its owner task, if any. Walks up that tree decide what reaches one task: a cancelling\n * owner, a scope. `#below` lists the tree downward around live work, so what lies below one node is a walk down from\n * it: a task's live ordinary owned work, which holds its outcome as `completing` and delays its abort handler, a\n * scope's tasks, a cascade's reach. No pass visits every live task; the sets below hold each pass's candidates.\n *\n * The ownership indexes are bounded by live work: an owner edge and an ended task's ownership fields are kept only while\n * something is listed below them in `#below`, so only the chains above live tasks are known, whole. Work that appears\n * later below a dropped node finds it unknown and loads its chain from storage again.\n *\n * Invariant: every task transition is decided and written by one callback serialized on the Session line. That covers\n * reservation, marks, runtime commits, finalization, and the synchronous step before each phase, which applies the\n * precedence rules and writes a fault or handover. Handlers and joins run off the line. An invocation ends inside the\n * step that decides its end, so a runtime commit it queued either lands before that decision or is rejected.\n */\nexport class TaskScheduler {\n\treadonly #session: SessionImpl;\n\treadonly #storage: Storage;\n\treadonly #registry: RegistryReader;\n\treadonly #models: ModelRuntime;\n\treadonly #agent: TaskSchedulerOptions[\"agent\"];\n\treadonly #settings: TaskSchedulerOptions[\"settings\"];\n\treadonly #env: TaskSchedulerOptions[\"env\"];\n\treadonly #now: () => number;\n\treadonly #report: (error: unknown) => void;\n\treadonly #settleOutcome: TaskSchedulerOptions[\"settleOutcome\"];\n\treadonly #withdrawInputs: TaskSchedulerOptions[\"withdrawInputs\"];\n\treadonly #conversation: TaskSchedulerOptions[\"conversation\"];\n\treadonly #context: Context;\n\treadonly #live = new Map<TaskId, AnyTaskRecord>();\n\t/**\n\t * Context range last read through a task runtime, per conversation: a later read, by any of its tasks, scans only\n\t * newer entries. `idleSince` is the Harness time it was first seen idle. Derived and never persisted; dropped at the\n\t * first idle check after `settings.contextRetentionMs` of idleness, and at close.\n\t */\n\treadonly #contexts = new Map<ConversationId, { range: ContextRange; idleSince: number | undefined }>();\n\t/** Timer for the earliest expiry of an idle context, only where timers can be unreferenced (see `#scheduleExpiry`). */\n\t#expiry: { readonly at: number; readonly timer: ReturnType<typeof setTimeout> } | undefined;\n\treadonly #invocations = new Map<TaskId, Invocation>();\n\treadonly #taskWaiters = new Waiters<TaskId, SettledTask<JsonValue>>();\n\t/** Idle waiters by conversation; `undefined` waits for the whole Harness. */\n\treadonly #idleWaiters = new Waiters<ConversationId | undefined, void>();\n\t/** Definition whose migration failed per task; retried only once the registry resolves another definition. */\n\treadonly #failedMigrations = new Map<TaskId, { readonly task: AnyTask; readonly error: unknown }>();\n\t/** Owner task of each known conversation, `null` when ownerless. */\n\treadonly #edges = new Map<ConversationId, TaskId | null>();\n\t/** Ownership fields of the known terminal tasks, which walks pass through. */\n\treadonly #settled = new Map<TaskId, TaskNode>();\n\t/**\n\t * Ended tasks and conversations found unneeded, dropped by `#sweep()` at the end of the commit's publication unless\n\t * needed again by then: a chain load installs nodes before the work below them is listed.\n\t */\n\treadonly #dropQueue = new Set<Node>();\n\t/**\n\t * The tree downward around live work: each node's child nodes that are live tasks or have nodes listed below them.\n\t * A conversation's parent is its owner task; ownerless ones with work are in `#roots`.\n\t */\n\treadonly #below = new Map<Node, Set<Node>>();\n\treadonly #roots = new Set<ConversationId>();\n\t/** Known tasks whose chain may not be loaded; every other known task's chain is, and stays, loaded. */\n\treadonly #unloaded = new Set<TaskId>();\n\t/** Live tasks with cancellation intent, the sources of abort cascades (spec §5.4). */\n\treadonly #intent = new Set<TaskId>();\n\t/** Live tasks that are not `completing`, the candidates of a reservation pass; ones found waiting leave it. */\n\treadonly #runnable = new Set<TaskId>();\n\t/** `completing` tasks the next finalize pass checks: those that started holding, and holders of ended work. */\n\treadonly #finalizeChecks = new Set<TaskId>();\n\t/** Live waiting tasks by each task in their `on`. */\n\treadonly #waiters = new Map<TaskId, Set<TaskId>>();\n\t/**\n\t * `failFast` waiters the next reconcile checks for a failed task in `on`: at open, when they start waiting, and when\n\t * one of their tasks fails.\n\t */\n\treadonly #failFastChecks = new Set<TaskId>();\n\t/**\n\t * Live tasks with `abandonOnRestart` found at open, from an earlier Harness. The first reservation pass abort-marks\n\t * them with reason `restart`, so nothing of them or below them runs a phase again.\n\t */\n\treadonly #abandoned = new Set<TaskId>();\n\t#reconcileScheduled = false;\n\t#sweepScheduled = false;\n\t#cascadePending = false;\n\t#unsubscribeRegistry: () => void = () => {};\n\t#enabled = false;\n\t#closing = false;\n\t#dirty = false;\n\t#draining = false;\n\n\tconstructor(options: TaskSchedulerOptions) {\n\t\tthis.#session = options.session;\n\t\tthis.#storage = options.storage;\n\t\tthis.#registry = options.registry;\n\t\tthis.#models = options.models;\n\t\tthis.#agent = options.agent;\n\t\tthis.#settings = options.settings;\n\t\tthis.#env = options.env;\n\t\tthis.#now = options.now;\n\t\tthis.#report = options.report;\n\t\tthis.#settleOutcome = options.settleOutcome;\n\t\tthis.#withdrawInputs = options.withdrawInputs;\n\t\tthis.#conversation = options.conversation;\n\t\tthis.#context = options.context;\n\t}\n\n\t/** Load live tasks and change surviving `running` tasks back to `pending`. Dispatches nothing. */\n\tasync open(context: Context): Promise<void> {\n\t\tthis.#session.observeCommits((publication) => this.#observe(publication));\n\t\tthis.#session.subscribeClose(() => this.#seal());\n\t\tthis.#unsubscribeRegistry = this.#registry.subscribe(() => this.#kick());\n\t\tawait this.#session.commitWith(async (tx) => {\n\t\t\t// Every table read before the first write.\n\t\t\tconst scans = [];\n\t\t\tfor (const status of LIVE_STATUSES) {\n\t\t\t\tscans.push(await scanAll((cursor) => tx.scanTasks({ status }, SCAN_PAGE_SIZE, cursor)));\n\t\t\t}\n\t\t\tfor (const records of scans) {\n\t\t\t\tfor (const record of records) {\n\t\t\t\t\tthis.#track(undefined, record);\n\t\t\t\t\tif (record.abandonOnRestart === true) this.#abandoned.add(record.id);\n\t\t\t\t\tif (record.state.status === \"running\") {\n\t\t\t\t\t\ttx.setTask(withState(record, { status: \"pending\", checkpoint: record.state.checkpoint }));\n\t\t\t\t\t}\n\t\t\t\t\tif (record.state.status === \"waiting\" && record.state.policy === \"failFast\") {\n\t\t\t\t\t\tthis.#failFastChecks.add(record.id);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}, context);\n\t\t// Derive abort marks a crash left unapplied below cancelled owners, and finalize held outcomes.\n\t\tthis.#cascadePending = true;\n\t\tthis.#scheduleReconcile();\n\t}\n\n\t/** Enable scheduling. Idempotent; the kick does nothing once closing. */\n\tresume(): void {\n\t\tthis.#enabled = true;\n\t\tthis.#kick();\n\t}\n\n\t/**\n\t * Signal every invocation and wait for them; writes nothing. Close calls this after every close listener has run, so\n\t * waits, watches, and streams a task holds end with the Session's reason, not as cancelled by its signal.\n\t */\n\tasync join(): Promise<void> {\n\t\tfor (const invocation of this.#invocations.values()) invocation.controller.abort();\n\t\tawait Promise.allSettled([...this.#invocations.values()].map((invocation) => invocation.done));\n\t}\n\n\t/**\n\t * Commit the abort mark, or settle a task that no registered definition can take as `orphaned` when nothing it owns\n\t * is live, then join the run invocation seen on the line; the commit listener signalled it. The abort invocation\n\t * starts once the task's ordinary owned work is gone. A `completing` task is only marked. A request replaces a\n\t * `restart` mark, so a task abandoned after a restart that waits for its definition is orphaned; with `keepRestart`,\n\t * as for an owner's own cleanup, such a task keeps its mark and waits on.\n\t */\n\tasync abort(id: TaskId, context: Context, keepRestart = false): Promise<\"marked\" | \"terminal\"> {\n\t\tconst marked = await this.#session.commitWith(async (tx) => {\n\t\t\tconst current = await tx.task(id);\n\t\t\tif (current === undefined) throw new Error(`Task ${id} does not exist`);\n\t\t\tif (current.state.status === \"terminal\") return { result: \"terminal\" as const };\n\t\t\tconst invocation = this.#invocations.get(id);\n\t\t\t// A restart-marked task has no run invocation; it only waits for its abort.\n\t\t\tif (keepRestart && current.abortReason === \"restart\") return { result: \"marked\" as const };\n\t\t\tif (invocation === undefined && current.state.status !== \"completing\") {\n\t\t\t\tawait this.#loadScopes(false);\n\t\t\t\tif (!this.#hasOwnedLive(id)) {\n\t\t\t\t\tconst resolution = this.#resolve(current as RunnableTaskRecord, this.#registry.snapshot());\n\t\t\t\t\tif (resolution.kind === \"blocked\") {\n\t\t\t\t\t\tawait this.#terminate(tx, current, { status: \"orphaned\", reason: resolution.reason });\n\t\t\t\t\t\treturn { result: \"marked\" as const };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!current.abortRequested || current.abortReason !== undefined) tx.setTask(withAbortMark(current));\n\t\t\treturn { result: \"marked\" as const, run: invocation?.mode === \"run\" ? invocation : undefined };\n\t\t}, context);\n\t\t// The commit listener signalled the run; join it. A run that ignores its signal can outlive a failed Session,\n\t\t// which ends the wait instead.\n\t\tif (marked.run !== undefined) {\n\t\t\tawait awaitWithContext(Promise.race([marked.run.done, this.#session.failed]), context);\n\t\t}\n\t\treturn marked.result;\n\t}\n\n\tasync waitForTask(id: TaskId, context: Context): Promise<SettledTask<JsonValue>> {\n\t\t// Check and register on the line so no terminal publication falls between them.\n\t\tconst found = await this.#session.readOnLine(async () => {\n\t\t\tif (this.#closing) throw closedError(this.#session);\n\t\t\tif (this.#live.has(id)) return { promise: this.#taskWaiters.add(id, context) };\n\t\t\tconst record = await this.#storage.task(id, context);\n\t\t\tif (record === undefined) throw new Error(`Task ${id} does not exist`);\n\t\t\treturn { promise: Promise.resolve(record as SettledTask<JsonValue>) };\n\t\t});\n\t\treturn found.promise;\n\t}\n\n\t/**\n\t * Resolve when ordinary traversal from the conversation, or from every ownerless conversation, reaches no live\n\t * non-background task.\n\t */\n\twaitForIdle(conversationId: ConversationId | undefined, context: Context): Promise<void> {\n\t\tif (this.#closing) return Promise.reject(closedError(this.#session));\n\t\tif (this.#idle(conversationId)) return Promise.resolve();\n\t\tthis.#scheduleReconcile();\n\t\treturn this.#idleWaiters.add(conversationId, context);\n\t}\n\n\t/**\n\t * `Conversation.abort()`: in one commit, withdraw the queued inputs and mark every live non-background task that\n\t * ordinary traversal from the conversation reaches; resolves once the scope is idle. With `background`, traversal\n\t * crosses background boundaries, and the wait also covers every task it reached.\n\t */\n\tasync abortConversation(conversationId: ConversationId, background: boolean, context: Context): Promise<void> {\n\t\tconst reached = await this.#session.commitWith(async (tx) => {\n\t\t\tconst queued = await this.#loadScopes(true);\n\t\t\tconst scope = { conversation: conversationId };\n\t\t\tconst reached: TaskId[] = [];\n\t\t\tconst walk = this.#walkDown(conversationNode(conversationId), { crossBackground: background });\n\t\t\tfor (const { node, live } of walk) {\n\t\t\t\tif (live === undefined || (node.background && !background)) continue;\n\t\t\t\treached.push(live.id);\n\t\t\t\tif (!live.abortRequested || live.abortReason !== undefined) tx.setTask(withAbortMark(live));\n\t\t\t}\n\t\t\tfor (const id of queued) {\n\t\t\t\tif (this.#inScope({ conversation: id }, scope, background) === true) await this.#withdrawInputs(tx, id);\n\t\t\t}\n\t\t\treturn reached;\n\t\t}, context);\n\t\tif (background) for (const id of reached) await this.waitForTask(id, context);\n\t\tawait this.waitForIdle(conversationId, context);\n\t}\n\n\t// ─── Scheduling ────────────────────────────────────────────────────────\n\n\t#observe(publication: CommitPublication): void {\n\t\tconst updated: AnyTaskRecord[] = [];\n\t\tconst failed: TaskId[] = [];\n\t\tlet changed = false;\n\t\t// Edges first, so the tasks a commit creates in a new conversation hang from it.\n\t\tfor (const change of publication.changes) {\n\t\t\tif (change.type === \"conversation\" && !this.#edges.has(change.value.id)) {\n\t\t\t\tthis.#setEdge(change.value.id, change.value.owner?.taskId ?? null);\n\t\t\t}\n\t\t}\n\t\tfor (const change of publication.changes) {\n\t\t\tif (change.type !== \"task\") continue;\n\t\t\tchanged = true;\n\t\t\tconst record = change.value;\n\t\t\tconst previous = this.#live.get(record.id);\n\t\t\tif (failedOutcome(record) && (previous === undefined || !failedOutcome(previous))) failed.push(record.id);\n\t\t\tthis.#track(previous, record);\n\t\t\tif (record.state.status === \"terminal\") {\n\t\t\t\tthis.#failedMigrations.delete(record.id);\n\t\t\t\tthis.#failFastChecks.delete(record.id);\n\t\t\t\tthis.#taskWaiters.resolve(record.id, record as SettledTask<JsonValue>);\n\t\t\t\t// Its owner may finalize now.\n\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (record.abortRequested && previous?.abortRequested !== true) {\n\t\t\t\tthis.#cascadePending = true;\n\t\t\t\t// Signal a run invocation of the newly marked task; its next step ends it.\n\t\t\t\tconst invocation = this.#invocations.get(record.id);\n\t\t\t\tif (invocation?.mode === \"run\") invocation.controller.abort();\n\t\t\t}\n\t\t\t// A request replacing a `restart` mark upgrades the marks of the work below.\n\t\t\tif (previous?.abortReason !== undefined && record.abortReason === undefined) this.#cascadePending = true;\n\t\t\tconst status = record.state.status;\n\t\t\tif (status === \"completing\" && previous?.state.status !== \"completing\") {\n\t\t\t\tif (cancellationIntent(record)) this.#cascadePending = true;\n\t\t\t\tthis.#scheduleReconcile();\n\t\t\t}\n\t\t\tif (status === \"waiting\" && record.state.policy === \"failFast\" && previous?.state.status !== \"waiting\") {\n\t\t\t\tthis.#failFastChecks.add(record.id);\n\t\t\t\tthis.#scheduleReconcile();\n\t\t\t}\n\t\t\t// Its owners and place never change: what is above it is checked once, when it becomes live.\n\t\t\tif (previous === undefined) updated.push(record);\n\t\t}\n\t\tfor (const id of failed) {\n\t\t\tfor (const waiter of this.#waiters.get(id) ?? []) {\n\t\t\t\tconst state = this.#live.get(waiter)?.state;\n\t\t\t\tif (state?.status === \"waiting\" && state.policy === \"failFast\") {\n\t\t\t\t\tthis.#failFastChecks.add(waiter);\n\t\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const change of publication.changes) {\n\t\t\t// A queued input below a cancelled owner is withdrawn, even after its cascade.\n\t\t\tif (change.type !== \"submission\" || change.value.status !== \"queued\" || change.value.type !== \"input\")\n\t\t\t\tcontinue;\n\t\t\t// Only an owner with cancellation intent withdraws it; a later intent's mark runs the cascade then.\n\t\t\tif (this.#intent.size === 0) continue;\n\t\t\tconst conversation = change.value.conversationId;\n\t\t\tif (!this.#known(conversationNode(conversation)) || this.#belowCancelled({ conversation })) {\n\t\t\t\tthis.#cascadePending = true;\n\t\t\t}\n\t\t}\n\t\tfor (const record of updated) {\n\t\t\t// Work created below a cancelled owner, even after its cascade, is aborted too.\n\t\t\tif (this.#unloaded.has(record.id)) this.#scheduleReconcile();\n\t\t\telse if (!record.background && !record.abortRequested && this.#belowCancelled(parentOf(record))) {\n\t\t\t\tthis.#cascadePending = true;\n\t\t\t}\n\t\t}\n\t\t// A cascade that a reservation or step found pending runs with the next commit of any kind.\n\t\tif (this.#cascadePending) this.#scheduleReconcile();\n\t\tthis.#sweep();\n\t\tif (!changed) return;\n\t\tthis.#settleIdle();\n\t\tthis.#kick();\n\t}\n\n\t/**\n\t * `settings.contextRetentionMs`, or 0 when the host's settings throw. Kept contexts are only a cache, so dropping them\n\t * is safe, while a throw here would escape commit listeners, reconciliation, and the expiry timer.\n\t */\n\t#contextRetentionMs(): number {\n\t\ttry {\n\t\t\treturn this.#settings().contextRetentionMs;\n\t\t} catch (error) {\n\t\t\tthis.#report(error);\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\t/** Resolve idle waiters, and drop each kept context whose conversation has been idle for the retention period. */\n\t#settleIdle(): void {\n\t\tfor (const conversationId of this.#idleWaiters.keys()) {\n\t\t\tif (this.#idle(conversationId)) this.#idleWaiters.resolve(conversationId);\n\t\t}\n\t\tconst now = this.#now();\n\t\tconst retention = this.#contextRetentionMs();\n\t\tfor (const [conversationId, kept] of this.#contexts) {\n\t\t\tif (kept.idleSince !== undefined && now - kept.idleSince >= retention) {\n\t\t\t\tthis.#contexts.delete(conversationId);\n\t\t\t} else if (!this.#idle(conversationId)) {\n\t\t\t\tkept.idleSince = undefined;\n\t\t\t} else if (retention > 0) {\n\t\t\t\tkept.idleSince ??= now;\n\t\t\t} else {\n\t\t\t\tthis.#contexts.delete(conversationId);\n\t\t\t}\n\t\t}\n\t\tthis.#scheduleExpiry();\n\t}\n\n\t/**\n\t * Run `#settleIdle()` when the earliest idle context expires. The timer is unreferenced, so it never keeps the process\n\t * alive. Where timers cannot be unreferenced, as in Cloudflare Workers, none is kept: a pending timer could keep a\n\t * Durable Object from being evicted, and eviction frees the contexts. There, task changes alone check expiry.\n\t */\n\t#scheduleExpiry(): void {\n\t\tconst retention = this.#contextRetentionMs();\n\t\tlet at: number | undefined;\n\t\tfor (const kept of this.#contexts.values()) {\n\t\t\tif (kept.idleSince !== undefined && (at === undefined || kept.idleSince + retention < at)) {\n\t\t\t\tat = kept.idleSince + retention;\n\t\t\t}\n\t\t}\n\t\tif (this.#expiry !== undefined && this.#expiry.at === at) return;\n\t\tif (this.#expiry !== undefined) clearTimeout(this.#expiry.timer);\n\t\tthis.#expiry = undefined;\n\t\tif (at === undefined || this.#closing) return;\n\t\tconst timer = setTimeout(\n\t\t\t() => {\n\t\t\t\tthis.#expiry = undefined;\n\t\t\t\tthis.#settleIdle();\n\t\t\t},\n\t\t\tMath.min(Math.max(0, at - this.#now()), MAX_TIMER_DELAY),\n\t\t);\n\t\tconst unref = (timer as { unref?: unknown }).unref;\n\t\tif (typeof unref !== \"function\") {\n\t\t\tclearTimeout(timer);\n\t\t\treturn;\n\t\t}\n\t\tunref.call(timer);\n\t\tthis.#expiry = { at, timer };\n\t}\n\n\t// ─── Ownership ───────────────────────────────────────────────────────────\n\n\t#scheduleReconcile(): void {\n\t\tif (this.#reconcileScheduled || this.#closing) return;\n\t\tthis.#reconcileScheduled = true;\n\t\tqueueMicrotask(() => void this.#reconcile());\n\t}\n\n\t/**\n\t * One commit that applies what committed records imply: abort marks below live owners with cancellation intent\n\t * (spec §5.4), `failFast` marks (spec §5.5), withdrawn queued inputs below cancelled owners, and the final terminal\n\t * record of every `completing` task whose ordinary owned work is gone. The durable records are the intent, so this\n\t * also repairs whatever a crash left unapplied. Resolves idle waiters that the loaded edges decide.\n\t */\n\tasync #reconcile(): Promise<void> {\n\t\tthis.#reconcileScheduled = false;\n\t\tconst cascade = this.#cascadePending;\n\t\tthis.#cascadePending = false;\n\t\tconst checks = [...this.#failFastChecks];\n\t\tthis.#failFastChecks.clear();\n\t\ttry {\n\t\t\tawait this.#session.commitWith(async (tx) => {\n\t\t\t\tif (this.#closing) return;\n\t\t\t\tconst queued = await this.#loadScopes(cascade);\n\t\t\t\t// A cascade from an abandoned owner passes its `restart` reason on; any other intent marks, or upgrades a\n\t\t\t\t// `restart` mark, as a request. Collected first, so a request wins over a `restart` mark of the same pass.\n\t\t\t\tconst marks = new Map<TaskId, { readonly record: AnyTaskRecord; readonly reason: \"restart\" | undefined }>();\n\t\t\t\tconst mark = (record: AnyTaskRecord, reason: \"restart\" | undefined): void => {\n\t\t\t\t\tconst staged = marks.get(record.id);\n\t\t\t\t\tif (staged !== undefined && staged.reason === undefined) return;\n\t\t\t\t\tif (record.abortRequested && (record.abortReason === undefined || reason !== undefined)) return;\n\t\t\t\t\tmarks.set(record.id, { record, reason });\n\t\t\t\t};\n\t\t\t\t// Every live foreground task below a live owner with cancellation intent, which is its nearest one: a walk down\n\t\t\t\t// from each owner with intent does not enter another, whose own walk covers what is below it. Derived again on\n\t\t\t\t// every pass, as loading edges can reveal a cancelled owner.\n\t\t\t\tfor (const id of this.#intent) {\n\t\t\t\t\tconst owner = this.#live.get(id)!;\n\t\t\t\t\t// Only an owner abandoned after a restart, and nothing else, passes its reason on.\n\t\t\t\t\tconst restart = owner.abortReason === \"restart\" && !failedOutcome(owner);\n\t\t\t\t\tfor (const { node, live } of this.#walkDown(id, { enter: (below) => !this.#intent.has(below) })) {\n\t\t\t\t\t\tif (live !== undefined && !node.background) mark(live, restart ? \"restart\" : undefined);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const id of checks) {\n\t\t\t\t\tconst waiter = this.#live.get(id);\n\t\t\t\t\tif (waiter?.state.status !== \"waiting\" || !(await this.#anyFailed(waiter.state.on))) continue;\n\t\t\t\t\t// Every other live task: the failed one keeps its own outcome.\n\t\t\t\t\tfor (const member of waiter.state.on) {\n\t\t\t\t\t\tconst record = this.#live.get(member);\n\t\t\t\t\t\tif (record !== undefined && !failedOutcome(record)) mark(record, undefined);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const { record, reason } of marks.values()) tx.setTask(withAbortMark(record, reason));\n\t\t\t\tfor (const id of queued) if (this.#belowCancelled({ conversation: id })) await this.#withdrawInputs(tx, id);\n\t\t\t\tawait this.#finalize(tx);\n\t\t\t}, this.#context);\n\t\t} catch (error) {\n\t\t\t// No extension code runs in this commit: a throw is a storage failure, a host callback, or a bug. None is fixed by\n\t\t\t// running the pass again, so it fails the Session, which reports it.\n\t\t\tthis.#failSession(error);\n\t\t}\n\t\tthis.#settleIdle();\n\t}\n\n\t/** Whether any of `ids` holds or ended with an outcome other than `completed`. */\n\tasync #anyFailed(ids: readonly TaskId[]): Promise<boolean> {\n\t\tfor (const id of ids) {\n\t\t\tconst record = this.#live.get(id) ?? (await this.#storage.task(id, this.#context));\n\t\t\tif (record !== undefined && failedOutcome(record)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Write the terminal record of every `completing` task without live ordinary owned work. Finalizing one can free its\n\t * owner, so this repeats over the commit's candidates until nothing changes. A held scheduler outcome gets its\n\t * Harness cleanup here.\n\t */\n\tasync #finalize(tx: Transaction): Promise<void> {\n\t\t// A worklist: the tasks that started holding, and the holders of work that ended. Finalizing one can free the\n\t\t// nearest live task above it, which goes on the list. Tasks finalized here have no live work below them, so walks\n\t\t// down skip them.\n\t\t// In rounds: the holders the tasks of one round free are checked once, in the next, so a holder of many tasks that\n\t\t// end together is walked once, not once per task.\n\t\tlet round = [...this.#finalizeChecks];\n\t\tthis.#finalizeChecks.clear();\n\t\tconst done = new Set<TaskId>();\n\t\tconst overlay = overlayOf(tx);\n\t\twhile (round.length > 0) {\n\t\t\tconst next = new Set<TaskId>();\n\t\t\tfor (const id of round) {\n\t\t\t\tconst record = overlay.tasks.get(id) ?? this.#live.get(id);\n\t\t\t\tif (record?.state.status !== \"completing\" || done.has(id)) continue;\n\t\t\t\tif (this.#hasOwnedLive(id, overlay, done)) continue;\n\t\t\t\tconst outcome = record.state.outcome;\n\t\t\t\tconst terminal = withState(record, { status: \"terminal\", outcome });\n\t\t\t\ttx.setTask(terminal);\n\t\t\t\t(overlay.tasks as Map<TaskId, AnyTaskRecord>).set(id, terminal);\n\t\t\t\tdone.add(id);\n\t\t\t\t// REMINDER: only the scheduler writes `faulted` and `orphaned` (spec §5.4); their cleanup waits for this commit.\n\t\t\t\tif (outcome.status === \"faulted\" || outcome.status === \"orphaned\") {\n\t\t\t\t\tawait this.#settleOutcome(tx, record, outcome);\n\t\t\t\t}\n\t\t\t\tconst above = this.#nearestLiveAbove(record, overlay);\n\t\t\t\tif (above?.state.status === \"completing\") next.add(above.id);\n\t\t\t}\n\t\t\tround = [...next];\n\t\t}\n\t}\n\n\t/**\n\t * Load the owner chains of the tasks in `#unloaded` and, with `queued`, of every conversation with queued inputs,\n\t * on the Session line; returns the latter. Reads committed Storage directly, so it may run inside a commit callback.\n\t */\n\tasync #loadScopes(queued: boolean): Promise<ConversationId[]> {\n\t\tfor (const id of [...this.#unloaded]) {\n\t\t\t// An earlier load in this loop may have passed it.\n\t\t\tif (this.#unloaded.has(id)) await this.#loadChain({ task: id });\n\t\t}\n\t\tif (!queued) return [];\n\t\tconst submissions = await scanAll((cursor) =>\n\t\t\tthis.#storage.scanSubmissions({ status: \"queued\" }, SCAN_PAGE_SIZE, cursor, this.#context),\n\t\t);\n\t\tconst inputs = submissions.filter((submission) => submission.type === \"input\");\n\t\tconst conversations = [...new Set(inputs.map((submission) => submission.conversationId))];\n\t\tfor (const id of conversations) await this.#loadChain({ conversation: id });\n\t\treturn conversations;\n\t}\n\n\t/**\n\t * Load the owner edges and task nodes from `start` up to its ownerless root. A known task outside `#unloaded` ends the\n\t * walk, as its chain is loaded; the `#unloaded` tasks passed have a loaded chain afterwards. Loading a node can reveal\n\t * a cancelled owner, so it makes the next reconcile derive cascade marks.\n\t */\n\tasync #loadChain(start: Up, overlay?: Overlay): Promise<void> {\n\t\tconst passed: TaskId[] = [];\n\t\tlet at: Up | undefined = start;\n\t\twhile (at !== undefined) {\n\t\t\tif (\"task\" in at) {\n\t\t\t\tconst id: TaskId = at.task;\n\t\t\t\tlet node: TaskNode | undefined = this.#live.get(id) ?? this.#settled.get(id);\n\t\t\t\t// Created in this commit: the load from its own record covers what is above it.\n\t\t\t\tif (node === undefined && overlay?.tasks.has(id) === true) break;\n\t\t\t\tif (node !== undefined && !this.#unloaded.has(id)) break;\n\t\t\t\tif (node === undefined) {\n\t\t\t\t\tconst record = await this.#storage.task(id, this.#context);\n\t\t\t\t\tif (record === undefined) return;\n\t\t\t\t\tnode = nodeOf(record);\n\t\t\t\t\tif (record.state.status === \"terminal\") this.#settle(id, node);\n\t\t\t\t\t// A loaded node can reveal a cancelling owner: the next reconcile derives marks again.\n\t\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\t}\n\t\t\t\tpassed.push(id);\n\t\t\t\tat = parentOf(node);\n\t\t\t} else {\n\t\t\t\tlet edge = this.#edge(at.conversation, overlay);\n\t\t\t\tif (edge === undefined) {\n\t\t\t\t\tconst record = await this.#storage.conversation(at.conversation, this.#context);\n\t\t\t\t\tedge = record?.owner?.taskId ?? null;\n\t\t\t\t\tthis.#setEdge(at.conversation, edge);\n\t\t\t\t\t// A loaded node can reveal a cancelling owner: the next reconcile derives marks again.\n\t\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\t}\n\t\t\t\tat = edge === null ? undefined : { task: edge };\n\t\t\t}\n\t\t}\n\t\tfor (const id of passed) this.#unloaded.delete(id);\n\t}\n\n\t#setEdge(conversationId: ConversationId, owner: TaskId | null): void {\n\t\tthis.#edges.set(conversationId, owner);\n\t\t// The conversation now hangs from its owner, or is a root; with nothing below it, it waits for the sweep.\n\t\tthis.#relist(conversationNode(conversationId));\n\t\tthis.#dropIfUnneeded(conversationNode(conversationId));\n\t}\n\n\t/** Know a terminal task a chain load read, so walks pass through it; its own chain is not loaded yet. */\n\t#settle(id: TaskId, node: TaskNode): void {\n\t\tthis.#settled.set(id, node);\n\t\tthis.#unloaded.add(id);\n\t\tthis.#relist(id);\n\t\tthis.#dropIfUnneeded(id);\n\t}\n\n\t/** Queue an ended task or a conversation for the sweep when nothing is listed below it. */\n\t#dropIfUnneeded(node: Node): void {\n\t\tif (typeof node !== \"string\" && this.#live.has(node)) return;\n\t\tif (this.#below.has(node)) return;\n\t\tthis.#dropQueue.add(node);\n\t\tthis.#scheduleSweep();\n\t}\n\n\t/**\n\t * Sweep in a job of its own on the Session line, after the operation underway: a rejected commit, one with nothing to\n\t * write, and a read publish nothing, so the sweep at the end of `#observe` would not run for what they loaded.\n\t */\n\t#scheduleSweep(): void {\n\t\tif (this.#sweepScheduled || this.#closing) return;\n\t\tthis.#sweepScheduled = true;\n\t\tthis.#session\n\t\t\t.readOnLine(async () => {\n\t\t\t\tthis.#sweepScheduled = false;\n\t\t\t\tthis.#sweep();\n\t\t\t})\n\t\t\t// Rejected only once the Session is closing or failed, when nothing is kept anyway.\n\t\t\t.catch(() => {});\n\t}\n\n\t/**\n\t * Drop the queued nodes that are still unneeded: not live, nothing listed below. Runs once a publication is fully\n\t * tracked, and as a job of its own on the line, never inside an operation: work a commit creates below a chain its\n\t * own callback loaded keeps that chain. A flat loop: unlisting already queued every node on the way up that lost its\n\t * last listed node.\n\t */\n\t#sweep(): void {\n\t\tfor (const node of this.#dropQueue) {\n\t\t\tif (this.#below.has(node)) continue;\n\t\t\tif (typeof node === \"string\") {\n\t\t\t\tthis.#edges.delete(conversationOf(node));\n\t\t\t\tthis.#roots.delete(conversationOf(node));\n\t\t\t} else if (!this.#live.has(node)) {\n\t\t\t\tthis.#settled.delete(node);\n\t\t\t\tthis.#unloaded.delete(node);\n\t\t\t}\n\t\t}\n\t\tthis.#dropQueue.clear();\n\t}\n\n\t/**\n\t * Bring the scheduler's sets in line with a task's committed record. A task that ended may free the nearest live task\n\t * above it: one holding its outcome finalizes, an abort-marked one runs its abort handler; its waiters may run.\n\t */\n\t#track(previous: AnyTaskRecord | undefined, record: AnyTaskRecord): void {\n\t\tconst id = record.id;\n\t\tif (previous?.state.status === \"waiting\") for (const on of previous.state.on) deleteFrom(this.#waiters, on, id);\n\t\tif (record.state.status === \"terminal\") {\n\t\t\tconst node = nodeOf(record);\n\t\t\tthis.#live.delete(id);\n\t\t\tthis.#intent.delete(id);\n\t\t\tthis.#runnable.delete(id);\n\t\t\tthis.#finalizeChecks.delete(id);\n\t\t\tthis.#settled.set(id, node);\n\t\t\t// Before anything is forgotten: the walk up to the task it held passes the ended tasks between them. Its chain is\n\t\t\t// loaded, as every commit that ends a task loads the chains of `#unloaded` first.\n\t\t\tthis.#release(node);\n\t\t\tfor (const waiter of this.#waiters.get(id) ?? []) this.#runnable.add(waiter);\n\t\t\tthis.#relist(id);\n\t\t\tthis.#dropIfUnneeded(id);\n\t\t\treturn;\n\t\t}\n\t\tthis.#live.set(id, record);\n\t\tif (previous === undefined) {\n\t\t\tif (!this.#known(parentNode(record))) this.#unloaded.add(id);\n\t\t\tthis.#relist(id);\n\t\t}\n\t\tif (cancellationIntent(record)) this.#intent.add(id);\n\t\telse this.#intent.delete(id);\n\t\tif (record.state.status === \"completing\") {\n\t\t\tthis.#runnable.delete(id);\n\t\t\tthis.#finalizeChecks.add(id);\n\t\t} else {\n\t\t\tthis.#runnable.add(id);\n\t\t}\n\t\tif (record.state.status === \"waiting\") for (const on of record.state.on) addTo(this.#waiters, on, id);\n\t}\n\n\t/** The nearest live task above ended ordinary work may be free now: one holding its outcome, or an aborting one. */\n\t#release(node: TaskNode, overlay?: Overlay): AnyTaskRecord | undefined {\n\t\tconst above = this.#nearestLiveAbove(node, overlay);\n\t\tif (above?.state.status === \"completing\") this.#finalizeChecks.add(above.id);\n\t\telse if (above?.abortRequested === true) this.#runnable.add(above.id);\n\t\treturn above;\n\t}\n\n\t/**\n\t * List `start` under its parent node in `#below` while it is a live task or has nodes listed below it, and unlist it\n\t * otherwise; then its parent, as far up as that changes. So `#below` holds exactly the tree around live work; a\n\t * parent that loses its last listed node is queued for the sweep. A loop, as ownership chains can be deeper than the\n\t * call stack.\n\t */\n\t#relist(start: Node): void {\n\t\tlet node: Node = start;\n\t\tfor (;;) {\n\t\t\tconst needed = (typeof node !== \"string\" && this.#live.has(node)) || this.#below.has(node);\n\t\t\tlet parent: Node | null | undefined;\n\t\t\tif (typeof node === \"string\") {\n\t\t\t\tparent = this.#edges.get(conversationOf(node));\n\t\t\t} else {\n\t\t\t\tconst known = this.#live.get(node) ?? this.#settled.get(node);\n\t\t\t\tif (known === undefined) return;\n\t\t\t\tparent = parentNode(known);\n\t\t\t}\n\t\t\tif (parent === undefined) return;\n\t\t\tif (parent === null) {\n\t\t\t\tconst root = conversationOf(node as `c${number}`);\n\t\t\t\tif (needed) this.#roots.add(root);\n\t\t\t\telse this.#roots.delete(root);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ((this.#below.get(parent)?.has(node) === true) === needed) return;\n\t\t\tif (needed) {\n\t\t\t\tconst first = !this.#below.has(parent);\n\t\t\t\taddTo(this.#below, parent, node);\n\t\t\t\tif (!first) return;\n\t\t\t} else {\n\t\t\t\tdeleteFrom(this.#below, parent, node);\n\t\t\t\tif (this.#below.has(parent)) return;\n\t\t\t\tthis.#dropIfUnneeded(parent);\n\t\t\t}\n\t\t\tnode = parent;\n\t\t}\n\t}\n\n\t/**\n\t * The nearest live task above ended ordinary work `node`, in the overlay's view: the one that work held, if any. Work\n\t * at or below a background task holds nothing above it.\n\t */\n\t#nearestLiveAbove(node: TaskNode, overlay?: Overlay): AnyTaskRecord | undefined {\n\t\tfor (let current = node; !current.background; ) {\n\t\t\tconst owner = current.owner ?? this.#edge(current.conversationId, overlay);\n\t\t\tif (owner === undefined || owner === null) return undefined;\n\t\t\tconst record = overlay?.tasks.get(owner) ?? this.#live.get(owner);\n\t\t\tif (record !== undefined && record.state.status !== \"terminal\") return record;\n\t\t\tconst above = record ?? this.#settled.get(owner);\n\t\t\tif (above === undefined) return undefined;\n\t\t\tcurrent = above;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Whether the chain above `node` is loaded, without walking: known tasks outside `#unloaded` have a loaded chain. */\n\t#known(node: Node): boolean {\n\t\tif (typeof node !== \"string\") {\n\t\t\treturn (this.#live.has(node) || this.#settled.has(node)) && !this.#unloaded.has(node);\n\t\t}\n\t\tconst owner = this.#edges.get(conversationOf(node));\n\t\treturn owner === null || (owner !== undefined && this.#known(owner));\n\t}\n\n\t/** Owner task of a conversation, `null` when ownerless, `undefined` while not loaded. */\n\t#edge(id: ConversationId, overlay?: Overlay): TaskId | null | undefined {\n\t\treturn overlay?.edges.has(id) === true ? overlay.edges.get(id) : this.#edges.get(id);\n\t}\n\n\t#node(id: TaskId, overlay?: Overlay): TaskNode | undefined {\n\t\treturn overlay?.tasks.get(id) ?? this.#live.get(id) ?? this.#settled.get(id);\n\t}\n\n\t/** Walk up from `start`: owner tasks and conversations, ending at an ownerless root or an edge not loaded yet. */\n\t*#above(start: Up, overlay?: Overlay): Generator<Step> {\n\t\tlet at: Up | undefined = start;\n\t\twhile (at !== undefined) {\n\t\t\tif (\"task\" in at) {\n\t\t\t\tconst node = this.#node(at.task, overlay);\n\t\t\t\tif (node === undefined) {\n\t\t\t\t\tyield { unknown: true };\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tyield { task: at.task, node };\n\t\t\t\tat = parentOf(node);\n\t\t\t} else {\n\t\t\t\tyield { conversation: at.conversation };\n\t\t\t\tconst edge = this.#edge(at.conversation, overlay);\n\t\t\t\tif (edge === undefined) {\n\t\t\t\t\tyield { unknown: true };\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tat = edge === null ? undefined : { task: edge };\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The tasks below `start` that a walk down reaches: those `#below` lists and, under an overlay, the commit's new tasks,\n\t * with its candidates in place of committed records. Background tasks are reached but not entered, unless\n\t * `crossBackground`, and neither are the tasks `enter` rejects. A loop, as chains can be deeper than the call stack.\n\t */\n\t*#walkDown(\n\t\tstart: Node,\n\t\toptions: {\n\t\t\treadonly overlay?: Overlay;\n\t\t\treadonly crossBackground?: boolean;\n\t\t\treadonly enter?: (id: TaskId) => boolean;\n\t\t} = {},\n\t): Generator<{ readonly id: TaskId; readonly node: TaskNode; readonly live: AnyTaskRecord | undefined }> {\n\t\tconst { overlay, crossBackground = false, enter } = options;\n\t\tconst links = overlay === undefined ? undefined : this.#links(overlay);\n\t\tconst pending: Node[] = [start];\n\t\tfor (let at = pending.pop(); at !== undefined; at = pending.pop()) {\n\t\t\tfor (const children of [this.#below.get(at), links?.get(at)]) {\n\t\t\t\tfor (const child of children ?? []) {\n\t\t\t\t\tif (typeof child === \"string\") {\n\t\t\t\t\t\tpending.push(child);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst record = overlay?.tasks.get(child) ?? this.#live.get(child);\n\t\t\t\t\tconst node = record ?? this.#settled.get(child);\n\t\t\t\t\tif (node === undefined) continue;\n\t\t\t\t\tconst live = record !== undefined && record.state.status !== \"terminal\" ? record : undefined;\n\t\t\t\t\tyield { id: child, node, live };\n\t\t\t\t\tif ((crossBackground || !node.background) && (enter === undefined || enter(child))) pending.push(child);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The links walks down need for the commit's new tasks: each one under its parent node, then each node above it that\n\t * `#below` does not list yet, until one it lists, a live task (always listed), or the chain's end.\n\t */\n\t#links(overlay: Overlay): ReadonlyMap<Node, ReadonlySet<Node>> {\n\t\tif (overlay.links !== undefined) return overlay.links;\n\t\tconst links = new Map<Node, Set<Node>>();\n\t\tfor (const record of overlay.tasks.values()) {\n\t\t\tif (this.#live.has(record.id) || this.#settled.has(record.id)) continue;\n\t\t\tlet child: Node = record.id;\n\t\t\tlet parent: Node | null | undefined = parentNode(record);\n\t\t\twhile (parent !== undefined && parent !== null && links.get(parent)?.has(child) !== true) {\n\t\t\t\taddTo(links, parent, child);\n\t\t\t\tif (typeof parent !== \"string\" && (this.#live.has(parent) || overlay.tasks.has(parent))) break;\n\t\t\t\tlet above: Node | null | undefined;\n\t\t\t\tif (typeof parent === \"string\") {\n\t\t\t\t\tabove = this.#edge(conversationOf(parent), overlay);\n\t\t\t\t} else {\n\t\t\t\t\tconst fields = this.#settled.get(parent);\n\t\t\t\t\tabove = fields === undefined ? undefined : parentNode(fields);\n\t\t\t\t}\n\t\t\t\tif (above !== undefined && above !== null && this.#below.get(above)?.has(parent) === true) break;\n\t\t\t\tchild = parent;\n\t\t\t\tparent = above;\n\t\t\t}\n\t\t}\n\t\toverlay.links = links;\n\t\treturn links;\n\t}\n\n\t/**\n\t * The live ordinary owned work of `owner` (spec §5.5): the live non-background tasks below it that a walk down reaches\n\t * without entering a background task; with `first`, only the first. Candidates in `overlay` replace committed records;\n\t * the walk does not enter tasks in `done`, which have none. Owner chains must be loaded.\n\t */\n\t#ownedLive(\n\t\towner: TaskId,\n\t\toptions: { readonly overlay?: Overlay; readonly first?: boolean; readonly done?: ReadonlySet<TaskId> } = {},\n\t): TaskId[] {\n\t\tconst { overlay, first = false, done } = options;\n\t\tconst found: TaskId[] = [];\n\t\tconst walk = this.#walkDown(owner, {\n\t\t\t...(overlay === undefined ? {} : { overlay }),\n\t\t\t...(done === undefined ? {} : { enter: (id: TaskId) => !done.has(id) }),\n\t\t});\n\t\tfor (const { id, node, live } of walk) {\n\t\t\tif (live === undefined || node.background) continue;\n\t\t\tfound.push(id);\n\t\t\tif (first) break;\n\t\t}\n\t\treturn found;\n\t}\n\n\t#hasOwnedLive(owner: TaskId, overlay?: Overlay, done?: ReadonlySet<TaskId>): boolean {\n\t\tconst options = {\n\t\t\tfirst: true,\n\t\t\t...(overlay === undefined ? {} : { overlay }),\n\t\t\t...(done === undefined ? {} : { done }),\n\t\t};\n\t\treturn this.#ownedLive(owner, options).length > 0;\n\t}\n\n\t/**\n\t * Whether ordinary traversal from `scope` reaches `start`: walking up reaches the scope's conversation, or an\n\t * ownerless one for `roots`, without crossing a background owner, unless `crossBackground`. `undefined` while an\n\t * edge is not loaded.\n\t */\n\t#inScope(start: Up, scope: Scope, crossBackground = false): boolean | undefined {\n\t\tfor (const step of this.#above(start)) {\n\t\t\tif (\"unknown\" in step) return undefined;\n\t\t\tif (\"conversation\" in step) {\n\t\t\t\tif (\"conversation\" in scope && step.conversation === scope.conversation) return true;\n\t\t\t} else if (step.node.background && !crossBackground) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn \"roots\" in scope;\n\t}\n\n\t/**\n\t * Whether a live owner's cancellation intent reaches `start`: walking up finds an owner with intent before a\n\t * background owner without it. Terminal owners never cascade (spec §5.4).\n\t */\n\t#belowCancelled(start: Up): boolean {\n\t\treturn this.#cancellingOwner(start) !== undefined;\n\t}\n\n\t/** The nearest live owner above `start` whose cancellation intent reaches it, if any; see `#belowCancelled`. */\n\t#cancellingOwner(start: Up): AnyTaskRecord | undefined {\n\t\t// Nothing cancels, the common case: no walk.\n\t\tif (this.#intent.size === 0) return undefined;\n\t\tfor (const step of this.#above(start)) {\n\t\t\tif (\"unknown\" in step) return undefined;\n\t\t\tif (!(\"task\" in step)) continue;\n\t\t\tconst live = this.#live.get(step.task);\n\t\t\tif (live !== undefined && cancellationIntent(live)) return live;\n\t\t\tif (step.node.background) return undefined;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Fail the Session, which reports it, for a throw in one of the scheduler's own commits; ignored once closing. */\n\t#failSession(error: unknown): void {\n\t\tif (!this.#closing) this.#session.fail(error);\n\t}\n\n\t/** Close listener: runs synchronously once admission is sealed, before `join()`, or when the Session fails. */\n\t#seal(): void {\n\t\tthis.#closing = true;\n\t\ttry {\n\t\t\tthis.#unsubscribeRegistry();\n\t\t} catch (error) {\n\t\t\tthis.#report(error);\n\t\t}\n\t\tconst error = closedError(this.#session);\n\t\tthis.#taskWaiters.rejectAll(error);\n\t\tthis.#idleWaiters.rejectAll(error);\n\t\tthis.#contexts.clear();\n\t\tif (this.#expiry !== undefined) clearTimeout(this.#expiry.timer);\n\t\tthis.#expiry = undefined;\n\t}\n\n\t#kick(): void {\n\t\tthis.#dirty = true;\n\t\tif (this.#draining || !this.#enabled || this.#closing) return;\n\t\tthis.#draining = true;\n\t\t// Never commit synchronously from a commit or registry listener.\n\t\tqueueMicrotask(() => void this.#drain());\n\t}\n\n\tasync #drain(): Promise<void> {\n\t\ttry {\n\t\t\twhile (this.#dirty && this.#enabled && !this.#closing) {\n\t\t\t\tthis.#dirty = false;\n\t\t\t\tfor (const reservation of await this.#reserve()) this.#start(reservation);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// As in `#reconcile()`: the reservation commit runs no extension code.\n\t\t\tthis.#failSession(error);\n\t\t} finally {\n\t\t\tthis.#draining = false;\n\t\t\t// A wakeup that arrived after the loop's last check still needs its pass.\n\t\t\tif (this.#dirty) this.#kick();\n\t\t}\n\t}\n\n\t/**\n\t * Reserve every eligible task in one commit; orphan abort-marked tasks no definition can take, unless abandoned after\n\t * a restart. The first pass after open only abort-marks the abandoned tasks, so later passes see the marks.\n\t */\n\tasync #reserve(): Promise<Reservation[]> {\n\t\tconst reservations: Reservation[] = [];\n\t\tlet abandoned: TaskId[] = [];\n\t\ttry {\n\t\t\tawait this.#session.commitWith(async (tx) => {\n\t\t\t\tif (!this.#enabled || this.#closing) return;\n\t\t\t\tfor (const id of this.#abandoned) {\n\t\t\t\t\tconst record = this.#live.get(id);\n\t\t\t\t\tif (record !== undefined && !record.abortRequested) tx.setTask(withAbortMark(record, \"restart\"));\n\t\t\t\t}\n\t\t\t\tif (this.#abandoned.size > 0) {\n\t\t\t\t\tabandoned = [...this.#abandoned];\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait this.#loadScopes(false);\n\t\t\t\t// Taken once per pass, and only when some task is a candidate.\n\t\t\t\tlet snapshot: RegistrySnapshot | undefined;\n\t\t\t\tfor (const id of [...this.#runnable]) {\n\t\t\t\t\tconst record = this.#live.get(id);\n\t\t\t\t\tif (record === undefined || record.state.status === \"completing\" || this.#invocations.has(id)) {\n\t\t\t\t\t\tthis.#runnable.delete(id);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\t// It returns once what it waits for ends, its record changes, or the work below it ends.\n\t\t\t\t\tif (this.#waitingOn(record, true).length > 0) {\n\t\t\t\t\t\tthis.#runnable.delete(id);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst runnable = record as RunnableTaskRecord;\n\t\t\t\t\tconst mode = record.abortRequested ? \"abort\" : \"run\";\n\t\t\t\t\t// Work below an owner with cancellation intent waits for its cascade mark instead of running a phase; schedule\n\t\t\t\t\t// the cascade, which may not have run yet.\n\t\t\t\t\tif (mode === \"run\" && !record.background && this.#belowCancelled(parentOf(record))) {\n\t\t\t\t\t\tthis.#cascadePending = true;\n\t\t\t\t\t\tthis.#scheduleReconcile();\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tsnapshot ??= this.#registry.snapshot();\n\t\t\t\t\tconst resolution = this.#resolve(runnable, snapshot);\n\t\t\t\t\tif (resolution.kind === \"blocked\") {\n\t\t\t\t\t\t// An abandoned task waits for its definition, so its abort handler can clean up.\n\t\t\t\t\t\tif (mode === \"abort\" && record.abortReason === undefined) {\n\t\t\t\t\t\t\tawait this.#terminate(tx, record, { status: \"orphaned\", reason: resolution.reason });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (resolution.record !== runnable || record.state.status !== \"running\") {\n\t\t\t\t\t\ttx.setTask(\n\t\t\t\t\t\t\twithState(resolution.record, {\n\t\t\t\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\t\t\t\tcheckpoint: resolution.record.state.checkpoint,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\t// Registered on the line, so marks and later reservations see it and close joins it; `#end` makes it a\n\t\t\t\t\t// candidate again.\n\t\t\t\t\tthis.#runnable.delete(id);\n\t\t\t\t\tconst invocation = this.#createInvocation(record, mode);\n\t\t\t\t\treservations.push({ invocation, task: resolution.task, snapshot });\n\t\t\t\t}\n\t\t\t}, this.#context);\n\t\t} catch (error) {\n\t\t\tfor (const { invocation } of reservations) {\n\t\t\t\tthis.#invocations.delete(invocation.taskId);\n\t\t\t\tthis.#runnable.add(invocation.taskId);\n\t\t\t\tinvocation.finish();\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\t// Marked, or already marked or gone: done with them. Reserve again, now seeing the marks.\n\t\tfor (const id of abandoned) this.#abandoned.delete(id);\n\t\tif (abandoned.length > 0) this.#dirty = true;\n\t\treturn reservations;\n\t}\n\n\t/**\n\t * Live tasks a task waits for before its next invocation: its live ordinary owned work when abort-marked, since\n\t * abort runs bottom-up, otherwise the live part of the `on` of a wait.\n\t */\n\t#waitingOn(record: AnyTaskRecord, first = false): readonly TaskId[] {\n\t\tif (record.abortRequested) return this.#ownedLive(record.id, { first });\n\t\tif (record.state.status !== \"waiting\") return [];\n\t\tif (!first) return record.state.on.filter((id) => this.#live.has(id));\n\t\tconst live = record.state.on.find((id) => this.#live.has(id));\n\t\treturn live === undefined ? [] : [live];\n\t}\n\n\t/** Resolve the record's definition by kind, migrating an older stored version. */\n\t#resolve(record: RunnableTaskRecord, snapshot: RegistrySnapshot): Resolution {\n\t\tconst fit = this.#fit(record, snapshot.task(record.kind));\n\t\tif (\"reason\" in fit) return { kind: \"blocked\", reason: fit.reason };\n\t\tif (!fit.migrates) return { kind: \"ready\", task: fit.task, record };\n\t\tconst definition = erased(fit.task);\n\t\ttry {\n\t\t\tif (definition.migrate === undefined) throw missingMigration(record, definition);\n\t\t\tconst migrated = definition.migrate(record.input, record.state.checkpoint, record.version);\n\t\t\tconst state = { ...record.state, checkpoint: copyJson(migrated.checkpoint) };\n\t\t\tconst migratedRecord = { ...record, version: definition.version, input: copyJson(migrated.input), state };\n\t\t\treturn { kind: \"ready\", task: fit.task, record: migratedRecord as RunnableTaskRecord };\n\t\t} catch (error) {\n\t\t\tthis.#failedMigrations.set(record.id, { task: fit.task, error });\n\t\t\tthis.#report(error);\n\t\t\treturn { kind: \"blocked\", reason: \"migration_failed\" };\n\t\t}\n\t}\n\n\t#fit(record: AnyTaskRecord, task: AnyTask | undefined): Fit {\n\t\tif (task === undefined) return { reason: \"missing_task\" };\n\t\tconst version = task.definition.version;\n\t\tif (version === record.version) return { task, migrates: false };\n\t\tif (version < record.version) return { reason: \"task_too_old\" };\n\t\tconst failed = this.#failedMigrations.get(record.id);\n\t\tif (failed?.task === task) return { reason: \"migration_failed\", error: failed.error };\n\t\treturn { task, migrates: true };\n\t}\n\n\t/** Sizes of the ownership indexes, for tests that bound the scheduler's memory. */\n\tget indexSizes(): Readonly<\n\t\tRecord<\"live\" | \"settled\" | \"edges\" | \"below\" | \"roots\" | \"unloaded\" | \"dropQueue\", number>\n\t> {\n\t\tlet below = 0;\n\t\tfor (const children of this.#below.values()) below += children.size;\n\t\treturn {\n\t\t\tlive: this.#live.size,\n\t\t\tsettled: this.#settled.size,\n\t\t\tedges: this.#edges.size,\n\t\t\tbelow,\n\t\t\troots: this.#roots.size,\n\t\t\tunloaded: this.#unloaded.size,\n\t\t\tdropQueue: this.#dropQueue.size,\n\t\t};\n\t}\n\n\t/**\n\t * Scheduling state and every live task with its derived state, read on the Session line. Runs no task code: a\n\t * pending migration shows as `ready` with `migrates`, and only a migration the scheduler already tried, or one that\n\t * cannot exist, shows as failed.\n\t */\n\tasync inspect(\n\t\tsnapshot: RegistrySnapshot,\n\t): Promise<{ scheduling: HarnessInspection[\"scheduling\"]; tasks: TaskInspection[] }> {\n\t\tawait this.#loadScopes(false);\n\t\tconst tasks: TaskInspection[] = [];\n\t\tfor (const record of this.#live.values()) tasks.push({ record, state: this.#inspectTask(record, snapshot) });\n\t\tconst scheduling = this.#closing ? \"closing\" : this.#enabled ? \"running\" : \"paused\";\n\t\treturn { scheduling, tasks };\n\t}\n\n\t#inspectTask(record: AnyTaskRecord, snapshot: RegistrySnapshot): TaskInspection[\"state\"] {\n\t\tif (this.#invocations.has(record.id)) return { kind: \"running\" };\n\t\tif (record.state.status === \"completing\") return { kind: \"completing\" };\n\t\tconst on = this.#waitingOn(record);\n\t\tif (on.length > 0) return { kind: \"waiting\", on };\n\t\tconst fit = this.#fit(record, snapshot.task(record.kind));\n\t\tif (\"reason\" in fit) return { kind: \"blocked\", ...fit };\n\t\tif (fit.migrates && fit.task.definition.migrate === undefined) {\n\t\t\treturn { kind: \"blocked\", reason: \"migration_failed\", error: missingMigration(record, erased(fit.task)) };\n\t\t}\n\t\treturn { kind: \"ready\", migrates: fit.migrates };\n\t}\n\n\t#createInvocation(record: AnyTaskRecord, mode: \"run\" | \"abort\"): Invocation {\n\t\tconst controller = new AbortController();\n\t\tconst { promise: done, resolve: finish } = Promise.withResolvers<void>();\n\t\tconst invocation: Invocation = {\n\t\t\ttaskId: record.id,\n\t\t\tconversationId: record.conversationId,\n\t\t\tmode,\n\t\t\tcontroller,\n\t\t\tcontext: withAbortSignal(controller.signal, this.#context),\n\t\t\twatches: new Set(),\n\t\t\tended: false,\n\t\t\tdone,\n\t\t\tfinish: () => finish(),\n\t\t};\n\t\tthis.#invocations.set(record.id, invocation);\n\t\treturn invocation;\n\t}\n\n\t#start(reservation: Reservation): void {\n\t\tconst invocation = reservation.invocation;\n\t\tvoid (async () => {\n\t\t\ttry {\n\t\t\t\tif (invocation.mode === \"run\") await this.#run(reservation);\n\t\t\t\telse await this.#runAbort(reservation);\n\t\t\t} catch (error) {\n\t\t\t\tthis.#report(error);\n\t\t\t} finally {\n\t\t\t\tthis.#end(invocation);\n\t\t\t\tinvocation.finish();\n\t\t\t\tthis.#kick();\n\t\t\t}\n\t\t})();\n\t}\n\n\t/** Run phase handlers, each preceded by a step that decides on the line whether the invocation continues. */\n\tasync #run(reservation: Reservation): Promise<void> {\n\t\tconst invocation = reservation.invocation;\n\t\tconst state = { task: reservation.task, snapshot: reservation.snapshot, reported: undefined as ReportedTask };\n\t\tconst phase: Phase = { snapshot: () => state.snapshot, task: () => state.task, agent: undefined };\n\t\tconst runtime = this.#runtime(invocation, phase);\n\t\tlet previous: PhaseResult | undefined;\n\t\tfor (;;) {\n\t\t\tconst current = await this.#step(invocation, (tx, current) => this.#decide(tx, current, previous, state));\n\t\t\t// Close may seal between the decision and dispatch.\n\t\t\tif (current === undefined || this.#closing) return;\n\t\t\tconst checkpoint = current.state.checkpoint;\n\t\t\t// Each phase handler resolves its agent afresh, at first use.\n\t\t\tphase.agent = undefined;\n\t\t\ttry {\n\t\t\t\tawait erased(state.task).phases[checkpoint.phase]!(current, runtime, invocation.context);\n\t\t\t\tprevious = { checkpoint };\n\t\t\t} catch (error) {\n\t\t\t\tprevious = { checkpoint, failure: { error } };\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Precedence rules for a run invocation, on the line. Rules 1 (terminal, `completing`, or `waiting`) and 2 (closing)\n\t * are applied by `#step`. Returns whether the invocation continues with the next phase.\n\t */\n\t#decide(\n\t\ttx: Transaction,\n\t\tcurrent: ErasedRunningTask,\n\t\tprevious: PhaseResult | undefined,\n\t\tstate: { task: AnyTask; snapshot: RegistrySnapshot; reported: ReportedTask },\n\t): Decision {\n\t\t// 3. abort mark: end; a fresh abort invocation starts once the task's ordinary owned work is gone.\n\t\tif (current.abortRequested) return false;\n\t\t// An owner's cancellation intent ends it too, before its cascade marks it; reservation then holds it back.\n\t\tif (!current.background && this.#belowCancelled(parentOf(current))) {\n\t\t\tthis.#cascadePending = true;\n\t\t\tthis.#scheduleReconcile();\n\t\t\treturn false;\n\t\t}\n\t\tif (previous === undefined) return true;\n\t\t// 4. uncaught error.\n\t\tif (previous.failure !== undefined) return { fault: previous.failure.error };\n\t\t// 6. no durable progress.\n\t\tif (jsonEqual(current.state.checkpoint, previous.checkpoint)) {\n\t\t\tconst message = `Task ${current.kind} phase ${previous.checkpoint.phase} returned without durable progress`;\n\t\t\treturn { fault: new Error(message) };\n\t\t}\n\t\t// 5. progress: refresh the snapshot; hand over to a replacement definition that can take the task.\n\t\tstate.snapshot = this.#registry.snapshot();\n\t\tconst next = state.snapshot.task(current.kind);\n\t\tif (next !== state.task) {\n\t\t\tif (next !== undefined && canReserve(next, current)) {\n\t\t\t\ttx.setTask(withState(current, { status: \"pending\", checkpoint: current.state.checkpoint }));\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (state.reported === undefined || state.reported.task !== next) {\n\t\t\t\tstate.reported = { task: next };\n\t\t\t\tconst cause = next === undefined ? \"missing_task\" : \"incompatible_task\";\n\t\t\t\tthis.#report(\n\t\t\t\t\tnew Error(`Task ${current.id} keeps running under its old ${current.kind} definition`, { cause }),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** Run the abort handler once; rules 1, 2, and 4 apply, and returning without an outcome faults. */\n\tasync #runAbort(reservation: Reservation): Promise<void> {\n\t\tconst invocation = reservation.invocation;\n\t\tconst current = this.#live.get(invocation.taskId) as ErasedRunningTask | undefined;\n\t\tif (current === undefined || this.#closing) return;\n\t\tlet failure: { readonly error: unknown } | undefined;\n\t\ttry {\n\t\t\tconst phase: Phase = { snapshot: () => reservation.snapshot, task: () => reservation.task, agent: undefined };\n\t\t\tconst runtime = this.#runtime(invocation, phase);\n\t\t\tawait erased(reservation.task).abort(current, runtime, invocation.context);\n\t\t} catch (error) {\n\t\t\tfailure = { error };\n\t\t}\n\t\tconst message = `Abort handler of task ${invocation.taskId} returned without a terminal outcome`;\n\t\tawait this.#step(invocation, () => ({ fault: failure?.error ?? new Error(message) }));\n\t}\n\n\t/**\n\t * One synchronous decision on the Session line. A task that is no longer running (rule 1: terminal, `completing`, or\n\t * `waiting`) or a closing Harness (rule 2) ends the invocation without a write; otherwise `decide` may stage a write\n\t * and returns whether the invocation continues. Ending happens inside the callback, before a fault's Harness\n\t * cleanup. A rejected step, such as admission after close, also ends the invocation.\n\t */\n\tasync #step(\n\t\tinvocation: Invocation,\n\t\tdecide: (tx: Transaction, current: ErasedRunningTask) => Decision,\n\t): Promise<ErasedRunningTask | undefined> {\n\t\ttry {\n\t\t\treturn await this.#session.commitWith(async (tx) => {\n\t\t\t\tconst found = this.#live.get(invocation.taskId);\n\t\t\t\tconst current = found?.state.status === \"running\" ? (found as ErasedRunningTask) : undefined;\n\t\t\t\tconst decision = current !== undefined && !this.#closing ? decide(tx, current) : false;\n\t\t\t\tif (decision === true) return current;\n\t\t\t\tthis.#end(invocation);\n\t\t\t\tif (decision !== false) {\n\t\t\t\t\tconst message = errorMessage(decision.fault);\n\t\t\t\t\tawait this.#terminate(tx, current!, { status: \"faulted\", error: { message } });\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t}, this.#context);\n\t\t} catch (error) {\n\t\t\t// The step writes the scheduler's own decision, a fault or a terminal record; a throw there would otherwise\n\t\t\t// leave the task running, to be reserved and run again.\n\t\t\tthis.#end(invocation);\n\t\t\tthis.#failSession(error);\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Write an outcome the scheduler decided. While the task's ordinary owned work is live it holds as `completing` and\n\t * its Harness cleanup waits for the final commit (spec §5.5, rule 4); otherwise it is terminal with its cleanup.\n\t */\n\tasync #terminate(tx: Transaction, record: AnyTaskRecord, outcome: SchedulerOutcome): Promise<void> {\n\t\tawait this.#loadScopes(false);\n\t\tif (this.#hasOwnedLive(record.id, overlayOf(tx))) {\n\t\t\ttx.setTask(withState(record, { status: \"completing\", outcome }));\n\t\t\treturn;\n\t\t}\n\t\ttx.setTask(withState(record, { status: \"terminal\", outcome }));\n\t\tawait this.#settleOutcome(tx, record, outcome);\n\t}\n\n\t/**\n\t * Replace a running task's state with what it committed. A terminal state holds as `completing` while ordinary owned\n\t * work is live, judged on the commit's candidates, so work the same commit creates below the task counts. A wait is\n\t * validated first.\n\t */\n\tasync #commitState(\n\t\ttx: Transaction,\n\t\tinvocation: Invocation,\n\t\tcurrent: ErasedRunningTask,\n\t\tnext: NextTaskState<Checkpoint, JsonValue>,\n\t): Promise<void> {\n\t\tif (next.status === \"waiting\") await this.#validateWait(tx, invocation, current, next.on, next.policy);\n\t\tif (next.status === \"terminal\") {\n\t\t\tconst overlay = overlayOf(tx);\n\t\t\tawait this.#loadScopes(false);\n\t\t\tfor (const record of overlay.tasks.values()) await this.#loadChain(parentOf(record), overlay);\n\t\t\tif (this.#hasOwnedLive(current.id, overlay)) {\n\t\t\t\ttx.setTask(withState(current, { status: \"completing\", outcome: next.outcome }));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\ttx.setTask(withState(current, next));\n\t}\n\n\t/**\n\t * A wait names existing tasks, and `failFast` only tasks the waiter owns. It may not close a cycle in the wait-for\n\t * graph, whose edges run from each task to what it waits on and to its live ordinary owned work (spec §5.5); waiting\n\t * on itself or on an owner holding it are the shortest such cycles. An abort handler cannot wait.\n\t *\n\t * Invariant: the wait-for graph is acyclic. Only a wait adds an edge between existing tasks, as a new task has only\n\t * incoming edges, so checking each wait maintains it.\n\t */\n\tasync #validateWait(\n\t\ttx: Transaction,\n\t\tinvocation: Invocation,\n\t\tcurrent: ErasedRunningTask,\n\t\ton: readonly TaskId[],\n\t\tpolicy: string,\n\t): Promise<void> {\n\t\tif (invocation.mode === \"abort\") throw new Error(`Abort handler of task ${current.id} cannot wait`);\n\t\tconst overlay = overlayOf(tx);\n\t\tconst targets: TaskId[] = [];\n\t\tfor (const id of on) {\n\t\t\tconst member = overlay.tasks.get(id) ?? this.#live.get(id) ?? (await this.#storage.task(id, this.#context));\n\t\t\tif (member === undefined) throw new Error(`Task ${id} does not exist`);\n\t\t\tif (policy === \"failFast\" && member.owner !== current.id) {\n\t\t\t\tthrow new Error(`Task ${current.id} can wait failFast only on tasks it owns; ${id} is not one`);\n\t\t\t}\n\t\t\t// A live child already holds the waiter (task-owned tasks are never background): waiting on it adds no edge. A\n\t\t\t// terminal task has no edges.\n\t\t\tif (member.state.status !== \"terminal\" && member.owner !== current.id) targets.push(id);\n\t\t}\n\t\tif (targets.length === 0) return;\n\t\tconst cycle = await this.#waitCycle(current.id, targets, overlay);\n\t\tif (cycle !== undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`Task ${current.id} cannot wait on ${cycle[0]}: ${[current.id, ...cycle].join(\" -> \")} is a wait cycle`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * The path from a member of `on` back to `task` in the wait-for graph, if the wait would close a cycle (spec §5.1).\n\t * An edge X -> Y means X cannot settle before Y: Y is in the `on` of waiting X that is not abort-marked, or Y is live\n\t * ordinary owned work of X,\n\t * which holds X as `completing`. Each task is visited once and each subtree walked once, so a check is bounded by the\n\t * live work it reaches.\n\t */\n\tasync #waitCycle(task: TaskId, on: readonly TaskId[], overlay: Overlay): Promise<TaskId[] | undefined> {\n\t\t// Owned work is found by walks down, which need the chains of every live task loaded.\n\t\tawait this.#loadScopes(false);\n\t\tconst from = new Map<TaskId, TaskId | undefined>();\n\t\tconst walked = new Set<TaskId>();\n\t\tconst pending: TaskId[] = [];\n\t\tconst reach = (id: TaskId, via: TaskId | undefined) => {\n\t\t\tif (from.has(id)) return;\n\t\t\tfrom.set(id, via);\n\t\t\tpending.push(id);\n\t\t};\n\t\tconst path = (end: TaskId): TaskId[] => {\n\t\t\tconst steps: TaskId[] = [];\n\t\t\tfor (let at: TaskId | undefined = end; at !== undefined; at = from.get(at)) steps.unshift(at);\n\t\t\treturn steps;\n\t\t};\n\t\tfor (const id of on) reach(id, undefined);\n\t\tfor (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n\t\t\tif (id === task) return path(id);\n\t\t\tconst record = overlay.tasks.get(id) ?? this.#live.get(id);\n\t\t\tif (record === undefined || record.state.status === \"terminal\") continue;\n\t\t\t// An abort-marked task waits only for its owned work, as abort runs bottom-up (`#waitingOn`).\n\t\t\tif (record.state.status === \"waiting\" && !record.abortRequested) {\n\t\t\t\tfor (const member of record.state.on) reach(member, id);\n\t\t\t}\n\t\t\tif (walked.has(id)) continue;\n\t\t\twalked.add(id);\n\t\t\t// Below a walked task the walk does not go again: its own walk covered what lies below.\n\t\t\tconst found: TaskId[] = [];\n\t\t\tconst walk = this.#walkDown(id, { overlay, enter: (below) => !walked.has(below) });\n\t\t\tfor (const { id: below, node, live } of walk) {\n\t\t\t\tif (live === undefined || node.background) continue;\n\t\t\t\tfound.push(below);\n\t\t\t\treach(below, id);\n\t\t\t}\n\t\t\tfor (const below of found) walked.add(below);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** End an invocation: its runtime operations reject from now on, its signal aborts, its watches stop, and its task is free. */\n\t#end(invocation: Invocation): void {\n\t\tif (invocation.ended) return;\n\t\tinvocation.ended = true;\n\t\tif (this.#invocations.get(invocation.taskId) === invocation) {\n\t\t\tthis.#invocations.delete(invocation.taskId);\n\t\t\tif (this.#live.has(invocation.taskId)) this.#runnable.add(invocation.taskId);\n\t\t}\n\t\tfor (const watch of invocation.watches) void watch.stop();\n\t\t// Pending waits bound to the invocation, such as a tool's waitForTask(), reject with it.\n\t\tinvocation.controller.abort(endedError(invocation));\n\t}\n\n\t/** No live non-background task in the scope; a task whose owner edges are not loaded yet counts as inside. */\n\t#idle(conversationId: ConversationId | undefined): boolean {\n\t\tconst scope: Scope = conversationId === undefined ? { roots: true } : { conversation: conversationId };\n\t\t// Tasks whose chain is not loaded are not listed below their scope yet; one counts as inside unless its walk up\n\t\t// decides otherwise.\n\t\tfor (const id of this.#unloaded) {\n\t\t\tconst record = this.#live.get(id);\n\t\t\tif (record !== undefined && !record.background && this.#inScope(parentOf(record), scope) !== false)\n\t\t\t\treturn false;\n\t\t}\n\t\tconst starts = conversationId === undefined ? this.#roots : [conversationId];\n\t\tfor (const start of starts) {\n\t\t\tfor (const { node, live } of this.#walkDown(conversationNode(start))) {\n\t\t\t\tif (live !== undefined && !node.background) return false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ─── Invocation runtime ──────────────────────────────────────────────────\n\n\t#runtime(invocation: Invocation, phase: Phase): ErasedRuntime {\n\t\t// Resolved at most once per phase handler, at first use, with the invocation's context; fixed for the phase.\n\t\tconst agent = (): Promise<Agent> => {\n\t\t\tif (invocation.ended) return Promise.reject(endedError(invocation));\n\t\t\tif (phase.agent === undefined) {\n\t\t\t\tphase.agent = this.#agent(invocation.conversationId, phase.snapshot(), invocation.context);\n\t\t\t\t// A caller that stops waiting must not leave the shared resolution's failure unobserved.\n\t\t\t\tphase.agent.catch(() => {});\n\t\t\t}\n\t\t\treturn phase.agent;\n\t\t};\n\t\tconst hooks: HookRunner<Record<string, unknown>> = {\n\t\t\teach: async (name, invoke) => {\n\t\t\t\tfor (const handlers of agentHooks(await agent(), phase.task().definition.name)) {\n\t\t\t\t\tconst handler = (handlers as Record<string, unknown>)[name];\n\t\t\t\t\tif (typeof handler !== \"function\") continue;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait invoke(handler.bind(handlers));\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (invocation.controller.signal.aborted) throw error;\n\t\t\t\t\t\tthis.#report(error);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\tconst settings = this.#settings;\n\t\treturn {\n\t\t\ttaskId: invocation.taskId as TaskId<JsonValue>,\n\t\t\tconversationId: invocation.conversationId,\n\t\t\tsignal: invocation.controller.signal,\n\t\t\tmodels: this.#models,\n\t\t\tagent: (context) =>\n\t\t\t\tinvocation.ended ? Promise.reject(endedError(invocation)) : awaitWithContext(agent(), context),\n\t\t\tget settings() {\n\t\t\t\treturn settings();\n\t\t\t},\n\t\t\tenv: (context) => this.#read(invocation, () => this.#env(invocation.conversationId, context)),\n\t\t\thooks: hooks as ErasedRuntime[\"hooks\"],\n\t\t\tget registry() {\n\t\t\t\treturn phase.snapshot();\n\t\t\t},\n\t\t\tcommit: (change, context) =>\n\t\t\t\tthis.#gated(\n\t\t\t\t\tinvocation,\n\t\t\t\t\tasync (tx, current) => {\n\t\t\t\t\t\tconst next = await change(tx, current);\n\t\t\t\t\t\tif (next !== undefined) await this.#commitState(tx, invocation, current, next);\n\t\t\t\t\t},\n\t\t\t\t\tcontext,\n\t\t\t\t),\n\t\t\tmemo: ((name: string, ...rest: readonly unknown[]) => {\n\t\t\t\tif (rest.length === 1) {\n\t\t\t\t\treturn this.#read(invocation, async () => memoOf(this.#live.get(invocation.taskId), name));\n\t\t\t\t}\n\t\t\t\tconst candidate = rest[0] as JsonValue;\n\t\t\t\treturn this.#gated(\n\t\t\t\t\tinvocation,\n\t\t\t\t\t(tx, current) => {\n\t\t\t\t\t\tconst winner = memoOf(current, name);\n\t\t\t\t\t\tif (winner !== undefined) return winner;\n\t\t\t\t\t\ttx.setTask({ ...current, memos: { ...current.memos, [name]: candidate } } as AnyTaskRecord);\n\t\t\t\t\t\treturn candidate;\n\t\t\t\t\t},\n\t\t\t\t\trest[1] as Context,\n\t\t\t\t);\n\t\t\t}) as ErasedRuntime[\"memo\"],\n\t\t\tsleep: (until, context) => this.#sleep(invocation, until, context),\n\t\t\twatchDoc: ((...args: readonly unknown[]) => this.#watchDoc(invocation, args)) as ErasedRuntime[\"watchDoc\"],\n\t\t\tsnapshot: ((...args: readonly unknown[]) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tsessionMethod(this.#session, \"snapshot\")(...args),\n\t\t\t\t)) as ErasedRuntime[\"snapshot\"],\n\t\t\tsnapshotAsOf: ((...args: readonly unknown[]) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tsessionMethod(this.#session, \"snapshotAsOf\")(...args),\n\t\t\t\t)) as ErasedRuntime[\"snapshotAsOf\"],\n\t\t\tgetTask: ((id: TaskId, context: Context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.#session.readOnLine(() => this.#storage.task(id, context)),\n\t\t\t\t)) as ErasedRuntime[\"getTask\"],\n\t\t\twaitForTask: ((id: TaskId, context: Context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.waitForTask(id, withAbortSignal(invocation.controller.signal, context)),\n\t\t\t\t)) as ErasedRuntime[\"waitForTask\"],\n\t\t\townedTasks: (context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.#session.readOnLine(async () => {\n\t\t\t\t\t\t// The step that ends the invocation may have run on the line before this.\n\t\t\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\t\t\tcontext.abortSignal?.throwIfAborted();\n\t\t\t\t\t\t// Every live task is listed under its parent node, its owner task when it has one.\n\t\t\t\t\t\tconst owned: AnyTaskRecord[] = [];\n\t\t\t\t\t\tfor (const node of this.#below.get(invocation.taskId) ?? []) {\n\t\t\t\t\t\t\tconst record = typeof node === \"string\" ? undefined : this.#live.get(node);\n\t\t\t\t\t\t\tif (record?.owner === invocation.taskId) owned.push(record);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Copies, as from storage: the scheduler reads its own.\n\t\t\t\t\t\treturn owned\n\t\t\t\t\t\t\t.sort((a, b) => a.id - b.id)\n\t\t\t\t\t\t\t.map((record) => copyJson(record as unknown as JsonValue) as unknown as AnyTaskRecord);\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\tabortOwned: (id, context) =>\n\t\t\t\tthis.#read(invocation, async () => {\n\t\t\t\t\tconst bound = withAbortSignal(invocation.controller.signal, context);\n\t\t\t\t\tconst record = await this.#session.readOnLine(() => this.#storage.task(id, bound));\n\t\t\t\t\tif (record?.owner !== invocation.taskId) {\n\t\t\t\t\t\tthrow new Error(`Task ${id} is not owned by task ${invocation.taskId}`);\n\t\t\t\t\t}\n\t\t\t\t\tif (record.state.status === \"terminal\") return;\n\t\t\t\t\tawait this.abort(id, bound, true);\n\t\t\t\t\tawait this.waitForTask(id, bound);\n\t\t\t\t}),\n\t\t\toutcomes: ((ids: readonly TaskId[], context: Context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.#session.readOnLine(async () => {\n\t\t\t\t\t\tconst outcomes: TaskOutcome<JsonValue>[] = [];\n\t\t\t\t\t\tfor (const id of ids) {\n\t\t\t\t\t\t\tconst state = (await this.#storage.task(id, context))?.state;\n\t\t\t\t\t\t\tif (state?.status !== \"terminal\") throw new Error(`Task ${id} is not terminal`);\n\t\t\t\t\t\t\toutcomes.push(state.outcome);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn outcomes;\n\t\t\t\t\t}),\n\t\t\t\t)) as ErasedRuntime[\"outcomes\"],\n\t\t\tconversation: (id, context) =>\n\t\t\t\tthis.#read(invocation, () =>\n\t\t\t\t\tthis.#conversation(\n\t\t\t\t\t\tid,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsignal: invocation.controller.signal,\n\t\t\t\t\t\t\tcheck: () => {\n\t\t\t\t\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\tentry: ((...args: readonly unknown[]) => {\n\t\t\t\tconst [token, id, context] =\n\t\t\t\t\targs.length === 2\n\t\t\t\t\t\t? [undefined, args[0] as EntryId, args[1] as Context]\n\t\t\t\t\t\t: [args[0] as { readonly kind: string }, args[1] as EntryId, args[2] as Context];\n\t\t\t\treturn this.#read(invocation, async () => {\n\t\t\t\t\tconst found = await this.#session.readOnLine(() =>\n\t\t\t\t\t\tthis.#storage.entry(invocation.conversationId, id, context),\n\t\t\t\t\t);\n\t\t\t\t\tconst entry: EntryRecord | undefined = found?.entry;\n\t\t\t\t\treturn token === undefined || entry?.kind === token.kind ? entry : undefined;\n\t\t\t\t});\n\t\t\t}) as ErasedRuntime[\"entry\"],\n\t\t\tcontext: (conversationId, context, options) =>\n\t\t\t\tthis.#read(invocation, async () => {\n\t\t\t\t\tconst { view, range } = await readContextFrom(\n\t\t\t\t\t\tthis.#session,\n\t\t\t\t\t\tthis.#storage,\n\t\t\t\t\t\tconversationId,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\toptions?.at,\n\t\t\t\t\t\tthis.#contexts.get(conversationId)?.range,\n\t\t\t\t\t);\n\t\t\t\t\t// Keep it unless the invocation ended or a concurrent read already kept a newer range.\n\t\t\t\t\tconst kept = this.#contexts.get(conversationId);\n\t\t\t\t\tif (\n\t\t\t\t\t\trange !== undefined &&\n\t\t\t\t\t\t!this.#closing &&\n\t\t\t\t\t\t!invocation.ended &&\n\t\t\t\t\t\t(kept === undefined || kept.range.bounds.tail <= range.bounds.tail)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// A read of another, idle conversation starts or continues its retention period.\n\t\t\t\t\t\tif (!this.#idle(conversationId)) {\n\t\t\t\t\t\t\tthis.#contexts.set(conversationId, { range, idleSince: undefined });\n\t\t\t\t\t\t} else if (this.#contextRetentionMs() > 0) {\n\t\t\t\t\t\t\tthis.#contexts.set(conversationId, { range, idleSince: kept?.idleSince ?? this.#now() });\n\t\t\t\t\t\t\tthis.#scheduleExpiry();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn view;\n\t\t\t\t}),\n\t\t\tnow: () => {\n\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\treturn this.#now();\n\t\t\t},\n\t\t\treport: (error) => {\n\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\tthis.#report(error);\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Run a committed-state read unless the invocation has ended. */\n\tasync #read<T>(invocation: Invocation, read: () => Promise<T>): Promise<T> {\n\t\tif (invocation.ended) throw endedError(invocation);\n\t\treturn read();\n\t}\n\n\t/** Commit after rereading the task on the line and gating the invocation. */\n\t#gated<T>(\n\t\tinvocation: Invocation,\n\t\tchange: (tx: Transaction, current: ErasedRunningTask) => T | Promise<T>,\n\t\tcontext: Context,\n\t): Promise<T> {\n\t\tif (invocation.ended) return Promise.reject(endedError(invocation));\n\t\treturn this.#session.commitWith(\n\t\t\tasync (tx) => {\n\t\t\t\tif (invocation.ended) throw endedError(invocation);\n\t\t\t\tif (this.#closing) throw closedError(this.#session);\n\t\t\t\tconst found = this.#live.get(invocation.taskId);\n\t\t\t\tif (found === undefined) throw new Error(`Task ${invocation.taskId} is terminal`);\n\t\t\t\tif (found.state.status !== \"running\") throw new Error(`Task ${invocation.taskId} is ${found.state.status}`);\n\t\t\t\tconst current = found as ErasedRunningTask;\n\t\t\t\tif (invocation.mode === \"run\" && current.abortRequested) {\n\t\t\t\t\tthrow new Error(`Task ${invocation.taskId} has a durable abort mark`);\n\t\t\t\t}\n\t\t\t\treturn change(tx, current);\n\t\t\t},\n\t\t\tcontext,\n\t\t\t{ conversationId: invocation.conversationId, taskId: invocation.taskId },\n\t\t);\n\t}\n\n\t/** Wait until the Harness clock reaches `until`, rechecking it after every timer. */\n\tasync #sleep(invocation: Invocation, until: number, context: Context): Promise<void> {\n\t\tif (invocation.ended) throw endedError(invocation);\n\t\tconst signals = [invocation.controller.signal];\n\t\tif (context.abortSignal !== undefined) signals.push(context.abortSignal);\n\t\tconst signal = AbortSignal.any(signals);\n\t\tfor (;;) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tconst remaining = until - this.#now();\n\t\t\tif (remaining <= 0) return;\n\t\t\tawait delay(Math.min(remaining, MAX_TIMER_DELAY), signal);\n\t\t}\n\t}\n\n\tasync #watchDoc(invocation: Invocation, args: readonly unknown[]): Promise<DocumentWatch<JsonObject> | undefined> {\n\t\tif (invocation.ended) throw endedError(invocation);\n\t\tconst watch = (await sessionMethod(this.#session, \"watchDoc\")(...args)) as DocumentWatch<JsonObject> | undefined;\n\t\tif (watch === undefined) return undefined;\n\t\tif (invocation.ended) {\n\t\t\tvoid watch.stop();\n\t\t\tthrow endedError(invocation);\n\t\t}\n\t\tinvocation.watches.add(watch);\n\t\tvoid watch.closed.then(() => invocation.watches.delete(watch));\n\t\treturn watch;\n\t}\n}\n\n/** The record with an abort mark: `restart` for an abandonment; without a reason, a request, which replaces `restart`. */\nfunction withAbortMark(record: AnyTaskRecord, reason?: \"restart\"): AnyTaskRecord {\n\tconst { abortReason: _reason, ...rest } = record;\n\treturn { ...rest, abortRequested: true, ...(reason === undefined ? {} : { abortReason: reason }) } as AnyTaskRecord;\n}\n\n/** A live owner's durable cancellation intent: its abort mark, or a held outcome other than `completed`. */\nfunction cancellationIntent(record: AnyTaskRecord): boolean {\n\treturn record.state.status !== \"terminal\" && (record.abortRequested || failedOutcome(record));\n}\n\n/** Whether the record holds or ends with an outcome other than `completed`. */\nfunction failedOutcome(record: AnyTaskRecord): boolean {\n\tconst state = record.state;\n\treturn (state.status === \"completing\" || state.status === \"terminal\") && state.outcome.status !== \"completed\";\n}\n\nfunction parentOf(node: TaskNode): Up {\n\treturn node.owner !== undefined ? { task: node.owner } : { conversation: node.conversationId };\n}\n\nfunction nodeOf(record: AnyTaskRecord): TaskNode {\n\treturn {\n\t\tconversationId: record.conversationId,\n\t\t...(record.owner === undefined ? {} : { owner: record.owner }),\n\t\tbackground: record.background,\n\t};\n}\n\nfunction overlayOf(tx: Transaction): Overlay {\n\tconst tasks = new Map(tx.stagedTasks().map((record) => [record.id, record]));\n\tconst edges = new Map(tx.stagedConversations().map((record) => [record.id, record.owner?.taskId ?? null]));\n\treturn { tasks, edges };\n}\n\nfunction addTo<K, V>(map: Map<K, Set<V>>, key: K, value: V): void {\n\tconst values = map.get(key);\n\tif (values === undefined) map.set(key, new Set([value]));\n\telse values.add(value);\n}\n\nfunction deleteFrom<K, V>(map: Map<K, Set<V>>, key: K, value: V): void {\n\tconst values = map.get(key);\n\tif (values === undefined) return;\n\tvalues.delete(value);\n\tif (values.size === 0) map.delete(key);\n}\n\n/** Own memo entry only; memo names such as `toString` must not resolve to inherited properties. */\nfunction memoOf(record: AnyTaskRecord | undefined, name: string): JsonValue | undefined {\n\tconst memos = record?.memos;\n\treturn memos !== undefined && Object.hasOwn(memos, name) ? memos[name] : undefined;\n}\n\n/** Overloaded Session method bound for forwarding an argument list unchanged. */\nfunction sessionMethod(\n\tsession: SessionImpl,\n\tname: \"snapshot\" | \"snapshotAsOf\" | \"watchDoc\",\n): (...args: readonly unknown[]) => Promise<unknown> {\n\treturn (session[name] as (...args: readonly unknown[]) => Promise<unknown>).bind(session);\n}\n\nfunction missingMigration(record: AnyTaskRecord, definition: ErasedDefinition): Error {\n\treturn new Error(`Task ${record.kind} version ${definition.version} has no migration from ${record.version}`);\n}\n\nfunction erased(task: AnyTask): ErasedDefinition {\n\treturn task.definition as unknown as ErasedDefinition;\n}\n\nfunction endedError(invocation: Invocation): Error {\n\treturn new Error(`Task ${invocation.taskId} invocation has ended`);\n}\n\n/** Replace a live record's state; memos disappear once an outcome is decided. */\nfunction withState(record: AnyTaskRecord, state: TaskState<JsonValue, JsonValue>): AnyTaskRecord {\n\tif (state.status !== \"terminal\" && state.status !== \"completing\") return { ...record, state } as AnyTaskRecord;\n\tconst { memos: _memos, ...rest } = record;\n\treturn { ...rest, state };\n}\n\n/** Whether a definition can take the task at reservation: same version, or newer with a migration. */\nfunction canReserve(task: AnyTask, record: AnyTaskRecord): boolean {\n\tconst definition = task.definition;\n\treturn (\n\t\tdefinition.version === record.version || (definition.version > record.version && definition.migrate !== undefined)\n\t);\n}\n\nfunction delay(ms: number, signal: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst onAbort = (): void => {\n\t\t\tclearTimeout(timer);\n\t\t\treject(signal.reason);\n\t\t};\n\t\tconst timer = setTimeout(() => {\n\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n}\n\n/** Structural equality of two JSON values; object key order is ignored. */\nfunction jsonEqual(left: JsonValue | undefined, right: JsonValue | undefined): boolean {\n\tif (left === right) return true;\n\tif (typeof left !== \"object\" || typeof right !== \"object\" || left === null || right === null) return false;\n\tif (Array.isArray(left) || Array.isArray(right)) {\n\t\tif (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;\n\t\treturn left.every((value, index) => jsonEqual(value, right[index]));\n\t}\n\tconst keys = Object.keys(left);\n\tif (keys.length !== Object.keys(right).length) return false;\n\treturn keys.every((key) => Object.hasOwn(right, key) && jsonEqual(left[key], right[key]));\n}\n"]}