Repository navigation
fix(mcp-gateway): chat creation rejects a parentThreadId that isn't a chat - #175
Merged
Merged
Conversation
… chat An explicit parentThreadId on another environment was stored unchecked, because the target server can only verify parents it owns. A Captain passed an MCP request namespace (mcp:<uuid>) as the parent, and its children never appeared under it. The gateway now looks the parent up on its environment and fails with invalid_input when it is not a chat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
The parent check listed every thread shell on the parent's environment (about 5,000 on a busy one). It now reads the parent with the bounded getThread snapshot and lists only when that read fails, to tell a missing thread from any other error (relays pass errors on as text). The gateway projection and relay schema now carry archivedAt and deletedAt, so archived and deleted parents stay rejected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
t3_create_thread/t3_create_and_start_threadaccepted any explicitparentThreadId. When the parent's environment differs from the target, the target server cannot check it (the orchestrator only validates same-environment parents), so it was stored as-is. On 30 Oct a Captain passedmcp:b33476a4-…, an MCP request namespace copied out of adelegate_taskID, withparentEnvironmentIdset to its own environment. Six children were stored with a parent that doesn't exist and never appeared under Captain.Fix
When
parentThreadIdis given explicitly, the gateway reads it on the parent's environment (parentEnvironmentId, or the target) through the existinggetThreadOrNotFound:getThreadsnapshot (server row and turn limits), not the full thread list.If the parent is missing, archived, or deleted, the call fails with
invalid_inputbefore any chat is created:Other errors propagate. No change when the parent is omitted (it still defaults to the calling chat) or set to
null(standalone).To see archived and deleted parents,
gatewayThreadProjectionand theMcpGatewayRelayThreadrelay schema now carryarchivedAt/deletedAt. Both fields are optional, so older apps still decode, and their archived parents pass the check.Other paths checked:
t3_set_thread_parentalready rejects missing/archived same-env parents in the orchestrator (requireValidParentThread).t3_thread_launch/create_threadsonly ever parent to the calling chat, so they take no explicit parent.Evidence
Extended
parents chats a T3 chat creates on any environmentintools.test.ts. It asserts that a fakemcp:<uuid>parent (cross-env and same-env) and an archived parent are rejected with that message, and thatcreateThreadisn't called. Default, explicit-existing, and null cases are unchanged.promise resolved instead of rejecting).runtimePort.test.ts29/29.Risk
Low. One bounded read, only on creates with an explicit parent. Two optional fields are added to the gateway thread projection.
Done by Claude Opus 5.5 in Claude Code (T3 Code).
🤖 Generated with Claude Code