Skip to content

[Bug]: Pi provider extension declares every T3 tool twice for openai-completions models (mcp__t3_code__ aliases leak into the active tool list) #41759

Done

Description

@brosiog

Before submitting

Area

packages/provider-pi

Summary

Pi sessions launched through T3 Code with an openai-completions model (e.g. Pi + a local model served over an OpenAI-compatible endpoint) get 182 T3 tools declared instead of 91: every tool appears twice, once as mcp__t3-code__* and once as mcp__t3_code__*. The underscore set is meant to be a reserved, model-only alias placeholder, but it leaks into the active tool loadout, so the model is handed both copies.

Impact

In a fresh Pi session the duplicate schemas cost ~61,842 chars (~17K tokens) inside systemMessage.toolsAdded (195 tools / 139,639 chars total, of which 91 are byte-identical duplicates). That eats roughly a fifth of an 82K context window before the conversation starts, and it accelerates Pi auto-compaction — sessions compact every 1–3 turns instead of lasting materially longer. It affects every openai-completions model through Pi, not just one model (verified on a local Inkling 2 Mini; the same trigger applies to Qwen served the same way).

Steps to reproduce

  1. In T3 Code, launch a Pi thread with any model whose api is openai-completions.
  2. In the session, count the agent's tools by prefix, or inspect the Pi session file's systemMessage.toolsAdded.
  3. Observe 91 tools under mcp__t3-code__* and 91 byte-identical tools under mcp__t3_code__* (plus 3 mcp__parallel__* and 10 builtins).

Where it happens

packages/provider-pi/src/server/mcpExtensionSource.ts (PI_T3_MCP_EXTENSION_SOURCE), materialized at runtime to ~/.t3/caches/pi-t3-mcp-extension.ts. ALIAS_PREFIX = "mcp__t3_code__".

When supportsExposure is true (Pi exposes registerMcpServer, Pi ≥ 0.99), every tool is registered under both prefixes ["mcp__t3-code__", ALIAS_PREFIX]. The underscore set is a deliberate reserved placeholder with exposure "model-only", and prepareLoadout hides its declaration from the transcript.

But reconcileDiscovery() eagerly activates all 91 mcp__t3-code__* tools for openai-completions models, followsPublicTool() then returns true for all 91, and the extension pushes all 91 aliases into the active tool list too. prepareLoadout only affects transcript projection, while the agent loop records every active tool into systemMessage.toolsAdded — so both sets get declared to the model.

Expected behavior

The model should see 91 T3 tools (the canonical mcp__t3-code__* set). The mcp__t3_code__* aliases should stay model-only placeholders and never enter the active loadout.

Actual behavior

The model sees 182 T3 tools — both prefix sets, byte-identical, pointing at the same MCP server and bearer token.

Workaround (verified)

Add to the pi provider instance config in ~/.t3/userdata/settings.json:

"config": { "launchArgs": "--exclude-tools 'mcp__t3_code__*'" }

Verified in a fresh session: underscore 0 / hyphen 91, canonical tools intact. (Editing the materialized cache file alone does not persist — materializePiT3McpExtension hash-verifies against app.asar and overwrites it on launch.)

Suggested fix

Don't push the model-only alias set into the active loadout for openai-completions models — e.g. exclude the mcp__t3_code__* aliases in reconcileDiscovery() / followsPublicTool(), so the active loadout matches what prepareLoadout projects.

Environment

  • T3 Code desktop app 0.1.11 (macOS, arm64, Mac mini M6, macOS 27.0.1)
  • Pi 1.6.0
  • Model: local Inkling 2 Mini via an OpenAI-compatible endpoint (api: openai-completions)
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions