Skip to content

feat(flows): FlowRunFinished event — fully event-driven runs rail (completes B35) - #5115

Merged
graycyrus merged 2 commits into
tinyhumansai:mainfrom
graycyrus:feat/flows-run-finished-event
Jul 22, 2026
Merged

graycyrus merged 2 commits into
tinyhumansai:mainfrom
graycyrus:feat/flows-run-finished-event

Conversation

@graycyrus

Copy link
Copy Markdown
Contributor

What & why

Completes B35. B35 added FlowRunStarted so a run appears in the RUNS rail the instant it starts; this adds the terminal companion so status updates (Completed / Failed / Completed-with-warnings / Cancelled) arrive live too — and lets the rail drop its short poll fallbacks.

Changes

  • Rust: DomainEvent::FlowRunFinished { flow_id, run_id, status } (event_bus/events.rs), emitted from finish_flow_run_row (flows/ops.rs) with the terminal status, bridged to Socket.IO as flow:run_finished / flow_run_finished (core/socketio.rs) — mirroring the FlowRunStarted plumbing.
  • Frontend: new useFlowRunFinished hook (copies useFlowRunStarted, incl. the bounded dedup-over-both-aliases + PII-safe invalid-payload log). FlowRunsSidebar / FlowRunsDrawer / WorkflowRunsPage subscribe to it (refetch on finish).
  • Polling: with start + progress + finish all event-driven, the short useFlowRunPoller (2s) / useFlowRunsLiveRefresh (5s) fallbacks are dropped/relaxed (see the hook doc updates).

Tests

  • cargo check clean; frontend typecheck clean.
  • Vitest: 63 pass across the run hooks + rail components (incl. a new useFlowRunFinished test asserting single-invocation dedup over both aliases).

…vent-driven

Completes B35. Adds DomainEvent::FlowRunFinished { flow_id, run_id, status }
emitted from finish_flow_run_row and bridged to Socket.IO (flow:run_finished),
plus a useFlowRunFinished hook (dedup-once over both aliases, PII-safe log).
FlowRunsSidebar/Drawer/WorkflowRunsPage subscribe to it so terminal status
updates arrive live, letting the short 2s/5s poll fallbacks be dropped in favor
of the start+progress+finish event stream.
@graycyrus
graycyrus requested a review from a team July 22, 2026 08:57
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5f6e3f51-c3f6-4775-a183-b492753996fd

📥 Commits

Reviewing files that changed from the base of the PR and between 0eeee12 and 5477d6d.

📒 Files selected for processing (15)
  • app/src/components/flows/FlowRunsDrawer.test.tsx
  • app/src/components/flows/FlowRunsDrawer.tsx
  • app/src/components/flows/FlowRunsSidebar.tsx
  • app/src/hooks/__tests__/useFlowRunFinished.test.ts
  • app/src/hooks/__tests__/useFlowRunPoller.test.ts
  • app/src/hooks/__tests__/useFlowRunsLiveRefresh.test.ts
  • app/src/hooks/useFlowRunFinished.ts
  • app/src/hooks/useFlowRunPoller.ts
  • app/src/hooks/useFlowRunsLiveRefresh.ts
  • app/src/pages/WorkflowRunsPage.test.tsx
  • app/src/pages/WorkflowRunsPage.tsx
  • src/core/event_bus/events.rs
  • src/core/socketio.rs
  • src/openhuman/flows/ops.rs
  • src/openhuman/flows/ops_tests.rs

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff4f565972

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +3776 to +3780
crate::core::event_bus::publish_global(crate::core::event_bus::DomainEvent::FlowRunFinished {
flow_id: flow_id.to_string(),
run_id: thread_id.to_string(),
status: status.to_string(),
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Emit finish events only for terminal runs

When a workflow pauses for an approval gate, finalize_terminal_status returns "pending_approval", and this helper is still called with that status before the run later resumes using the same thread_id. Publishing FlowRunFinished here for the pause makes useFlowRunFinished cache the ${flow_id}:${run_id} key, so the real completion event after flows_resume is treated as an alias replay and ignored; approval-gated runs can then stay stale in the runs list until the 30s backstop. Please gate this publish to actual terminal statuses (or otherwise avoid de-duping the pause and final settle as the same finish).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed and fixed — finish_flow_run_row now returns before publishing FlowRunFinished when status == "pending_approval". The row is still persisted either way (so poll-based fallbacks see the paused state), but the event only fires for actual terminal settles. Added a regression test (flows_run_finished_event_skips_pending_approval_and_fires_once_on_resume) that runs an approval-gated graph, asserts no FlowRunFinished fires at the pause, then resumes and asserts exactly one fires with status: "completed". Will push shortly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 5477d6d — FlowRunFinished now only fires for genuinely TERMINAL statuses; a run that pauses at an approval gate (finalize_terminal_status → pending_approval) no longer emits a premature finish event.

@graycyrus
graycyrus marked this pull request as draft July 22, 2026 09:48
@graycyrus
graycyrus marked this pull request as ready for review July 22, 2026 10:53
@graycyrus
graycyrus merged commit 9b72616 into tinyhumansai:main Jul 22, 2026
20 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.

1 participant