diff --git a/goals/shift-manager/workers-message-each-other/goal.md b/goals/shift-manager/workers-message-each-other/goal.md index 67a5cb03ea..03437cecf0 100644 --- a/goals/shift-manager/workers-message-each-other/goal.md +++ b/goals/shift-manager/workers-message-each-other/goal.md @@ -2,13 +2,13 @@ **Issue:** FIX-1989; legs 6 to 8, FIX-2160 (`specs/issues/FIX-2160/SPEC.md`); legs 10, 10b and 10c, FIX-2239 (`specs/issues/FIX-2239/SPEC.md`), which replace leg 2b. Its spec's goal: `specs/issues/FIX-1989/SPEC.md` → "The goal, and how we'll know it's met". -**Outcome:** any worker with a conversation can message any other worker on its user's roster. The message lands in the recipient's own conversation under the sender's name and wakes it; its answer comes back to the session that asked, or to the sender's own conversation when that session was a task's whose turn has ended, and wakes the sender. No task, delegation or person relays it. A chain of messages with no person between them stops at 6, one turn sends at most 3, a worker on another user's roster is refused as if it didn't exist, and the person sees every message, both sides, in Shift Manager's Messages view, across a restart. +**Outcome:** any worker can message any other worker on its user's roster with `sendMessage`, and hears one on `onMessageReceived`. A message lands as its own item, under the sender's name, in the session it is about: an answer (`inReplyTo`) in the session its original was sent from, even a finished task's; a message to the filer of the sender's task in the filing conversation; anything else in the recipient's own conversation. It wakes the recipient, whose plain text reaches no one. One budget per message a person types: 6 messages in all, 3 per request, a refused send spending nothing, and a delegate's ongoing session counting on in its filer's budget. A worker on another user's roster is refused as if it didn't exist, the coder (which hears only in its tasks' sessions) is refused by name before anything is written, a round-robin coordinator is heard, and the person sees every message, both sides, in Shift Manager's Messages view, across a restart. **Input:** - Shift Manager's DevTeam install as the commit ships it, served by Shift Manager's own command over a fresh SQLite store (`DEVTEAM_STORE`). Alice is its owner and Bob its second member, each with their own verified bearer, each through the shipped clients (`createWorkforceClient`, the session client, an action client on the flow a session names), loaded from the commit under test. -- The workers: the Shift Coordinator (`chief-of-staff`, the standard coordinator) and Researcher (`researcher`, a standard agent worker), and three Alice hires through the roster flow's `hire`: Helper A (`helper-a`, with Helper B as its delegate, and a favourite colour), Helper B (`helper-b`) and the herald (`herald`). Bob hires one worker of his own. Each person's line goes into the worker's own conversation, the session `ensureWorkerSession({ worker })` opens at its derived address. -- The Shift Coordinator routes by best fit. Its conversation's default delegates are removed first, so every line the person sends it reaches its own turn; leg 2 adds Researcher for the task and removes it after. Routing is FIX-1791's and not what this goal grades. +- The workers: the Shift Coordinator (`chief-of-staff`, the standard coordinator) and Researcher (`researcher`, a standard agent worker), and three Alice hires through the roster flow's `hire`: Helper A (`helper-a`, with Helper B as its delegate, and a favourite colour), Helper B (`helper-b`), the herald (`herald`) and a round-robin coordinator (`rr-lead`, delegate Helper A). Bob hires one worker of his own. Each person's line goes into the worker's own conversation, the session `ensureWorkerSession({ worker })` opens at its derived address. +- The Shift Coordinator routes by best fit. Its conversation's default delegates are removed first, so every line the person sends it reaches its own turn; leg 2 adds Researcher for the task and removes it after. Leg 1b opens the coordinator's second conversation with Alice, and leg 2 files from it, so a message to the filer can be told from one to the default conversation. Routing is FIX-1791's and not what this goal grades. - Held out, picked at run time: two codenames, Helper A's favourite colour, leg 3b's word, the ring's word and Bob's worker's id. **Signal:** each failure is tagged `:`. @@ -35,11 +35,17 @@ **Controls:** each is one scratch patch to one Workforce module, applied as the process under test loads it (`goals/lib/module-patch.mjs` through `NODE_OPTIONS`; printed in full by the run, and refused when it never reached the code). A control runs the legs it needs. -- `GOAL_CONTROL=no-wake`: a message is a line only, never a wake (`messages/worker-message-entry.ts`). Leg 1 must fail **`1:answer-holds-codename`**. -- `GOAL_CONTROL=drop-ended`: an answer to a message from a task goes back to the task's ended session (`messages/send-message.ts`). Leg 2 must fail **`2:lands-in-own-conversation`**. -- `GOAL_CONTROL=no-hop-cap`: no hop limit (`messages/send-message.ts`). Leg 3 must fail **`3:ring-stops-at-6`**. +- `GOAL_CONTROL=relay-back`: the recipient sends every message straight back to its sender, as the relay did (`messages/message-received-entry.ts`). Leg 1 must fail **`1:no-relay`**. +- `GOAL_CONTROL=no-wake`: a message is a line only, never a wake (`messages/message-received-entry.ts`). Leg 1 must fail **`1:answer-holds-codename`**. +- `GOAL_CONTROL=answer-to-conversation`: an answer lands in the recipient's own conversation, not the session its original was sent from (`messages/send-message.ts`). Leg 2 must fail **`2:lands-in-task-session`**. +- `GOAL_CONTROL=ongoing-at-0`: a delegate's ongoing session counts on its own, born at 0, and its task's turn starts there rather than at its filing's count (`conversation-board/board.ts`, `conversation-board/task-entry.ts`). Leg 3 must fail **`3:ring-stops-at-6`**. +- `GOAL_CONTROL=no-hop-cap`: no budget (`messages/send-message.ts`). Leg 3 must fail **`3:ring-stops-at-6`**. +- `GOAL_CONTROL=pay-first`: a send takes its place in the chain before the recipient is checked, so a refused send spends one (`messages/send-message.ts`). Leg 3 must fail **`3:refused-pays-nothing`**. +- `GOAL_CONTROL=fresh-hop-on-task`: a task's session starts a fresh exchange at hop 0 (`conversation-board/task-entry.ts`). Leg 3b must fail **`3b:counts-on`**. - `GOAL_CONTROL=no-roster-check`: a worker not on the sender's user's roster is taken as theirs (`messages/send-message.ts`). Leg 4 must fail **`4:bobs-worker-refused`**. -- `GOAL_CONTROL=fresh-hop-on-task`: a task's session starts a fresh exchange at hop 0 (`conversation-board/board.ts`). Leg 3b must fail **`3b:counts-on`**. +- `GOAL_CONTROL=refuse-at-receive`: the send no longer refuses a worker that hears only in its tasks' sessions, so the row is written and the refusal is left to its entry (`messages/send-message.ts`). Leg 4 must fail **`4:coder-refused`**. +- `GOAL_CONTROL=no-turn-back`: a coordinator that hands every line on is refused `no_turn`, as before (`messages/send-message.ts`). Leg 4 must fail **`4:round-robin-heard`**. +- `GOAL_CONTROL=no-hire-check`: `hireWorkforce` takes a worker flow with no `onMessageReceived` (`workers/register.ts`). Leg 4 must fail **`4:hire-refuses`**. - `GOAL_CONTROL=memory-log`: the log is kept in the server's memory (`messages/message-log.ts`). Leg 5 must fail **`5:lists-every-message`** after the restart. - `GOAL_CONTROL=task-to-conversation`: a `{ task }` message lands in the conversation that filed the task (`messages/message-target.ts`). Leg 6 must fail **`6:lands-in-task-session`**. - `GOAL_CONTROL=no-kind-check`: a `{ session }` target isn't checked for a task's or a delegate's session (`messages/message-target.ts`). Leg 7 must fail **`7:refusals`**. @@ -53,7 +59,7 @@ The spec's other-organization signals (`6:other-org`, and another org's session in `7:refusals`) and its `no-org-check` control are not run here: DevTeam verifies every bearer into its one organization, so no person here has a second one. The engine's `request-sessions.test.ts` covers that refusal. -**Before-state:** `GOAL_COMMIT=e2ee2c18` is `main` with the spec merged and nothing built. Every leg must fail there: there is no message tool. For legs 6 to 8 (FIX-2160), `GOAL_COMMIT=` is the stack's base: `to` takes a worker's id only, so every leg fails. +**Before-state:** `GOAL_COMMIT=e2ee2c18` is `main` with FIX-1989's spec merged and nothing built: every leg fails, there is no message tool. For FIX-2238, `main` before it (`e2c190e64`) has no `sendMessage`, so every leg fails, `1:own-item` first. For legs 6 to 8 (FIX-2160), `GOAL_COMMIT=` is the stack's base: `to` takes a worker's id only, so every leg fails. ## Verdict log | Date | Commit | Model | Verdict | Notes | @@ -61,4 +67,5 @@ The spec's other-organization signals (`6:other-org`, and another org's session | 2026-10-14 | `590b0c049` (stack head) | workers `openai/gpt-5.4-mini`, coordinator `anthropic/claude-haiku-5-5` | **PASS** | 3 of 3 runs passed every leg (1, 1b, 2, 2b, 3b, 3, 4, 5). Leg 3's exchange held exactly 6 messages each time, with the 7th send refused at the hop limit; in two runs some of the 6 were answers or forwards that didn't repeat the ring's word, which is why the leg counts the exchange by its chain. Every control failed on its assertion, and each patch was confirmed to reach its code: `no-wake` 1:answer-holds-codename (run on `5a9c69710`, whose Workforce code is the same), `drop-ended` 2:lands-in-own-conversation, `no-hop-cap` 3:ring-stops-at-6 (25 messages; the run stopped it at 20), `no-roster-check` 4:bobs-worker-refused, `fresh-hop-on-task` 3b:counts-on (the task's message started a new chain at hop 1), `memory-log` 5:lists-every-message (0 of 2 listed after the restart). Before-state `e2ee2c18`: every leg failed (1, 1b, 2b on their assertions with no tool to call; 2, 3b, 3, 4 threw; 5 found no Messages view). | | 2026-10-14 | `fd8081663` (stack head) | workers `openai/gpt-5.4-mini`, coordinator `anthropic/claude-haiku-5-5` | **FAIL** | 1, 1b, 2b, 3b, 5 PASS. 2 FAIL `2:answered` (Helper A, woken, answered in plain text instead of calling `messageWorker`; leg 2 passed in 2 of 5 runs). 3 FAIL `3:ring-stops-at-6` (10 passed: woken workers both forwarded and answered, so the ring branched; each branch stopped at the hop limit). 4 FAIL `4:bobs-worker-refused`, `4:coder-refused` (the model declined to call the tool for an id not in its list, so no refusal was seen; leg 4 passed on an earlier run). Every control failed on its assertion: `no-wake` 1:answer-holds-codename, `drop-ended` 2:lands-in-own-conversation, `no-hop-cap` 3:ring-stops-at-6 (46 passed), `no-roster-check` 4:bobs-worker-refused, `fresh-hop-on-task` 3b:hop-2, `memory-log` 5:lists-every-message. Before-state `e2ee2c18`: every leg failed except 2b, which passed with no tool to call; `2b:sent` now requires a message to have gone out. | | 2026-10-28 | `3cbab3a64` (main, FIX-2160 merged) | workers `openai/gpt-5.4-mini`, coordinator `anthropic/claude-haiku-5-5` | **PASS** | Legs 6, 7, 8 (FIX-2160): 4 of 4 runs passed (three on the PR's heads `a0149c2d1` and `973404f23`, one on merged `main`). Every control failed on its assertion: `task-to-conversation` 6:lands-in-task-session, `no-kind-check` 7:refusals, `coder-resumes-open` 8:running-refused. The send's own controls were re-anchored to the by-name path and rerun on `main`: `pay-first` 3:refused-pays-nothing, `no-roster-check` 4:bobs-worker-refused, `no-turn-back` 4:round-robin-heard. Before-state `acdd3303c` (FIX-2238's head, `to` takes a worker's id only): 6, 7 and 8 all failed (6 on every signal it checks, 7 on second-conversation, project-conversation and refusals, 8 on finished-answered and running-refused). | +| 2026-10-28 | `570849be4` (#4021, FIX-2238 and its follow-up on `main` with FIX-2160) | workers `openai/gpt-5.4-mini`, coordinator `anthropic/claude-haiku-5-5` | **PASS** for FIX-2238's legs | Legs 1 to 5 passed in 3 runs: on `bfbae4c08` with the follow-up's changes uncommitted, and twice on `570849be4`. A fourth run on `570849be4` failed `3:ring-stops-at-6`: the ring stopped after 3 messages, with no budget refusal, which is a hand-off the model didn't make (the ring stopped at 6 in 5 of 6 full runs this session). Legs 6 to 8 (FIX-2160) ran alongside and failed `6:lands-in-task-session` in 1 of 3 runs on `570849be4`: by the turn's record, which the engine writes when a deferred request is queued; nothing of the message ran while the task's turn was open, and #4026 times the turn by its first item instead. Every FIX-2238 control failed on its assertion (run on `5d7ca952b` / `bfbae4c08`): `relay-back` 1:no-relay, `no-wake` 1:answer-holds-codename, `answer-to-conversation` 2:lands-in-task-session, `ongoing-at-0` and `no-hop-cap` 3:ring-stops-at-6, `pay-first` 3:refused-pays-nothing, `fresh-hop-on-task` 3b:counts-on, `no-roster-check` 4:bobs-worker-refused, `refuse-at-receive` 4:coder-refused, `no-turn-back` 4:round-robin-heard, `no-hire-check` 4:hire-refuses, `memory-log` 5:lists-every-message (0 of 3 listed after the restart). | | 2026-10-28 | `f417cda1e`; controls on `4e69b7e10` | workers `openai/gpt-5.4-mini`, coordinator `anthropic/claude-haiku-5-5` | **PASS** | Legs 10, 10b, 10c (a worker's call): 3 of 3 runs passed every assertion (two on `f6536df27`, one on `f417cda1e`). Every control failed on its assertion, and each patch was confirmed to reach its code: `no-person-hold` 10b:queued, `ignore-deadline` 10b:queued, `no-default-deadline` 10:default-deadline, `send-again` 10b:kept, `relay-the-call` 10:no-second-line, `no-step-guard` 10c:one-wait-per-step. `no-default-deadline` and `no-step-guard` patch the wait check that a call shares with `getTask` (orchestration's `checkWaitable`). | diff --git a/packages/workforce/src/conversation-board/board.ts b/packages/workforce/src/conversation-board/board.ts index 6e16940445..a3879c1a34 100644 --- a/packages/workforce/src/conversation-board/board.ts +++ b/packages/workforce/src/conversation-board/board.ts @@ -566,6 +566,19 @@ async function keepFiledHopInChain(ctx: BlockContext, collection: TaskCollection return collection.get(task.id) ?? task; } +/** + * A row held before its first start (FIX-2238): its filed mark becomes a + * fresh chain, as {@link heldFromFiling}'s filing writes, keeping the filer's + * user lines the mark counted. A started row's hold is midway, and keeps its + * budget; a row with no mark runs at its session's count anyway. + */ +async function freshenFiledHop(ctx: BlockContext, collection: TaskCollectionRef, id: string): Promise { + const task = collection.get(id); + const mark = hopMarkOf(task?.metadata?.[FILED_HOP]); + if (task === undefined || mark === undefined || hasStarted(task)) return; + await collection.patchMetadata(id, { [FILED_HOP]: { ...freshHopMark(ctx), lines: mark.lines } }); +} + /** The filing session's worker, for a session the hand-over opens: where a message to it from there lands (FIX-2238). */ function filingWorkerOf(state: unknown): Record { const worker = (state as Record | undefined)?.[WORKER_ID_STATE_KEY]; @@ -1300,6 +1313,9 @@ export function defineConversationBoard(options: ConversationBoardOptions) { const metadata = patch.metadata === undefined ? undefined : (callerMetadata(patch.metadata) ?? {}); await owePass(ctx); const outcome = await ref.patchSettings(id, metadata === undefined ? patch : { ...patch, metadata }); + // Held before its first start, a task is held from its filing: released, + // it starts a fresh chain, as one filed held does (FIX-2238). + if (outcome.outcome !== "declined" && patch.held === true) await freshenFiledHop(ctx, ref, id); if (outcome.outcome !== "declined" && hasStartable(ref, id)) await triggerPass(ctx); return outcome; }, diff --git a/packages/workforce/src/conversation-board/steer.ts b/packages/workforce/src/conversation-board/steer.ts index bcd4537df1..3cdcd10ff7 100644 --- a/packages/workforce/src/conversation-board/steer.ts +++ b/packages/workforce/src/conversation-board/steer.ts @@ -57,6 +57,16 @@ async function sessionOpenTask(ctx: BlockContext): Promise<{ ledger: TaskCollect return { ledger, row: latest(here.length > 0 ? here : open) }; } +/** + * Whether every task in this task session's chain has finished (FIX-2238): + * a line here no longer steers. `false` outside a task session and with no + * board to read, where nothing says the task ended. + */ +export async function sessionTaskChainEnded(ctx: BlockContext): Promise { + if (sessionTaskOf(ctx) === undefined || (await sessionLedger(ctx)) === undefined) return false; + return (await sessionOpenTask(ctx)) === undefined; +} + export { startOwedSteerTurn }; /** What a line steering the session's task answers: the task it steered. */ diff --git a/packages/workforce/src/standing-rules/user-turn.ts b/packages/workforce/src/standing-rules/user-turn.ts index 00a10113eb..4bd70999ea 100644 --- a/packages/workforce/src/standing-rules/user-turn.ts +++ b/packages/workforce/src/standing-rules/user-turn.ts @@ -28,11 +28,25 @@ export const userTurnStateSchema = z.object({ [USER_TURN_STATE]: z.boolean().opt * conversation's delegate session: that message is task input. A user's * turn also starts the worker-message hop count again, at 0 in a new chain * (FIX-1989 D2), and counts one more user's line on the session (FIX-2106). + * + * Once the task and every follow-up in its session have ended, a user's line + * there is still no user's turn (no rule tools), but it is one a user typed: + * it starts a fresh budget all the same (FIX-2238). */ export async function markUserTurn(ctx: BlockContext): Promise { const state = (ctx.session.state ?? {}) as Record; - if (typeof state[TASK_ID_STATE_KEY] === "string" || typeof state[FILING_SESSION_STATE_KEY] === "string") return; - await startTurnAtHop(ctx, 0, newChainId(), { [USER_TURN_STATE]: true }, (current) => ({ + const taskId = state[TASK_ID_STATE_KEY]; + let mark: Record = { [USER_TURN_STATE]: true }; + if (typeof taskId === "string") { + // The same read that sends the line to the task as a steer while it is open. + // Loaded here, not at the top: its module graph reaches back to this one. + const { sessionTaskChainEnded } = await import("../conversation-board/steer"); + if (!(await sessionTaskChainEnded(ctx))) return; + mark = {}; + } else if (typeof state[FILING_SESSION_STATE_KEY] === "string") { + return; + } + await startTurnAtHop(ctx, 0, newChainId(), mark, (current) => ({ [USER_LINES_STATE]: sessionUserLinesOf(current) + 1 })); } diff --git a/packages/workforce/test/worker-messages.test.ts b/packages/workforce/test/worker-messages.test.ts index 1bb6b46cb0..b662bd6c6d 100644 --- a/packages/workforce/test/worker-messages.test.ts +++ b/packages/workforce/test/worker-messages.test.ts @@ -337,6 +337,34 @@ describe("a message sent from a task's turn", () => { await h.dispose(); } }); + + // An answer reopens the exchange in a finished task's session, so a user's + // line there is one a user typed: it starts a fresh budget, as anywhere else. + it("starts a fresh budget at a user's line in a finished task's session", async () => { + const agentAnswer = mockGenerator({ + script: [ + ...callOnce("Ask helper-a for its favourite colour", "sendMessage", { to: "helper-a", text: "What is your favourite colour?" }, "Asked."), + fallback + ] + }); + const h = boot({ standard: teamWorkers(), agentAnswer }); + try { + const chief = await h.conversation("alice", "chief"); + await h.act("alice", chief, "createTask_tasks", { goal: "Ask helper-a for its favourite colour", assignee: "otto" }); + await h.settled(); + expect((await h.rows("alice"))[0]!.status).toBe("completed"); + const taskSession = (await logRows(h, "alice")).find((row) => row.from === "otto")!.fromSession; + const before = (await h.session(taskSession)).state; + + await h.post("alice", taskSession, "respond", { message: "Thanks, anything else?" }, "agent"); + await h.settled(); + const after = (await h.session(taskSession)).state; + expect(after.workforceUserLines, "the user's line counted").toBe(((before.workforceUserLines as number | undefined) ?? 0) + 1); + expect(after.workforceMessageChain, "a chain of its own").not.toBe(before.workforceMessageChain); + } finally { + await h.dispose(); + } + }); }); /** @@ -747,6 +775,41 @@ describe("the hop count through a delegation", () => { } }); + // A task held by `updateTask` before it starts is held from its filing too + // (FIX-2238): released, it starts afresh, as one filed held does. + it("starts a task held before its first start afresh when it is released", async () => { + const h = boot({ + standard: teamWorkers({ unassignedWaits: true }), + agentAnswer: mockGenerator({ script: relayThroughTask({}, { unassigned: true }) }) + }); + try { + const alice = h.client("alice"); + const otto = await alice.ensureWorkerSession({ worker: "otto" }); + await h.post("alice", otto.id, "respond", { message: "Please ask helper-a" }, "agent"); + await h.settled(); + const [filed] = await h.rows("alice"); + expect(filed!.metadata?.[FILED_HOP]).toMatchObject({ hop: 1 }); + + const helperA = await alice.ensureWorkerSession({ worker: "helper-a" }); + const held = await h.act("alice", helperA.id, "updateTask_tasks", { id: filed!.id, status: "held" }, "agent"); + expect(held.error, messageOf(held.error)).toBeUndefined(); + expect((await h.rows("alice"))[0]!.status).toBe("held"); + const assigned = await h.act("alice", helperA.id, "updateTask_tasks", { id: filed!.id, assignee: "helper-b" }, "agent"); + expect(assigned.error, messageOf(assigned.error)).toBeUndefined(); + const released = await h.act("alice", helperA.id, "updateTask_tasks", { id: filed!.id, status: "pending" }, "agent"); + expect(released.error, messageOf(released.error)).toBeUndefined(); + await h.settled(); + + expect((await h.rows("alice")).map((row) => row.status)).toEqual(["completed"]); + const rows = await logRows(h, "alice"); + expect(rows.map((row) => `${row.from}>${row.to}@${row.hop}`).sort()).toEqual(["helper-b>otto@1", "otto>helper-a@1"]); + const first = rows.find((row) => row.from === "otto")!; + expect(rows.find((row) => row.from === "helper-b")!.chain, "a fresh chain, not the filing's").not.toBe(first.chain); + } finally { + await h.dispose(); + } + }); + it("runs an ongoing-session task filed before rows recorded a count at its session's count, which counts on from its filer's", async () => { const h = boot({ standard: teamWorkers(), agentAnswer: mockGenerator({ script: relayThroughTask({ session: "ongoing", held: true }) }) }); try {