Skip to content

P1: Bind the caller's thread id at the MCP transport (closes thread_stop/thread_archive approval bypass) #1425

Closed

Description

@currentbits

From the T3 Code Orchestrator V2 comparison (report: reports/T3 Code orchestrator for Solenta.md on branch coder/i-want-you-to-research-t3-codes-orchestr-fae77a). This is item 1 of 4. T3 V2 mints a session-scoped token for each provider session, so the server knows who is calling. Solenta's coder-threads server instead trusts a thread id the agent passes in.

Bug

  • assertCrossThreadApproved (electron/orchServer.js:536) starts with if (!fromId || fromId === targetId) return;, and fromThreadId is an optional argument the agent supplies.
  • thread_stop (:1058) and thread_archive (:1012) check only requireOwnThread, i.e. that the target is in the same project.
  • So any agent that leaves out fromThreadId can stop or archive any thread in its project without approval. That breaks the Cross-thread message delivery contract: hold until idle, attributed card, per-thread inbound policy #551/Non-bypassable destructive-action gate outside the trust dials #322 rule that these are "the user's decision in every permission mode, including Auto and Bypass".
  • The merge gate's machine-turn check (runner.isAutoTurn, electron/runner.js:9033) has the same weakness: it runs on whichever thread id the caller claims.
  • Found by reading the code, not reproduced live.

Fix

  • Do for the thread id what Isolate Kimi runs: no cross-project threads, memory, or workspaces #671 did for projectId. Write threadId=<caller> into the per-thread coder-threads MCP URL (electron/memory-sup.js, near the bound config around :1713). Read it next to boundProjectId (electron/orchServer.js:1964) and pass it to createToolHandlers as the bound caller.
  • If no fromThreadId is given, use the bound id. If a different fromThreadId is claimed, reject the call.
  • Stopping or archiving yourself (bound id === target) stays ungated.
  • External pairing clients (electron/pairing.js) keep their capability tokens. Check they still work and can't bypass the gate.
  • In the same change, enforce privilege narrowing in forkThread (electron/services.js): a child's snapped permission mode must not rank above its parent's. If it does, refuse with a typed error (T3 calls this runtime_mode_escalation_denied). Headless grok needs auto, so any override must be a user-set flag on the pool alias, never an argument the agent passes.

Tests

  • A worker calling thread_stop on its lead without fromThreadId is refused.
  • A thread can still stop itself.
  • A fromThreadId that conflicts with the bound id is rejected.
  • A fork whose permission mode would be higher than its parent's is refused.

Size: S. A work_suggest chip with a full prompt for this fix is already on thread fae77a0b.

