Skip to content

node: do not retry a provider that does not attest the required labels - #954

Merged
aojea merged 1 commit into
google:mainfrom
HosniBelfeki:fix/label-refusal-no-retry
Nov 26, 2026
Merged

aojea merged 1 commit into
google:mainfrom
HosniBelfeki:fix/label-refusal-no-retry

Conversation

@HosniBelfeki

Copy link
Copy Markdown
Contributor

Same reasoning as #722, for the label check: when a provider's credential does not attest a label the caller requires, or one of the egress floor, CallMCPTool no longer retries the call.

connectMCPSessionWithRetry stops on ErrAuthRejected and ErrProviderNotGranted, but a failed label check in checkProvider carried neither, so it was retried as if the peer could not be reached. The provider presents the same credential on every attempt, so the call ran three handshakes, waited 1s and 2s, and returned failed after 3 retries: provider ... does not attest every label of ....

This adds ErrLabelsNotSatisfied, which checkProvider wraps around a failed label check, and the retry loop stops on it. An authorizer that stopped at a run limit is not wrapped, so a timeout is still retried and the facts and iterations limits keep their own handling from #842.

Measured in Docker (golang:1.26):

Test, refused call Before After
TestCallMCPTool_LabelEnforcement (caller requires region=na-us) 3.40s, failed after 3 retries 0.38s, one refusal
TestCallMCPTool_EgressFloorEnforcement (floor jurisdiction=eu) 3.42s, failed after 3 retries 0.36s, one refusal

Both tests now check errors.Is(err, ErrLabelsNotSatisfied) and that the call was not retried. They fail without the change, and still fail with only the mcp.go line reverted.

Not changed: the HTTP label gate (VerifyProvider) still answers 403, and its messages are unchanged.

Tested in Docker (golang:1.26): go test ./internal/node/..., go test -race -count=5 on the TestCallMCPTool_*, TestCheckPeerLabels*, TestLabelGate* and TestVerifyPeerLabels* tests, go vet, and golangci-lint v2.14.0.

When a provider's credential did not attest a label the caller required,
or one of the egress floor, connectMCPSessionWithRetry treated the
refusal as a failure to reach the peer. It ran the handshake three
times, waited 1s and 2s between attempts, and returned "failed after 3
retries". The provider presents the same credential on every attempt,
so the answer cannot change.

checkProvider now wraps a failed label check in ErrLabelsNotSatisfied,
and the retry loop stops on it as it does on ErrProviderNotGranted. An
authorizer that stopped at a run limit is not wrapped, so a timeout is
still retried.

In TestCallMCPTool_LabelEnforcement and
TestCallMCPTool_EgressFloorEnforcement the refused call took about 3.4s
and now takes about 0.4s.
@HosniBelfeki
HosniBelfeki requested a review from aojea as a code owner November 26, 2026 20:02

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new error, ErrLabelsNotSatisfied, to represent cases where a provider's credentials do not satisfy the required labels or egress floor. It updates checkProvider to wrap authorization errors with this new error and modifies connectMCPSessionWithRetry to prevent retries when this error is encountered. Additionally, integration tests in mcp_handlers_test.go are updated to assert this behavior. I have no further feedback to provide as there are no review comments to evaluate.

@aojea
aojea merged commit 54acad5 into google:main Nov 26, 2026
19 checks passed
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