Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4eb29cb
refactor(workforce): rename worker messages to sendMessage and onMess…
claude Oct 27, 2026
86f9091
feat(workforce): a received message is its own item, and nothing is r…
claude Oct 27, 2026
f201a3e
FIX-2238: landing rules, task-sessions refusal and one budget
claude Oct 27, 2026
0a814fe
refactor(orchestration): lift the take rule and resend backoff into p…
claude Oct 27, 2026
cdc1107
refactor(orchestration): lift the take rule and resend backoff into p…
claude Oct 27, 2026
874afbf
feat(workforce): a worker message lands once (FIX-2240)
claude Oct 27, 2026
dbd9e84
feat(workforce): a taken message is never ended for its age; sends re…
claude Oct 27, 2026
b1b86b4
feat(shift-manager): a message reads on its way until taken, and coul…
claude Oct 27, 2026
6b3a3bb
docs(workforce): a message lands once: delivery, statuses, the late-f…
claude Oct 27, 2026
393f159
Merge remote-tracking branch 'origin/claude/project-thread-3uc91a' in…
claude Oct 27, 2026
dd932cb
chore(workforce): say user, not person, in the delivery comments (FIX…
claude Oct 27, 2026
9413821
FIX-2238: every worker flow on an installation hears a message
claude Oct 27, 2026
933dc2f
feat(orchestration,engine): a task id finds its partition, and a bloc…
claude Oct 27, 2026
ddd8a9b
feat(harness-manager): harnessTalkTurn, the session door's talk half,…
claude Oct 27, 2026
a30cfd9
feat(workforce): sendMessage takes { task } and { session }, checked …
claude Oct 27, 2026
c8f0c0c
fix(workforce): name a message row's target field addressedBy
claude Oct 27, 2026
ce4902a
docs(workforce): leave FIX-2238's renames to its own PR (FIX-2240)
claude Oct 27, 2026
b42660c
feat(shift-manager): the coder answers a message to its finished task…
claude Oct 27, 2026
1feba42
FIX-2238: docs, changeset, goal amended, epic seams updated
claude Oct 27, 2026
77f3584
Merge FIX-2160 into FIX-2240 for the stack
claude Oct 27, 2026
85da1aa
spec(FIX-2240): record the three seams folded while building
claude Oct 27, 2026
d94227d
feat(orchestration,engine): a task id finds its partition, and a bloc…
claude Oct 27, 2026
aa3852c
feat(harness-manager): harnessTalkTurn, the session door's talk half,…
claude Oct 27, 2026
dfd7fe1
feat(workforce): sendMessage takes { task } and { session }, checked …
claude Oct 27, 2026
c3e3cb6
fix(workforce): name a message row's target field addressedBy
claude Oct 27, 2026
cf5e871
feat(shift-manager): the coder answers a message to its finished task…
claude Oct 27, 2026
ae2bb6b
test(goals): legs 6-8 message a task, a conversation and the coder's …
claude Oct 27, 2026
0979138
test(workforce): a taker that dies after the take is resent and lands…
claude Oct 27, 2026
b03e4fe
Merge main into FIX-2238; review fixes
claude Oct 27, 2026
759d851
docs: message a task or a conversation by id; harnessTalkTurn; the le…
claude Oct 27, 2026
c6d6191
test(goals): leg 6 opens a delegate session for leg 7; goal.md names …
claude Oct 27, 2026
39b85ea
fix: parse id-index markers with their schema; the request host is cl…
claude Oct 27, 2026
0b01f18
Merge FIX-2160 (#4012) into FIX-2240 for the stack
claude Oct 27, 2026
acdd330
FIX-2238: one chain for a task filed held; drop the dead messaged-wor…
claude Oct 27, 2026
b5a893e
Merge FIX-2238's branch (main merged) into FIX-2160
claude Oct 27, 2026
a0149c2
spec(FIX-2160): notes from the cross-spec review, recorded at impleme…
claude Oct 27, 2026
973404f
fix(workforce): a { task } target counts only partitions that hold th…
claude Oct 27, 2026
dd83e61
Merge FIX-2160 (#4012, with main) into FIX-2240
claude Oct 27, 2026
e088b23
chore(workforce): keep undeliveredLine module-private (FIX-2240)
claude Oct 27, 2026
752d290
FIX-2238: a received message's budget is what its chain has left
claude Oct 27, 2026
0961e69
fix(goals): type leg 8's setWorkProject call (FIX-2160)
claude Oct 27, 2026
c748982
Merge FIX-2160 (#4012) into FIX-2240
claude Oct 27, 2026
367eb69
FIX-2238: an answer reaches a worker that hears only in its tasks' se…
claude Oct 27, 2026
5d7ca95
FIX-2238 goal: the ring's own hand-offs aren't stray rows; the herald…
claude Oct 27, 2026
bfbae4c
FIX-2238 goal: 3:budget-left grades what the chain had left when heard
claude Oct 27, 2026
fa37e7d
fix(workforce): record a message delivered only once its items are st…
claude Oct 27, 2026
d19f32a
spec(FIX-2240): record the accepted fast-path loss window
claude Oct 27, 2026
0776b40
refactor(workforce): one close step in the message pass; parse the ow…
claude Oct 27, 2026
67b7ee5
Merge FIX-2238's latest into FIX-2160
claude Oct 27, 2026
18268d2
refactor(workforce): the take answers the row or nothing; one refusal…
claude Oct 27, 2026
00fef9e
Merge FIX-2160 (#4012) into FIX-2240
claude Oct 27, 2026
6b3987d
fix(workforce): a worker's other conversation can answer it (FIX-2160)
claude Oct 27, 2026
594fd76
fix(workforce): a resent answer keeps the send's answering exception …
claude Oct 27, 2026
7b5466b
fix(workforce): a taken message whose destination is gone ends past t…
claude Oct 27, 2026
3aecb45
fix(workforce): a repeat of a refused send answers the refusal (FIX-2…
claude Oct 27, 2026
5efdc4d
fix(workforce): a resend to a task refuses once the task moved sessio…
claude Oct 27, 2026
ac6d701
Merge remote-tracking branch 'origin/claude/project-thread-i68jr1' in…
claude Oct 27, 2026
eec5d61
Merge main (FIX-2238 #4010 and FIX-2160 #4012 landed) into FIX-2240
claude Oct 27, 2026
6123c83
fix(engine): a failed item write rejects the filesystem store's flush…
claude Oct 27, 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
feat(workforce): sendMessage takes { task } and { session }, checked …
…before the row (FIX-2160)

A { task } target finds its row through the conversation ledger's id index
and lands in the session its run named; a { session } target lands in that
conversation of the user's. Both are checked on the session's record
(requestHost.sessions.read): the user, org and tenant, the worker and its
flow now, and for { session } that it is a conversation. A coder's task
still running is refused task_running. Shift Manager names the target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiD7QxMPGxa4XV4dZEF
  • Loading branch information
claude committed Oct 27, 2026
commit dfd7fe1a7f8d89f32b0123cb9e7fb1e570b3ceb1
11 changes: 10 additions & 1 deletion packages/shift-manager/src/components/ToolLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,18 @@ function isMessageCall(item: ToolOutputItem): boolean {
return item.toolCall?.name === SEND_MESSAGE_TOOL;
}

/** Who a message call names: a worker's id, a task, or a conversation (FIX-2160). */
function messageTargetLabel(to: unknown): string {
if (typeof to === "string") return to;
const target = (typeof to === "object" && to !== null ? to : {}) as { task?: unknown; session?: unknown };
if (typeof target.task === "string") return `task ${target.task}`;
if (typeof target.session === "string") return `conversation ${target.session}`;
return "another worker";
}

function MessageCallLine({ item }: { item: ToolOutputItem }) {
const args = argsOf(item) as { to?: unknown; text?: unknown } | undefined;
const to = typeof args?.to === "string" ? args.to : "another worker";
const to = messageTargetLabel(args?.to);
const text = typeof args?.text === "string" ? args.text : "";
const state = stateOf(item);
const output = item.output as { ok?: unknown; error?: unknown; unconfirmed?: unknown } | undefined;
Expand Down
14 changes: 14 additions & 0 deletions packages/shift-manager/test/messages-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ describe("a message the worker sent, in its own conversation", () => {
expect(screen.queryByTestId("message-call-reason")).toBeNull();
});

it("names a task or a conversation it was sent to, not 'another worker' (FIX-2160)", () => {
render(
<ToolLineGroup
items={[
call("t1", { to: { task: "task_42" }, text: "Done yet?" }, { sent: "msg_a" }),
call("t2", { to: { session: "s_other" }, text: "FYI" }, { ok: false, error: "no_session: no conversation" })
]}
/>
);
const [toTask, toSession] = screen.getAllByTestId("message-call");
expect(toTask!.textContent).toContain("To task task_42: Done yet?");
expect(toSession!.textContent).toContain("Not sent to conversation s_other: FYI");
});

it("draws no warning for a delivered send", () => {
render(<ToolLineGroup items={[call("t1", { to: "coordinator", text: "hi" }, { sent: "msg_a" })]} />);
expect(screen.queryByTestId("message-call-unconfirmed")).toBeNull();
Expand Down
2 changes: 2 additions & 0 deletions packages/workforce/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export {
export { DEFAULT_MESSAGE_HOP_LIMIT, DEFAULT_MESSAGES_PER_TURN, type MessageLimits } from "./message-limits";
export { sendMessageInputSchema } from "./message-tool";
export { sendMessage, type SendOutcome, type SendMessageInput } from "./send-message";
// A message to a task or a conversation, checked before anything is written (FIX-2160).
export { checkTargetSession, checkTaskTarget, type CheckedTarget, type MessageTarget, type TargetCheck } from "./message-target";
7 changes: 7 additions & 0 deletions packages/workforce/src/messages/log-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export const workerMessageRowSchema = z.object({
from: z.string().min(1),
/** The recipient worker's id. */
to: z.string().min(1),
/**
* How the sender addressed it (FIX-2160): by a task (`task`) or a conversation
* (`session`). Absent when by the worker's name, as on every row from before.
*/
toKind: z.enum(["task", "session"]).optional(),
/** The task it was addressed to, when `toKind` is `task`. */
toTask: z.string().min(1).optional(),
text: z.string(),
/** The first message's id in this exchange: a message's own id, or the exchange of the message it answers. */
exchange: z.string().min(1),
Expand Down
117 changes: 117 additions & 0 deletions packages/workforce/src/messages/message-target.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* Where a message addressed to a task or a session lands (FIX-2160), checked
* before anything is written.
*
* `{ task: id }` lands in the session that works the task: the conversation
* ledger finds the row by id (its id index), and the row's run link names the
* session. `{ session: id }` lands in that conversation of the user's. Both are
* then checked the same way, on the session's own record as the engine reads
* it for this user (`requestHost.sessions.read`): the user, their organization
* and tenant, the worker it runs and that worker's flow now. A task's session
* skips the markers check (it is a task session by design) and adds one of its
* own: a worker that hears only in its tasks' sessions (the coder) is refused
* while a task there is open, since its only answer would resume the coding
* session the work is in.
*
* {@link checkTargetSession} is the check on its own, for a send that already
* knows the session: a resend reruns it on the session its row names.
*/
import type { BlockContext, SessionView } from "@flow-state-dev/core/types";
import {
findTaskPartitions,
isTerminalStatus,
rowsInSession,
type TaskCollectionRef
} from "@flow-state-dev/orchestration/tasks";
import { CONVERSATION_LEDGER_ID, conversationLedgerAt } from "../conversation-board/ledger";
import type { RosterWorker, WorkerInstallation } from "../workers/installation";
import { FILING_SESSION_STATE_KEY, TASK_ID_STATE_KEY, WORKER_ID_STATE_KEY } from "../workers/keys";
import { messageHearingOf } from "./message-received-entry";

/** A message's target: a worker by its id, a task by its id, or one of the user's conversations by its session id. */
export type MessageTarget = string | { readonly task: string } | { readonly session: string };

/** A target the check let through: the session it lands in, and the worker that runs it. */
export interface CheckedTarget {
readonly sessionId: string;
readonly worker: RosterWorker;
}

/** What a check came to: the target, or a refusal for the model. */
export type TargetCheck = { readonly ok: true; readonly target: CheckedTarget } | { readonly ok: false; readonly error: string };

const refuse = (error: string): TargetCheck => ({ ok: false, error });

/**
* Check a session a message would land in, before anything is written.
*
* @param of What the session was reached by: a `{ session }` as typed, or a
* task's session, with the ledger the task is on (its rows decide whether
* a coding task there still runs).
*/
export async function checkTargetSession(
ctx: BlockContext,
installation: WorkerInstallation,
sessionId: string,
of: { readonly session: true } | { readonly task: string; readonly ledger: TaskCollectionRef }
): Promise<TargetCheck> {
const viaTask = "task" in of;
const notFound = viaTask
? `no_task_session: no task "${of.task}" of yours has a session to message. A task that hasn't started has none.`
: `no_session: no conversation "${sessionId}" of yours.`;
const sessions = ctx.requestHost?.sessions;
if (sessions === undefined) return refuse(`${notFound} (This host can't check a session, so only a worker's name reaches one.)`);
const view: SessionView | undefined = await sessions.read(sessionId);
if (view === undefined) return refuse(notFound);

const state = view.state;
if (!viaTask && (state[TASK_ID_STATE_KEY] != null || state[FILING_SESSION_STATE_KEY] != null)) {
return refuse(
`not_a_conversation: "${sessionId}" is a session working a task, not a conversation. Message the task with to: { task: id }.`
);
}
const workerId = state[WORKER_ID_STATE_KEY];
const worker = typeof workerId === "string" ? await installation.rosterWorker(ctx as never, workerId) : undefined;
if (worker === undefined) return refuse(`no_worker: the worker in "${sessionId}" isn't on your roster now.`);
if (worker.problem !== undefined) return refuse(`worker_unavailable: worker "${worker.id}" can't be messaged: ${worker.problem}.`);
if ((view.flowId ?? view.flowKind) !== worker.flow) {
return refuse(`worker_unavailable: worker "${worker.id}" has moved to another flow since "${sessionId}" was opened.`);
}

if (messageHearingOf(installation.workerFlows()[worker.flow]?.flow) === "task-sessions") {
if (!viaTask) {
return refuse(
`not_a_conversation: "${worker.id}" has no conversations; it answers only from its tasks' sessions. Message one of its tasks with to: { task: id }.`
);
}
// The task and its follow-ups, which run in that session one at a time.
if (rowsInSession(of.ledger, sessionId).some((row) => !isTerminalStatus(row.status))) {
return refuse(
`task_running: task "${of.task}" is still running, and a message would reach the work itself. ` +
`Read it with getTask, or message it once it has ended.`
);
}
}
if (sessionId === ctx.session.identity.id) return refuse("not_yourself: that is the session you're writing from.");
return { ok: true, target: { sessionId, worker } };
}

/**
* Resolve `{ task: id }` to the session its run named, then check it.
* No row, no run link (not started, or a plan step), an id held in more than
* one of the user's conversations, and another user's: one refusal,
* `no_task_session`, so it says nothing of another user's tasks.
*/
export async function checkTaskTarget(
ctx: BlockContext,
installation: WorkerInstallation,
taskId: string
): Promise<TargetCheck> {
const notFound = refuse(`no_task_session: no task "${taskId}" of yours has a session to message. A task that hasn't started has none.`);
const partitions = await findTaskPartitions(ctx, CONVERSATION_LEDGER_ID, taskId);
if (partitions.length !== 1) return notFound;
const ledger = await conversationLedgerAt(ctx, partitions[0]!);
const sessionId = ledger?.get(taskId)?.run?.sessionId;
if (ledger === undefined || sessionId == null) return notFound;
return checkTargetSession(ctx, installation, sessionId, { task: taskId, ledger });
}
22 changes: 18 additions & 4 deletions packages/workforce/src/messages/message-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* row, no delegate, no result owed.
*
* Its input is strict (`to`, `text`, `inReplyTo`), so a call can't name a
* sender, a hop count or a session, and there is no `wait`: an answer arrives
* sender or a hop count, and a session only as a target the server checks
* (FIX-2160), and there is no `wait`: an answer arrives
* later as a message of the recipient's own and wakes this worker. Its description
* lists who the worker can message, read before each model call: the roster's
* workers that have a conversation, by id and description.
Expand All @@ -17,6 +18,7 @@ import { WORKER_ID_STATE_KEY } from "../workers/keys";
import { messageTurnStateSchema } from "./hop";
import { SEND_MESSAGE_TOOL } from "./keys";
import { MAX_MESSAGE_CHARS, workerMessagesResources } from "./message-log";
import { conversationLedgerResources } from "../conversation-board/ledger";
import { recipientRefusal, sendMessage } from "./send-message";

/** The most workers the description lists, and the longest description it quotes for one. */
Expand All @@ -26,7 +28,16 @@ const MAX_DESCRIPTION = 160;
/** What the model passes. Strict: nothing else is taken. */
export const sendMessageInputSchema = z
.object({
to: z.string().min(1).describe("The id of the worker to message, as the list below names it."),
to: z
.union([
z.string().min(1),
z.object({ task: z.string().min(1) }).strict(),
z.object({ session: z.string().min(1) }).strict()
])
.describe(
"Who to message: a worker's id, as the list below names it; { task: id } for the session that works a task; " +
"or { session: id } for one of the user's conversations, when the user gives you its id."
),
// Something other than blank space: the send refuses a blank message too.
text: z.string().max(MAX_MESSAGE_CHARS).regex(/\S/, "say something").describe("What to say."),
inReplyTo: z
Expand All @@ -47,7 +58,9 @@ const BASE_DESCRIPTION =
"conversation and wakes it. This is not a task: nothing is filed and no result is owed, and you don't wait for an " +
"answer. If it answers, it sends you a message of its own, which wakes you. To answer a message " +
"you were sent, pass its id as inReplyTo. A message can't be waited on: to wait on a colleague's result before " +
"you answer, file a task for them with createTask, then call getTask({ id, wait: true }) where getTask takes wait.";
"you answer, file a task for them with createTask, then call getTask({ id, wait: true }) where getTask takes wait. " +
"To ask about a task, send to { task: id }: it lands in the session working that task, after its current turn, " +
"and doesn't change the task. To reach a conversation the user named, send to { session: id }.";

/** Who the running worker can message, as the description's list: every roster worker the send would take. */
async function recipientsLine(ctx: BlockContext, installation: WorkerInstallation, self: string): Promise<string> {
Expand Down Expand Up @@ -77,7 +90,8 @@ export function defineSendMessageCapability(installation: WorkerInstallation, fl
inputSchema: sendMessageInputSchema,
outputSchema: sendMessageOutputSchema,
requestStateSchema: messageTurnStateSchema,
resources: { ...installation.resources, ...workerMessagesResources },
// The conversation ledger finds a `{ task }` target's row by id (FIX-2160).
resources: { ...installation.resources, ...workerMessagesResources, ...conversationLedgerResources },
execute: async (input, ctx) => {
const sent = await sendMessage(ctx as never, installation, flowKind, input, SEND_MESSAGE_TOOL);
if (!sent.ok) return { ok: false as const, error: sent.error };
Expand Down
55 changes: 37 additions & 18 deletions packages/workforce/src/messages/send-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* The check, in order, before anything is written:
*
* - the session runs a worker, and the text fits;
* - a target by task or session (FIX-2160, `./message-target`) resolves to a
* session of the user's, checked on its own record: refused by name when it
* doesn't, and otherwise delivered there;
* - the recipient is another worker on the user's roster now (one of theirs or
* a standard one: another user's worker is simply not there), whose row
* reads;
Expand Down Expand Up @@ -43,6 +46,7 @@ import { newChainId, TURN_CHAIN_STATE, TURN_MESSAGED_STATE, TURN_SENT_STATE, tur
import { MESSAGE_RECEIVED_ENTRY } from "./keys";
import { messageLimitsOf } from "./message-limits";
import { messageHearingOf } from "./message-received-entry";
import { checkTargetSession, checkTaskTarget, type MessageTarget } from "./message-target";
import {
MAX_MESSAGE_CHARS,
messageChainsOf,
Expand All @@ -54,7 +58,8 @@ import {

/** What a send asks for: the tool's input. */
export interface SendMessageInput {
readonly to: string;
/** A worker's id, a task (`{ task }`), or one of the user's conversations (`{ session }`). */
readonly to: MessageTarget;
readonly text: string;
readonly inReplyTo?: string;
}
Expand Down Expand Up @@ -148,25 +153,38 @@ export async function sendMessage(
return refuse(`message_too_long: a message holds at most ${MAX_MESSAGE_CHARS} characters; this one has ${input.text.length}. Nothing was sent.`);
}

// ---- the recipient: on the roster, and hearing by name -------------------
const recipient = await installation.rosterWorker(ctx as never, input.to);
const refused = recipientRefusal(installation, sender, input.to, recipient);
if (refused !== undefined || recipient === undefined) return refuse(refused ?? `no_worker: no worker "${input.to}" on your roster.`);

// ---- where it lands ------------------------------------------------------
// ---- the recipient, and where it lands -----------------------------------
const log = messageLogOf(ctx);
const to = input.to;
let recipient: RosterWorker;
let destination: MessageAddress;
let exchange: string | undefined;
if (input.inReplyTo !== undefined) {
const answered = (await log.getOptional(input.inReplyTo))?.state;
if (answered === undefined || answered.to !== sender || answered.from !== input.to) {
return refuse(`no_such_message: inReplyTo "${input.inReplyTo}" names no message "${input.to}" sent you. Leave inReplyTo out to start a new one.`);
if (typeof to !== "string") {
// A task's session or a conversation, checked on its record (FIX-2160).
if (input.inReplyTo !== undefined) {
return refuse("no_such_message: an answer goes to the worker that sent the message, by its id. Leave inReplyTo out, or send to that worker.");
}
// In the session that sent the original, even after its task ended.
destination = { sessionId: answered.fromSession, flow: answered.fromFlow };
exchange = answered.exchange;
const checked = "task" in to ? await checkTaskTarget(ctx, installation, to.task) : await checkTargetSession(ctx, installation, to.session, { session: true });
if (!checked.ok) return refuse(checked.error);
recipient = checked.target.worker;
destination = { sessionId: checked.target.sessionId, flow: recipient.flow };
} else {
destination = filingSessionFor(state, input.to) ?? (await conversationAddress(ctx, installation, input.to, recipient.flow, state));
// ---- by name: on the roster, and hearing by name ------------------------
const named = await installation.rosterWorker(ctx as never, to);
const refused = recipientRefusal(installation, sender, to, named);
if (refused !== undefined || named === undefined) return refuse(refused ?? `no_worker: no worker "${to}" on your roster.`);
recipient = named;
if (input.inReplyTo !== undefined) {
const answered = (await log.getOptional(input.inReplyTo))?.state;
if (answered === undefined || answered.to !== sender || answered.from !== to) {
return refuse(`no_such_message: inReplyTo "${input.inReplyTo}" names no message "${to}" sent you. Leave inReplyTo out to start a new one.`);
}
// In the session that sent the original, even after its task ended.
destination = { sessionId: answered.fromSession, flow: answered.fromFlow };
exchange = answered.exchange;
} else {
destination = filingSessionFor(state, to) ?? (await conversationAddress(ctx, installation, to, recipient.flow, state));
}
}

// ---- the budget ----------------------------------------------------------
Expand Down Expand Up @@ -213,14 +231,15 @@ export async function sendMessage(
const hop = Math.max(floor, place + 1);
await atomicRequest((current) => {
const messaged = Array.isArray(current[TURN_MESSAGED_STATE]) ? (current[TURN_MESSAGED_STATE] as string[]) : [];
return { [TURN_MESSAGED_STATE]: [...messaged, input.to] };
return { [TURN_MESSAGED_STATE]: [...messaged, recipient.id] };
});

// ---- the row, then the delivery ------------------------------------------
const row: WorkerMessageRow = {
id,
from: sender,
to: input.to,
to: recipient.id,
...(typeof to === "string" ? {} : "task" in to ? { toKind: "task" as const, toTask: to.task } : { toKind: "session" as const }),
text: input.text,
exchange: exchange ?? id,
...(input.inReplyTo === undefined ? {} : { inReplyTo: input.inReplyTo }),
Expand Down Expand Up @@ -260,7 +279,7 @@ export async function sendMessage(
}
if (!outcome.ok) {
await ref.patchState({ status: "refused", reason: `${outcome.refused}: ${outcome.detail}` });
return refuse(`not_delivered: the message to "${input.to}" was refused (${outcome.refused}: ${outcome.detail}).`);
return refuse(`not_delivered: the message to "${recipient.id}" was refused (${outcome.refused}: ${outcome.detail}).`);
}
await ref.patchState({ status: "delivered", toSession: outcome.sessionId });
return { ok: true, id };
Expand Down
Loading