Skip to content

refactor(frontend): re-file use-refresh-model-inputs into services and utils#14045

Open
tarciorodrigues wants to merge 2 commits into
release-1.11.0from
refactor/le-1735-wp4
Open

refactor(frontend): re-file use-refresh-model-inputs into services and utils#14045
tarciorodrigues wants to merge 2 commits into
release-1.11.0from
refactor/le-1735-wp4

Conversation

@tarciorodrigues

@tarciorodrigues tarciorodrigues commented Jul 13, 2026

Copy link
Copy Markdown
Member

Why

LE-1735 Tier A componentization — work package 4. hooks/use-refresh-model-inputs.ts mixed three concerns in one 326-line file: five pure template/node helpers, the refresh orchestration with a module-level concurrency queue, and the React hook itself. This PR re-files each concern where it belongs, behavior-preserving, so the hook path stays a thin React-facing surface.

What

  • Add utils/model-node-helpers.ts with the five pure helpers (isModelNode, findModelFieldKey, buildRefreshPayload, createUpdatedNode, validateModelValue) moved verbatim. validateModelValue was private and is now exported only from the new module.
  • Add services/refresh-model-inputs.ts with refreshAllModelInputs, the private refreshSingleNode, the module-level concurrency queue (isRefreshInProgress + pendingRefresh) and the RefreshOptions type, all moved verbatim. The queue lives in exactly one module. Note: src/services/ is a new top-level directory.
  • hooks/use-refresh-model-inputs.ts keeps only the useRefreshModelInputs hook plus one-way @deprecated re-exports, so all seven prod consumers and the six path-based jest mocks compile unchanged. No consumer was repointed; the deprecated re-exports are transitional and get removed in a follow-up once consumers migrate.
  • The redundant double concurrency guard (module flag + per-hook ref) is intentionally untouched — removing it is a behavior change and gets its own follow-up.

Tests

  • use-refresh-model-inputs.test.ts (873 lines, 34 tests) green before and after each commit — it exercises the moved queue and orchestration directly through the old path.
  • All consumer suites green: model-selector, ModdelToggleQueue, useProviderConfigurationDisconnect
    — 66 tests.
  • make format_frontend no drift; full make test_frontend: 443 of 445 suites green; the two red suites (AuthModal, KnowledgeBaseUploadModal) are userEvent 5s timeouts under a loaded parallel run, pass 51/51 in isolation and do not touch this diff.
  • Import-direction check: hooks import services,thing imports back — no cycle; git grep showszero imports of the private symbols from anywhere else.
  • Manual smoke on the branch: model dropdown Refresh List fires exactly one POST custom_component/update per click with
    the selection preserved and the dropdown closing opens and closes without spurious refreshes; zero console errors.
  • Before/after screenshots light and dark below.

Note

Rapid double-refresh through the UI is not reproducible from the dropdown because it closes on the first click; the
anti-storm queue behavior is asserted by the 34-

Refs LE-1735

Screenshots

Model dropdown

Light

Before

before-model-dropdown-light

After

after-model-dropdown-light

Dark

Before

before-model-dropdown-dark

After

after-model-dropdown-dark

Summary by CodeRabbit

  • New Features
    • Added reliable refreshing of model inputs across the current flow.
    • Automatically preserves valid selections or chooses an available model when options change.
    • Supports silent refreshes without displaying notifications.
  • Bug Fixes
    • Prevented overlapping refresh requests from causing inconsistent updates.
    • Improved handling of unavailable providers, outdated components, and temporary refresh errors.
    • Preserved node translations and related flow data after model inputs are refreshed.

…-inputs

Move the five pure helpers (isModelNode, findModelFieldKey,
buildRefreshPayload, createUpdatedNode, validateModelValue) verbatim to
utils/model-node-helpers.ts. The hook file keeps one-way deprecated
re-exports for the four previously public helpers so every consumer and
path-based jest.mock compiles unchanged; validateModelValue was private
and is now exported only from the new module. No behavior change.
Move refreshAllModelInputs, the private refreshSingleNode and the
module-level concurrency queue (isRefreshInProgress + pendingRefresh)
verbatim to services/refresh-model-inputs.ts, together with the
RefreshOptions type. The hook file keeps only the ~20-line
useRefreshModelInputs hook plus one-way deprecated re-exports, so all
seven consumers and the path-based jest.mocks compile unchanged. The
queue lives in exactly one module; the double concurrency guard is
intentionally untouched. No behavior change.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

The model-input refresh implementation is extracted from the hook into shared service and utility modules. The hook preserves its public entry point and deprecated exports through re-exports.

Model input refresh

Layer / File(s) Summary
Model-node refresh helpers
src/frontend/src/utils/model-node-helpers.ts
Adds shared helpers for identifying model nodes, building refresh payloads, updating nodes, and validating model selections.
Refresh service orchestration
src/frontend/src/services/refresh-model-inputs.ts
Adds refresh coordination with cache invalidation, concurrent node updates, queued requests, notifications, translation syncing, and race-condition handling.
Hook compatibility exports
src/frontend/src/hooks/use-refresh-model-inputs.ts
Replaces local implementations with deprecated re-exports while retaining the React hook and refresh alias.
Estimated code review effort: 4 (Complex) ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant refreshAllModelInputs
  participant QueryClient
  participant BackendAPI
  participant FlowStore
  Caller->>refreshAllModelInputs: request model input refresh
  refreshAllModelInputs->>QueryClient: invalidate model queries
  refreshAllModelInputs->>BackendAPI: refresh model node
  BackendAPI-->>refreshAllModelInputs: return updated template
  refreshAllModelInputs->>FlowStore: update node and translations
