feat: Add Hook for Auto Refresh of Model Provider Input by deon-sanchez · Pull Request #10996 · langflow-ai/langflow (original) (raw)
Important
Review skipped
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Walkthrough
This PR introduces a new hook mechanism for refreshing model-type inputs after model provider changes, including utilities to detect and update model nodes, plus a comprehensive test suite. It also fixes an infinite-loop issue in the model input component by guarding empty-state mutations with a processed flag.
Changes
| Cohort / File(s) | Summary |
|---|---|
| Model Input Refresh Hook Implementation src/frontend/src/hooks/use-refresh-model-inputs.ts | New hook module providing end-to-end model input refresh capability with API-driven orchestration, concurrency guards, and internal utilities (isModelNode, findModelFieldKey, buildRefreshPayload, createUpdatedNode) for detecting and updating model nodes. Includes error handling via alert store and optional query client invalidation. |
| Model Input Refresh Hook Tests src/frontend/src/hooks/__tests__/use-refresh-model-inputs.test.ts | Comprehensive test suite covering utility predicates/transformers, core refresh logic, hook behavior, API error handling, concurrency prevention, and edge cases (empty options, silent mode, cache invalidation). |
| Modal Integration src/frontend/src/modals/modelProviderModal/index.tsx | Integrates useRefreshModelInputs hook; adds side effect to call refreshAllModelInputs on modal close before invoking onClose callback. |
| Model Input Component Fix src/frontend/src/components/core/parameterRenderComponent/components/modelInputComponent/index.tsx | Adds hasProcessedEmptyRef to prevent infinite loop when handling empty model options; guards handleOnNewValue call to execute only once per empty state and resets flag when options become available. |
Sequence Diagram(s)
sequenceDiagram actor User participant Modal as Model Provider Modal participant Hook as useRefreshModelInputs participant Flow as Flow State participant API as API Service participant QueryClient participant Store as Alert Store participant Nodes as Node Templates
User->>Modal: Close modal
Modal->>Hook: refreshAllModelInputs()
activate Hook
Hook->>Flow: Get current flow nodes
Flow-->>Hook: All nodes in flow
loop For each model node
Hook->>API: POST refresh with node template + context
alt API Success
API-->>Hook: Updated template + options
Hook->>Nodes: Update node with new template
Note over Hook: Avoid duplicate updates by<br/>checking response template
else API Error
API-->>Hook: Error response
Hook->>Store: Log warning (per-node)
end
end
alt queryClient provided
Hook->>QueryClient: Invalidate model-related queries
end
alt Not silent mode
Hook->>Store: Notify user of refresh completion
end
Hook-->>Modal: Refresh complete
deactivate Hook
Modal->>User: Close and show updated stateLoading
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
- Areas requiring extra attention:
src/frontend/src/hooks/use-refresh-model-inputs.ts— Core logic for API orchestration, concurrency guards, and node update mechanisms; verify proper error propagation and infinite-loop preventionsrc/frontend/src/hooks/__tests__/use-refresh-model-inputs.test.ts— Verify test coverage adequacy for all utility functions and edge cases (concurrent calls, API failures, empty payloads)- Integration point in
src/frontend/src/modals/modelProviderModal/index.tsx— Ensure refresh timing doesn't conflict with existing updateEnabledModels logic
Suggested labels
enhancement, size:M, lgtm
Suggested reviewers
- Cristhianzl
- mfortman11
- edwinjosechittilappilly
Pre-merge checks and finishing touches
Important
Pre-merge checks failed
Please resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error, 2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Test Coverage For New Implementations | ❌ Error | PR lacks regression tests for hasProcessedEmptyRef infinite loop prevention and modelProviderModal integration with useRefreshModelInputs hook. | Add regression tests for hasProcessedEmptyRef guard logic and unit tests for modelProviderModal integration with refreshAllModelInputs invocation. |
| Test Quality And Coverage | ⚠️ Warning | Test suite for use-refresh-model-inputs hook is comprehensive with proper async patterns, but critical coverage gaps exist for modified files modelInputComponent and modelProviderModal with zero dedicated tests, plus untested type-safety concerns. | Add dedicated test suites for modelInputComponent's hasProcessedEmptyRef flag behavior, modelProviderModal's refreshAllModelInputs invocation, and createUpdatedNode type-safety validation for non-genericNode types. |
| Excessive Mock Usage Warning | ⚠️ Warning | Test suite has excessive global mocks obscuring actual behavior; pure utility functions tested with unnecessary mocks. | Separate unit tests for pure functions from integration tests; use simple fixtures instead of global mocks; reduce module-level mock scope. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'feat: Add Hook for Auto Refresh of Model Provider Input' directly and specifically describes the main change: introducing a new React hook (useRefreshModelInputs) that automatically refreshes model provider inputs. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%. |
| Test File Naming And Structure | ✅ Passed | The test file use-refresh-model-inputs.test.ts fully satisfies all requirements with correct naming, proper organization, comprehensive test structure, and thorough edge case coverage. |
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands and usage tips.