Skip to content

fix(pi): restore Pi tool names on Claude responses - #253

Closed
gustavo-neiva wants to merge 1 commit into
cortexkit:mainfrom
gustavo-neiva:fix/pi-tool-name-roundtrip
Closed

gustavo-neiva wants to merge 1 commit into
cortexkit:mainfrom
gustavo-neiva:fix/pi-tool-name-roundtrip

Conversation

@gustavo-neiva

@gustavo-neiva gustavo-neiva commented Sep 23, 2026 •

Copy link
Copy Markdown

Cause

Pi >=0.86 passes tools in transcript system messages, not context.tools. The request converter already resolves those tools and exposes names like Bash to Claude, but the response stream still reads context.tools (undefined), returning Bash instead of Pi’s bash and causing Tool Bash not found.

Fix

Resolve active tools from the normalized transcript on the response side, as the request converter already does, then map Claude Code names back to Pi names. A mocked SSE regression exercises the actual request and response path without credentials or API calls.

Validation

  • Regression red before fix (Bash), green after (bash).
  • Pi package: 133 tests pass; typecheck, Biome check, and git diff --check pass.

This addresses the remaining response-side issue described in #244. #245 also proposes this fix but is currently conflicting with main; this PR is scoped to the missing response-side change on current main.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Fixes Pi tool name round-tripping in Claude responses. The response stream now resolves active tools from the normalized transcript (as the request converter already does) instead of reading context.tools, so Claude's Bash is mapped back to Pi's bash. Previously, tool calls returned Bash and failed with "Tool Bash not found". Adds a mocked SSE regression test that exercises the real request/response path.

Written for commit 020067a. Summary will update on new commits.

Review in cubic

RetriggerConfidence Score: 5/5

The PR appears safe to merge; request and response tool-name resolution are aligned and the regression path is covered.

Summary

This PR restores Pi-native tool names in streamed Claude responses by resolving active tools from the normalized transcript, matching request-side conversion.

  • Replaces response mapping against the obsolete top-level context.tools value with transcript-derived active tools.
  • Adds an end-to-end mocked SSE regression proving bash is sent as Bash and restored to bash.
  • Keeps request and response tool-name conversion aligned.
Diagram
sequenceDiagram
    participant Pi
    participant Stream as Pi stream adapter
    participant Converter as Request converter
    participant Claude

    Pi->>Stream: Context with transcript toolsAdded: bash
    Stream->>Stream: Normalize transcript and resolve active tools
    Stream->>Converter: Build Anthropic request
    Converter->>Claude: Tool schema name: Bash
    Claude-->>Stream: SSE tool_use name: Bash
    Stream->>Stream: Map against active transcript tools
    Stream-->>Pi: Tool call name: bash
Loading

Reviews (1) · Last reviewed commit: "fix(pi): restore Pi tool names on Claude..."

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.

1 participant