← Back to Pull requests

node: do not retry a tool call the provider answered with an error #856

Open
unknown opened this pull request with 385 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 02, 2026 21:49 UTC
Author

What

CallMCPTool stops retrying when the provider node's task check refuses the call. The rule comes from d2046162:

A denial is an answer, not a failure to reach anyone; retrying it just delays the same reply and knocks on the remote peer three times for one call.

The loop already recognizes ErrAuthRejected and ErrProviderNotGranted (#722). A tool outside the caller's task is refused later, inside an allowed MCP stream: authorizeMCPRequest (internal/node/mcp_service.go) answers the tools/call itself with a JSON-RPC error, and the MCP backend never sees it. The loop treated that answer as a failure to connect and retried it. On main it returns after 3 attempts and about 7 seconds:

failed after 3 retries: failed to call tool mcp://code-reviewer/delete_repo: calling "tools/call": task authorization denied tool "delete_repo": tar_block[1] ("review-only") denied request to mcp://code-reviewer

Each retry opens a new stream, so the provider also logs three TAR denied warnings for one call.

Fix

  • authorizeMCPRequest answers a task denial with codeTaskDenied (-31403) instead of CodeInvalidRequest (-32600). This applies to all three denials in that function (initialize/ping/tools/list, tools/call, and other methods), so the same denial has one code. -31403 is AgentMesh's own code, outside the -32768 to -32000 range JSON-RPC reserves; the go-sdk already uses -32001 to -32005, -32002, -32020 to -32022, -32042 and -31001. Nothing in the repo reads the old code. The message text is unchanged, so the examples that match on it keep working.

  • CallMCPTool stops retrying on that code only. Every other error is retried as before, including any JSON-RPC error from the MCP backend (for example unknown tool). The loop does not sort backend errors.
  • Tests

    TestCallMCPTool_TaskDeniedToolIsNotRetried is new. It calls a tool outside the caller's task, checks that the answer carries codeTaskDenied and comes back once, and then checks that the same task token still reaches the tool it allows. With the caller-side check removed:

    --- FAIL: TestCallMCPTool_TaskDeniedToolIsNotRetried (7.10s)
    mcp_handlers_test.go:747: CallMCPTool(delete_repo) = failed after 3 retries: ... want one answer with no retry

    With the fix, it passes in 0.10s. I also checked by hand that a backend unknown tool error is still retried three times, as on main.

  • go test -race ./internal/node/ passes (darwin/arm64). On macOS it needs a short TMPDIR, because the default temp path is longer than the Unix socket limit for the sidecar tests.

  • go test ./internal/... ./api/... passes.

  • gofmt and go vet are clean, and golangci-lint v2.14.0 (the version hack/lint.sh uses) reports 0 issues on ./internal/node/....
  • Not changed here

  • site/content/docs/use-cases/private-diy-stack.md shows sample output for a denied tool that starts with failed after 3 retries:. With this change that prefix goes away. I can update the sample here if you want.

  • Label-gate refusals are still retried, as #722 noted.
  • Diff: 385 lines (+288 / -97) across 4 files Reviewer: aojea Review duration: 5992m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.48) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 385 lines diff across 4 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.356
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #856"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48% (MEDIUM) · Higher = larger blast radius
    48%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.6% · Safe to merge
    25.6%