Skip to content

Egress gateway no longer fetches an actor's egress policy twice when requests race - #2095

Merged
Lior Lieberman (LiorLieberman) merged 1 commit into
agent-substrate:mainfrom
thompsonmax:egress-policycache-flake
Oct 1, 2026
Merged

Lior Lieberman (LiorLieberman) merged 1 commit into
agent-substrate:mainfrom
thompsonmax:egress-policycache-flake

Conversation

@thompsonmax

Copy link
Copy Markdown
Collaborator

The egress gateway's policy cache checks for a cached entry and then joins any in-flight fetch, and the two steps aren't atomic. If the in-flight fetch stores its result in between, the caller starts a second, redundant fetch from ateapi. TestPolicyCacheFetchOutlivesCanceledCaller asserts a single fetch, so it fails intermittently (about 1 in 300 runs under -race; seen on #1961).

  • Re-checks the cache at the start of the shared fetch, so a late caller reuses the entry that just landed instead of fetching again.
  • Moves the cache lookup into a cached helper that both the fast path and the shared fetch use.

The only behavior change is skipping the duplicate fetch.

Testing: with the fix, the existing test passed 2000 of 2000 runs under -race. E2E hasn't run locally.

  • Tests pass
  • Appropriate changes to documentation are included in the PR

policyCache.get checks for a live entry and then joins any in-flight
fetch through singleflight, but the two steps are not atomic. When the
in-flight fetch stores its entry and finishes between them, the caller
starts a second fetch from ateapi. TestPolicyCacheFetchOutlivesCanceledCaller
asserts a single fetch and failed about once in 300 runs under -race.

Look the entry up again at the start of the shared fetch, so a late
caller reuses the one that just landed, and move the lookup into a
cached helper that both paths use.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@LiorLieberman
Lior Lieberman (LiorLieberman) added this pull request to the merge queue Oct 1, 2026
Merged via the queue into agent-substrate:main with commit 07a9dac Oct 1, 2026
10 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