feat(mcp): merge back conversation context#8697

closed3
agents/mcp-conversations/fork
agents/mcp-conversations/merge-back
openedAug 29, 2026byJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 2d ago

Problem

A durable conversation fork could produce a result, but agents had no safe way to return that conversation context to the fork's original parent.

Change

Add t3_thread_merge_back on top of the fork transfer service, backed by the existing thread.merge_back V2 command through ThreadManagementService.

Behavior

The tool validates original fork lineage, source and target permission ceilings, and an explicit provider-finished source before dispatch. It returns source, target, fork-base provenance, the committed receipt, superseded pending transfers, and truthful next-target-turn consumption. Stable retries replay the same accepted transfer before mutable lineage or lifecycle checks. It never performs a Git merge or changes workspace state.

Focused validation

  • transfer contract and production root-object schema tests
  • non-fork, source/target ceiling, accepted-retry, and projection-failure coverage
  • event-driven real MCP-to-V2/provider-adapter integration covering merge-back, retry, supersession, and managed-adapter consumption on the target's next turn
  • 5 focused files / 16 tests passed across the complete native stack
  • server and contracts scoped typechecks, targeted formatting, and git diff --check

Dependency

Upper layer of native stack 8776. Depends on #8696 for the focused conversation transfer contract, service, fork creation, and bounded transfer read path.

Implemented by GPT-5.6-Sol via Codex in T3 Code.

Synced from GitHub

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

āš™ļø Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 34e8d8ed-503a-415d-8853-c714eb5f14b7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • šŸ” Trigger review

Warning

Your free Security trial is over. An organization admin can activate Security or dismiss this notice.


Comment @coderabbitai help to get the list of available commands.

Synced from GitHub

Thread transfer impact

āš ļø The latest CI run did not produce a thread transfer result for afe9681.

This comment will update automatically after the next completed run.

Synced from GitHub

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR introduces a new destructive MCP workflow for durably merging forked conversation context back into a parent, including retries, permission ceilings, supersession, and next-turn consumption. It changes production orchestration and public tool contracts across several components, so human review is appropriate.

No code changes detected at afe9681. Prior analysis still applies.

You can add or adjust custom eligibility rules. Learn more.

apps/server/src/mcp/ConversationTransferMcpService.tsline 511Outdated Ā· d7d2ffaOpen thread
……@@ -360,8 +423,169 @@ export const make = Effect.gen(function* () {
508+ `Thread ${source.thread.id} can merge back only to its recorded parent ${recordedTargetId}.`,
509+ );
510+ }
511+ const { target } = yield* loadScoped(scope, requestedTargetId);
MmacroscopeappBoton line 511Aug 30, 2026

🟠 High mcp/ConversationTransferMcpService.ts:511

mergeBack allows a lower-policy caller to transfer context from a fork whose runtime or interaction mode was later escalated, bypassing the source-versus-caller ceiling enforced by fork. Lines 511–528 validate only the parent target against parent, so add the same checks for source.thread before dispatching the merge-back.

šŸš€ Reply "fix it for me" or copy this AI Prompt for your agent:
text
1In file @apps/server/src/mcp/ConversationTransferMcpService.ts around line 511:
2
3`mergeBack` allows a lower-policy caller to transfer context from a fork whose runtime or interaction mode was later escalated, bypassing the source-versus-caller ceiling enforced by `fork`. Lines 511–528 validate only the parent target against `parent`, so add the same checks for `source.thread` before dispatching the merge-back.

Fixed at b8724db4928ed0f5b96abac69baa6106021dc817. Fresh merge-back now checks the source as well as the target against both the captured and current caller ceilings inside the existing total-order source/target/caller dispatch locks. Accepted stable-key retries still replay before mutable source, target, lineage, or policy checks. Focused real MCP/V2 coverage proves source escalation is denied at the mutation boundary and that an accepted merge remains replayable after the caller narrows. Transfer service plus toolkit integration tests pass 5/5; contracts and server typechecks pass.

Added 3 commits

  • fix(mcp): enforce merge-back source ceiling073dd59
  • feat(mcp): merge back conversation context9efa23d
  • test(mcp): type merge-back denial fixtureafe9681

Superseded as the active MCP proposal by #10558 in the rebuilt MCP stack, following the maintainer request to review thin service wrappers separately from service hardening.

This is not a full feature-parity replacement. Each invocation generates a new command. No additional clientRequestId protocol, transfer journal or provider implementation. Merge targets remain in the calling project.

Closing this mixed proposal without merging. The remote branch agents/mcp-conversations/merge-back and exact head afe96811882382ce92e911edbe21b6251a1ffee3 are retained so the service changes can be extracted for separate review later.