Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c8600eb
wip(FIX-2080): substrate slice
claude Oct 21, 2026
d2cdf84
wip(FIX-2080): orchestration tests
claude Oct 21, 2026
d62aea0
wip(FIX-2080): workforce
claude Oct 21, 2026
356cc00
wip(FIX-2080): direct filed cascade
claude Oct 21, 2026
2302506
wip(FIX-2080): ui and goals vocabulary
claude Oct 21, 2026
2f0d88a
wip(FIX-2080): filing-settings goal
claude Oct 21, 2026
28eb765
wip(FIX-2080): docs, goal verdicts, filing-settings goal.md
claude Oct 21, 2026
7052203
wip(FIX-2080): changeset; devtool finds a board's tools without block…
claude Oct 21, 2026
0d5a235
fix(FIX-2080): retired-term wording in tests; unexport module-interna…
claude Oct 21, 2026
98db332
fix(FIX-2080): break the cascade/ledger import cycle by handing the l…
claude Oct 21, 2026
76a057a
Merge origin/main into fix/FIX-2080 (FIX-2076 lands first)
claude Oct 21, 2026
d414662
fix(FIX-2080): release a retried legacy blocked row; keep its reason …
claude Oct 21, 2026
af73d28
fix(FIX-2080): a dependency that ends while its dependent is written …
claude Oct 21, 2026
966252f
fix(FIX-2080): a late filed-cascade payment cancels only the ending's…
claude Oct 21, 2026
1cdb63a
test(FIX-2080): a refused Workforce batch files none of its rows
claude Oct 21, 2026
5578448
fix(FIX-2080): a batch row filed already ended counts as a dead depen…
claude Oct 21, 2026
fef68ec
fix(FIX-2080): refuse a Workforce batch that names one id twice
claude Oct 21, 2026
767e85f
fix(FIX-2080): a piece added after its task ended is cancelled by its…
claude Oct 21, 2026
898357f
fix(FIX-2080): a touch cancels dependents an ending in another proces…
claude Oct 21, 2026
92406a5
fix(FIX-2080): updateTask releases last, after a reassignment lands
claude Oct 21, 2026
a7e4e37
fix(FIX-2080): refuse a follow-up of a task that never ran; rename it…
claude Oct 21, 2026
397137a
fix(FIX-2080): a replan naming a failed task skips it instead of fail…
claude Oct 21, 2026
e02bfb8
docs(FIX-2080): a held task keeps a board from finishing; batch and t…
claude Oct 21, 2026
efe6a5c
test(FIX-2080): reword a test goal off a retired term
claude Oct 21, 2026
1602e62
fix(FIX-2080): keep the dead-dependents sweep module-internal
claude Oct 21, 2026
d4e601d
test(FIX-2080): the filing-settings goal files its pieces for a helper
claude Oct 21, 2026
b194f86
fix(FIX-2080): pay a drain's owed cascades after its workers, not bef…
claude Oct 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip(FIX-2080): direct filed cascade
  • Loading branch information
claude committed Oct 21, 2026
commit 356cc00a05f0d2263c9247cb80991f45cc71e221
90 changes: 34 additions & 56 deletions packages/workforce/src/conversation-board/cascade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@
* when a task fails, retries or is cancelled, the open tasks its session
* filed are cancelled, so no filed task outlives the task that filed it.
*
* - **Which tasks.** A task's session files its pieces on its own board,
* each marked as a piece of the task (`PIECE_OF`). The first piece it files
* stamps the task's row on the board above with where that session is
* (`FILED_MARKER`: the session and its flow), server-written, so the ending
* knows where to send the cancel.
* - **The debt.** The ledger's ending recorder writes `Task.cascadeOwed` in
* the ending's own write for a row that carries the marker
* ({@link filedCascade}`.owes`), so a crash between the ending and the
* cancel leaves it owed, not lost.
* - **The payment.** In the task's own session (the claim gate's ending, a
* retry), its open pieces are cancelled on its board directly. Anywhere else
* (a cancel from the conversation), the cancel is sent into the task's
* session (`CANCEL_PIECES_ENTRY`). A send that is refused leaves the debt
* for the board's next touch past its due time.
* - **Which tasks.** A task's session files its pieces on its own board (the
* ledger at that session's partition), each marked as a piece of the task
* (`PIECE_OF`). The first piece it files stamps the task's row on the board
* above with where those pieces are (`FILED_MARKER`: the session and its
* partition), server-written, so the ending knows where to cancel.
* - **The debt.** Orchestration writes `Task.cascadeOwed` in the ending's own
* write for a row that carries the marker ({@link filedCascade}`.owes`), so
* a crash between the ending and the cancels leaves it owed, not lost.
* - **The payment.** Whichever request wrote the ending cancels the open
* pieces on that board, directly: the ledger sits at the user's own scope,
* so the task's own session (the claim gate's ending, a retry) and the
* conversation that filed it (a cancel) reach it alike, within the ending's
* own pass. One that fails leaves the debt for the board's next touch past
* its due time.
*
* Each piece's cancel is itself an ending on the session's board, so a piece
* that filed work of its own cascades in turn, down the chain.
*/
import type { BlockContext } from "@flow-state-dev/core/types";
import { dispatchThroughSeam } from "@flow-state-dev/core/types";
import {
endsFiledWork,
isTerminalStatus,
type DeclaredFiledCascade,
type Task
} from "@flow-state-dev/orchestration/tasks";
import { z } from "zod";
import { FILING_SESSION_STATE_KEY, TASK_FLOW_STATE_KEY } from "../workers/keys";
import { CANCEL_PIECES_ENTRY, FILED_MARKER, PIECE_OF } from "./board-entries";
import { conversationLedgerAt, ownConversationLedger } from "./ledger";
import { FILING_SESSION_STATE_KEY } from "../workers/keys";
import { FILED_MARKER, PIECE_OF } from "./board-entries";
import { filingSessionIdOf } from "./filing-session";
import { conversationLedgerAt } from "./ledger";

const filedMarkerSchema = z.object({ session: z.string().min(1), flow: z.string().min(1) });
const filedMarkerSchema = z.object({ session: z.string().min(1), partition: z.string().min(1) });

/** Where a task's session filed its pieces: that session, and the flow it runs on. */
/** Where a task's session filed its pieces: that session, and its board's partition. */
export type FiledMarker = z.infer<typeof filedMarkerSchema>;

/** The row's filed marker, when it carries one that reads. */
Expand All @@ -45,28 +45,22 @@ export function filedMarkerOf(row: Pick<Task, "metadata"> | undefined): FiledMar
return parsed.success ? parsed.data : undefined;
}

function stringAt(ctx: BlockContext, key: string): string | undefined {
const value = ((ctx.session.state ?? {}) as Record<string, unknown>)[key];
return typeof value === "string" ? value : undefined;
}

/**
* Stamp `taskId`'s row on the board above with this session, before the
* running task session files its first piece for it. A crash between the
* stamp and the piece's add leaves a marker with nothing to cancel, which
* costs a no-op; the reverse order could leave a piece no cascade reaches.
*/
export async function markFiled(ctx: BlockContext, taskId: string): Promise<void> {
const partition = stringAt(ctx, FILING_SESSION_STATE_KEY);
const flow = stringAt(ctx, TASK_FLOW_STATE_KEY);
if (partition === undefined || flow === undefined) return;
const above = await conversationLedgerAt(ctx, partition);
const row = above?.get(taskId);
if (above === undefined || row === undefined) return;
const marker: FiledMarker = { session: ctx.session.identity.id, flow };
const above = ((ctx.session.state ?? {}) as Record<string, unknown>)[FILING_SESSION_STATE_KEY];
if (typeof above !== "string") return;
const ref = await conversationLedgerAt(ctx, above);
const row = ref?.get(taskId);
if (ref === undefined || row === undefined) return;
const marker: FiledMarker = { session: ctx.session.identity.id, partition: await filingSessionIdOf(ctx.session) };
const current = filedMarkerOf(row);
if (current !== undefined && current.session === marker.session && current.flow === marker.flow) return;
await above.patchMetadata(taskId, { [FILED_MARKER]: marker });
if (current !== undefined && current.session === marker.session && current.partition === marker.partition) return;
await ref.patchMetadata(taskId, { [FILED_MARKER]: marker });
}

/** Why a cascade cancelled a piece, in the piece's row. */
Expand All @@ -84,28 +78,12 @@ export const filedCascade: DeclaredFiledCascade = {
pay: async (ctx, row) => {
const marker = filedMarkerOf(row);
if (marker === undefined) return true;
if (ctx.session?.identity?.id === marker.session) {
const own = await ownConversationLedger(ctx);
if (own === undefined) return true;
for (const piece of own.list()) {
if (piece.metadata?.[PIECE_OF] !== row.id || isTerminalStatus(piece.status)) continue;
await own.cancel(piece.id, cancelReason(row));
}
return true;
}
try {
await dispatchThroughSeam(ctx, {
type: "internal",
action: CANCEL_PIECES_ENTRY,
flowKind: marker.flow,
session: { id: marker.session },
payload: { taskId: row.id },
from: "task-cascade"
});
return true;
} catch {
// Owed still: the board's next touch past the due time sends it again.
return false;
const board = await conversationLedgerAt(ctx, marker.partition);
if (board === undefined) return false;
for (const piece of board.list()) {
if (piece.metadata?.[PIECE_OF] !== row.id || isTerminalStatus(piece.status)) continue;
Comment thread
jhoffner marked this conversation as resolved.
Resolved
await board.cancel(piece.id, cancelReason(row));
}
return true;
}
};
23 changes: 17 additions & 6 deletions packages/workforce/test/conversation-board-filing-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,37 @@ describe("the work a task filed goes with it (FIX-2080 D2)", () => {
}
});

it("cancels the open piece a running task filed when the conversation cancels the task", async () => {
it("cancels the open piece a running task filed within seconds of the conversation cancelling the task", async () => {
const h = bootSplitHost();
try {
h.controls.plans.planner = [{ goal: "Plan the launch", assignee: "s1" }];
h.controls.plans.s1 = [{ goal: "[slow:3000] Book the venue", assignee: "eng.tasker" }];
h.controls.holdAfterFiling.s1 = 1500;
h.controls.plans.s1 = [{ goal: "[slow:6000] Book the venue", assignee: "eng.tasker" }];
// The task's turn runs on long after the cancel, so nothing it does when
// it ends can be what cancels the piece.
h.controls.holdAfterFiling.s1 = 5000;
const planner = await h.open("alice", "planner");
await h.turn("alice", planner);
// Wait until the piece is filed and the task is still running its turn.
expect(await h.until(async () => (await h.rowsNamed("alice", "[slow:3000] Book the venue")).length === 1)).toBe(true);
expect(await h.until(async () => (await h.rowsNamed("alice", "[slow:6000] Book the venue")).length === 1)).toBe(true);
const top = await one(h, "Plan the launch");
expect(top.status).toBe("in_progress");

expect(await h.tool("alice", planner, "cancelTask", { taskId: top.id, reason: "not needed" })).toEqual({ ok: true });
const cancelledAt = Date.now();
const pieceCancelled = await h.until(
async () => (await one(h, "[slow:6000] Book the venue")).status === "cancelled",
2500
);
expect(pieceCancelled).toBe(true);
// Paid while the task's turn was still running, not when it ended.
expect(Date.now() - cancelledAt).toBeLessThan(4000);
expect(h.controls.turns.filter((turn) => turn.worker === "s1")).toHaveLength(1);
await h.settled();

expect((await one(h, "Plan the launch")).status).toBe("cancelled");
expect((await one(h, "[slow:3000] Book the venue")).status).toBe("cancelled");
expect((await one(h, "[slow:6000] Book the venue")).status).toBe("cancelled");
} finally {
await h.dispose();
}
});
}, 20_000);
});