Skip to content

fix: deflake //rs/tests/boundary_nodes:rate_limit_canister_test#9706

Open
basvandijk wants to merge 3 commits intomasterfrom
ai/deflake-rate_limit_canister_test-2026-04-01
Open

fix: deflake //rs/tests/boundary_nodes:rate_limit_canister_test#9706
basvandijk wants to merge 3 commits intomasterfrom
ai/deflake-rate_limit_canister_test-2026-04-01

Conversation

@basvandijk
Copy link
Copy Markdown
Collaborator

@basvandijk basvandijk commented Apr 1, 2026

The //rs/tests/boundary_nodes:rate_limit_canister_test flaked in Step 9 with:

The replica returned an HTTP Error: Http Error: status 403 Forbidden, 
content type \"text/plain; charset=utf-8\", content: error: forbidden\ndetails:
Request is forbidden according to currently active policy, it might work later.

Root Cause

In Step 9, set_rate_limit_rules was called via api_bn_agent (API boundary node agent) using call_and_wait(). This works in two phases:

  1. Call: Submit the update → goes through API BN → reaches replica → consensus → canister applies the rules (including a self-blocking rule for the rate-limit canister)
  2. Wait/Poll: Agent polls read_state for the result → API BN may have already picked up the new self-blocking rule → returns 403 Forbidden

This is a race condition: the self-blocking rule can be applied and picked up by the API boundary node between the call and the polling phases.

Fix

Use nns_agent (direct to NNS node, bypassing the API boundary node) for Step 9, just like Step 11 already does.


This PR was created following the steps in .claude/skills/fix-flaky-tests/SKILL.md.

Use nns_agent (direct to NNS node) instead of api_bn_agent for Step 9's
set_rate_limit_rules call. The call adds a self-blocking rule for the
rate-limit canister. With api_bn_agent, call_and_wait() first submits
the update, then polls read_state for the result. If the API boundary
node picks up the new self-blocking rule before polling completes, the
poll is rejected with 403 Forbidden, causing a flaky failure.

The nns_agent bypasses the API boundary node entirely, avoiding this
race condition. Step 11 already used nns_agent for the same reason.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Deflakes the boundary-node rate limit canister test by avoiding a race where call_and_wait() polls through the API boundary node after the canister has applied a self-blocking rule, causing intermittent 403s during the polling phase.

Changes:

  • Switch Step 9 set_rate_limit_rules to use an nns_agent (direct to an NNS node) instead of api_bn_agent to avoid the call_and_wait() polling race.
  • Move nns_agent initialization earlier and reuse it later (Step 11), removing the duplicate agent construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@basvandijk basvandijk marked this pull request as ready for review April 1, 2026 14:52
@basvandijk basvandijk requested a review from a team as a code owner April 1, 2026 14:52
@github-actions github-actions bot added the @node label Apr 1, 2026
@r-birkner
Copy link
Copy Markdown
Contributor

The suggested change just bypasses the API BN. The test is there to ensure that we can make calls through the API BN. While the suggested fix makes the test pass, it makes the test less useful.

I think we can improve the test by just adding some retries. Most likely there is some race condition (making the call vs. removing rate-limits).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants