From 8681d32e1294929e1d7c644ef4f16ffff7c923dc Mon Sep 17 00:00:00 2001 From: Bil0000 <62337003+Bil0000@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:24:12 +0100 Subject: [PATCH 1/4] fix(server): agents can tell another agent's message from the user's A message sent by another thread's agent, a linked environment's agent, a scheduled task, or an agent tool reached the receiving model as bare user text. Only the UI knew who sent it, so agents took other agents' requests as the user's instructions. T3 Code now puts one line before such text, naming the sender, at every point where it builds the text a provider reads: new turns, steers, and history handoffs. This is shared server code, so every provider gets it. Stored messages, the UI, the user's own messages and T3 Code's own notices stay the same. Slash commands stay as sent, because providers parse them from the start of the prompt. Fixes #24711 --- .../ProviderTurnControlService.test.ts | 11 +++- .../ProviderTurnControlService.ts | 12 ++-- .../ProviderTurnStartService.test.ts | 22 ++++++++ .../ProviderTurnStartService.ts | 12 ++-- .../SteeringCompletion.integration.test.ts | 24 +++++++- .../codex_transcript.ndjson | 6 +- .../contracts/src/orchestrationV2.test.ts | 55 ++++++++++++++++++- packages/contracts/src/orchestrationV2.ts | 31 +++++++++++ .../provider-core/src/server/handoffBudget.ts | 3 + 9 files changed, 158 insertions(+), 18 deletions(-) diff --git a/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts index cb9550efe5799..2cd887a69f012 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts @@ -378,7 +378,7 @@ it.effect( }), ); -it.effect("steers a running turn with the thread's MCP app model context", () => +it.effect("steers a running turn with its sender and the thread's MCP app model context", () => Effect.gen(function* () { const now = yield* DateTime.now; const threadId = ThreadId.make("thread:steer-app-context"); @@ -412,8 +412,9 @@ it.effect("steers a running turn with the thread's MCP app model context", () => id: MessageId.make("message:steer-app-context"), text: "What did the app report?", attachments: [], - createdBy: "user", - creationSource: "web", + createdBy: "agent", + creationSource: "mcp", + senderThreadId: ThreadId.make("thread:steer-sender"), } as unknown as NonNullable< ProjectionStore.ProjectionProviderControlContext["message"] >, @@ -453,6 +454,10 @@ it.effect("steers a running turn with the thread's MCP app model context", () => }).pipe(Effect.provide(layerControl)); assert.equal(steered.length, 1); + assert.equal( + steered[0]!.message.text, + '[T3 Code: the agent in T3 thread "thread:steer-sender" sent this message, not the user.]\n\nWhat did the app report?', + ); assert.deepEqual("appContext" in steered[0]! ? steered[0].appContext : undefined, [ { key: "mcp_app_turn-item_call-1", text: "Pressed: blue" }, ]); diff --git a/apps/server/src/orchestration-v2/ProviderTurnControlService.ts b/apps/server/src/orchestration-v2/ProviderTurnControlService.ts index 25df164788e76..088b4d386d177 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnControlService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnControlService.ts @@ -8,6 +8,7 @@ import { ProviderTurnId, RunAttemptId, ThreadId, + withMessageSenderNote, } from "@t3tools/contracts"; import type * as DateTime from "effect/DateTime"; import * as Context from "effect/Context"; @@ -463,10 +464,13 @@ export const layer: Layer.Layer< ...(appContext.length === 0 ? {} : { appContext }), message: { messageId: message.id, - text: projectComposerContextForProvider({ - text: message.text, - records: message.context?.records ?? [], - }), + text: withMessageSenderNote( + message, + projectComposerContextForProvider({ + text: message.text, + records: message.context?.records ?? [], + }), + ), attachments: message.attachments, createdBy: message.createdBy, creationSource: message.creationSource, diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts index f83fa70ca6bae..c192c07aa2b1e 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts @@ -467,6 +467,7 @@ function makeLocalCommandHarness(input: { readonly fileSystem?: FileSystem.FileSystem; readonly previousNativeSession?: boolean; readonly previousMessages?: ReadonlyArray; + readonly messageFields?: Partial; readonly logoutFailure?: string; readonly openFailure?: unknown; readonly ensureThreadFailure?: unknown; @@ -569,6 +570,7 @@ function makeLocalCommandHarness(input: { creationSource: "web", createdAt: now, updatedAt: now, + ...input.messageFields, }; let projection: OrchestrationV2ThreadProjection = { thread: { @@ -2669,6 +2671,26 @@ effectIt.effect.each([ }), ); +effectIt.effect("tells the provider that another thread's agent sent a message", () => + Effect.gen(function* () { + const harness = makeLocalCommandHarness({ + text: "Merge the PR now.", + messageFields: { + createdBy: "agent", + creationSource: "mcp", + senderThreadId: ThreadId.make("thread:sender"), + }, + previousTurn: { runStatus: "completed", turnStatus: "completed" }, + }); + + yield* harness.start; + + expect(harness.startRootRun.mock.calls[0]?.[0].message.text).toBe( + '[T3 Code: the agent in T3 thread "thread:sender" sent this message, not the user.]\n\nMerge the PR now.', + ); + }), +); + effectIt.effect("leaves delegated children to their own runs when the parent starts a turn", () => Effect.gen(function* () { const harness = makeLocalCommandHarness({ diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index 2b4967ce5b619..501d148d5554e 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -5,6 +5,7 @@ import { CommandId, PROVIDER_SEND_TURN_MAX_INPUT_CHARS, latestProviderTurnForAttempt, + withMessageSenderNote, type OrchestrationV2DomainEvent, type OrchestrationV2ContextHandoff, type OrchestrationV2ExecutionNode, @@ -970,10 +971,13 @@ export const layer: Layer.Layer< }); let effectiveHandoffs = handoffs; let resumeFellBack = false; - const userText = projectComposerContextForProvider({ - text: providerMessage.text, - records: providerMessage.context?.records ?? [], - }); + const userText = withMessageSenderNote( + providerMessage, + projectComposerContextForProvider({ + text: providerMessage.text, + records: providerMessage.context?.records ?? [], + }), + ); // Native goal commands go verbatim; handoff history waits a turn. const goalDriver = session.driver === "codex" || diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index ca794563234d7..5e11550b6ba98 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -20,6 +20,7 @@ import { TurnItemId, type ModelSelection, type OrchestrationV2DomainEvent, + withMessageSenderNote, } from "@t3tools/contracts"; import { expandAssistantCitationsForProvider, @@ -2427,7 +2428,16 @@ it.effect("steers a promoted scheduled delivery with the thread's current select yield* worker.drain(); const projection = yield* orchestrator.getThreadProjection(threadId); - assert.deepEqual(steered, ["scheduled"]); + assert.deepEqual(steered, [ + withMessageSenderNote( + { + createdBy: "user", + creationSource: "web", + scheduledTaskId: ScheduledTaskId.make("task:scheduled"), + }, + "scheduled", + ), + ]); assert.deepEqual(projection.thread.modelSelection, composerSelection); }).pipe(Effect.provide(layer)); }), @@ -3180,7 +3190,15 @@ it.effect("starts a restart that stops the running turn ahead of an older held q const { queue, started: startedTexts } = yield* read(threadId); assert.deepEqual( { queue, started: startedTexts }, - { queue: ["queued"], started: ["first", "second", "do this instead"] }, + { + queue: ["queued"], + started: [ + "first", + ...["second", "do this instead"].map((text) => + withMessageSenderNote({ createdBy: "agent", creationSource: "mcp" }, text), + ), + ], + }, ); }).pipe(Effect.provide(layer)); }), @@ -3300,7 +3318,7 @@ it.effect("replays an accepted steer after its target turn completes", () => .pipe(Effect.flip); assert.equal(fresh._tag, "ThreadManagementNoSteerableRunError"); yield* worker.drain(); - assert.deepEqual(steered, [input.text]); + assert.deepEqual(steered, [withMessageSenderNote(input, input.text)]); assert.lengthOf(started, 1); }).pipe( Effect.provide( diff --git a/apps/server/src/orchestration-v2/testkit/fixtures/delegated_task_status/codex_transcript.ndjson b/apps/server/src/orchestration-v2/testkit/fixtures/delegated_task_status/codex_transcript.ndjson index 8f42b9cc89a8e..1c50f492edcab 100644 --- a/apps/server/src/orchestration-v2/testkit/fixtures/delegated_task_status/codex_transcript.ndjson +++ b/apps/server/src/orchestration-v2/testkit/fixtures/delegated_task_status/codex_transcript.ndjson @@ -15,7 +15,7 @@ {"type":"emit_inbound","label":"child.thread/start","frame":{"id":5,"result":{"thread":{"id":"019f1000-0000-7000-8000-000000000003","forkedFromId":null,"preview":"","ephemeral":false,"modelProvider":"openai","createdAt":1776739468,"updatedAt":1776739468,"status":{"type":"idle"},"path":"/home/replay-user/.codex/sessions/delegated-task-status-child.jsonl","cwd":"/home/replay-user/t3code","cliVersion":"0.120.0","source":"vscode","agentNickname":null,"agentRole":null,"gitInfo":null,"name":null,"turns":[]},"model":"gpt-5.4","modelProvider":"openai","serviceTier":"fast","cwd":"/home/replay-user/t3code","approvalPolicy":"on-request","approvalsReviewer":"user","sandbox":{"type":"workspaceWrite","writableRoots":[],"readOnlyAccess":{"type":"fullAccess"},"networkAccess":false,"excludeTmpdirEnvVar":false,"excludeSlashTmp":false},"reasoningEffort":"xhigh"}}} {"type":"expect_outbound","label":"config/read","frame":{"id":6,"method":"config/read","params":{"cwd":"","includeLayers":false}}} {"type":"emit_inbound","label":"config/read","frame":{"id":6,"result":{"config":{},"origins":{}}}} -{"type":"expect_outbound","label":"child.original.turn/start","frame":{"id":7,"method":"turn/start","params":{"approvalPolicy":"never","cwd":"","input":[{"text":"Inspect the delegated API boundary and return the result.","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019f1000-0000-7000-8000-000000000003","approvalsReviewer":"user","summary":"auto","collaborationMode":{"mode":"default","settings":{"model":"gpt-5.4"}}}}} +{"type":"expect_outbound","label":"child.original.turn/start","frame":{"id":7,"method":"turn/start","params":{"approvalPolicy":"never","cwd":"","input":[{"text":"[T3 Code: the agent in T3 thread \"thread:mcp-orchestrator-parent\" sent this message, not the user.]\n\nInspect the delegated API boundary and return the result.","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019f1000-0000-7000-8000-000000000003","approvalsReviewer":"user","summary":"auto","collaborationMode":{"mode":"default","settings":{"model":"gpt-5.4"}}}}} {"type":"emit_inbound","label":"child.thread/started","frame":{"method":"thread/started","params":{"thread":{"id":"019f1000-0000-7000-8000-000000000003","forkedFromId":null,"preview":"","ephemeral":false,"modelProvider":"openai","createdAt":1776739468,"updatedAt":1776739468,"status":{"type":"idle"},"path":"/home/replay-user/.codex/sessions/delegated-task-status-child.jsonl","cwd":"/home/replay-user/t3code","cliVersion":"0.120.0","source":"vscode","agentNickname":null,"agentRole":null,"gitInfo":null,"name":null,"turns":[]}}}} {"type":"emit_inbound","label":"child.original.turn/start","frame":{"id":7,"result":{"turn":{"id":"019f1000-0000-7000-8000-000000000004","items":[],"status":"inProgress","error":null,"startedAt":null,"completedAt":null,"durationMs":null}}}} {"type":"emit_inbound","label":"child.original.thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"019f1000-0000-7000-8000-000000000003","status":{"type":"active","activeFlags":[]}}}} @@ -27,7 +27,7 @@ {"type":"emit_inbound","label":"child.original.turn/completed","frame":{"method":"turn/completed","params":{"threadId":"019f1000-0000-7000-8000-000000000003","turn":{"id":"019f1000-0000-7000-8000-000000000004","items":[],"status":"completed","error":null,"startedAt":1776739468,"completedAt":1776739469,"durationMs":1000}}}} {"type":"expect_outbound","label":"config/read","frame":{"id":8,"method":"config/read","params":{"cwd":"","includeLayers":false}}} {"type":"emit_inbound","label":"config/read","frame":{"id":8,"result":{"config":{},"origins":{}}}} -{"type":"expect_outbound","label":"child.running.turn/start","frame":{"id":9,"method":"turn/start","params":{"approvalPolicy":"never","cwd":"","input":[{"text":"Remain active until the parent cancels this delegated task.","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019f1000-0000-7000-8000-000000000003","approvalsReviewer":"user","summary":"auto","collaborationMode":{"mode":"default","settings":{"model":"gpt-5.4"}}}}} +{"type":"expect_outbound","label":"child.running.turn/start","frame":{"id":9,"method":"turn/start","params":{"approvalPolicy":"never","cwd":"","input":[{"text":"[T3 Code: the agent in T3 thread \"thread:mcp-orchestrator-parent\" sent this message, not the user.]\n\nRemain active until the parent cancels this delegated task.","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019f1000-0000-7000-8000-000000000003","approvalsReviewer":"user","summary":"auto","collaborationMode":{"mode":"default","settings":{"model":"gpt-5.4"}}}}} {"type":"emit_inbound","label":"child.running.turn/start","frame":{"id":9,"result":{"turn":{"id":"019f1000-0000-7000-8000-000000000005","items":[],"status":"inProgress","error":null,"startedAt":null,"completedAt":null,"durationMs":null}}}} {"type":"emit_inbound","label":"child.running.thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"019f1000-0000-7000-8000-000000000003","status":{"type":"active","activeFlags":[]}}}} {"type":"emit_inbound","label":"child.running.turn/started","frame":{"method":"turn/started","params":{"threadId":"019f1000-0000-7000-8000-000000000003","turn":{"id":"019f1000-0000-7000-8000-000000000005","items":[],"status":"inProgress","error":null,"startedAt":1776739470,"completedAt":null,"durationMs":null}}}} @@ -37,7 +37,7 @@ {"type":"emit_inbound","label":"child.running.turn/completed","frame":{"method":"turn/completed","params":{"threadId":"019f1000-0000-7000-8000-000000000003","turn":{"id":"019f1000-0000-7000-8000-000000000005","items":[],"status":"interrupted","error":null,"startedAt":1776739470,"completedAt":1776739471,"durationMs":1000}}}} {"type":"expect_outbound","label":"config/read","frame":{"id":11,"method":"config/read","params":{"cwd":"","includeLayers":false}}} {"type":"emit_inbound","label":"config/read","frame":{"id":11,"result":{"config":{},"origins":{}}}} -{"type":"expect_outbound","label":"child.queued.turn/start","frame":{"id":12,"method":"turn/start","params":{"approvalPolicy":"never","cwd":"","input":[{"text":"Complete the queued follow-up and return the final result.","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019f1000-0000-7000-8000-000000000003","approvalsReviewer":"user","summary":"auto","collaborationMode":{"mode":"default","settings":{"model":"gpt-5.4"}}}}} +{"type":"expect_outbound","label":"child.queued.turn/start","frame":{"id":12,"method":"turn/start","params":{"approvalPolicy":"never","cwd":"","input":[{"text":"[T3 Code: the agent in T3 thread \"thread:mcp-orchestrator-parent\" sent this message, not the user.]\n\nComplete the queued follow-up and return the final result.","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019f1000-0000-7000-8000-000000000003","approvalsReviewer":"user","summary":"auto","collaborationMode":{"mode":"default","settings":{"model":"gpt-5.4"}}}}} {"type":"emit_inbound","label":"child.queued.turn/start","frame":{"id":12,"result":{"turn":{"id":"019f1000-0000-7000-8000-000000000006","items":[],"status":"inProgress","error":null,"startedAt":null,"completedAt":null,"durationMs":null}}}} {"type":"emit_inbound","label":"child.queued.thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"019f1000-0000-7000-8000-000000000003","status":{"type":"active","activeFlags":[]}}}} {"type":"emit_inbound","label":"child.queued.turn/started","frame":{"method":"turn/started","params":{"threadId":"019f1000-0000-7000-8000-000000000003","turn":{"id":"019f1000-0000-7000-8000-000000000006","items":[],"status":"inProgress","error":null,"startedAt":1776739472,"completedAt":null,"durationMs":null}}}} diff --git a/packages/contracts/src/orchestrationV2.test.ts b/packages/contracts/src/orchestrationV2.test.ts index 76f78f536d7c5..1fa8a0b8407a2 100644 --- a/packages/contracts/src/orchestrationV2.test.ts +++ b/packages/contracts/src/orchestrationV2.test.ts @@ -2,7 +2,14 @@ import { describe, expect, it } from "@effect/vitest"; import * as DateTime from "effect/DateTime"; import * as Schema from "effect/Schema"; -import { NodeId, RunAttemptId, TrimmedNonEmptyString } from "./index.ts"; +import { + EnvironmentId, + NodeId, + RunAttemptId, + ScheduledTaskId, + ThreadId, + TrimmedNonEmptyString, +} from "./index.ts"; import { latestProviderTurnForAttempt, OrchestrationV2CheckpointFileSummary, @@ -16,6 +23,7 @@ import { OrchestrationV2ThreadHistoryPage, OrchestrationV2TurnItem, OrchestrationV2TurnItemJson, + withMessageSenderNote, } from "./orchestrationV2.ts"; const now = DateTime.makeUnsafe("2026-04-20T00:00:00.000Z"); @@ -650,3 +658,48 @@ describe("latestProviderTurnForAttempt", () => { expect(latestProviderTurnForAttempt(turns, null)).toBeUndefined(); }); }); + +describe("withMessageSenderNote", () => { + const thread = { + createdBy: "agent", + creationSource: "mcp", + senderThreadId: ThreadId.make("t"), + } as const; + it.each([ + [thread, "Hi", '[T3 Code: the agent in T3 thread "t" sent this message, not the user.]\n\nHi'], + [thread, "", '[T3 Code: the agent in T3 thread "t" sent this message, not the user.]'], + [thread, "/review the diff", "/review the diff"], + [ + thread, + "/home/user/app is broken", + '[T3 Code: the agent in T3 thread "t" sent this message, not the user.]\n\n/home/user/app is broken', + ], + [ + { + createdBy: "agent", + creationSource: "mcp", + linkedSender: { + environmentId: EnvironmentId.make("e"), + threadId: ThreadId.make("r"), + title: "x", + }, + }, + "Hi", + '[T3 Code: the agent in T3 thread "r" on linked environment "e" sent this message, not the user.]\n\nHi', + ], + [ + { createdBy: "user", creationSource: "web", scheduledTaskId: ScheduledTaskId.make("s") }, + "Hi", + '[T3 Code: scheduled task "s" sent this prompt on its schedule. Nobody typed it just now.]\n\nHi', + ], + [ + { createdBy: "agent", creationSource: "mcp" }, + "Hi", + "[T3 Code: this message came through T3 Code's tools, not from the user typing in this chat.]\n\nHi", + ], + [{ createdBy: "user", creationSource: "web" }, "Hi", "Hi"], + [{ createdBy: "agent", creationSource: "server" }, "Hi", "Hi"], + ] as const)("labels %j's message %j for the provider", (message, text, expected) => { + expect(withMessageSenderNote(message, text)).toBe(expected); + }); +}); diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index f59ac95c5cffb..d1f437b543222 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -602,6 +602,37 @@ export function isCompactionCommandMessage(message: CompactionMessageFields): bo ); } +const SLASH_COMMAND_PROMPT = /^\s*\/[^\s/]+(?:\s|$)/u; + +/** + * Who sent a message, in a line the model reads before its text, or the text unchanged when a + * person typed it. Providers parse slash commands from the start of a prompt, so those stay as sent. + */ +export function withMessageSenderNote( + message: { + readonly createdBy: OrchestrationV2Actor; + readonly creationSource: OrchestrationV2CreationSource; + readonly scheduledTaskId?: ScheduledTaskId | undefined; + readonly senderThreadId?: ThreadId | undefined; + readonly linkedSender?: OrchestrationV2LinkedSender | undefined; + }, + text: string, +): string { + const agent = message.createdBy === "agent"; + const note = + agent && message.linkedSender !== undefined + ? `[T3 Code: the agent in T3 thread ${JSON.stringify(message.linkedSender.threadId)} on linked environment ${JSON.stringify(message.linkedSender.environmentId)} sent this message, not the user.]` + : agent && message.senderThreadId !== undefined + ? `[T3 Code: the agent in T3 thread ${JSON.stringify(message.senderThreadId)} sent this message, not the user.]` + : message.scheduledTaskId !== undefined + ? `[T3 Code: scheduled task ${JSON.stringify(message.scheduledTaskId)} sent this prompt on its schedule. Nobody typed it just now.]` + : agent && message.creationSource === "mcp" + ? "[T3 Code: this message came through T3 Code's tools, not from the user typing in this chat.]" + : undefined; + if (note === undefined || SLASH_COMMAND_PROMPT.test(text)) return text; + return text === "" ? note : `${note}\n\n${text}`; +} + export type OrchestrationV2GoalCommand = | { readonly type: "show" } | { readonly type: "clear" } diff --git a/packages/provider-core/src/server/handoffBudget.ts b/packages/provider-core/src/server/handoffBudget.ts index 18bd5fb1fd284..ddf9b692c337c 100644 --- a/packages/provider-core/src/server/handoffBudget.ts +++ b/packages/provider-core/src/server/handoffBudget.ts @@ -8,6 +8,7 @@ import type { OrchestrationV2ProviderThread, OrchestrationV2TurnItem, } from "@t3tools/contracts"; +import { withMessageSenderNote } from "@t3tools/contracts"; import * as Config from "effect/Config"; @@ -137,6 +138,8 @@ export function historicalMessage( let text: string; switch (item.type) { case "user_message": + text = withMessageSenderNote(item, item.text); + break; case "assistant_message": text = item.text; break; From c4a269a4662214854b59b8c73b4e1b78ad226554 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 19:49:09 +0000 Subject: [PATCH 2/4] test(server): drop start test the replay fixture already covers Co-Authored-By: Claude Opus 5.5 --- .../ProviderTurnStartService.test.ts | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts index c192c07aa2b1e..f83fa70ca6bae 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts @@ -467,7 +467,6 @@ function makeLocalCommandHarness(input: { readonly fileSystem?: FileSystem.FileSystem; readonly previousNativeSession?: boolean; readonly previousMessages?: ReadonlyArray; - readonly messageFields?: Partial; readonly logoutFailure?: string; readonly openFailure?: unknown; readonly ensureThreadFailure?: unknown; @@ -570,7 +569,6 @@ function makeLocalCommandHarness(input: { creationSource: "web", createdAt: now, updatedAt: now, - ...input.messageFields, }; let projection: OrchestrationV2ThreadProjection = { thread: { @@ -2671,26 +2669,6 @@ effectIt.effect.each([ }), ); -effectIt.effect("tells the provider that another thread's agent sent a message", () => - Effect.gen(function* () { - const harness = makeLocalCommandHarness({ - text: "Merge the PR now.", - messageFields: { - createdBy: "agent", - creationSource: "mcp", - senderThreadId: ThreadId.make("thread:sender"), - }, - previousTurn: { runStatus: "completed", turnStatus: "completed" }, - }); - - yield* harness.start; - - expect(harness.startRootRun.mock.calls[0]?.[0].message.text).toBe( - '[T3 Code: the agent in T3 thread "thread:sender" sent this message, not the user.]\n\nMerge the PR now.', - ); - }), -); - effectIt.effect("leaves delegated children to their own runs when the parent starts a turn", () => Effect.gen(function* () { const harness = makeLocalCommandHarness({ From 704bbae970fc93fbce1f2ae6a92da8c60583ec28 Mon Sep 17 00:00:00 2001 From: Bil0000 <62337003+Bil0000@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:53:06 +0100 Subject: [PATCH 3/4] fix(server): keep every slash prompt as sent and drop the schedule claim from task notes --- .../SteeringCompletion.integration.test.ts | 19 +++++++------------ .../contracts/src/orchestrationV2.test.ts | 9 ++------- packages/contracts/src/orchestrationV2.ts | 6 ++---- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index 5e11550b6ba98..ebe5e7215bcbd 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -20,7 +20,6 @@ import { TurnItemId, type ModelSelection, type OrchestrationV2DomainEvent, - withMessageSenderNote, } from "@t3tools/contracts"; import { expandAssistantCitationsForProvider, @@ -2429,14 +2428,7 @@ it.effect("steers a promoted scheduled delivery with the thread's current select const projection = yield* orchestrator.getThreadProjection(threadId); assert.deepEqual(steered, [ - withMessageSenderNote( - { - createdBy: "user", - creationSource: "web", - scheduledTaskId: ScheduledTaskId.make("task:scheduled"), - }, - "scheduled", - ), + '[T3 Code: scheduled task "task:scheduled" sent this prompt, not the user typing in this chat.]\n\nscheduled', ]); assert.deepEqual(projection.thread.modelSelection, composerSelection); }).pipe(Effect.provide(layer)); @@ -3194,8 +3186,9 @@ it.effect("starts a restart that stops the running turn ahead of an older held q queue: ["queued"], started: [ "first", - ...["second", "do this instead"].map((text) => - withMessageSenderNote({ createdBy: "agent", creationSource: "mcp" }, text), + ...["second", "do this instead"].map( + (text) => + `[T3 Code: this message came through T3 Code's tools, not from the user typing in this chat.]\n\n${text}`, ), ], }, @@ -3318,7 +3311,9 @@ it.effect("replays an accepted steer after its target turn completes", () => .pipe(Effect.flip); assert.equal(fresh._tag, "ThreadManagementNoSteerableRunError"); yield* worker.drain(); - assert.deepEqual(steered, [withMessageSenderNote(input, input.text)]); + assert.deepEqual(steered, [ + `[T3 Code: this message came through T3 Code's tools, not from the user typing in this chat.]\n\n${input.text}`, + ]); assert.lengthOf(started, 1); }).pipe( Effect.provide( diff --git a/packages/contracts/src/orchestrationV2.test.ts b/packages/contracts/src/orchestrationV2.test.ts index 1fa8a0b8407a2..73ca1a08dc387 100644 --- a/packages/contracts/src/orchestrationV2.test.ts +++ b/packages/contracts/src/orchestrationV2.test.ts @@ -668,12 +668,7 @@ describe("withMessageSenderNote", () => { it.each([ [thread, "Hi", '[T3 Code: the agent in T3 thread "t" sent this message, not the user.]\n\nHi'], [thread, "", '[T3 Code: the agent in T3 thread "t" sent this message, not the user.]'], - [thread, "/review the diff", "/review the diff"], - [ - thread, - "/home/user/app is broken", - '[T3 Code: the agent in T3 thread "t" sent this message, not the user.]\n\n/home/user/app is broken', - ], + [thread, " /git/review staged", " /git/review staged"], [ { createdBy: "agent", @@ -690,7 +685,7 @@ describe("withMessageSenderNote", () => { [ { createdBy: "user", creationSource: "web", scheduledTaskId: ScheduledTaskId.make("s") }, "Hi", - '[T3 Code: scheduled task "s" sent this prompt on its schedule. Nobody typed it just now.]\n\nHi', + '[T3 Code: scheduled task "s" sent this prompt, not the user typing in this chat.]\n\nHi', ], [ { createdBy: "agent", creationSource: "mcp" }, diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index d1f437b543222..f8c066cad20c0 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -602,8 +602,6 @@ export function isCompactionCommandMessage(message: CompactionMessageFields): bo ); } -const SLASH_COMMAND_PROMPT = /^\s*\/[^\s/]+(?:\s|$)/u; - /** * Who sent a message, in a line the model reads before its text, or the text unchanged when a * person typed it. Providers parse slash commands from the start of a prompt, so those stay as sent. @@ -625,11 +623,11 @@ export function withMessageSenderNote( : agent && message.senderThreadId !== undefined ? `[T3 Code: the agent in T3 thread ${JSON.stringify(message.senderThreadId)} sent this message, not the user.]` : message.scheduledTaskId !== undefined - ? `[T3 Code: scheduled task ${JSON.stringify(message.scheduledTaskId)} sent this prompt on its schedule. Nobody typed it just now.]` + ? `[T3 Code: scheduled task ${JSON.stringify(message.scheduledTaskId)} sent this prompt, not the user typing in this chat.]` : agent && message.creationSource === "mcp" ? "[T3 Code: this message came through T3 Code's tools, not from the user typing in this chat.]" : undefined; - if (note === undefined || SLASH_COMMAND_PROMPT.test(text)) return text; + if (note === undefined || text.trimStart().startsWith("/")) return text; return text === "" ? note : `${note}\n\n${text}`; } From c36378324dfaa17f5686534b412c08ab7599e1a7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 20:50:18 +0000 Subject: [PATCH 4/4] fix(server): keep a leading $skill mention as sent so Grok still expands it Grok only expands a skill mention at the start of the prompt, so the sender note in front of `$deploy ship it` stopped the skill from running. Leading skill mentions now skip the note, the same way leading slash commands do. Co-Authored-By: Claude Opus 5.5 --- packages/contracts/src/orchestrationV2.test.ts | 6 ++++++ packages/contracts/src/orchestrationV2.ts | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/contracts/src/orchestrationV2.test.ts b/packages/contracts/src/orchestrationV2.test.ts index 73ca1a08dc387..bacf812ab8057 100644 --- a/packages/contracts/src/orchestrationV2.test.ts +++ b/packages/contracts/src/orchestrationV2.test.ts @@ -669,6 +669,12 @@ describe("withMessageSenderNote", () => { [thread, "Hi", '[T3 Code: the agent in T3 thread "t" sent this message, not the user.]\n\nHi'], [thread, "", '[T3 Code: the agent in T3 thread "t" sent this message, not the user.]'], [thread, " /git/review staged", " /git/review staged"], + [thread, "$deploy ship it", "$deploy ship it"], + [ + thread, + "$25 left", + '[T3 Code: the agent in T3 thread "t" sent this message, not the user.]\n\n$25 left', + ], [ { createdBy: "agent", diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index f8c066cad20c0..b5fd428d6b4cc 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -602,9 +602,12 @@ export function isCompactionCommandMessage(message: CompactionMessageFields): bo ); } +const LEADING_COMMAND = /^\s*(?:\/|\p{Sc}[a-zA-Z0-9:_-]*[a-zA-Z])/u; + /** * Who sent a message, in a line the model reads before its text, or the text unchanged when a - * person typed it. Providers parse slash commands from the start of a prompt, so those stay as sent. + * person typed it. Providers parse slash commands and skill mentions such as `$deploy` from the + * start of a prompt, so those stay as sent. */ export function withMessageSenderNote( message: { @@ -627,7 +630,7 @@ export function withMessageSenderNote( : agent && message.creationSource === "mcp" ? "[T3 Code: this message came through T3 Code's tools, not from the user typing in this chat.]" : undefined; - if (note === undefined || text.trimStart().startsWith("/")) return text; + if (note === undefined || LEADING_COMMAND.test(text)) return text; return text === "" ? note : `${note}\n\n${text}`; }