Skip to content

feat(server): t3_thread_import, conversation only - #16731

Draft
juliusmarminge wants to merge 1 commit into
t3code/peer/remote-delegatefrom
t3code/peer/thread-import
Draft

juliusmarminge wants to merge 1 commit into
t3code/peer/remote-delegatefrom
t3code/peer/thread-import

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Part of cross-environment orchestration. Moving a thread to another environment needs its conversation over there. This PR adds the receiving half for the conversation. The code moves in the next PR, and the handoff that drives both comes after that.

What changes

  • New tool. t3_thread_import (behind a new threadImport capability) creates a thread whose history is the given user and assistant messages.
  • History as context. The messages are written runless, and the thread is marked historyOrigin: "v1_import". That makes its first run receive the history as a text context handoff, which works the same for every provider. continuationPrompt, when given, becomes that run's message.
  • Retry-safe. The thread id is a hash of the source environment, the source thread, and a handoff id. The continuation's command id derives from the thread. So a retried import returns the thread the first call created and starts nothing new, and a different handoff of the same source thread gets a new thread.
  • Access. The tool goes through startsThreads, so modes are capped by the caller's. A link's import carries its linkOrigin (feat(server): work a linked environment starts stays within its link #16695). If worktreePath is given, it must be one of the project's worktrees.
  • Header wording. The imported-history header no longer says "the previous T3 Code orchestrator", because history now also arrives from other environments. It now reads "Imported conversation history from before this thread ran here."
  • Test helper. The capturing Codex adapter from the V1 cutover test moves to testkit/CapturingCodexAdapter.ts for reuse.

Verification

  • orchestration-v2/ThreadImportService.test.ts runs a real orchestrator (replay harness, SQLite) with a capturing adapter:
    • The import creates a thread whose history comes before any run, marked imported and carrying the link origin.
    • Its first run's provider input contains the context handoff, the earlier assistant finding, then the continuation prompt.
    • A retry returns the same thread with created: false, and adds no messages, runs or provider turns.
    • Another handoff id gives a new thread.
  • Mutation-checked: each of these fails the test when removed:
    • the imported marker;
    • deriving the id from the handoff;
    • deterministic ids;
    • a replay-safe continuation;
    • carrying the link origin.
  • Also ran mcp, peer, ContextHandoffService, legacy (including the V1 cutover integration test on the extracted adapter), AgentSessionImporter, Orchestrator.migration, shared t3McpToolPresentation and the toolkit catalog checks. All passed. Server and contracts typecheck clean, and lint is clean on the changed lines.

Opus 5.5 via Claude Code.

🤖 Generated with Claude Code

@juliusmarminge
juliusmarminge added this pull request to stack #16656 October 7, 2026 05:31
@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Oct 7, 2026
@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 7, 2026
@github-actions github-actions Bot added the size:XL 500-999 changed lines (additions + deletions). label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 5.0 KiB — 6.8 KiB ✅
Codex Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Codex Live turn WebSocket decoded — 20.9 KiB — 29.3 KiB ✅
Codex Live turn messages — 2 — 8 ✅
Claude Total thread wire — 5.0 KiB — 6.8 KiB ✅
Claude Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Claude Live turn WebSocket decoded — 21.2 KiB — 29.3 KiB ✅
Claude Live turn messages — 2 — 8 ✅

Baseline: unavailable · PR result: f139c6e · Source CI: failure

Scenario and decoded snapshot size

10 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.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

A thread moving here from a linked environment needs its conversation.
t3_thread_import creates the thread with that history as runless, imported
messages, so its first run gets it as a text context handoff whatever the
provider, then sends continuationPrompt as that run's message.

The thread id is a hash of the source environment, thread and handoff id,
and the continuation's command id derives from the thread, so a retried
import returns the thread the first created and starts nothing new. The
tool goes through startsThreads: modes are capped by the caller's, and a
link's import carries its linkOrigin. worktreePath, when given, must be one
of the project's worktrees.

The imported-history header no longer names "the previous T3 Code
orchestrator", since history now also arrives from other environments. The
capturing Codex adapter from the V1 cutover test moves to a testkit.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@juliusmarminge
juliusmarminge force-pushed the t3code/peer/thread-import branch from f139c6e to 70a654c Compare October 7, 2026 08:24
@juliusmarminge

Copy link
Copy Markdown
Member Author

End-to-end run, two real servers

Two t3 serve processes from the top of this stack, each with its own data directory, on one machine. A laptop (port 3971) and a box (port 3972). Their projects are clones of one bare origin, so they share a repository. An outside agent (OAuth with a pairing code) drives the laptop's /mcp, and real Claude Sonnet 5.5 turns run on both sides. The last part repeats the run over Tailscale HTTPS (https://cups.tail131df4.ts.net:3972).

Every handoff in the run seeded the box's thread through t3_thread_import. The first turn there had the conversation. The laptop thread was told "Remember the codeword MANGO", and after the move the box answered "CODEWORD MANGO". Thread ids were deterministic (thread:import:<hash>).

Opus 5.5 via Claude Code.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:XL 500-999 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant