Skip to content

fix(workbench): attach alert-started jobs to the alert's Flow - #4733

Draft
chrisakinrinade wants to merge 1 commit into
masterfrom
chris/prod-5402-alert-started-workbench-jobs-dont-appear-on
Draft

chrisakinrinade wants to merge 1 commit into
masterfrom
chris/prod-5402-alert-started-workbench-jobs-dont-appear-on

Conversation

@chrisakinrinade

Copy link
Copy Markdown
Contributor

Summary

Jobs started by an alert (AlertCreated) were created without a flow_id, so they never showed up on the alert's Flow. The Flow jobs table filters on flow_id, and alerts reach a Flow through their service.

This sets flow_id on 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. Setting flow_id without a FlowWorkbench would fail the WorkbenchJob policy check, so the association check is required.

Authorization needs no change. Existing jobs are not backfilled.

Linear: PROD-5402

Test Plan

  • Added recurse_test.exs cases for AlertCreated:
    • Service with a Flow that the workbench is associated with: job gets flow_id.
    • Service with a Flow that the workbench is not associated with: job is created with flow_id == nil.
    • Existing no-service test now asserts flow_id == nil.
  • mix test test/console/deployments/pubsub/recurse_test.exs: 53 passed.
  • Manual check to do after deploy: fire a TransactionErrorRateHigh alert 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

  • I have added a meaningful title and summary to convey the impact of this PR to a user.
  • If required, I have updated the Plural documentation accordingly.
  • I have added tests to cover my changes.
  • I have deployed the agent to a test environment and verified that it works as expected (required only when changing agent code).

Plural Flow: console

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>
@linear

linear Bot commented Nov 24, 2026

Copy link
Copy Markdown

PROD-5402

@chrisakinrinade chrisakinrinade added the bug-fix This pull request fixes a bug label Nov 24, 2026
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P1 Alert investigations fail to start ▶

Summary

Attaches alert-started jobs to their service's Flow when that Flow includes the workbench.

  • Alert-started jobs join their service's Flow when the workbench is linked.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 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.

@chrisakinrinade
chrisakinrinade marked this pull request as draft November 24, 2026 21:50

This branch has not been deployed

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

Labels

bug-fix This pull request fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant