Skip to content

feat(t3code): move the backend onto T3 Orchestrator V2's /mcp transport - #5

Merged
bryceeppler merged 1 commit into
bryceeppler:t3code-backendfrom
arthurcruzd:fm/t3-backend-p0-pr
Oct 10, 2026
Merged

bryceeppler merged 1 commit into
bryceeppler:t3code-backendfrom
arthurcruzd:fm/t3-backend-p0-pr

Conversation

@arthurcruzd

Copy link
Copy Markdown

Moves this branch's t3code backend from the pre-V2 HTTP transport onto T3 Code's Orchestrator V2 /mcp endpoint, signed in as an OAuth mcp-client.
T3's Orchestrator V2 (pingdotgg/t3code#2829) removed POST /api/orchestration/dispatch: the 0.0.46 nightly answers 404 for it, and an mcp-client session is accepted only on /mcp, so the shell snapshot, thread detail, and WebSocket stream are unavailable to it as well.
Reference: kunchenguid#6904

Fixes kunchenguid#6904

What changes

  • Transport. New bin/fm-t3-mcp.mjs, a dependency-free MCP streamable-HTTP client (protocol 2025-06-18, JSON or SSE replies) that the adapter calls as a compact CLI.
    login is the captain-run sign-in: a two-minute pairing code from t3 auth pairing create --scope orchestration:read --scope orchestration:operate, the OAuth decision at the full-access ceiling, and a PKCE token exchange.
    The credential, origin, environment id, and server version are written to the existing config/t3code-token (mode 0600, never printed); expiry warns five days ahead and refuses once expired.
    The origin still defaults to FM_T3CODE_ORIGIN, then ~/.t3/userdata/server-runtime.json.

  • Capability gate. Every call runs tools/list and requires the t3_thread_*, t3_project_list/create, and t3_environment_read tools, then refuses unless t3_environment_read reports the environment id recorded at sign-in.
    This replaces the dispatch probe, version floor, and threadAutoSettleOptOut check.

  • Primitive mapping in bin/backends/t3code.sh, keeping its function names, the status-table shape, config/t3code-instances, model and effort selection, and every spawn, lease, environment, and teardown call site:

    Primitive Before Now
    project shell snapshot + project.create t3_project_list (real-path match) + t3_project_create
    thread create client uuid + thread.create + thread.auto-settle.set t3_thread_launch (existing_worktree, or root for a secondmate home) with a binding read-back; T3 assigns mcp:<uuid>
    launch turn, steer, doorbell thread.turn.start t3_thread_send mode auto with a clientRequestId
    busy / liveness / turn age thread detail + shell backgroundLiveness t3_thread_read V2 status and latest run times
    Escape / Ctrl-C thread.turn.interrupt t3_thread_interrupt confirmed by t3_thread_wait
    teardown, abort thread.session.stop + thread.archive interrupt an active run, t3_thread_organize archive, then read back archived:true with no active run
    away-mode captain thread shell snapshot cwd match t3_thread_list (active statuses) + t3_thread_read on the home's project

Behavior the transport forces

  • fm-control.sh exit on t3code now refuses before sending anything: the V2 tools have no session stop, and an interrupt leaves the thread idle and alive, so no stop can be proven.
    interrupt and relaunch behave as before.
  • The WebSocket push path (t3code-eventwait.cjs, t3code-thread-status.cjs, and the events suite) is removed, because T3 rejects an mcp-client on it; T3 windows stay on the watcher's poll loop, and pending approvals read busy rather than blocked.
  • t3_thread_launch has no idempotency key, so a launch whose response is lost is never retried; spawn keeps the lease and names the slot to check, replacing the two-attempt commandId retry.
  • A thread T3 bound to another worktree, provider instance, or runtime mode is archived and the spawn refuses.
  • thread_create now prints the id T3 assigned, and endpoint validation accepts the mcp: prefix.
  • Docs: docs/t3code-backend.md setup (sign-in, expiry, revocation, telemetry off, capability gate), lifecycle, status table, push, away mode, and limits are rewritten for V2; cross-references in agent-control.md, architecture.md, configuration.md, scripts.md, and README.md are updated.

Verification

  • tests/fm-t3-mcp.test.sh (new, 15 cases) drives the helper against tests/t3-fake-server.mjs, a fake V2 /mcp and OAuth server shared with the backend suite.
  • tests/fm-backend-t3code.test.sh is ported onto the same fake server: 55 cases, including spawn, secondmate spawn, abort and uncertain-launch lease retention, teardown ordering, the exit and relaunch refusals, the watcher wedge and dead-agent paths, and away-mode stale-alert retention.
  • tests/fm-backend-t3code-live-e2e.test.sh is now a token-free, read-only guard (gate, project catalog, missing-thread read, supervisor lookup) that skips cleanly without a credential.
  • Also exit 0: fm-backend, fm-control, fm-control-relaunch, fm-send-inbox, fm-teardown-endpoint-safety, fm-test-run, fm-bootstrap, fm-daemon, fm-secondmate-harness, fm-watch-inbox-meta; bin/fm-lint.sh on the changed shell files and bin/fm-doc-audience-check.sh pass.
  • The transport was verified live on 2026-10-08 against t3 0.0.46-nightly.20261008.2833 (telemetry off, Claude Code 2.1.295, codex-cli 0.160.1) through an earlier standalone wiring of the same helper: a real fm-brief.sh Claude scout from spawn to report, an inbox steer, a confirmed interrupt, a proven archive on teardown, and a Codex scout smoke; docs/verification/runtime-backends.md records it.
    This branch's own wiring has fake-server coverage only and has not yet been run against a live server.

Follow-ups (not in this PR)

  • Per-task environment on t3_thread_launch (an env overlay ask to T3), which would replace the per-directory .claude/settings.local.json and .codex/config.toml channel.
  • A telemetry opt-out beyond the current warning when the server is not proven to run with T3CODE_TELEMETRY_ENABLED=false.
  • A semantic busy source with approval polling (pendingRequestCount), watcher push through t3_thread_wait, a recovery-grade exit and relaunch, restart reconciliation, and the wedge alarm.
  • A live run of this wiring against a V2 server.

T3's Orchestrator V2 removed POST /api/orchestration/dispatch, and an OAuth
mcp-client session is accepted only on /mcp. Add bin/fm-t3-mcp.mjs, a
dependency-free MCP client with the captain-run PKCE sign-in, a tools/list
capability gate pinned to the signed-in environment id, and the thread verbs
the adapter needs, and port bin/backends/t3code.sh onto it: launch, send,
read, interrupt, archive with a proven close, and the away-mode thread lookup.

The transport forces three changes: fm-control exit refuses on t3code (V2 has
no session stop), the WebSocket push path is removed (an mcp-client is refused
on it, so T3 windows poll), and a launch whose reply is lost keeps its lease
instead of retrying (t3_thread_launch has no idempotency key).

Fixes kunchenguid#6904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants