diff --git a/.changeset/wait-reads-an-ended-task-once.md b/.changeset/wait-reads-an-ended-task-once.md new file mode 100644 index 0000000000..1fd052d5d5 --- /dev/null +++ b/.changeset/wait-reads-an-ended-task-once.md @@ -0,0 +1,5 @@ +--- +"@flow-state-dev/orchestration": patch +--- + +A `getTask({ id, wait: true })` on a task that already ended returns it at once, and that answer is the filer's delivery: when the flow's `onTaskSettled` waits behind the turn that filed the task, as Workforce's turns make it, the ending's notice request still runs but no longer calls your block. Task collection refs gain an optional `dropNoticeReadByWait(id)`, which both built-in backings implement; a ref without it keeps the old behaviour (FIX-2112). diff --git a/apps/docs/docs/orchestration/task-board.md b/apps/docs/docs/orchestration/task-board.md index 79e69e778a..4992ea755b 100644 --- a/apps/docs/docs/orchestration/task-board.md +++ b/apps/docs/docs/orchestration/task-board.md @@ -846,6 +846,9 @@ getTask({ id: "task_8f2", wait: true }) You can wait in the same turn or in a later one. Your turn pauses until the task ends, then carries on with the task as `getTask` always returns it: its status, and its output once it completed. Nothing holds a request open while it waits, so a server restart loses nothing. +A task that already ended is returned at once, and no `onTaskSettled` follows for it, as long +as your `onTaskSettled` waits behind the turn that filed the task. A Workforce conversation or +task turn works that way. The request still runs, but your block isn't called. A wait has a deadline, five minutes unless you pass `deadline` in milliseconds. At the deadline your turn carries on with the task as it stands, usually still `in_progress`. Nothing is diff --git a/goals/task-board/waits-on-a-task-it-filed/goal.md b/goals/task-board/waits-on-a-task-it-filed/goal.md index 098a94fa13..9f694aa49d 100644 --- a/goals/task-board/waits-on-a-task-it-filed/goal.md +++ b/goals/task-board/waits-on-a-task-it-filed/goal.md @@ -8,7 +8,7 @@ **Signal:** each failure is tagged `:`. -- `a` A conversation files with `createTask` and its request ends. A later request of that conversation waits with `getTask` and parks; once the task ends it gets the task `completed`, with its worker's token, in that request, and no `onTaskSettled` runs for it. A second conversation of the same user is refused (on a per-conversation board it can't reach the row: `task_not_found`), and a second request of the filing conversation is refused `wait_taken` while the first waits. +- `a` A conversation files with `createTask` and its request ends. A later request of that conversation waits with `getTask` and parks; once the task ends it gets the task `completed`, with its worker's token, in that request, and no `onTaskSettled` runs for it. A second conversation of the same user is refused (on a per-conversation board it can't reach the row: `task_not_found`), and a second request of the filing conversation is refused `wait_taken` while the first waits. A piece that ends between a task turn's `createTask` and its `getTask` wait, in one request, is returned by the wait, no `onTaskSettled` delivers it (a notice request that finds it no longer owed delivers nothing), and the waiting turn's answer is the task's result (FIX-2112). - `b` Five nested waits, four through task requests (the conversation, then `doer.a` to `doer.c`) and one waited dispatch (`doer.d`'s), each resume with the result below: the top request's answer carries the probe's token. The probe's own waited dispatch, a sixth, is refused `wait_too_deep` and dispatches nothing (one probe request). A chain of five parked waits built below a task nobody waited on, then a late wait on that task, is refused `wait_too_deep` and marks nothing. A task session's turn files 101 steps for itself: 100 land on the plan ledger and the 101st is refused at the chain's cap. - `c` A deadline shorter than the work resumes the request with the task `in_progress` on attempt 1, and a second wait gets it `completed`, still attempt 1. A task ending after the deadline while its request still runs reaches that request once, on its next `getTask`, and no `onTaskSettled` runs for it. A request that ends without waiting again hears the ending once, as `onTaskSettled`. An ending and a deadline due together resume the request once and deliver the ending once. A second process parks a wait and is killed with SIGKILL; reopened on the same store, the deadline resumes the wait within its due time plus 2 s. The task whose request waits is cancelled: that request makes no further model call and records no return. - `d` A worker's step filed `session: "new"` runs in a session of its own while its plan's drain parks on it, waiting again at each of two deadlines (at least three parks) and starting no later step; once it ends, the next step's turn reads a token only that session's turn produced. A second plan whose step filed `session: "new"` is its last: once it ends, nothing is left open, and the worker still gets one answering turn, told that step's token, and its task completes with that answer (FIX-2110). @@ -40,3 +40,5 @@ On `main` before FIX-2082 legs `a` and `b` fail: `getTask` takes no `wait`, a ta | 2026-10-22 | fix/FIX-2082 fd85658ab (review round on #3653, main with FIX-2088 and FIX-2086 merged in) | n/a (model-free) | FAIL (control `drain-moves-on`, expected) | d only: the drain parked 1 time and moved on, and its request never finished | | 2026-10-23 | fix/FIX-2110 on 14778344c, plan.ts fix set aside | n/a (model-free) | FAIL (expected, before the fix) | d: with the step in its own session last, 0 answering turns; its task landed the plan turn's earlier answer. The rest of d passes | | 2026-10-23 | fix/FIX-2110 on 14778344c | n/a (model-free) | PASS | All legs. d: the drain parked 3 times; step 3 read step 2's token; with the step in its own session last, 1 answering turn, and its task landed the answer told that step's token. `drain-moves-on` still FAILs d (expected) | +| 2026-10-23 | fix/FIX-2112 da86f88b8 (on `main` 14778344c) | n/a (model-free) | PASS | All legs. a: a piece that ended before its task turn's wait was read by it; 1 `onTaskSettled` request in the task's session, admitting nothing (`owed: false`), 0 delivering it. b, c, d, e as before; the kill resumed 132 ms past due | +| 2026-10-23 | `main` 14778344c with this run's leg a (FIX-2112's fix stashed) | n/a (model-free) | FAIL (expected) | a: 1 `onTaskSettled` delivered the piece's ending after the wait read it, and its "heard" answer replaced the task's result | diff --git a/goals/task-board/waits-on-a-task-it-filed/run.mts b/goals/task-board/waits-on-a-task-it-filed/run.mts index 27e669a193..bb97d02659 100644 --- a/goals/task-board/waits-on-a-task-it-filed/run.mts +++ b/goals/task-board/waits-on-a-task-it-filed/run.mts @@ -471,6 +471,57 @@ await runGoal(async (failures, tell) => { tell.over("a · onTaskSettled for a waited task", heard, { emptyIs: "the claim: the waiting request had the ending" }); if (heard.length !== 0) failures.push(`a:the ending reached its waiter, not onTaskSettled — ${heard.length} onTaskSettled request(s)`); notes.push(`a: the later request read ${PRODUCED.get("a-work")}; another session: ${/"error":"([a-z_]+)/.exec(otherSaid)?.[1]}; the filing session's second request: wait_taken`); + + // A task that ends between its filing and its filer's wait, in one request + // (a task's turn, which a notice waits behind): the wait returns it at + // once, and that is the filer's one hearing of it. + const quick = await h.http.open("desk", { workerId: "lead" }); + const pieceGoal = word("a-quick-piece"); + const topGoal = word("a-quick-top"); + await h.send("desk", quick, "respond", { + message: scripted("a-quick-file", [ + { + tool: "createTask", + args: { + goal: scripted(topGoal, [ + { tool: "createTask", args: { goal: scripted(pieceGoal, [{ answer: "a-quick-piece" }]), assignee: "doer.b" } }, + { hold: "a-quick" }, + { tool: "getTask", args: { id: "$0", wait: true } }, + { answer: "a-quick-waiter" } + ]), + assignee: "doer.a" + } + }, + { answer: "a-quick-filer" } + ]) + }); + const endedFirst = await h.until(async () => (await h.byGoal(pieceGoal))[0]?.status === "completed", 20_000); + gate("a-quick").open(); + await h.until(async () => (await h.byGoal(topGoal))[0]?.status === "completed", 20_000); + await h.idle(); + // Past the notice's due time, so a resend by the filer's pass has had its chance too. + await sleep(2_500); + await h.idle(); + const [top] = await h.byGoal(topGoal); + const [piece] = await h.byGoal(pieceGoal); + const quickRead = top?.run?.requestId === undefined ? "" : (await h.toolOutputs(top.run.requestId, "getTask")).join(" "); + const notices = top?.run?.sessionId === undefined ? [] : (await h.requestsOf(top.run.sessionId)).filter((r) => r.actionName === "onTaskSettled"); + // A notice request that finds its notice no longer owed delivers nothing (the entry's admit): count the ones it admitted. + const delivered = tell.over( + "a · onTaskSettled requests that delivered the piece's ending", + notices.filter((r) => r.result?.output?.owed === true && r.result.output.notice?.taskId === piece?.id), + { emptyIs: "the claim: the wait's answer was the delivery" } + ); + if (!endedFirst || !quickRead.includes('"status":"completed"') || !quickRead.includes(PRODUCED.get("a-quick-piece") ?? "")) { + failures.push(`a:a task that ended before the wait is returned by it — ended first: ${endedFirst}; read ${quickRead.slice(0, 300)}`); + } + if (delivered.length !== 0) { + failures.push(`a:an ending read by the filer's wait starts no notice turn — ${delivered.length} onTaskSettled delivered it too`); + } + if (top?.status !== "completed" || !JSON.stringify(top.output ?? "").includes(PRODUCED.get("a-quick-waiter") ?? "")) { + failures.push(`a:the waiting turn's answer is the task's result — task ${top?.status}, output ${JSON.stringify(top?.output ?? "").slice(0, 200)}`); + } + notes.push(`a: a piece that ended before its wait was read by it; ${notices.length} onTaskSettled request(s) in the task's session, ${delivered.length} delivering it`); }); // ---- b. nested waits, and the depth --------------------------------------------- diff --git a/packages/orchestration/README.md b/packages/orchestration/README.md index fc37c889ac..7f1283ef1c 100644 --- a/packages/orchestration/README.md +++ b/packages/orchestration/README.md @@ -988,8 +988,11 @@ See [Per-generator binding](https://flow-state.dev/docs/skills/binding) for the `getTask({ id, wait: true, deadline? })` parks the calling turn on a task its session filed, until the task ends or the deadline passes, and returns the task as `getTask` always does. The deadline is milliseconds from the call, five minutes by default, within the host's -`waitDeadlines` bounds. At the deadline the task runs on and nothing is cancelled. If it ends -before the waiting request does, that request's next `getTask` on it returns the ending. If +`waitDeadlines` bounds. A task that already ended is returned at once, and no `onTaskSettled` +follows for it when the flow's `onTaskSettled` waits behind the turn that filed the task, as +Workforce's `respond` and `work` turns make it: the request still runs, but your block isn't +called. At the deadline the task runs on and nothing is cancelled. If it ends before the +waiting request does, that request's next `getTask` on it returns the ending. If the request ends without reading it, the ending goes to `onTaskSettled`, once. Waits nest: a task's own turn may wait too. A wait is refused when it would make a chain of more than five waits (`MAX_WAIT_DEPTH`), counting the waits above you and any already below the task you wait diff --git a/packages/orchestration/src/tasks/collection/internal.ts b/packages/orchestration/src/tasks/collection/internal.ts index 6a06b95f4f..9cc719e3ed 100644 --- a/packages/orchestration/src/tasks/collection/internal.ts +++ b/packages/orchestration/src/tasks/collection/internal.ts @@ -20,7 +20,7 @@ import { } from "../schema/task-status"; import { extractTaskItems } from "../items/extract-window"; import { applyEndingRecorder, endingOf, type TaskEnding, type TaskEndingRecorder } from "./ending"; -import { droppedHeldNotices, recordEnding as recordNoticeOwed, releasedHeldNotices } from "../notice/task-notice"; +import { deliveredByWait, droppedHeldNotices, recordEnding as recordNoticeOwed, releasedHeldNotices } from "../notice/task-notice"; import { assertDepsEditable, TaskFilingRefusedError } from "./filing"; import { hasStarted, lockedFields, type TaskEditField } from "./field-rules"; import { steersForAttempt, untakenSteers } from "../steers"; @@ -279,6 +279,19 @@ export function releaseWaitWrite( }; } +/** + * The one rule for a wait that found its row already ended + * (`TaskCollectionRef.dropNoticeReadByWait`, FIX-2112): the wait's answer + * delivered the ending, so the notice the ending owes the filer is dropped. + * + * @returns The patch to write, or `undefined` when the row owes no notice for its ending. + */ +export function noticeReadByWaitWrite(task: Task): { patch: Partial } | undefined { + const dropped = deliveredByWait(task); + if (Object.keys(dropped).length === 0) return undefined; + return { patch: { metadata: { ...(task.metadata ?? {}), ...dropped } } }; +} + /** * The fields a filing may change until the task first starts (FIX-2080, * ER-4; the brief's fields and the assignee since FIX-2081). Each field's rule diff --git a/packages/orchestration/src/tasks/collection/resource-backed.ts b/packages/orchestration/src/tasks/collection/resource-backed.ts index db479b1e08..b7d0db7374 100644 --- a/packages/orchestration/src/tasks/collection/resource-backed.ts +++ b/packages/orchestration/src/tasks/collection/resource-backed.ts @@ -135,6 +135,7 @@ import { lapseWaitWrite, markWaitWrite, releaseWaitWrite, + noticeReadByWaitWrite, settingsWrite, settingsChangeKind, type TaskSettingsPatch, @@ -1386,6 +1387,10 @@ export async function createResourceBackedTaskCollection releaseWaitWrite(task as Task, { ...release, dueAt })?.patch as Partial> | undefined); }, + async dropNoticeReadByWait(id) { + return patchRef(id, "metadata_changed", (task) => noticeReadByWaitWrite(task as Task)?.patch as Partial> | undefined); + }, + async refresh(id) { const taskRef = mirror.get(id); if (taskRef !== undefined) await readCommitted(taskRef, () => undefined); diff --git a/packages/orchestration/src/tasks/collection/state-backed.ts b/packages/orchestration/src/tasks/collection/state-backed.ts index ed598017d8..a6ab6188c7 100644 --- a/packages/orchestration/src/tasks/collection/state-backed.ts +++ b/packages/orchestration/src/tasks/collection/state-backed.ts @@ -67,6 +67,7 @@ import { lapseWaitWrite, markWaitWrite, releaseWaitWrite, + noticeReadByWaitWrite, settingsWrite, settingsChangeKind, type EndingRecording, @@ -1069,6 +1070,10 @@ export function createStateBackedTaskCollection releaseWaitWrite(task as Task, { ...release, dueAt })?.patch as Partial> | undefined); }, + async dropNoticeReadByWait(id) { + return patchOne(id, "metadata_changed", (task) => noticeReadByWaitWrite(task as Task)?.patch as Partial> | undefined); + }, + async payOwedCascades() { return payOwedCascades(cascadeWrites, now()); }, diff --git a/packages/orchestration/src/tasks/collection/types.ts b/packages/orchestration/src/tasks/collection/types.ts index ada52088b6..e02b8ef3c5 100644 --- a/packages/orchestration/src/tasks/collection/types.ts +++ b/packages/orchestration/src/tasks/collection/types.ts @@ -1041,6 +1041,16 @@ export interface TaskCollectionRef { * the slot is not a lapsed one that request holds. */ releaseWait?(id: string, release: { readonly requestId: string; readonly read: boolean }): Promise; + /** + * The filer's wait found the row already ended and returned it (FIX-2112): + * drop the notice the ending owes the filer, which that answer delivered. + * `unchanged` when the row owes none for its ending. Server-owned, as the + * other wait writes are: a caller's `patchMetadata` can't clear a notice. + * + * Optional: both built-in backings implement it. On a ref without it the + * filer hears the ending again, as `onTaskSettled`. + */ + dropNoticeReadByWait?(id: string): Promise; /** * A touch of the board: pay every cascade owed past its due time * (`Task.cascadeOwed`, FIX-2080 D2), so one a crash left owed is paid. diff --git a/packages/orchestration/src/tasks/helpers/wait-on-task.ts b/packages/orchestration/src/tasks/helpers/wait-on-task.ts index 4678a5d179..8bffa00b3a 100644 --- a/packages/orchestration/src/tasks/helpers/wait-on-task.ts +++ b/packages/orchestration/src/tasks/helpers/wait-on-task.ts @@ -16,7 +16,8 @@ * any already below the task it waits on, counted by the engine. A wait * that waits again at its deadline counts again before each new park, * except a drain on a row it handed over, whose wait already exists. - * A task already ended is returned at once. + * A task already ended is returned at once, and the notice its ending + * owes the filer is dropped: this answer delivered it (FIX-2112). * 2. **Take the row's wait slot** in one conditional write (`markWait`): a * second request waiting on the same task is refused. * 3. **Park** on the one wait gate (`parkOnWait`), whose deadline the engine @@ -66,7 +67,7 @@ import type { TaskCollectionRef } from "../collection/types"; import type { TaskClaimTicket } from "../claim-ticket"; import { resolveResourceCollection } from "../collection/resolve-resource-collection"; import { getOrCreateTaskCollection } from "../collection/get-or-create"; -import { holdsAnEnding, LAPSED_SLOT_CHECK_CAP_MS, LAPSED_SLOT_CHECK_MS } from "../notice/task-notice"; +import { deliveredByWait, holdsAnEnding, LAPSED_SLOT_CHECK_CAP_MS, LAPSED_SLOT_CHECK_MS } from "../notice/task-notice"; // The running request's own task, as the claim and the gate know it. Reached by // path, not through the task-board barrel, which imports this module. import { currentWorkerClaim } from "../../task-board/flow-policy-wiring"; @@ -481,14 +482,35 @@ function claimBoardOf(ctx: BlockContext, collectionId: string) { } } -/** The waited-on row ended: clear what it owes the resume, and return it. */ +/** + * The waited-on row ended: clear what it owes the resume, and return it. An + * ending that came before the wait owes its filer a notice; when the filer is + * the one waiting, this answer delivers it, so it is dropped (FIX-2112). + */ async function ended(ctx: BlockContext, collection: TaskCollectionRef, taskId: string): Promise { await clearMarker(collection, taskId); const task = collection.get(taskId)!; await deliverHeldEnding(ctx, collection, task); + await deliverEndedBeforeWait(ctx, collection, collection.get(taskId) ?? task); return { ok: true, task: collection.get(taskId) ?? task, ended: true }; } +/** + * Drop the notice an ending owes its filer, when the filer's own wait read it + * (FIX-2112). Never fails the call: a drop that fails leaves the notice owed, + * and the filer hears the ending a second time. + */ +async function deliverEndedBeforeWait(ctx: BlockContext, collection: TaskCollectionRef, task: Task): Promise { + const filer = collection.filerOf?.(task) ?? task.filer?.sessionId; + if (filer === undefined || filer !== ctx.session.identity.id) return; + if (Object.keys(deliveredByWait(task)).length === 0) return; + try { + await collection.dropNoticeReadByWait?.(task.id); + } catch (error) { + console.warn(`[orchestration] wait "${task.id}": its ending's notice stays owed: ${(error as Error).message}`); + } +} + /** * Clear the row's resume-owed marker. Never fails the call: a clear that fails * leaves the marker, and the next touch clears it, the gate already resolved. diff --git a/packages/orchestration/src/tasks/notice/task-notice.ts b/packages/orchestration/src/tasks/notice/task-notice.ts index a4808427f3..25aacb9ee0 100644 --- a/packages/orchestration/src/tasks/notice/task-notice.ts +++ b/packages/orchestration/src/tasks/notice/task-notice.ts @@ -31,7 +31,9 @@ * * A retry owes none: it is the row's start, not its ending. A waited-on row * owes none either: the request parked on it is resumed instead - * (`Task.resumeOwed`), and no notice runs for it. + * (`Task.resumeOwed`), and no notice runs for it. A row that ended before its + * filer's wait on it was made owes one at its ending, and the wait that finds + * it ended drops it ({@link deliveredByWait}): the wait's answer delivered it. * * ## An ending held for the request that waited (FIX-2082) * @@ -218,6 +220,19 @@ export function droppedHeldNotices(row: Task): Record { return patch; } +/** + * The metadata patch that drops the notice `row`'s ending owes, when a wait on + * the row found it already ended (FIX-2112): the wait's answer is the + * ending's delivery, as it is for a wait the ending resumes. Empty when the + * row hasn't ended or owes nothing for it. A marker held for a request whose + * wait lapsed is that request's to deliver ({@link droppedHeldNotices}). + */ +export function deliveredByWait(row: Task): Record { + if (row.status !== "completed" && row.status !== "errored" && row.status !== "cancelled") return {}; + const key = markerKey(row.attempts, row.status); + return isSendable(key, (row.metadata ?? {})[key]) ? { [key]: null } : {}; +} + /** * The metadata patch that releases every held marker on `row`, due at `dueAt` * (FIX-2082): the request it was held for ended without reading the row, so diff --git a/packages/orchestration/test/tasks/task-notice.test.ts b/packages/orchestration/test/tasks/task-notice.test.ts index c1e3e12631..59109cba26 100644 --- a/packages/orchestration/test/tasks/task-notice.test.ts +++ b/packages/orchestration/test/tasks/task-notice.test.ts @@ -17,6 +17,7 @@ import { cancelledDependents, clearNotice, decideNotice, + deliveredByWait, NOTICE_DUE_MS, noticeDueAt, isNoticeOwed, @@ -159,6 +160,19 @@ describe("a notice delivered", () => { const cleared = { ...completed, metadata: { ...completed.metadata, ...clearNotice(first) } } as Task; expect(owedNotices(cleared, "tasks").map((n) => n.ending)).toEqual(["completed"]); }); + + it("by a wait that found the row ended drops the ending's notice only (FIX-2112)", () => { + // An earlier attempt's question is not what the wait returned: it stays owed. + const parked = recordEnding(row({ status: "parked" }), { kind: "parked", question: "Which region?", quiet: false }); + const completed = recordEnding({ ...parked, status: "completed", attempts: 2 }, { kind: "completed", output: 1 }); + const read = { ...completed, metadata: { ...completed.metadata, ...deliveredByWait(completed) } } as Task; + expect(owedNotices(read, "tasks").map((n) => n.ending)).toEqual(["parked"]); + // A row still running owes nothing a wait could have read. + expect(deliveredByWait(parked)).toEqual({}); + // A notice held for the request whose wait lapsed is that request's read to deliver, not this one's. + const held = recordEnding(row({ wait: { gateId: "g", deadline: 1, requestId: "r", lapsed: true } } as Partial), { kind: "completed", output: 1 }); + expect(deliveredByWait(held)).toEqual({}); + }); }); describe("the dedupe key", () => { diff --git a/packages/orchestration/test/tasks/wait-fixture.ts b/packages/orchestration/test/tasks/wait-fixture.ts index 184dc211b2..785687699d 100644 --- a/packages/orchestration/test/tasks/wait-fixture.ts +++ b/packages/orchestration/test/tasks/wait-fixture.ts @@ -109,6 +109,11 @@ export function waitFlow( endsAfterMark?: unknown; /** Declare `onTaskSettled`, recording each notice it hears in `heard`: the filer's pass then runs on its own. */ heard?: TaskSettledInput[]; + /** + * A notice waits for the running turn to end, as a Workforce session's + * does: `run` holds the session's line and `onTaskSettled` defers on it. + */ + noticeAfterTurn?: boolean; /** The board's scope: `session` (the default), or `user`, which every session of the user reaches. */ scope?: "session" | "user"; } = {} @@ -272,7 +277,8 @@ export function waitFlow( block: sequencer({ name: "turn" }).step( generator({ name: "agent", model, prompt: "p", tools: [wait, waitAgainTool, readTaskTool] }) ), - inputSchema: z.object({}).passthrough() + inputSchema: z.object({}).passthrough(), + ...(options.noticeAfterTurn === true ? { concurrency: "hold" as const } : {}) }, settle: { block: settle }, touch: { block: touch }, @@ -291,7 +297,8 @@ export function waitFlow( options.heard!.push(notice); return {}; } - }) + }), + ...(options.noticeAfterTurn === true ? { concurrency: "defer" as const } : {}) }) } } diff --git a/packages/orchestration/test/tasks/wait-on-task.test.ts b/packages/orchestration/test/tasks/wait-on-task.test.ts index de4b752f6d..73320153b5 100644 --- a/packages/orchestration/test/tasks/wait-on-task.test.ts +++ b/packages/orchestration/test/tasks/wait-on-task.test.ts @@ -327,6 +327,39 @@ describe("wait on a task: an ending first, and the deadline that cancels nothing } }); + it("a row that ended before the wait is heard once, through the wait: no onTaskSettled runs for it", async () => { + // The filer waited on it, so the wait's answer is its delivery. A notice + // too would wake a second turn on the same ending, whose answer replaces + // the first. The notice waits for the turn to end, as in a Workforce session. + const notices: TaskSettledInput[] = []; + const { model, seen } = stepModel([waitCall("c1"), finalAnswer]); + const flow = waitFlow(model, { endsOnFiling: "already done", heard: notices, noticeAfterTurn: true }); + const state = runtimeFor(flow); + try { + // Through the host's dispatch, which keeps the turn's line (a direct run keeps none). + const router = await state.getRouter(); + const path = ["wait-board", SESSION, "actions", "run"]; + const sent = await router.POST( + new Request(`http://localhost/api/flows/${path.join("/")}`, { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ userId: USER, input: {} }) + }), + { params: { path } } + ); + expect(sent.status).toBe(202); + const requestId = ((await sent.json()) as { request: { id: string } }).request.id; + await until(state, requestId, "completed", 10_000); + expect(toolResults(seen[1]!.messages)).toContain("already done"); + // Past the notice's due time: the fast path's copy and the pass's resend have both had their chance. + await new Promise((r) => setTimeout(r, 2_500)); + expect(owedMarkers((await rows(state, flow))[0]!)).toEqual([]); + expect(notices).toEqual([]); + } finally { + await state.dispose(); + } + }); + it("a row that ended after the slot was taken and before the park, with no touch after, answers at the deadline with its ending", async () => { const { model, seen } = stepModel([waitCall("c1", "q", 50), finalAnswer]); const flow = waitFlow(model, { endsAfterMark: "Yes, renewed 2026-08" });