Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-ui): distinguish recipe read failure from no input contract (H1)
Diego Zacarias1ebe03d4da3e
diff --git a/desktop-app/ui/src/hooks/domain/useWorkflowController.ts b/desktop-app/ui/src/hooks/domain/useWorkflowController.tsindex fd6a32773..5901e30ee 100644--- a/desktop-app/ui/src/hooks/domain/useWorkflowController.ts+++ b/desktop-app/ui/src/hooks/domain/useWorkflowController.ts@@ -275,6 +275,12 @@ export function useWorkflowController(params: UseWorkflowControllerParams) {return null}+ // A rejected read must stay distinguishable from the legitimate "recipe+ // declares no input contract" case. Collapsing both into `null` (the old+ // `.catch(() => null)`) let a transient read failure masquerade as "no+ // inputs", firing a contract-less trigger that skipped the input modal.+ // We capture the outcome, run the race guards below unchanged, and only+ // then re-throw a failure for the still-current selection.const detailPromise = queryClient.fetchQuery({queryKey: desktopQueryKeys.workflowDetail(wf.namespace, wf.name),@@ -282,10 +288,11 @@ export function useWorkflowController(params: UseWorkflowControllerParams) {window.clerum.workflows.read(wf.namespace, wf.name) as Promise<WorkflowRecipeResource>,staleTime: 0,})- .catch(() => null)+ .then(detail => ({ ok: true as const, detail }))+ .catch((error: unknown) => ({ ok: false as const, error }))const runsPromise = loadWorkflowRunsFor(wf)- const detail = await detailPromise+ const detailResult = await detailPromiseif (seq !== selectWorkflowSeqRef.current) return nullconst currentSelection = queryClient.getQueryData<WorkflowSelectionState>(desktopQueryKeys.workflowSelection@@ -297,6 +304,17 @@ export function useWorkflowController(params: UseWorkflowControllerParams) {return null}if (!sameWorkflow(currentSelection?.selectedWorkflow ?? null, wf)) return null+ // The read failed for a selection that is still current: surface it so the+ // caller can show an error instead of triggering with empty inputs. A+ // superseded selection already returned `null` above, so a stale failure+ // never reaches here.+ if (!detailResult.ok) {+ await runsPromise+ throw detailResult.error instanceof Error+ ? detailResult.error+ : new Error(toErrorMessage(detailResult.error))+ }+ const detail = detailResult.detailconst schema = detail?.spec?.inputContract ?? nullconst nextWorkflow = detail? {@@ -349,7 +367,17 @@ export function useWorkflowController(params: UseWorkflowControllerParams) {queryKey: desktopQueryKeys.workflowRuns(ns, name, RECENT_RUNS_LIMIT),})const wf = workflows.find(workflow => workflow.namespace === ns && workflow.name === name)- if (wf) await handleSelectWorkflow(wf)+ if (wf) {+ try {+ // Post-trigger refresh only re-syncs the selection; a read failure+ // here must not turn an already-successful trigger into a visible+ // "Trigger failed". handleSelectWorkflow now throws on read failure,+ // so swallow it — the row's next interaction retries the read.+ await handleSelectWorkflow(wf)+ } catch {+ // Selection refresh failed; the trigger itself already succeeded.+ }+ }} catch (error) {setStatus(`Trigger failed: ${error instanceof Error ? error.message : String(error)}`,diff --git a/desktop-app/ui/src/pages/WorkflowsPage.tsx b/desktop-app/ui/src/pages/WorkflowsPage.tsxindex 3adc2f80e..3896f6cb2 100644--- a/desktop-app/ui/src/pages/WorkflowsPage.tsx+++ b/desktop-app/ui/src/pages/WorkflowsPage.tsx@@ -207,9 +207,10 @@ export function WorkflowsPage() {// the modal's InputContractForm binds to the controller's input state.contract = await handleSelectWorkflow(wf)} catch (error) {- // handleSelectWorkflow swallows its own read failures today, so this is- // defensive. Report rather than fail silently if it ever does throw —- // matching handleTriggerWorkflow's "Trigger failed" feedback.+ // handleSelectWorkflow throws when the recipe read fails, so we can no+ // longer tell whether it declares an input contract. Report the failure+ // and stop — never fall through to a contract-less trigger that would+ // skip the input modal. Matches handleTriggerWorkflow's feedback.setPendingTriggerKey(null)setStatus(`Trigger failed: ${error instanceof Error ? error.message : String(error)}`,diff --git a/desktop-app/ui/src/pages/__tests__/WorkflowsPage.readFailure.test.tsx b/desktop-app/ui/src/pages/__tests__/WorkflowsPage.readFailure.test.tsxnew file mode 100644index 000000000..d6ea93bbe--- /dev/null+++ b/desktop-app/ui/src/pages/__tests__/WorkflowsPage.readFailure.test.tsx@@ -0,0 +1,88 @@+// @vitest-environment jsdom+import React from 'react'+import { afterEach, describe, expect, it, vi } from 'vitest'+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'+import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'+import type { WorkflowRecipeResource } from '../../../../src/types'+import { desktopQueryKeys } from '../../hooks/domain/queryKeys'+import { WorkflowsPage } from '../WorkflowsPage'++// H1 regression: a recipe that DECLARES a required input contract, but whose+// `workflows.read` fails transiently, must not fall through to a contract-less+// trigger. The old code swallowed the read error to `null`, which the page read+// as "no inputs" and fired `trigger({})`, skipping the input modal entirely.+// This drives the REAL useWorkflowController (not a mock) so the swallow →+// direct-trigger path is exercised end to end.++const setStatusSpy = vi.fn()++vi.mock('../../contexts/AuthContext', () => ({+ useAuthContext: () => ({ setStatus: setStatusSpy }),+}))++// A recipe with an on-demand user trigger AND a required input contract. The+// read fails below, so the page can never learn the contract — which is exactly+// the condition the fix must not misread as "no contract".+const WORKFLOW_RESOURCE: WorkflowRecipeResource = {+ metadata: {+ namespace: 'sandbox-recipes',+ name: 'needs-inputs',+ creationTimestamp: '2026-05-18T00:00:00Z',+ },+ spec: {+ triggers: { onDemand: { allowedActors: ['user'] } },+ inputContract: { properties: { topic: { type: 'string' } } },+ },+ status: { phase: 'Active' },+}++function createQueryClient() {+ return new QueryClient({ defaultOptions: { queries: { retry: false } } })+}++describe('WorkflowsPage — recipe read failure on Trigger (H1)', () => {+ afterEach(() => {+ cleanup()+ vi.clearAllMocks()+ delete (window as { clerum?: unknown }).clerum+ })++ it('does not fire a contract-less trigger when the recipe read fails; shows an error', async () => {+ const trigger = vi.fn(async () => undefined)+ ;(window as unknown as { clerum: unknown }).clerum = {+ workflows: {+ list: vi.fn(async () => ({ items: [WORKFLOW_RESOURCE], count: 1 })),+ read: vi.fn(async () => {+ throw new Error('read boom')+ }),+ runs: vi.fn(async () => ({ items: [], count: 0 })),+ listRunArtifacts: vi.fn(async () => ({ artifacts: [] })),+ trigger,+ },+ }++ const queryClient = createQueryClient()+ // Seed the (enabled:false) workflows query so the flat table has a row.+ queryClient.setQueryData(desktopQueryKeys.workflows, {+ items: [WORKFLOW_RESOURCE],+ count: 1,+ })++ render(+ <QueryClientProvider client={queryClient}>+ <WorkflowsPage />+ </QueryClientProvider>+ )++ const rowTrigger = within(screen.getByRole('table')).getByRole('button', { name: 'Trigger' })+ fireEvent.click(rowTrigger)++ // Observable result: an error status is surfaced.+ await waitFor(() =>+ expect(setStatusSpy).toHaveBeenCalledWith(expect.stringContaining('Trigger failed'), 'error')+ )+ // The bug: the read failure must never fire a trigger, and no modal opens.+ expect(trigger).not.toHaveBeenCalled()+ expect(screen.queryByRole('dialog')).toBeNull()+ })+})