Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions goals/shift-manager/workers-talk-together/scenes.mts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const RING_TWO = "ring-two";
/** Leg e's call deadline: long enough for Helper B's question to arrive, and the ring to run, while it is parked. */
export const PARKED_CALL_MS = 150_000;
const ENDED = new Set(["completed", "failed", "aborted", "cancelled", "errored", "expired", "interrupted"]);
const OWED_ENDS = new Set([...ENDED].filter((s) => s !== "interrupted"));
Comment thread
jhoffner marked this conversation as resolved.
Resolved
const TERMINAL = new Set(["completed", "failed", "cancelled", "errored"]);
const show = (value: unknown) => JSON.stringify(value)?.slice(0, 500);
const errorOf = (c: Call) => String(c.output?.error ?? "");
Expand All @@ -83,8 +84,8 @@ async function sendLine(who: Connected, session: SessionSummary, words: string):
}
}

/** A request's status in `sessionId`, polled until it ends or `timeoutMs`: every status seen, with when. */
async function follow(who: Connected, flowKind: string, requestId: string, timeoutMs: number): Promise<{ status: string; seen: string[]; seenAt: number[] }> {
/** A request's status in `sessionId`, polled until it ends (`ends`) or `timeoutMs`: every status seen, with when. */
async function follow(who: Connected, flowKind: string, requestId: string, timeoutMs: number, ends: ReadonlySet<string> = ENDED): Promise<{ status: string; seen: string[]; seenAt: number[] }> {
Comment thread
jhoffner marked this conversation as resolved.
Resolved
const client = who.flow(flowKind);
const seen: string[] = [];
const seenAt: number[] = [];
Expand All @@ -94,7 +95,7 @@ async function follow(who: Connected, flowKind: string, requestId: string, timeo
seen.push(now);
seenAt.push(Date.now());
}
if (now !== undefined && ENDED.has(now)) return { status: now, seen, seenAt };
if (now !== undefined && ends.has(now)) return { status: now, seen, seenAt };
}
return { status: "timed-out", seen, seenAt };
}
Expand Down Expand Up @@ -175,7 +176,10 @@ export async function sceneAC(world: World, servers: Servers, walked: Walked): P

// a:answer-in-request — the request that made the call, replayed by the host, reads the answer.
const requestId = line.request ?? asked ?? "";
const ended = await follow(world.alice, helperA().flowKind, requestId, 360_000);
// `interrupted` is not an end here: a call that died before it parked still owes its park, and the
Comment thread
jhoffner marked this conversation as resolved.
Resolved
// durability sweep continues it a stale threshold later (FIX-2269). A request that never leaves
// interrupted reads timed-out.
const ended = await follow(world.alice, helperA().flowKind, requestId, 360_000, OWED_ENDS);
const calls = (await callsIn(world.alice, helperA().id)).filter((c) => c.requestId === requestId && c.output != null && typeof c.output === "object");
const call = calls.find((c) => isWait(c) && c.output?.callId === line.id);
const lines = await linesIn(world.alice, helperA().id);
Expand Down
4 changes: 2 additions & 2 deletions labs/claude-code-style/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ and on a flow over 200 lines; `--wired` also fails while a fixture is left in `s
<!-- inventory:start -->
| Kind | Files | Lines |
|---|---:|---:|
| Configuration | 18 | 501 |
| React UI | 28 | 2685 |
| Configuration | 18 | 507 |
| React UI | 29 | 2754 |
| Small flows | 3 | 273 |
| Checks (not app code) | 10 | 1347 |
<!-- inventory:end -->
10 changes: 9 additions & 1 deletion packages/workforce/test/worker-calls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { afterEach, describe, expect, it } from "vitest";
import { defineFlow, handler } from "@flow-state-dev/core";
import type { GeneratorModel, GeneratorModelCallOptions } from "@flow-state-dev/core/types";
import { inMemoryStores, type StoreAdapter, type StoreRegistry } from "@flow-state-dev/engine";
import { disposeFlowApiRouter, inMemoryStores, type StoreAdapter, type StoreRegistry } from "@flow-state-dev/engine";
import { mockGenerator } from "@flow-state-dev/testing";
import { z } from "zod";
import { boardWorkers, bootBoardHost, ORG, type BoardHost, type BoardHostOptions } from "./conversation-board-harness";
Expand Down Expand Up @@ -555,6 +555,14 @@ async function callThenDie(dies: (method: string, args: unknown[]) => boolean, o
}

describe("a call whose process dies before it parks", { timeout: 60_000 }, () => {
// The dead host's request still owes its request-end hooks, and that debt is
// kept per process, which both hosts share here: the next host's shutdown
// would wait its whole drain budget for a run that never ends. Runs before
// the file's hook disposes `open`.
afterEach(async () => {
if (open !== undefined) await disposeFlowApiRouter(await open.state.getRouter(), { drainMs: 100 });
});

// The bug (FIX-2269): the caller's request was left `interrupted` behind no
// gate, so nothing continued it and the call never answered its user, though
// the recipient could still have answered it.
Expand Down
Loading