Skip to content

node: build the facts-limit test rules without the parser - #845

Merged
aojea merged 1 commit into
google:mainfrom
HosniBelfeki:fix/fact-limit-rules-without-parser
Nov 1, 2026
Merged

aojea merged 1 commit into
google:mainfrom
HosniBelfeki:fix/fact-limit-rules-without-parser

Conversation

@HosniBelfeki

Copy link
Copy Markdown
Contributor

Fixes the flaky TestCallMCPTool_ProviderNotGrantedIsNotRetried reported on #832, introduced by #842.

authorizerFactLimitRules parsed its 1100 rules one by one, and biscuit-go's parser.FromStringRule builds a new grammar on every call. Under -race that took about 12s, inside the test's 15s context, so on a busy runner the second tool call ran out of time (context canceled during retry / failed to open stream: timed out) before it reached the facts limit.

This builds the same rules as biscuit.Rule values. The authorizer evaluates the same rules, so both tests that use the helper still stop at datalog.ErrWorldRunLimitMaxFacts. No timeout is changed.

Measured in Docker (golang:1.26, 2 CPUs, -race):

Before After
Building the rules 12.26s negligible
TestCallMCPTool_ProviderNotGrantedIsNotRetried about 12.5s of its 15s 0.96s
TestLabelGateTellsAuthorizerLimitFromDenied about 12s 0.15s
stress -p 4 on both tests 20 of 20 runs failed 406 runs, 0 failures

Both tests still fail when checkProvider reports a facts limit as ErrProviderNotGranted again. go test -race ./internal/node/ ./internal/identity/ and golangci-lint v2.14.0 pass.

authorizerFactLimitRules parsed its 1100 rules one by one, and
biscuit-go's parser.FromStringRule builds a new grammar on every call.
Under the race detector that took about 12s, inside the 15s context of
TestCallMCPTool_ProviderNotGrantedIsNotRetried, so on a busy runner the
second tool call ran out of time and failed with "context deadline
exceeded" instead of the facts limit.

Build the same rules as biscuit.Rule values. The authorizer evaluates
exactly the same rules, so both tests still stop at the facts limit.
@HosniBelfeki
HosniBelfeki requested a review from aojea as a code owner November 1, 2026 21:59

@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 optimizes the 'authorizerFactLimitRules' test helper by programmatically constructing 'biscuit.Rule' structs instead of parsing them from strings. This avoids rebuilding the grammar for each of the 1100 rules, which previously caused test timeouts under the race detector. I have no further feedback to provide as there are no review comments to evaluate.

@aojea

aojea commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the prompt response, appreciate it

@aojea
aojea merged commit 1e25dac into google:main Nov 1, 2026
19 checks passed
@HosniBelfeki
HosniBelfeki deleted the fix/fact-limit-rules-without-parser branch November 1, 2026 22:28
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