Repository navigation
fix: deterministic MCP authorization repeated-initial-control status - #2085
Merged
Merged
Conversation
The authorization control relay selected between an already-received control error and the continuation's closing event channel at random, so a repeated initial frame could end the RPC OK. After the relay loop, a non-EOF control error already reported on controlDone now wins over an otherwise-OK result; unread frames are still not awaited and control errors still never cancel the continuation. The test now holds the resumed call until the repeated frame is delivered, pinning that a violation received while the continuation is live is reported, independent of goroutine scheduling. Co-authored-by: Mecatl <[email protected]>
Merged
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TestMCPAuthorizationGRPCRejectsRepeatedInitialControlflaked (OK, wantInvalidArgument) because the result depended on two races inrelayMCPAuthorizationControl:InvalidArgumenterror oncontrolDonewhen the continuation closesevents.selectpicks a ready case at random. If the close wins, the loop exits and the already-received error is dropped, so the RPC returnsOK.grpc.go): after the relay loop, if the result is otherwise OK, one non-blocking check ofcontrolDonelets an already-reported non-EOF control error become the RPC status. This makes race 1 deterministic. It never waits for unread frames and never cancels the continuation, so the H-K5/H-K23 rule (control-stream errors don't cancel a healthy continuation) is unchanged.CancelMcpAuthorizationshares the relay and gets the same behavior.The only observable difference is the final status code. Run completion, cancellation, and the delivered events are identical in every ordering.
Development stage
Contract linkage
InvalidArgument). It makes an already-specified status deterministic. No new interface, persistence, or trust-boundary change.Interface conformance
Issue relationship
Fixes #2082
Type of change
Test plan
Baseline checks
task lint)task test) — covered bytask test:racetask test:race)go run ./cmd/mecademo): tool call, permission ask/approval, resulttask docs) — N/Atask site:build) — N/Atask api:check) — N/Atask api:update+engine/CHANGELOG.md— N/Atask ac-trace-strict) — N/A/panel-review— not runFocused verification:
go test -race ./internal/adapter/server -run '^TestMCPAuthorizationGRPCRejectsRepeatedInitialControl$' -count=10000: passes (reproduced 1/300 failures before).go test -race ./internal/adapter/server -run MCPAuthorization -count=20: passes, covering the adjacent transport-fault and continuation-lifecycle tests.go test -race ./internal/adapter/server: passes.Changes
internal/adapter/server/grpc.gointernal/adapter/server/mcp_authorization_transport_test.gorequestsDrainedhook on the fake stream; repeated-initial test holds the continuation until the frame is deliveredUser-facing change
None. A misbehaving client that repeats the initial frame now always receives
InvalidArgument, not sometimesOK.Special notes for reviewers
grpc.gochange (0/10000 failures), because holding the continuation leaves the error ready long beforeeventscloses. Proving race 1 deterministically would require both channels ready at the same instant.relayMCPAuthorizationControltakes a concrete*agent.Run, so that needs a test seam I chose not to add. The server change is kept because without it the status in race 1 is a coin flip. It can be dropped if you'd rather ship only the test fix.