Loading

Suggested reviewers: adam-aghili, cristhianzl, deon-sanchez, jordanrfrazier, ramgopalsrikar


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error The PR adds/moves code only; no test files were added or modified for the new service/helper modules. Add or update frontend *.test.ts(x) coverage for src/frontend/src/services/refresh-model-inputs.ts and src/frontend/src/utils/model-node-helpers.ts.
✅ Passed checks (8 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the refactor that split use-refresh-model-inputs into service and utility modules.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Test Quality And Coverage ✅ Passed The frontend has a Jest/RTL test suite with 34 cases covering helpers, refresh orchestration, queueing, outdated-guard branches, and hook alias/memoization using proper async patterns.
Test File Naming And Structure ✅ Passed Relevant frontend test file is correctly named and structured, with descriptive cases, beforeEach setup, and positive/negative coverage; no backend/integration test issues in this PR.
Excessive Mock Usage Warning ✅ Passed The 8 mocks isolate external stores/API/query deps; the suite still exercises real helper logic and refresh orchestration, so mocking is scoped, not excessive.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/le-1735-wp4

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.

@github-actions github-actions Bot added the refactor Maintenance tasks and housekeeping label Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Test Coverage Advisor — tests appear to be missing

This PR changes source code but does not add or modify any test files.
This is an advisory check: it will not block this PR or any other job —
please add tests if the change is testable.

Frontend (TS/TSX) — no *.test.* / *.spec.* / tests/ change found

src/frontend/src/hooks/use-refresh-model-inputs.ts
src/frontend/src/services/refresh-model-inputs.ts
src/frontend/src/utils/model-node-helpers.ts

Advisory check only — it always passes and is never a required status.

@github-actions github-actions Bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jul 13, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/frontend/src/services/refresh-model-inputs.ts (1)

74-77: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoff

Unbounded parallel refresh fan-out.

Promise.all fires an api.post for every model node simultaneously. On flows with many model nodes this can burst the backend. Consider bounding concurrency (e.g. a small worker pool / p-limit) if large flows are expected. Preserved from prior behavior, so non-blocking.

🤖 Prompt for 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.

In `@src/frontend/src/services/refresh-model-inputs.ts` around lines 74 - 77,
Bound concurrency in the refresh flow around refreshTasks and refreshSingleNode
instead of starting every refresh request simultaneously with Promise.all. Use a
small worker pool or existing concurrency limiter while preserving
refreshSingleNode’s behavior and awaiting completion of all node refreshes.
🤖 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.

Nitpick comments:
In `@src/frontend/src/services/refresh-model-inputs.ts`:
- Around line 74-77: Bound concurrency in the refresh flow around refreshTasks
and refreshSingleNode instead of starting every refresh request simultaneously
with Promise.all. Use a small worker pool or existing concurrency limiter while
preserving refreshSingleNode’s behavior and awaiting completion of all node
refreshes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7efff2f1-6c3a-4c95-84cc-1c5e515f5993

📥 Commits

Reviewing files that changed from the base of the PR and between b4ac6a6 and e4f1315.

📒 Files selected for processing (3)
  • src/frontend/src/hooks/use-refresh-model-inputs.ts
  • src/frontend/src/services/refresh-model-inputs.ts
  • src/frontend/src/utils/model-node-helpers.ts

@Cristhianzl Cristhianzl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 45%
45.86% (63498/138451) 69.93% (8661/12385) 44.08% (1436/3257)

Unit Test Results

Tests Skipped Failures Errors Time
5273 0 💤 0 ❌ 0 🔥 19m 6s ⏱️

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.38650% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.23%. Comparing base (01d1c68) to head (e4f1315).
⚠️ Report is 7 commits behind head on release-1.11.0.

Files with missing lines Patch % Lines
src/frontend/src/utils/model-node-helpers.ts 98.36% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           release-1.11.0   #14045      +/-   ##
==================================================
+ Coverage           60.22%   60.23%   +0.01%     
==================================================
  Files                2390     2337      -53     
  Lines              230284   228826    -1458     
  Branches            34535    32111    -2424     
==================================================
- Hits               138688   137842     -846     
+ Misses              89980    89368     -612     
  Partials             1616     1616              
Flag Coverage Δ
frontend 59.29% <99.38%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/frontend/src/hooks/use-refresh-model-inputs.ts 100.00% <100.00%> (+0.30%) ⬆️
src/frontend/src/services/refresh-model-inputs.ts 100.00% <100.00%> (ø)
src/frontend/src/utils/model-node-helpers.ts 98.36% <98.36%> (ø)

... and 245 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor Maintenance tasks and housekeeping

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants