Repository navigation
fix(flows): show "awaiting approval" state in runs lists when a run is halted at an approval gate - #4932
Conversation
…s halted at an approval gate A run parked at an interactive ApprovalGate keeps status "running" in the DB (only the shared approval queue knows it's halted), so the sidebar, drawer, and all-runs list showed a generic "Running" instead of the existing amber "Awaiting approval" styling. Cross-reference the shared approval queue (openhuman.approval_list_pending) against each running run via source_context.kind === "flow" and override the DISPLAY status only, leaving run.status (and useFlowRunsLiveRefresh's terminal check) intact.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRunning flow runs now poll pending approvals, filter flow-origin gates, and display “Awaiting approval” with pending styling when a matching gate exists. Drawers, sidebars, and the workflow runs page use the shared status resolver with new polling and UI coverage. ChangesPending approval run status
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested labels: Sequence Diagram(s)sequenceDiagram
participant RunList
participant useRunsPendingApprovalSet
participant approvalApi
participant StatusResolver
RunList->>useRunsPendingApprovalSet: pass running flow runs
useRunsPendingApprovalSet->>approvalApi: fetchPendingApprovals()
approvalApi-->>useRunsPendingApprovalSet: pending approval records
useRunsPendingApprovalSet->>StatusResolver: provide pending run IDs
StatusResolver-->>RunList: render pending_approval or running
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/src/hooks/useRunsPendingApprovalSet.ts`:
- Around line 56-89: Update the useEffect polling flow in
useRunsPendingApprovalSet to add grep-friendly diagnostics for the no-running
branch, poll start/stop, fetchPendingApprovals outbound calls, retry timeout
scheduling, and pending-run state updates. Replace raw err serialization in the
poll-failure log with only a safe error type or code, avoiding sensitive error
content while preserving the existing retry and last-known-state behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d0233e44-4cb2-492f-8809-20c29a20c89f
📒 Files selected for processing (8)
app/src/components/flows/FlowRunsDrawer.test.tsxapp/src/components/flows/FlowRunsDrawer.tsxapp/src/components/flows/FlowRunsSidebar.test.tsxapp/src/components/flows/FlowRunsSidebar.tsxapp/src/hooks/__tests__/useRunsPendingApprovalSet.test.tsapp/src/hooks/useRunsPendingApprovalSet.tsapp/src/pages/WorkflowRunsPage.test.tsxapp/src/pages/WorkflowRunsPage.tsx
…ng in useRunsPendingApprovalSet (addresses @coderabbitai on app/src/hooks/useRunsPendingApprovalSet.ts:56-89)
…s halted at an approval gate (tinyhumansai#4932)
…s halted at an approval gate (tinyhumansai#4932)\n
Summary
When a flow run is halted at an interactive
ApprovalGate(e.g. aSLACK_SEND_MESSAGEnode awaiting Approve/Deny), the run's persistedFlowRun.statusstays"running"— only the shared approval queue (openhuman.approval_list_pending) knows the run is actually parked. As a result, every runs-list surface (canvas sidebar, run-history drawer, all-runs page) showed a generic green "Running" pill instead of the amber "Awaiting approval" state that already exists forpending_approval(FLOW_RUN_STATUS_DOT/_ACCENT/_KEYinFlowRunInspectorDrawer.tsx, i18n in all locales) — it was just never reached for this gate type.This is a frontend-only fix: cross-reference the shared approval queue with each runs list and override the display status, without touching the persisted
run.statusor the DB.Changes
New
app/src/hooks/useRunsPendingApprovalSet.ts:useRunsPendingApprovalSet(runs: FlowRun[]): Set<string>— while any run in the list isstatus === 'running', pollsfetchPendingApprovals()(openhuman.approval_list_pending, viaapp/src/services/api/approvalApi.ts) every 3s and collects therun_ids of entries whosesource_context?.kind === 'flow'into a Set. Stops polling once no run isrunning(teardown via effect cleanup) and on unmount. Best-effort: a failed poll is logged and simply retried next tick, keeping the last-known Set instead of surfacing an error.resolveDisplayStatus(run: FlowRun, pendingRunIds: Set<string>): FlowRunStatus— returns'pending_approval'whenrun.status === 'running' && pendingRunIds.has(run.id), elserun.statusunchanged.useFlowPendingApprovals.tsand the gate-on-activity contract ofuseFlowRunsLiveRefresh.ts.Wired into the three list surfaces — each calls
useRunsPendingApprovalSet(runs)after its existinguseFlowRunsLiveRefresh(...)call, then substitutesresolveDisplayStatus(run, pendingRunIds)forrun.statusat the status-dot / accent / label render sites only:app/src/components/flows/FlowRunsSidebar.tsxapp/src/components/flows/FlowRunsDrawer.tsxapp/src/pages/WorkflowRunsPage.tsxuseFlowRunsLiveRefreshis untouched — it still reads the originalrunsarray, so'running'stays non-terminal there and the list keeps refetching until the run actually finishes. No backend changes.Tests
app/src/hooks/__tests__/useRunsPendingApprovalSet.test.ts(11 tests, fake timers): no poll when all runs terminal / list empty; polls every 3s while a run is running; includes a run with a matching flow-origin approval; excludes a running run with no match; excludes a chat-origin approval (nosource_context); keeps the last-known set on a poll failure and keeps polling; tears down once runs settle to terminal; cleans up on unmount;resolveDisplayStatusunit cases.FlowRunsSidebar.test.tsx,FlowRunsDrawer.test.tsx,WorkflowRunsPage.test.tsxwith afetchPendingApprovalsmock and new cases asserting arunningrun with a matching flow approval renders "Awaiting approval" and arunningrun without a match still renders "Running".All 40 new/updated tests pass; the full
flowsdomain suite (224 tests, 22 files) still passes.Test plan
pnpm typecheckcleanpnpm lint— 0 errors (104 pre-existing warnings unrelated to this diff, confirmed identical before/after viagit stash)pnpm format/format:checkcleanuseRunsPendingApprovalSet.test.ts(11/11)FlowRunsSidebar.test.tsx,FlowRunsDrawer.test.tsx,WorkflowRunsPage.test.tsxflowsdomain test suite passes (224/224)Summary by CodeRabbit