From 81431faca76bf1c9ccdaddd3dcb36578e41bf8f6 Mon Sep 17 00:00:00 2001 From: Marvin Bitterlich <644950+marvin-bitterlich@users.noreply.github.com> Date: Fri, 6 Nov 2026 22:08:17 +0000 Subject: [PATCH] The pane's Areas section shows only busy lanes and waits for a busy Fleet Fleet's daemon.fleetItems lists only the areas that work holds, queues or reserves, instead of every repository folder. The Work Board pane shows those areas with held ones first and says when no area is busy. Board waits up to 20 seconds for each Fleet read, and keeps its whole Fleet view within 25 seconds so it answers inside Claude Code's 30-second plugin fetch. A Fleet that does not answer in time is named as such, and the pane calls a Board that the host stopped waiting for busy instead of stopped. --- .changeset/busy-areas-patient-fleet.md | 16 ++++++++ packages/work-board-plugin/README.md | 4 +- .../src/adapters/hostBoard.ts | 4 +- .../src/areaAvailability.dom.spec.ts | 4 +- packages/work-board-plugin/src/areaView.tsx | 23 +++++++----- .../work-board-plugin/src/areas.dom.spec.ts | 25 +++++++++---- packages/work-board-plugin/src/areasOf.ts | 8 ++-- packages/work-board-plugin/src/lines.ts | 9 +++++ .../work-board-plugin/src/lines.unit.test.ts | 20 ++++++++++ .../src/test-support/areaReadouts.ts | 6 +++ packages/work-board/README.md | 2 +- .../src/server/diagnostics/daemon.ts | 16 +++++--- .../src/server/integration/board.ts | 3 -- .../work-board/src/server/views/fleetItems.ts | 9 ++++- .../src/server/views/slowFleet.slow.spec.ts | 37 +++++++++++++++++++ .../src/test-support/workspaceBoardTraits.ts | 15 +++++++- .../work-fleet/src/host/areaLanes.spec.ts | 6 +-- .../work-fleet/src/host/daemonDiagnostics.ts | 12 +----- .../work-fleet/src/host/daemonHandlers.ts | 2 +- .../src/test-support/unavailableFleetItems.ts | 2 +- 20 files changed, 168 insertions(+), 55 deletions(-) create mode 100644 .changeset/busy-areas-patient-fleet.md create mode 100644 packages/work-board-plugin/src/lines.unit.test.ts create mode 100644 packages/work-board/src/server/views/slowFleet.slow.spec.ts diff --git a/.changeset/busy-areas-patient-fleet.md b/.changeset/busy-areas-patient-fleet.md new file mode 100644 index 00000000..18e98384 --- /dev/null +++ b/.changeset/busy-areas-patient-fleet.md @@ -0,0 +1,16 @@ +--- +"@shivaedev/work-board": minor +"@shivaedev/work-fleet": patch +--- + +### Changed + +- `@shivaedev/work-fleet`: `daemon.fleetItems` lists only the areas that Fleet work holds, queues or reserves. It no longer lists every repository folder as an idle area. + +### Fixed + +- `@shivaedev/work-board`: Board waits up to 20 seconds for each Fleet read, up from 5, so a busy Fleet no longer shows as unavailable. Its Fleet view, items and brief checks together, stays within 25 seconds, inside the 30 seconds Claude Code waits for a plugin's request. A Fleet that has not answered by then is reported as not answering in time. + +### Breaking + +- `@shivaedev/work-board`: The `board` integration object no longer exports `areaFolders` or `repositoryRoot`. Fleet stopped using them. A consumer that needs area folders reads the repository directly. diff --git a/packages/work-board-plugin/README.md b/packages/work-board-plugin/README.md index cdc764ed..e7f7e8fd 100644 --- a/packages/work-board-plugin/README.md +++ b/packages/work-board-plugin/README.md @@ -20,7 +20,7 @@ The plugin needs a running Work Board. It finds one by walking up from the sessi npx @shivaedev/work-board .work ``` -Without a `.work` folder, the pane and every tool say the session's folder has no Work Board and how to start one; with a Board that is not running, they say so and name the start command. The band stays hidden until the Board answers. Pressing a Needs you item opens it with `open -g` at the URL the Board says it is served on, so opening items works on macOS. +Without a `.work` folder, the pane and every tool say the session's folder has no Work Board and how to start one; with a Board that is not running, they say so and name the start command. Claude Code waits 30 seconds for each Board answer; a Board still working after that is reported as busy, not stopped, and the next refresh asks again. The band stays hidden until the Board answers. Pressing a Needs you item opens it with `open -g` at the URL the Board says it is served on, so opening items works on macOS. The plugin only reads the Board. Answer decisions in the Board itself or through [`@shivaedev/work-board`](../work-board/README.md). @@ -28,7 +28,7 @@ The plugin only reads the Board. Answer decisions in the Board itself or through The pane folds goals with status `done` under an “Achieved (N)” row, closed by default. Click it to show those goals. Open goals stay visible, including goals whose tasks are all done. In flight and goal running counts use the same Board overview snapshot. If Fleet cannot be reached, In flight shows why it is unavailable. -Areas appear as wrapping chips. Green means no holder and no approved task queued; amber marks a held area or a queue of fewer than five tasks; red marks five or more queued tasks. Each chip names its state and queue count. Open a chip to read its holders, stages and PR links, followed by the approved queue in Fleet's order. Package folders and the Board's other repository areas stay visible even when idle. A Fleet daemon that does not supply availability is shown as unknown. +Areas lists only the areas Fleet holds or queues work for, as wrapping chips with held areas first; free areas are left out, and with none busy the section says no area is held or queued. Amber marks a held area or a queue of fewer than five tasks; red marks five or more queued tasks. Each chip names its state and queue count. Open a chip to read its holders, stages and PR links, followed by the approved queue in Fleet's order. A Fleet daemon that does not supply availability is shown as unknown. ### Install diff --git a/packages/work-board-plugin/src/adapters/hostBoard.ts b/packages/work-board-plugin/src/adapters/hostBoard.ts index 3d86ab98..2f5cd61d 100644 --- a/packages/work-board-plugin/src/adapters/hostBoard.ts +++ b/packages/work-board-plugin/src/adapters/hostBoard.ts @@ -2,7 +2,7 @@ import type { EngineInterface, HttpResponse } from "claude-code"; import { platformClient } from "#adapters/platformClient.ts"; import type { Board } from "#boardTools.ts"; import { findBoard } from "#findBoard.ts"; -import { refusedLine, waitingLine } from "#lines.ts"; +import { refusedLine, unansweredLine, waitingLine } from "#lines.ts"; import { RPC_URL, rpcPost } from "#rpc.ts"; type Client = ReturnType; @@ -12,7 +12,7 @@ async function post($: EngineInterface, directory: string, body: string): Promis try { response = await $.http.fetch(RPC_URL, rpcPost(directory, body)); } catch (cause) { - throw new Error(waitingLine({ directory, kind: "down" }), { cause }); + throw new Error(unansweredLine(directory, cause), { cause }); } if (!response.ok) { throw new Error(refusedLine(response, directory)); diff --git a/packages/work-board-plugin/src/areaAvailability.dom.spec.ts b/packages/work-board-plugin/src/areaAvailability.dom.spec.ts index 0e434a02..153b9627 100644 --- a/packages/work-board-plugin/src/areaAvailability.dom.spec.ts +++ b/packages/work-board-plugin/src/areaAvailability.dom.spec.ts @@ -11,16 +11,16 @@ const files = Object.fromEntries( ); pluginFleet.it( - "the plugin's area chips read live Fleet ownership and queues through Board HTTP", + "the plugin's area chips read live Fleet ownership and queues through Board HTTP and leave idle folders out", [boardWork(files)], function* ({ approve, admit, openPane }) { yield* approve("holder"); yield* admit(); const pane = yield* openPane(); yield* outcomes([ + ["Chips", () => pane.areaChips(), ["work-fleet", "work-board"]], ["Held area", () => pane.areaState("work-fleet"), { color: "#d74253", state: "held · 5 queued" }], ["Short queue", () => pane.areaState("work-board"), { color: "#ad7400", state: "unheld · 1 queued" }], - ["Idle area", () => pane.areaState("free"), { color: "#16853f", state: "free" }], ]); }, ); diff --git a/packages/work-board-plugin/src/areaView.tsx b/packages/work-board-plugin/src/areaView.tsx index 699471d3..99dceab4 100644 --- a/packages/work-board-plugin/src/areaView.tsx +++ b/packages/work-board-plugin/src/areaView.tsx @@ -4,9 +4,6 @@ import type { WorkboardArea, WorkboardAreaTask, WorkboardBlock } from "#types/in function stateOf(area: WorkboardArea) { const count = area.queue.length; - if (area.holders.length === 0 && count === 0) { - return { color: "#16853f", label: "free" }; - } return { color: count >= 5 ? "#d74253" : "#ad7400", label: `${area.holders.length > 0 ? "held" : "unheld"} · ${count} queued` }; } @@ -16,13 +13,7 @@ export function areaView(t: Table, areas: WorkboardBlock, view: P return ( Areas - {areas.problem === null ? ( - - {areas.items.map((area) => areaChip(t, area, view.onToggleArea))} - - ) : ( - {areas.problem} - )} + {areas.problem === null ? areaChips(t, areas.items, view.onToggleArea) : {areas.problem}} {areas.problem === null && selected !== undefined ? ( {selected.area} @@ -38,6 +29,18 @@ export function areaView(t: Table, areas: WorkboardBlock, view: P ); } +function areaChips(t: Table, areas: WorkboardArea[], onToggle: (area: string) => void) { + const { Box, Text } = t; + if (areas.length === 0) { + return No area is held or queued.; + } + return ( + + {areas.map((area) => areaChip(t, area, onToggle))} + + ); +} + function areaChip(t: Table, area: WorkboardArea, onToggle: (area: string) => void) { const { Box, Text, Button } = t; const state = stateOf(area); diff --git a/packages/work-board-plugin/src/areas.dom.spec.ts b/packages/work-board-plugin/src/areas.dom.spec.ts index aeb778b3..97c2b590 100644 --- a/packages/work-board-plugin/src/areas.dom.spec.ts +++ b/packages/work-board-plugin/src/areas.dom.spec.ts @@ -5,19 +5,21 @@ import { areasAnswered, paneColumns, pluginPane } from "#test/pluginPane.ts"; const holder = { prUrl: "https://github.com/example/project/pull/42", stage: "reviewing", workId: "Build Fleet" }; const queue = ["First", "Second", "Third", "Fourth", "Fifth"].map((workId) => ({ prUrl: null, stage: "queued", workId })); const availability = areasAnswered([ - { area: "work-fleet", holders: [holder], queue }, + { area: ".pnpm-store", holders: [], queue: [] }, { area: "work-board", holders: [], queue: queue.slice(0, 1) }, + { area: "work-fleet", holders: [holder], queue }, + { area: "work-github", holders: [holder], queue: [] }, { area: "free", holders: [], queue: [] }, ]); pluginPane.it( - "area chips distinguish a held long queue, a short queue and idle work", + "area chips show only held and queued areas, held areas first, and tell a long queue from a short one", [availability, paneColumns(32)], - function* ({ areaState, click, areaDetails }) { + function* ({ areaChips, areaState, click, areaDetails }) { yield* outcomes([ + ["Chips", () => areaChips(), ["work-fleet", "work-github", "work-board"]], ["Held area", () => areaState("work-fleet"), { color: "#d74253", state: "held · 5 queued" }], ["Short queue", () => areaState("work-board"), { color: "#ad7400", state: "unheld · 1 queued" }], - ["Idle area", () => areaState("free"), { color: "#16853f", state: "free" }], ]); yield* click("work-fleet"); expect(yield* areaDetails()).toEqual([ @@ -31,13 +33,22 @@ pluginPane.it( ]); yield* click("work-board"); expect(yield* areaDetails()).toEqual(["work-board", "No holder", "1. First · queued"]); - yield* click("free"); - expect(yield* areaDetails()).toEqual(["free", "No holder", "No approved tasks queued"]); - yield* click("free"); + yield* click("work-board"); expect(yield* areaDetails()).toEqual([]); }, ); +pluginPane.it( + "a Fleet whose areas are all free shows that no area is held or queued", + [areasAnswered([{ area: "free", holders: [], queue: [] }])], + function* ({ areaChips, lookOf }) { + yield* outcomes([ + ["Chips", () => areaChips(), []], + ["Notice", () => lookOf("No area is held or queued."), "dimmed"], + ]); + }, +); + pluginPane.it("an older Fleet reply leaves area availability unknown", [], function* ({ lookOf }) { expect(yield* lookOf("This Fleet has not supplied area availability.")).toBe("dimmed"); }); diff --git a/packages/work-board-plugin/src/areasOf.ts b/packages/work-board-plugin/src/areasOf.ts index ef188aa9..adb1053c 100644 --- a/packages/work-board-plugin/src/areasOf.ts +++ b/packages/work-board-plugin/src/areasOf.ts @@ -15,8 +15,8 @@ export function areasOf(value: unknown): WorkboardBlock { return { prUrl: text(entry.prUrl) ?? null, stage: text(entry.stage) ?? "unknown", title: titles.get(workId) ?? workId, workId }; }); } - return { - items: records(value.areas).map((entry) => ({ area: text(entry.area) ?? "unknown", holders: tasks(entry.holders), queue: tasks(entry.queue) })), - problem: null, - }; + const busy = records(value.areas) + .map((entry) => ({ area: text(entry.area) ?? "unknown", holders: tasks(entry.holders), queue: tasks(entry.queue) })) + .filter((area) => area.holders.length > 0 || area.queue.length > 0); + return { items: [...busy.filter((area) => area.holders.length > 0), ...busy.filter((area) => area.holders.length === 0)], problem: null }; } diff --git a/packages/work-board-plugin/src/lines.ts b/packages/work-board-plugin/src/lines.ts index f9069945..416f3e4c 100644 --- a/packages/work-board-plugin/src/lines.ts +++ b/packages/work-board-plugin/src/lines.ts @@ -16,6 +16,15 @@ export function waitingLine(state: Exclude): return "Loading the Work Board…"; } +// The host aborts $.http.fetch after a fixed wait and says so in its error; any other failure means nothing answered on the socket. +export function unansweredLine(directory: string, cause: unknown): string { + const message = cause instanceof Error ? cause.message : String(cause); + const waited = /no complete answer within (?\d+)ms/u.exec(message)?.groups?.ms; + return waited === undefined + ? waitingLine({ directory, kind: "down" }) + : `The Work Board for ${directory} is busy: it took longer than ${Math.round(Number(waited) / 1000)} seconds to answer. The pane asks again on its next refresh.`; +} + export function refusedLine(response: RpcReply, directory: string): string { return `The Work Board for ${directory} refused the request (${response.status}): ${response.text.trim()}`; } diff --git a/packages/work-board-plugin/src/lines.unit.test.ts b/packages/work-board-plugin/src/lines.unit.test.ts new file mode 100644 index 00000000..0843c4bb --- /dev/null +++ b/packages/work-board-plugin/src/lines.unit.test.ts @@ -0,0 +1,20 @@ +import { describe, expect, it } from "vitest"; +import { unansweredLine } from "#lines.ts"; + +describe("a Board request that got no answer", () => { + it("calls a Board busy when the host gave up waiting for its answer", () => { + const cause = new Error( + "workboard: $.http.fetch(http://localhost/_board/rpc) over /work/.work/board.sock aborted: no complete answer within 30000ms", + ); + expect(unansweredLine("/work", cause)).toBe( + "The Work Board for /work is busy: it took longer than 30 seconds to answer. The pane asks again on its next refresh.", + ); + }); + + it("calls a Board not running when nothing answered on its socket", () => { + const cause = new Error( + "workboard: $.http.fetch(http://localhost/_board/rpc) over /work/.work/board.sock failed: ECONNREFUSED: connect ECONNREFUSED", + ); + expect(unansweredLine("/work", cause)).toBe("The Work Board for /work isn't running. Start it there: npx @shivaedev/work-board .work"); + }); +}); diff --git a/packages/work-board-plugin/src/test-support/areaReadouts.ts b/packages/work-board-plugin/src/test-support/areaReadouts.ts index 9c13cc89..c2197c78 100644 --- a/packages/work-board-plugin/src/test-support/areaReadouts.ts +++ b/packages/work-board-plugin/src/test-support/areaReadouts.ts @@ -2,6 +2,12 @@ import { Effect } from "effect"; export function areaReadouts(container: Element, tell: (text: string) => void) { return { + areaChips: () => + Effect.sync(() => { + tell("read the area chips in the order the pane shows them"); + const heading = [...container.querySelectorAll("span")].find((span) => span.textContent === "Areas"); + return [...(heading?.parentElement?.children[1]?.querySelectorAll("button") ?? [])].map((button) => button.textContent); + }), areaDetails: () => Effect.sync(() => { tell("read the open area's holder and ordered queue"); diff --git a/packages/work-board/README.md b/packages/work-board/README.md index cc1a0fa0..9b3527af 100644 --- a/packages/work-board/README.md +++ b/packages/work-board/README.md @@ -201,7 +201,7 @@ An open page updates in place as files change, and **Pause updates** holds what The view refreshes through `client.api.diagnostics.query()` every 15 seconds while visible. Pause updates holds the displayed state; resume and returning to a visible tab refresh it. The shared `DiagnosticsContract` and `DiagnosticsSnapshot` schemas live in `@shivaedev/work-board/diagnostics/daemonContract.ts`; the version 2 `FleetHealth` schema lives in `@shivaedev/work-board/diagnostics/health.ts`. The Fleet lane lists every running or waiting item from `client.api.fleetItems.query()` by source title, stage and recorded PR, with explicit loading, unavailable and empty states. Items without readable source retain their work ID; missing PRs remain explicit. The page also shows the publisher's observation time, freshness, running and queued counts, the **Needs you** count Today and the sidebar show, Fleet's counts of work waiting on the orchestrator and on Fleet agents, concurrency cap, last scheduler pass and last observed provider capacity rejection. Fleet's waiting counts never mark the Fleet card as needing attention, so the Board's count stays the only needs-you number on System. Stale snapshots show a Stale badge. Reset times show relative time and the browser’s local clock; System requires JavaScript. Communication failures and API-key accounts explain why their data is unavailable. A publisher clock ahead of Board is disclosed; absent scheduler/rejection observations remain unknown or unobserved. -`client.api.fleetItems.run(undefined)` reads per-item execution through the same daemon client. A `ready` result has `items` for every stage except `done` and `released`, and `completed` for current records completed within the last seven days, including the boundary. Each item carries `workId`, `stage`, a waiting `attentionOwner` when present, `prUrl` when known, and millisecond `stageEnteredAt` and `updatedAt`; completions also carry `completedAt`. Board joins each unique matching ID to `document: { file, title, metadata }`; missing or duplicate IDs keep the Fleet item with `document: null`. For legacy records, stage entry and completion times remain unknown until an observed stage transition; `updatedAt` becomes known on the next write. A stopped daemon returns `{ state: "unavailable", reason, startCommand }`; a communication failure or Board index failure returns `{ state: "unavailable", reason }`. When Board can read every source, an unavailable result also carries `authored`: tasks whose authored status is `ready`, each with `file`, `status`, `title` and `workId`. Set `BoardOptions.fleetPort: null` to disable the item integration. +`client.api.fleetItems.run(undefined)` reads per-item execution through the same daemon client. A `ready` result has `items` for every stage except `done` and `released`, and `completed` for current records completed within the last seven days, including the boundary. Each item carries `workId`, `stage`, a waiting `attentionOwner` when present, `prUrl` when known, and millisecond `stageEnteredAt` and `updatedAt`; completions also carry `completedAt`. Board joins each unique matching ID to `document: { file, title, metadata }`; missing or duplicate IDs keep the Fleet item with `document: null`. For legacy records, stage entry and completion times remain unknown until an observed stage transition; `updatedAt` becomes known on the next write. A stopped daemon returns `{ state: "unavailable", reason, startCommand }`; a communication failure or Board index failure returns `{ state: "unavailable", reason }`. Board waits up to 20 seconds for each daemon read, so a busy Fleet still answers, and keeps the whole Fleet view, items and brief checks together, within 25 seconds; a daemon that has not answered by then is reported as not answering in time. When Board can read every source, an unavailable result also carries `authored`: tasks whose authored status is `ready`, each with `file`, `status`, `title` and `workId`. Set `BoardOptions.fleetPort: null` to disable the item integration. #### Find what waits on you diff --git a/packages/work-board/src/server/diagnostics/daemon.ts b/packages/work-board/src/server/diagnostics/daemon.ts index 12c2cddb..76eae6cf 100644 --- a/packages/work-board/src/server/diagnostics/daemon.ts +++ b/packages/work-board/src/server/diagnostics/daemon.ts @@ -1,4 +1,4 @@ -import { Clock, Effect, Layer, Predicate, Schema } from "effect"; +import { Cause, Clock, Duration, Effect, Layer, Predicate, Schema } from "effect"; import { FetchHttpClient } from "effect/http"; import { RpcClient, RpcSerialization } from "effect/rpc"; import { RpcClientError } from "effect/rpc/RpcClientError"; @@ -10,12 +10,16 @@ function makeDaemonClient() { type DaemonClient = Effect.Success>; const FLEET_STOPPED = "Fleet isn't running, so agent work and its health are unknown."; +// A busy Fleet took up to 15 seconds for one read in measurement. +const FLEET_WAIT_SECONDS = 20; // npx runs the project's own @shivaedev/work-fleet, because the bare work-fleet command is rarely on PATH. export function daemonUnavailable(error: unknown, port: number, folder: string): { readonly reason: string; readonly startCommand?: string } { - const stopped = error instanceof RpcClientError && error.reason._tag === "HttpError" && error.reason.kind === "TransportError"; - return stopped - ? { reason: FLEET_STOPPED, startCommand: `npx @shivaedev/work-fleet serve ${shellWord(folder)} --port ${port}` } + if (error instanceof RpcClientError && error.reason._tag === "HttpError" && error.reason.kind === "TransportError") { + return { reason: FLEET_STOPPED, startCommand: `npx @shivaedev/work-fleet serve ${shellWord(folder)} --port ${port}` }; + } + return Cause.isTimeoutError(error) + ? { reason: `Fleet on port ${port} didn't answer within ${FLEET_WAIT_SECONDS} seconds, so agent work and its health are unknown.` } : { reason: `Fleet on port ${port} didn't answer as expected, so agent work and its health are unknown.` }; } @@ -23,7 +27,7 @@ function shellWord(value: string) { return /^[\w./@%+=:,-]+$/u.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`; } -export function readDaemon(port: number, read: (client: DaemonClient) => Effect.Effect) { +export function readDaemon(port: number, read: (client: DaemonClient) => Effect.Effect, wait = Duration.seconds(FLEET_WAIT_SECONDS)) { return Effect.scoped( Effect.gen(function* () { const client = yield* makeDaemonClient(); @@ -34,7 +38,7 @@ export function readDaemon(port: number, read: (client: DaemonClient) => E Layer.provide([FetchHttpClient.layer, RpcSerialization.layerNdjson]), ), ), - Effect.timeout("5 seconds"), + Effect.timeout(wait), ), ); } diff --git a/packages/work-board/src/server/integration/board.ts b/packages/work-board/src/server/integration/board.ts index 3965aecb..ccd34fec 100644 --- a/packages/work-board/src/server/integration/board.ts +++ b/packages/work-board/src/server/integration/board.ts @@ -3,7 +3,6 @@ import { type Changes, watchChanges } from "#server/files/changes.ts"; import { listMarkdown } from "#server/files/list.ts"; import { markdownPath } from "#server/files/markdownPath.ts"; import { areaDiagnostics } from "#server/metadata/areaDiagnostics.ts"; -import { areaFolders, repositoryRoot } from "#server/metadata/areaFolders.ts"; import { metadataModel } from "#server/metadata/model.ts"; import { type Snapshot, searchSnapshot } from "#server/search/snapshot.ts"; import { watchIndex } from "#server/search/watchIndex.ts"; @@ -18,13 +17,11 @@ const snapshot: ( export const board = { archiveSettled, areaDiagnostics, - areaFolders, listMarkdown, loadSettled, markdownPath, metadataModel, metadataParse, - repositoryRoot, searchSnapshot: snapshot, watchChanges, watchIndex, diff --git a/packages/work-board/src/server/views/fleetItems.ts b/packages/work-board/src/server/views/fleetItems.ts index d002cc6a..aa431707 100644 --- a/packages/work-board/src/server/views/fleetItems.ts +++ b/packages/work-board/src/server/views/fleetItems.ts @@ -1,5 +1,5 @@ import { join } from "node:path"; -import { Effect } from "effect"; +import { Clock, Duration, Effect } from "effect"; import { waitsOnYou } from "#browser/document/asks.ts"; import type { AuthoredProgress, FleetItemsProjection } from "#browser/views/FleetItemsProjection.ts"; import { laneOf } from "#browser/views/now.ts"; @@ -39,11 +39,15 @@ const fleetItemsUnavailable = Effect.fn("WorkBoard.fleetItemsUnavailable")(funct return projection; }); +// Both Fleet reads share one budget, so the Board answers inside the 30 seconds Claude Code's plugin fetch waits. +const FLEET_VIEW_MS = 25_000; + export function fleetItems(folder: string, fleetPort: number | null = DAEMON_PORT): Effect.Effect { if (fleetPort === null) { return fleetItemsUnavailable({ reason: "Fleet isn't set up for this Board." }); } return Effect.gen(function* () { + const started = yield* Clock.currentTimeMillis; const result = yield* readDaemon(fleetPort, (client) => client("daemon.fleetItems", {})).pipe(Effect.result); const workspace = yield* Workspace; if (result._tag === "Failure") { @@ -65,9 +69,10 @@ export function fleetItems(folder: string, fleetPort: number | null = DAEMON_POR ? [{ sourcePath: join(settings.realRoot, document.file), workId }] : []; }); + const left = Duration.millis(Math.max(0, FLEET_VIEW_MS - ((yield* Clock.currentTimeMillis) - started))); // One request covers the whole view: a request per brief kept views with many Fleet items waiting past client timeouts. const checked = yield* ( - briefs.length === 0 ? Effect.succeed([]) : readDaemon(fleetPort, (client) => client("daemon.briefProblems", { briefs })) + briefs.length === 0 ? Effect.succeed([]) : readDaemon(fleetPort, (client) => client("daemon.briefProblems", { briefs }), left) ).pipe(Effect.result); if (checked._tag === "Failure") { return yield* fleetItemsUnavailable({ reason: "Fleet brief validation is unavailable; these briefs have not been checked." }); diff --git a/packages/work-board/src/server/views/slowFleet.slow.spec.ts b/packages/work-board/src/server/views/slowFleet.slow.spec.ts new file mode 100644 index 00000000..f2677aa6 --- /dev/null +++ b/packages/work-board/src/server/views/slowFleet.slow.spec.ts @@ -0,0 +1,37 @@ +import { Clock } from "effect"; +import { expect, vi } from "vitest"; +import { boardStory, projectFiles } from "#test/boardStory.ts"; +import { slowFleetDaemon } from "#test/workspaceBoardTraits.ts"; + +vi.setConfig({ testTimeout: 60_000 }); + +const project = projectFiles({ "one.md": "---\nid: one\nkind: task\nstatus: draft\n---\n# First task" }); +const reported = { completed: [], items: [{ stage: "queued" as const, stageEnteredAt: 100, updatedAt: 200, workId: "one" }] }; + +boardStory.it("a busy Fleet that answers after 8 seconds still shows its work", [project, slowFleetDaemon(reported, 8)], function* ({ fleetWork }) { + expect(yield* fleetWork()).toMatchObject({ items: [expect.objectContaining({ workId: "one" })], state: "ready" }); +}); + +boardStory.it( + "a Fleet that has not answered after 20 seconds is reported as not answering in time", + [project, slowFleetDaemon(reported, 25)], + function* ({ fleetWork }) { + expect(yield* fleetWork()).toMatchObject({ + reason: expect.stringMatching(/^Fleet on port \d+ didn't answer within 20 seconds, so agent work and its health are unknown\.$/u), + state: "unavailable", + }); + }, +); + +boardStory.it( + "the Board answers within 25 seconds when Fleet's items and brief checks are both slow", + [project, slowFleetDaemon(reported, 15, 15)], + function* ({ fleetWork }) { + const started = yield* Clock.currentTimeMillis; + const fleet = yield* fleetWork(); + expect({ fleet, inTime: (yield* Clock.currentTimeMillis) - started < 26_000 }).toMatchObject({ + fleet: { reason: "Fleet brief validation is unavailable; these briefs have not been checked.", state: "unavailable" }, + inTime: true, + }); + }, +); diff --git a/packages/work-board/src/test-support/workspaceBoardTraits.ts b/packages/work-board/src/test-support/workspaceBoardTraits.ts index 8ae8acdd..b4335506 100644 --- a/packages/work-board/src/test-support/workspaceBoardTraits.ts +++ b/packages/work-board/src/test-support/workspaceBoardTraits.ts @@ -1,5 +1,5 @@ import { relative } from "node:path"; -import { Clock, Effect } from "effect"; +import { Clock, Duration, Effect } from "effect"; import { vi } from "vitest"; import { ServiceUnavailable } from "@shivaedev/errors/taxonomy.ts"; import type { FleetItems } from "#diagnostics/fleetItems.ts"; @@ -44,6 +44,19 @@ export function fleetDaemon(items: FleetItems) { ); } +export function slowFleetDaemon(items: FleetItems, seconds: number, briefSeconds = 0) { + return boardStory.trait("project", `Fleet takes ${seconds} seconds to report its items and ${briefSeconds} to check briefs`, function* (engine) { + const missing = { cause: "Not configured for the story", observedAt: 0, state: "not-configured" as const }; + const daemon = yield* rawDiagnosticsDaemon( + () => ({ codex: missing, fleet: missing, github: missing }), + 0, + Effect.as(Effect.sleep(Duration.seconds(seconds)), items), + Effect.as(Effect.sleep(Duration.seconds(briefSeconds)), []), + ); + engine.fleetPort = daemon.port; + }); +} + export function rejectingFleetDaemon(message: string) { return boardStory.trait("project", `Fleet rejects requests for its items: ${message}`, function* (engine) { const missing = { cause: "Not configured for the story", observedAt: 0, state: "not-configured" as const }; diff --git a/packages/work-fleet/src/host/areaLanes.spec.ts b/packages/work-fleet/src/host/areaLanes.spec.ts index b5c04c33..26deb47f 100644 --- a/packages/work-fleet/src/host/areaLanes.spec.ts +++ b/packages/work-fleet/src/host/areaLanes.spec.ts @@ -3,7 +3,7 @@ import { areaLanesProject } from "#test/areaLanesProject.ts"; import { host } from "#test/hostStory.ts"; import { refusal } from "#test/refusal.ts"; -host.it("Fleet items show package holders and eligible priority queues with the scheduler's waiting reasons", [areaLanesProject], function* (daemon) { +host.it("Fleet items list only busy areas with holders and eligible priority queues and waiting reasons", [areaLanesProject], function* (daemon) { yield* daemon.approve("holder"); yield* daemon.admit(); @@ -12,13 +12,13 @@ host.it("Fleet items show package holders and eligible priority queues with the const areas = (yield* daemon.fleetItems()).areas ?? []; expect({ blockers: { first: (yield* daemon.storedRecord("first")).value.blocker, urgent: (yield* daemon.storedRecord("urgent")).value.blocker }, - free: areas.find(({ area }) => area === "free"), + names: areas.map(({ area }) => area), refused, workBoard: areas.find(({ area }) => area === "work-board"), workFleet: areas.find(({ area }) => area === "work-fleet"), }).toEqual({ blockers: { first: "waiting for area work-fleet held by holder", urgent: "waiting for area work-fleet/host held by holder" }, - free: { area: "free", holders: [], queue: [] }, + names: ["work-board", "work-fleet", "work-fleet/host"], refused: { first: "admission refused: waiting for area work-fleet held by holder", urgent: "admission refused: waiting for area work-fleet/host held by holder", diff --git a/packages/work-fleet/src/host/daemonDiagnostics.ts b/packages/work-fleet/src/host/daemonDiagnostics.ts index 29ada9a4..0270db02 100644 --- a/packages/work-fleet/src/host/daemonDiagnostics.ts +++ b/packages/work-fleet/src/host/daemonDiagnostics.ts @@ -1,6 +1,5 @@ import { Effect } from "effect"; import { ServiceUnavailable } from "@shivaedev/errors/taxonomy.ts"; -import { board as boardApi } from "@shivaedev/work-board/server/integration/board.ts"; import { diagnostics as diagnosticsApi } from "@shivaedev/work-board/server/integration/diagnostics.ts"; import { withBoardReadPass } from "#board/readPass.ts"; import { failureMessage } from "#engine/failureMessage.ts"; @@ -27,7 +26,7 @@ function briefRefusals(engine: typeof Fleet.Service, briefs: readonly Brief[]) { ).pipe(Effect.map((refusals) => refusals.flat())); } -export const daemonDiagnostics = Effect.fn("FleetDaemon.daemonDiagnostics")(function* (boardDir: string) { +export const daemonDiagnostics = Effect.fn("FleetDaemon.daemonDiagnostics")(function* () { const provided = yield* Effect.serviceOption(DiagnosticsSources); const fleet = yield* HealthSnapshot; const sources = { @@ -38,14 +37,7 @@ export const daemonDiagnostics = Effect.fn("FleetDaemon.daemonDiagnostics")(func const read = yield* diagnostics(sources); const items = yield* fleetItems; const engine = yield* Effect.serviceOption(Fleet); - const areas = Effect.gen(function* () { - if (engine._tag === "None") { - return undefined; - } - const root = yield* boardApi.repositoryRoot(boardDir); - const folders = yield* boardApi.areaFolders(root); - return yield* withBoardReadPass(engine.value.areaLanes([...folders.keys()])); - }); + const areas = engine._tag === "None" ? Effect.succeed(undefined) : withBoardReadPass(engine.value.areaLanes([])); return DiagnosticsContract.application.toLayer( Effect.succeed( DiagnosticsContract.application.of({ diff --git a/packages/work-fleet/src/host/daemonHandlers.ts b/packages/work-fleet/src/host/daemonHandlers.ts index 790825ed..7bc61786 100644 --- a/packages/work-fleet/src/host/daemonHandlers.ts +++ b/packages/work-fleet/src/host/daemonHandlers.ts @@ -55,7 +55,7 @@ export const daemonHandlers = Effect.fn("FleetDaemon.daemonHandlers")(function* Stream.merge(Stream.tick("1 second").pipe(Stream.map(() => ({ epoch }))), { haltStrategy: "left" }), ); } - const diagnostics = yield* daemonDiagnostics(host.boardDir); + const diagnostics = yield* daemonDiagnostics(); const dispatch = yield* dispatchRequests(host); const live = yield* LiveConfig; const tier = yield* LaunchTier; diff --git a/packages/work-fleet/src/test-support/unavailableFleetItems.ts b/packages/work-fleet/src/test-support/unavailableFleetItems.ts index 7fb1b3de..cb536fa9 100644 --- a/packages/work-fleet/src/test-support/unavailableFleetItems.ts +++ b/packages/work-fleet/src/test-support/unavailableFleetItems.ts @@ -24,7 +24,7 @@ export const unavailableFleetItems = Effect.fn("HostStory.unavailableFleetItems" appHost({ config: { disablePreemptiveShutdown: true, host: "127.0.0.1", port: 0 }, group: diagnostics.DiagnosticsContract, - handlers: Layer.unwrap(daemonDiagnostics("/unused")), + handlers: Layer.unwrap(daemonDiagnostics()), policy: "loopback", rpcPath: diagnostics.DAEMON_RPC_PATH, services,