Activity

  1. added
    plan:todo
    on Oct 4, 2026
  2. currentbits commented on Oct 4, 2026

    @currentbits
    OwnerAuthor

    A code-level pass found more holes than this issue lists. Full design: reports/T3 Code orchestrator deep dive.md on branch coder/i-want-you-to-research-t3-codes-orchestr-fae77a. Revised size: small M, about 250–350 lines including tests (~2 days).

    Ship first: one-line fix (I3, verified)

    • thread_send starts the receiver's turn with fromInbound: true (electron/orchServer.js:766). But startRun resets the machine-turn counter for every turn that isn't a notice: if (!input.fromNotice && !isReplayTurn(input)) autoTurns.set(threadId, 0); (electron/runner.js:8253).
    • So a worker can thread_send its idle lead "the user approved, merge me". The lead's turn then counts as human, isAutoTurn is false, and the lead can pass approved:true to thread_merge. That defeats the gate the code calls "the real lock".
    • runner.js:8490 already treats fromInbound as a machine turn, so the two lines contradict each other.
    • Fix: add !input.fromInbound to the reset and count fromInbound turns as n+1. This also makes agent ping-pong count toward the 25-turn crew cap.

    All identity holes

    ID Hole Where
    I1 Leaving out fromThreadId skips the stop/archive approval gate. A test asserts this as correct: electron/test/orch-server.test.js:1066-1071 orchServer.js:536-539
    I2 A claimed threadId on thread_merge/thread_pr lets any running thread act as the lead orchServer.js:459-526
    I3 Agent thread_send resets autoTurns (above) runner.js:8251-8253
    I4 Leaving out fromThreadId on thread_send skips the unattended-sender refusal crossThread.js:83-88
    I5 Another thread can bump a teach thread's reviewsPassed counter, which drives its permission caps orchServer.js:905-916, services.js:3559
    I6 Agent forks escalate to bypassPermissions on grok/kimi/cursor/opencode/muse, and failover re-snaps the mode providers.js:194-215, subagentPool.js:381

    Corrections to the issue body

    • Binding is per project, not per thread. boundSolentaMcpUrl (memory-sup.js:635) adds only projectId. Each provider writes it somewhere different (Claude mcp-bound/ file, Codex argv, grok/kimi/cursor/muse home overlays), and OpenCode gets no coder-threads tools at all.
    • Isolate Kimi runs: no cross-project threads, memory, or workspaces #671 doesn't reject a mismatched projectId. The bound id silently wins.
    • ?threadId= alone can be forged. The shared bearer token sits in every per-thread config, so an agent with a shell can curl the loopback port with any thread id.

    Design

    1. Carry threadId in every per-run config. Update boundSolentaMcpUrl, kimiMcpServersForRun, getCodexMcpArgs, getClaudeMcpArgs, writeBoundMcpConfig (add threadId to its sha1 key) and mcpServersDoc. Runner call sites: 4177, 4209, 5081, 5876, 6723 and 7213, plus workflow.js 480/653/846/1025.
      • Never pass it to ensureGrok/Cursor/KimiMcpConfig. Those write user-global files where the last writer wins.
      • Retention reclaims mcp-bound/ files after 7 days (M1).
    2. Make the binding unforgeable. Per-thread configs carry HMAC-SHA256(token, threadId) instead of the shared token. authorized() (orchServer.js:147-155) accepts the shared token, which leaves the call unbound, or the HMAC, which sets boundThreadId.
    3. Add a caller(claimed) helper in createToolHandlers. The bound id wins.
      • assertCrossThreadApproved refuses when the caller is empty.
      • Every tool that takes the caller from args.threadId goes through it: fork, merge, pr, ask_user, hypothesis_record, work_suggest, spec_submit, teach_review, task_*, peer_send, refresh_worker_snapshot, preview.
    4. Rank permissions on fork. Add PERMISSION_RANK = {plan:0, default:1, acceptEdits:2, bypassPermissions:3} in services.js, and run the snap before createThread (services.js:1331). Throw code:"PERMISSION_ESCALATION", applied to thread_fork only.
      • Ships in the same PR: a user-set allowEscalation ("Full access") flag on pool entries (subagentPool.js:66-71 + SettingsModal). Without it, headless grok workers stop working.

    Tests

    • Bound and unbound thread_stop without fromThreadId are both refused. This rewrites the test at 1066-1071.
    • A bound caller's claimed fromThreadId is ignored.
    • A worker calling thread_merge with threadId=<lead> is refused.
    • HTTP: an HMAC bearer binds; the shared bearer with ?threadId= doesn't.
    • A default-mode lead forking grok gets PERMISSION_ESCALATION and no thread is created.
    • A fromInbound turn leaves isAutoTurn true.

    None of this was reproduced live. All of it comes from reading the code at fbba4e10.

  3. added
    plan:doing
    plan:done
    and removed
    plan:todo
    plan:doing
    on Oct 12, 2026
  4. currentbits commented on Oct 13, 2026

    @currentbits
    OwnerAuthor

    Landed from Solenta thread "P1: Bind the caller's thread id at the MCP transport (closes" (PR #1612). Closed on merge.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions