Cache foundational flow catalog item per request
What does this MR do and why?
Duo Code Review through the Duo Agent Platform can fail with a 403 when it posts its comments, until the instance is restarted. This happens on self-managed instances where the foundational flows are seeded after GitLab has started (for example, when the flows are enabled for the first time). Retries help only when they reach a different Puma worker, so the success rate looks random.
The cause is that each Puma worker keeps the foundational flow catalog item it looked up first, for its whole life. A worker that looked up the Code Review flow before it was seeded keeps "not found", so the DAP Code Review check fails in that worker. With this change, the lookup is cached for one request only, so a newly seeded (or re-seeded) item is used on the next request.
The specs had their own workarounds for the stale cache. They are no longer necessary, so this MR removes them.
References
How to set up and validate locally
Use a GDK with the Duo Agent Platform set up, and the Code Review flow enabled for gitlab-duo/test.
-
Make the Code Review flow catalog item temporarily invisible to the lookup. In a Rails console:
item = Ai::Catalog::Item.with_foundational_flow_reference('code_review/v1').first item.update_column(:foundational_flow_reference, 'code_review/v1-hidden') -
Open an MR in
gitlab-duo/testand reload the page a few times, so that each Puma worker looks up the item while it is missing. -
Put the item back, which acts like the flow being seeded after GitLab started:
item.update_column(:foundational_flow_reference, 'code_review/v1') -
On the MR, assign Duo as a reviewer and wait for the review to finish.
- On
master: Duo does not post the review comments.log/api_json.logshowsPOST /api/v4/ai/duo_workflows/code_review/add_commentswith status 403 until you rungdk restart rails-web. - On this branch: Duo posts the review comments without a restart.
- On
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.