Repository navigation
fix(workbench): attach alert-started jobs to the alert's Flow - #4733
chrisakinrinade wants to merge 1 commit into
Conversation
Jobs started by AlertCreated never set flow_id, so they did not appear on the Flow's jobs table. When the alert's service belongs to a Flow and the workbench is associated with that Flow, set flow_id on the job. Otherwise the job is created as before, since a flow_id without a FlowWorkbench would fail the WorkbenchJob policy check. Fixes PROD-5402 Co-authored-by: Cursor <cursoragent@cursor.com>
[Medium impact] The change affects the bounded workflow that starts workbench jobs from firing alerts. Fix the failed job creation for actors with only workbench access before merging. Findings
SummaryAttaches alert-started jobs to their service's Flow when that Flow includes the workbench.
Reviews (1) · Last reviewed commit: "fix(workbench): attach alert-started job..." · Reviewed by Greptile |
| # only attach the flow when the workbench is associated with it, otherwise the job's policy check would reject it | ||
| defp maybe_flow(attrs, %Service{flow_id: fid}, wid) when is_binary(fid) do | ||
| case Workbenches.flow_association(fid, wid) do | ||
| %FlowWorkbench{} -> Map.put(attrs, :flow_id, fid) |
There was a problem hiding this comment.
Alert investigations fail to start
Adding flow_id prevents job creation for non-admin actors who can read the workbench but not the service's Flow. A FlowWorkbench row does not guarantee that access. The job policy checks Flow access first, and cascade/3 keeps that error even when the workbench check passes. These alerts previously created jobs successfully.
Fix the fallback in cascade/3, or leave flow_id unset when needed to preserve job creation. Add a test with a non-admin actor who has only workbench access.
Summary
Jobs started by an alert (
AlertCreated) were created without aflow_id, so they never showed up on the alert's Flow. The Flow jobs table filters onflow_id, and alerts reach a Flow through their service.This sets
flow_idon the job when the alert's service belongs to a Flow and the workbench is associated with that Flow (Workbenches.flow_association/2). If either condition fails, the job is created as before. Settingflow_idwithout aFlowWorkbenchwould fail theWorkbenchJobpolicy check, so the association check is required.Authorization needs no change. Existing jobs are not backfilled.
Linear: PROD-5402
Test Plan
recurse_test.exscases forAlertCreated:flow_id.flow_id == nil.flow_id == nil.mix test test/console/deployments/pubsub/recurse_test.exs: 53 passed.TransactionErrorRateHighalert on a service in a Flow, with a workbench associated with that Flow, and confirm the job appears in the Flow's jobs table.Checklist
Plural Flow: console