t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: an agent's t3_thread_launch can claim a workflowRun on a linked environment, hiding the thread from every list

Open mikebanks opened this issue 1 week ago • 2 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

Found by reading the source while resolving the merge conflict on #27012. It has not been reproduced in a running app. This is the same pattern as #27004, on the sibling field workflowRun.

  1. Link environment A to environment B.
  2. In a thread on A, have the agent call t3_thread_launch with environmentId: <B> and a workflowRun value. The field is in the tool's input schema (apps/server/src/mcp/toolkits/project/tools.ts:169-170).
  3. Look for the new thread in B's thread list, from any client.

A second path: an agent in a thread on B that a link started calls t3_thread_launch locally with workflowRun.

Expected behavior

workflowRun is honoured only when a linked environment's workflow engine sets it, as the schema comment says ("Set by a linked environment whose workflow run this thread is a step of; ignored otherwise"). An agent's launch that passes it creates an ordinary top-level thread.

Actual behavior

From the source on main, the claimed workflowRun is stamped, and the thread is left out of every thread list although no workflow run owns it:

  • McpToolAccess.routed forwards the agent's params to the peer unchanged, including workflowRun (apps/server/src/mcp/McpToolAccess.ts, the forwarding.value.call in routed).
  • The receiving t3_thread_launch handler keeps workflowRun whenever linkOrigin is defined (apps/server/src/mcp/toolkits/project/handlers.ts:485-488). linkOrigin is defined for the link's own session and also for an agent in a thread a link started (apps/server/src/mcp/linkOrigin.ts:19-29).
  • thread.create stamps workflowRun and lineage.workflowStep: true with no further check (apps/server/src/orchestration-v2/Orchestrator.ts:4146, 4151).
  • isListedThreadLineage excludes workflowStep === true (packages/contracts/src/orchestrationV2.ts:202-205).

The real sender does not go through routed: WorkflowAgentLinks calls the peer directly and arrives as the link's own session, with no calling thread (apps/server/src/workflows/WorkflowAgentLinks.ts:200-222).

A possible fix, mirroring #27012: drop workflowRun next to delegatedFrom in routed, and keep it in the handler only when there is no calling thread (caller === undefined). Neither change touches the workflow engine's own path. I can open a PR for this if that is welcome.

Impact

Minor bug or occasional failure

Version or commit

main @ 93a7cfe745

Environment

Not applicable: found by reading the server source, not by running it.

Workaround

Do not pass workflowRun on t3_thread_launch.

Model and harness: Claude Fable 5.2 in Claude Code via T3 Code.

mikebanks avatar Nov 24 '26 16:11 mikebanks

I tried to reproduce this on the current build and could not.

Commit origin/main 4efbc37718. Not reproduced in a running app: that needs two T3 servers paired as linked environments. I showed it with the real in-process MCP server, the real t3_thread_launch handler and the real orchestrator on an in-memory database, in apps/server/src/mcp/linkOrigin.test.ts. Steps: (1) the linked session 'laptop' (client scope with linked=true) calls t3_thread_launch with workflowRun {environmentId, runId, workflow, step}. The thread is stamped with workflowRun and lineage.workflowStep=true, which is correct. (2) 'laptop' launches a second thread (it gets linkOrigin laptop), and message.dispatch start_immediately gives it an active run. (3) An agent in that thread (thread scope, no client) calls t3_thread_launch with the same workflowRun. Seen: the new thread's shell has workflowRun set (assertion 'expected { …(4) } to equal undefined'), and its lineage fails isListedThreadLineage, so it is left out of every thread list. The forwarded path (an agent on A launching on B through McpToolAccess.routed) I confirmed only by reading the code. routed passes all params on to forwarding.value.call, and B receives the call as the link's own session with no calling thread, the same as the workflow engine. So that half needs the fix on the sending side. Failing test pushed to factory/repro-42251.

Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

juliusmarminge avatar Nov 24 '26 16:11 juliusmarminge

@juliusmarminge I think this was closed by mistake. The comment above says "could not reproduce", but its own steps reproduce it: the test on factory/repro-42251 ("names a workflow run only from the link's own session") fails on main at 4efbc37718 with the claimed thread stamped with workflowRun and failing isListedThreadLineage. The same comment also confirms the forwarded path by reading routed.

Could this be reopened? Version is main @ 4efbc37718; steps are the ones in that test. I'm happy to open a PR with the fix (drop workflowRun in routed, keep it in the handler only when there is no calling thread) on top of that failing test.

mikebanks avatar Nov 24 '26 16:11 mikebanks