[Bug]: Thread context references show thread_<uuid>, but t3_thread_read only accepts the bare UUID
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
Summary
When a user attaches a thread as context, the provider prompt renders an inline marker [Thread: <title>; ref=thread_<uuid>], and the stored message keeps the link t3-context://v1/thread/thread_<uuid>. The thread-scoped MCP tools resolve threadId by exact lookup, so an agent that copies the ID from the marker or link fails. Only the bare UUID carried in the injected <t3_context> envelope (threadId: <uuid>) works.
On the current build the failure is masked by #15566 as an output-schema error, so the agent cannot tell it is an ID-format problem. In a live session I watched the agent fail with the prefixed ID and recover only after stripping the prefix on retry.
Steps to reproduce
-
In a running thread, attach another thread as context (composer context chip) and send the message.
-
As the agent, call
t3_thread_readwith the ID exactly as displayed in the reference — theref=value in the marker, or the last path segment of thet3-context://v1/thread/...link:{"threadId": "thread_<uuid>"} -
The call fails. With #15566 unfixed this surfaces as:
Structured content does not match the tool's output schema: data must have required property 'thread', data must have required property 'recentRuns', ...The server trace for the call shows the failed lookup:
McpServer.@effect/mcp/2025-06-18/tools/call tool=t3_thread_read parameters={"threadId":"thread_61431f2f-5a89-4dc9-8d6d-a2a357d20238"} exit=Success sql.transaction exit=Failure cause=ProjectionStoreThreadNotFoundError: No orchestration projection exists ... -
Call again with the bare UUID from the envelope's
threadId:line and it succeeds.
Expected behavior
The reference ID form the product displays should be accepted by the tool the injected context tells the agent to use, or the reference should display the canonical bare thread ID. Accepting both forms server-side (normalizing a leading thread_) seems least disruptive, because the marker ref is also the pairing key for the <t3_context> envelope entry while the payload already carries the bare threadId.
Actual behavior
t3_thread_read({threadId: "thread_<uuid>"}) fails with thread_not_found (masked as the #15566 schema error). t3_thread_read({threadId: "<uuid>"}) succeeds.
Relevant code:
packages/shared/src/composerContextReferences.ts:121-131— the provider marker emitsref=<contextId>.packages/shared/src/composerContextReferences.ts:236-242— the thread payload carries the barethreadId.apps/web/src/lib/composerContextReferences.ts:55-70, 160-180— thread context ids are built asthread_<uuid>.apps/server/src/mcp/OrchestratorMcpService.ts:849-875—loadReadableThreaddoes an exact lookup, and the attached-thread fallback set stores bare ids, so the prefixed form never resolves.
Impact
Minor bug or occasional failure, but it affects every attached-thread reference for agents that copy the visible ID. The intended path works, so this is a discoverability/robustness trap rather than a hard block.
Version or commit
0.0.46-nightly.20261004.2657 (live reproduction); source inspection on current main.
Environment
macOS, T3 Code desktop nightly, provider opencode (opencode-go).
Logs or stack traces
McpServer.@effect/mcp/2025-06-18/tools/call tool=t3_thread_read parameters={"threadId":"thread_61431f2f-5a89-4dc9-8d6d-a2a357d20238"} exit=Success
sql.transaction exit=Failure cause=ProjectionStoreThreadNotFoundError: No orchestration projection exists ...
Workaround
Pass the bare UUID from the <t3_context> envelope instead of the displayed ref.
[!NOTE] Grok responding on behalf of Julius.
Triage
Thanks @YL404 for the precise write-up and the server trace. Pinning down exactly which ID form works made this easy to follow. It reproduces on current main (801ca76ed6) and on v0.0.46-nightly.20261004.2657, and it's separate from #15566.
What I found
Two different IDs are in play:
- The inline marker
ref=and thet3-context://v1/thread/...link carry the context id, which is the key that pairs the marker with its<t3_context>entry. For a desktop thread that'sthread_<uuid>: desktop mints thread ids withnewThreadId()(apps/web/src/lib/utils.ts), andthreadContextIdprefixes it withthread_(apps/web/src/lib/composerContextRecords.ts) viatoKindScopedComposerContextIdinapps/web/src/lib/composerContextReferences.ts. - The tool argument is the
threadId:line inside the envelope.t3_thread_readlooks that value up exactly, anduserAttachedThreadIdsstoresrecord.threadId, notcontextId(apps/server/src/mcp/OrchestratorMcpService.ts). Sothread_<uuid>misses both the project lookup and the attached-thread fallback and becomesProjectionStoreThreadNotFoundError, which #15566 then masks as the schema error (failureMode: "return").
The envelope does tell the agent to call t3_thread_read(threadId), and the provider projection test locks in ref=thread_abc next to threadId: abc. The trap is that ref= is the first ID in the marker line and looks like a thread id.
One caveat on prefix stripping: it only recovers client-minted UUID ids. Server-minted ids contain : (for example thread:project:<projectId>:<uuid>, thread:delegated-task:<commandId>, and imported import:... ids). Those don't fit the context-id pattern and are stored as a slug plus a hash, so stripping thread_ wouldn't map them back. Replacing ref= with the raw thread id would break marker/envelope pairing.
Likely fix area
- One option is that after an exact miss,
t3_thread_readresolves the supplied id against a user-authored attached-thread record'scontextIdand reads that record'sthreadId, keeping the existing rule that agent-written records don't grant access. - Another is normalizing a leading
thread_server-side, which covers the reported case but not server-minted ids. - Changing the marker text so the bare thread id is more prominent is a third, prompt-side option.
A maintainer will decide on the fix direction.
I can implement this after you choose a direction. The triage lists three options:
- After an exact miss, resolve the supplied id against the
contextIdof a user-authored attached-thread record, and read that record'sthreadId. - Strip a leading
thread_server-side. - Change the marker text so the bare thread id is more prominent.
Option 1 looks like the most complete one to me. It covers server-minted ids with : that option 2 cannot map back. It also keeps the rule that agent-written records do not grant access. The change would be in OrchestratorMcpService.ts, with tests for a prefixed client id and a server-minted id.
Is option 1 acceptable, or do you prefer another option?
Closing for housekeeping — still reproducible. The triage laid out three fix directions and @phant0um offered to implement once one is chosen; feel free to reopen if a maintainer picks a direction.
Still reproduces on 0.1.3-nightly.20261025.3655 (Ubuntu 26.04), and on the same server: both threads are in one environment, only in different projects, so this is not the cross-server case. t3_thread_read({threadId: "thread_<uuid>"}) returns thread_not_found, while t3_thread_read({threadId: "<uuid>"}) succeeds for the same thread.
I have a fix for the second option in the triage: one threadRefId helper strips a leading thread_ before each lookup in the MCP thread tools (4 files, +54/−15, with tests). It merges cleanly on current main: https://github.com/bompus/t3code/tree/fix/thread-ref-id-normalize
It covers the desktop thread_<uuid> form only. As @phant0um noted, it cannot map server-minted ids that contain : back to their stored form. For example, an agent thread's thread_mcp-<uuid> fails against the stored mcp:<uuid>, and this fix leaves that case failing. Option 1 would cover both.
If a maintainer picks a direction, I can open the PR for option 2, or rework it for option 1. A newer report of the same failure, #24747, was closed as a duplicate of this issue.
Still reproducible on 0.1.7-nightly.20261031.3991 (Linux x64, server + OpenCode provider), same-environment case: both threads belong to one environment, no snapshot involved.
Attaching a thread as a live reference gives the agent:
- message text:
[Title](t3-context://v1/thread/thread_<uuid>) - context record:
contextId: "thread_<uuid>"next tothreadId: "<uuid>"
// id copied from the link / marker
{ "threadId": "thread_<uuid>" }
// -> {"_tag":"OrchestratorMcpFailure","code":"thread_not_found",
// "message":"Thread thread_<uuid> is no longer available."}
// canonical id from the same payload
{ "threadId": "<uuid>" } // -> ok
Two extra data points:
-
The dynamic tool namespace compounds it. The valid call in this harness is
tools["t3-code-<thread>"].t3_thread_read, so the agent's first attempt (tools.t3_thread_read) already fails withUnknown tool; when it retries with the right namespace it reuses the id it composed from the link — the prefixed one. It then reports to the user that the thread was deleted, which is the actual user-visible damage (not just a failed call). -
+1 for option 1 in the triage (on an exact miss, resolve the supplied id against the
contextIdof a user-authored attached-thread record and read that record'sthreadId). Option 2 (strip a leadingthread_) is a smaller diff but leavesmcp:/project:server-minted ids broken, as noted above by @phant0um and @bompus.
Happy to test a build if a direction gets picked.