Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(canvas): rebuild nodeTypes when the spec catalogue set changes
trohitg4707d6c9770e
diff --git a/client/src/Dashboard.tsx b/client/src/Dashboard.tsxindex 8cd83ad3..30358b82 100644--- a/client/src/Dashboard.tsx+++ b/client/src/Dashboard.tsx@@ -14,7 +14,7 @@ import {Edge,} from 'reactflow';import { featureFlags } from './lib/featureFlags';-import { prefetchAllNodeSpecs, listCachedNodeSpecs } from './lib/nodeSpec';+import { prefetchAllNodeSpecs, listCachedNodeSpecs, cachedNodeSpecTypesKey } from './lib/nodeSpec';import AIAgentNode from './components/AIAgentNode';import SquareNode from './components/SquareNode';import TriggerNode from './components/TriggerNode';@@ -115,7 +115,7 @@ const COMPONENT_BY_KIND: Record<string, React.ComponentType<any>> = {const createNodeTypes = (): Record<string, React.ComponentType<any>> => {const types: Record<string, React.ComponentType<any>> = {};// Cache-driven enumeration: empty on cold boot, filled once- // prefetchAllNodeSpecs resolves and `specsReady` triggers a rebuild.+ // prefetchAllNodeSpecs resolves and the `specsKey` change rebuilds.listCachedNodeSpecs().forEach(spec => {const kind = spec.componentKind;if (kind && COMPONENT_BY_KIND[kind]) {@@ -440,25 +440,33 @@ const DashboardContent: React.FC = () => {// Wave 6 Phase 2: warm the NodeSpec cache in the background once the// WS is up. No-op when VITE_NODESPEC_BACKEND is off. After prefetch- // completes, bumping `specsReady` flips the React Flow nodeTypes ref+ // completes, recomputing `specsKey` flips the React Flow nodeTypes ref// so spec.componentKind dispatch becomes effective (Wave 10.D step 2).const hasPrefetchedSpecs = React.useRef(false);// Seed from the persisted cache. With PersistQueryClientProvider in// place the cache is hydrated from localStorage before the first// render, so a warm start can skip the cold→warm remount entirely.- const [specsReady, setSpecsReady] = React.useState(- () => listCachedNodeSpecs().length > 0,- );+ //+ // `specsKey` is the identity of the cached spec-type SET, not a+ // latched boolean: when the prefetch burst busts a stale persisted+ // revision and lands types the hydrated snapshot didn't have (a node+ // shipped since the last visit), the key change rebuilds nodeTypes.+ // With the old `specsReady` boolean the set-change was invisible+ // (true -> true bails out of setState) and a freshly deployed node+ // type stayed missing from React Flow's map for the whole session —+ // the palette offered it (its groupIndex dep is reactive) but the+ // canvas rendered the fallback default node on first drop.+ const [specsKey, setSpecsKey] = React.useState(() => cachedNodeSpecTypesKey());React.useEffect(() => {if (!isReady || hasPrefetchedSpecs.current) return;if (!featureFlags.nodeSpecBackend) {// When the backend is disabled, mark ready so the legacy fallback// dispatch runs without waiting on a never-completing prefetch.- setSpecsReady(true);+ setSpecsKey('__legacy__');return;}hasPrefetchedSpecs.current = true;- void prefetchAllNodeSpecs(sendRequest).finally(() => setSpecsReady(true));+ void prefetchAllNodeSpecs(sendRequest).finally(() => setSpecsKey(cachedNodeSpecTypesKey()));}, [isReady, sendRequest]);// Paint executing / completed / error / pending classes on the React@@ -615,12 +623,13 @@ const DashboardContent: React.FC = () => {const proOptions = React.useMemo(() => ({ hideAttribution: true }), []);- // Wave 10.D step 2: nodeTypes dispatch map. Built once per hydration- // pass — `specsReady` is seeded from the persisted cache, so warm+ // Wave 10.D step 2: nodeTypes dispatch map. Keyed on the cached+ // spec-type SET identity — seeded from the persisted cache, so warm// starts get a populated map on the first render and no canvas-wide- // remount when prefetch lands. Cold first-ever visit still rebuilds- // when prefetch finishes (one-time cost per browser).- const nodeTypes = React.useMemo(() => createNodeTypes(), [specsReady]);+ // remount when an unchanged prefetch lands (same set -> same key).+ // Rebuilds exactly when the set changes: cold first-ever visit, and+ // a revision bust that adds/removes node types (one-time cost each).+ const nodeTypes = React.useMemo(() => createNodeTypes(), [specsKey]);const edgeTypes = moduleEdgeTypes;// Execute entire workflow from start node to end@@ -1362,7 +1371,7 @@ const DashboardContent: React.FC = () => {onToggleSection={toggleSection}onDragStart={handleComponentDragStart}proMode={proMode}- specsReady={specsReady}+ specsKey={specsKey}/>)}</div>diff --git a/client/src/components/ui/ComponentPalette.tsx b/client/src/components/ui/ComponentPalette.tsxindex 69f125c0..851ac2cd 100644--- a/client/src/components/ui/ComponentPalette.tsx+++ b/client/src/components/ui/ComponentPalette.tsx@@ -23,7 +23,7 @@ const ComponentPalette: React.FC<ComponentPaletteProps> = ({onToggleSection,onDragStart,proMode = false, // Default to simple mode- specsReady = false,+ specsKey = '',}) => {const { isBlocked, isAllowed } = useNodeAllowlist();@@ -104,8 +104,8 @@ const ComponentPalette: React.FC<ComponentPaletteProps> = ({});return categories;- // eslint-disable-next-line react-hooks/exhaustive-deps -- specsReady gates memo recomputation when the spec catalogue hydrates.- }, [searchQuery, proMode, groupIndex, isBlocked, isAllowed, specsReady]);+ // eslint-disable-next-line react-hooks/exhaustive-deps -- specsKey gates memo recomputation when the spec catalogue hydrates or changes set.+ }, [searchQuery, proMode, groupIndex, isBlocked, isAllowed, specsKey]);const totalComponents = Object.values(categorizedComponents).reduce((acc, components) => acc + components.length,diff --git a/client/src/lib/nodeSpec.ts b/client/src/lib/nodeSpec.tsindex 7daaf3a5..60f9c15b 100644--- a/client/src/lib/nodeSpec.ts+++ b/client/src/lib/nodeSpec.ts@@ -214,6 +214,25 @@ export function listCachedNodeSpecs(): NodeSpec[] {.filter((s): s is NodeSpec => !!s);}+/**+ * Identity key for the SET of cached spec types. Changes exactly when a+ * type is added or removed — i.e. when the boot prefetch lands a new+ * backend revision (`prefetchAllNodeSpecs` busts + refetches on+ * mismatch). Dashboard keys its React Flow `nodeTypes` memo (and the+ * ComponentPalette its category memo) on this string instead of a+ * latched boolean: a warm start whose persisted cache pre-dates a newly+ * deployed node type would otherwise never rebuild the dispatch map —+ * the palette offers the new node but React Flow has no component for+ * it and falls back to the default node (first-drop render bug).+ * String value equality keeps the no-change warm start a no-op.+ */+export function cachedNodeSpecTypesKey(): string {+ return listCachedNodeSpecs()+ .map(s => s.type)+ .sort()+ .join('|');+}+/*** Wave 10.E: types whose backend spec lists ``group`` includes the* given group key. Returns an empty array until prefetch lands; callersdiff --git a/client/src/types/ComponentTypes.ts b/client/src/types/ComponentTypes.tsindex 241db018..35e21e1a 100644--- a/client/src/types/ComponentTypes.ts+++ b/client/src/types/ComponentTypes.ts@@ -13,9 +13,11 @@ export interface ComponentPaletteActions {export interface ComponentPaletteProps extends ComponentPaletteState, ComponentPaletteActions {proMode?: boolean; // false = simple mode (only AI categories), true = pro mode (all categories)- // Flips true after Dashboard's prefetchAllNodeSpecs resolves so the- // palette's useMemo recomputes against the now-warm spec cache.- specsReady?: boolean;+ // Identity of the cached spec-type set (cachedNodeSpecTypesKey).+ // Changes when Dashboard's prefetchAllNodeSpecs lands a different+ // catalogue so the palette's useMemo recomputes against the now-warm+ // spec cache — including types added by a backend revision bust.+ specsKey?: string;}export interface WorkflowHandlers {