Notify the merge request when a pipeline flow lacks credits
What does this MR do and why?
Problem
A flow started by a pipeline hook can be refused by the GitLab Credits check. Nobody is told.
CreateWorkflowServicereturnsusage_quota_exceeded(402, no credits left) orusage_billing_forbidden(403, usage billing not available).Ai::FlowTriggers::RunServiceposts a progress note only for aNoteableresource. A pipeline is not one, so the refusal is only logged.Ai::FlowTriggers::EventTriggerServicediscards the return value.
This affects every flow with a pipeline-hook trigger: the business logic security review, fix_pipeline, and custom pipeline flows.
A second problem hits the business logic security review only. It takes a 24-hour per-pipeline lease before the credit check runs. After a refusal, retrying a job on that pipeline is skipped as "pipeline already scanned".
Impact
| Case | On master | With this MR |
|---|---|---|
| Pipeline flow refused: no credits left (402), open MR | Silent; only a log line | One credits note on the MR, as the flow's service account |
| Pipeline flow refused: usage billing not available (403), open MR | Silent; only a log line | One note with the existing billing message |
| Another pipeline on the same MR, same day | Silent | No second note |
| Pipeline flow refused for credits, no open MR | Silent | Silent (no change) |
| Retry a job after a credit refusal (business logic security review) | Skipped: "pipeline already scanned" | Flow is tried again (runs once credits are available) |
| Refused for any other reason | Logged | Logged (no change) |
This covers both refusal codes. The 402 note reads:
⚠️ did not run because no GitLab Credits remain for this billing period. To continue using this flow, contact your administrator.
It follows the Code Review flow's existing credit message. The 403 note reuses the existing usage_billing_forbidden_error text.
Changes
RunService: for a non-Noteableresource, when the run fails withusage_quota_exceededorusage_billing_forbidden:- release the flow's run-eligibility lease, through the existing
run_eligibility_resolverhook; - post one note on the pipeline's most recent open MR in the same project, as the flow's service account. It needs
create_noteon the MR. AnExclusiveLeaseper flow trigger and MR limits it to once a day.
- release the flow's run-eligibility lease, through the existing
BlSecurity::RunEligibility.release: cancels the per-pipeline lease.Ai::FoundationalFlowMessages.usage_quota_exceeded_error: the note text.
Backward compatibility / impact on existing flows
- Return value of
RunService#execute: unchanged. The note and lease release are side effects only. - Noteable resources (issues, MRs, work items): unchanged. They keep the existing progress note.
- Flows without a run-eligibility resolver (
fix_pipeline, custom flows):try(:release)is a no-op. They get the note only. - Other refusal reasons: unchanged.
- No feature flag: the change only adds a note where a refusal was silent.
Trade-offs
- Size: about 43 lines of non-test code (62 added, counting blank lines and comments).
- No feature flag: the change only adds a note where a refusal was silent. Happy to add a default-off flag if preferred.
- Lease release goes through
run_eligibility_resolver.try(:release, ...): no new attribute. A dedicated hook (likeon_session_failed) is a possible follow-up. - The dedupe lease is taken before the note is saved: if the save fails, no note is posted that day.
- A 403 group gets the note once a day on each active MR: the same message issues and MRs already get on every run.
- No rescue around the note: an exception there would stop the remaining triggers for that pipeline, the same as the existing progress note.
- Out of scope: credit refusals on issues and MRs still show the generic "Could not start processing" text. Refusals for other reasons still keep the per-pipeline lease.
How to set up and validate locally
Verified end to end in a GDK in SaaS mode: an Ultimate group whose usage-quota check answers 402, then 403, from a mock CustomersDot. The business logic security flow is enabled with a merge-request-pipeline scan profile. No product code was stubbed.
| Step | On master | With this MR |
|---|---|---|
| MR pipeline succeeds, run refused (402) | No note; log: Flow execution failed ... Usage quota exceeded |
One note by the flow's service account (below) |
| New commit on the same MR, second pipeline, same day | n/a | Refused again, no second note |
| Retry a job on the refused pipeline | Skipping BL security flow: pipeline already scanned, credit check not called |
Credit check runs again; no "already scanned" line |
| MR pipeline, run refused (403) | n/a | One note: "Usage billing is not available for this account. To continue using this feature, contact your administrator." |
The 402 note posted on the MR:
⚠️ Duo Business Logic Security Scan did not run because no GitLab Credits remain for this billing period. To continue using this flow, contact your administrator.
Neither note is linked to an agent session.
Specs: ee/spec/services/ai/flow_triggers/run_service_spec.rb (257 examples), ee/spec/models/ai/catalog/foundational_flow/bl_security/run_eligibility_spec.rb and ee/spec/lib/ai/foundational_flow_messages_spec.rb pass. Reverting each production change on its own fails a new spec on its assertion.
To reproduce:
- In a SaaS-mode GDK, enable the business logic security flow for an Ultimate group and attach a Business Logic scan profile with a merge request pipeline trigger.
- Make the group's usage-quota check return 402 (no GitLab Credits).
- Open an MR and let its pipeline succeed. One note from the flow's service account appears.
- Push another commit. No second note appears.
- Retry a job on the first pipeline. The flow is tried again instead of being skipped.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.