Skip to content

fix(rag): scope lazy-load catches so model failures aren't mislabeled 'not installed' (#118)#124

Open
daviddgonzalez wants to merge 1 commit into
mainfrom
fix/rag-loadpipeline-error-scoping
Open

fix(rag): scope lazy-load catches so model failures aren't mislabeled 'not installed' (#118)#124
daviddgonzalez wants to merge 1 commit into
mainfrom
fix/rag-loadpipeline-error-scoping

Conversation

@daviddgonzalez

Copy link
Copy Markdown
Collaborator

Closes #118.

Problem

loadPipeline in packages/rag/src/embedding-providers/transformers-embedding-provider.ts wrapped both the dynamic import('@xenova/transformers') and the model download/inference in a single try/catch that always rethrew a fixed @xenova/transformers is not installed message. Any failure in step B (model download, network error, onnxruntime-node native backend, OOM, …) was reported as "not installed" even when the package was installed and importable — and the real error was swallowed, not even attached as cause.

This actively misled debugging: a Windows CI failure was initially diagnosed as a missing/optional dependency when the package was in fact installed; the real failure was the model download / native backend. PR #119 fixed the test-reliability symptom by skipping those tests on Windows, but the misleading error remained.

Fix

transformers-embedding-provider.ts — split the two failure modes so each surfaces an accurate message:

  • Import failure → keeps the actionable @xenova/transformers is not installed hint, now with the original error attached as cause (previously dropped entirely).
  • Model/inference failure → throws Failed to load transformers model '<model>' preserving the original error as cause.

A type-only import of pipeline types the holder variable across the two try blocks without an import() type annotation (lint) or any runtime dependency on the optional package.

onnx-embedding-provider.ts (the issue's "audit siblings" note) — its install-hint catch (loadOnnxRuntime) was already correctly scoped to the import alone, so it was left unchanged. But loadModel's model download (ensureModelFiles) and session creation (InferenceSession.create) previously bubbled raw errors with no provider/model context, so they now throw Failed to download ONNX model '<model>' / Failed to load ONNX model '<model>' with cause preserved.

Tests

No new tests. This is a pure error-message refinement adding no new branches that aren't already exercised by the existing integration paths; the happy path stays covered by the integration tests. Full bun run validate (lint, typecheck, unit + integration + system tests, duplication) passes.

Changelog

Added an entry under ### Fixed in the [Unreleased] section.

… 'not installed'

loadPipeline in transformers-embedding-provider.ts wrapped both the dynamic
import and the model download/inference in one catch that always rethrew
'@xenova/transformers is not installed', swallowing the real error. Split the
two failure modes: import failure keeps the install hint (now with cause),
model/inference failure throws 'Failed to load transformers model' with cause.

Audited onnx-embedding-provider.ts: its install-hint catch was already scoped
to the import alone, but loadModel's download + session creation bubbled raw
errors with no model context, so they now wrap with 'Failed to download/load
ONNX model' preserving cause.

Closes #118
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.69%. Comparing base (5d6f2ff) to head (a17a423).

Files with missing lines Patch % Lines
...src/embedding-providers/onnx-embedding-provider.ts 0.00% 18 Missing ⚠️
...dding-providers/transformers-embedding-provider.ts 0.00% 13 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #124      +/-   ##
==========================================
- Coverage   81.78%   81.69%   -0.10%     
==========================================
  Files         223      223              
  Lines       17135    17155      +20     
  Branches     3326     3326              
==========================================
  Hits        14014    14014              
- Misses       3121     3141      +20     
Files with missing lines Coverage Δ
...dding-providers/transformers-embedding-provider.ts 1.92% <0.00%> (-0.35%) ⬇️
...src/embedding-providers/onnx-embedding-provider.ts 20.86% <0.00%> (-1.98%) ⬇️
Files with missing lines Coverage Δ
...dding-providers/transformers-embedding-provider.ts 1.92% <0.00%> (-0.35%) ⬇️
...src/embedding-providers/onnx-embedding-provider.ts 20.86% <0.00%> (-1.98%) ⬇️
🚀 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.

@daviddgonzalez

Copy link
Copy Markdown
Collaborator Author

This is just to do with I/O which will be tested in integration tests. Putting it in unit tests is redundant/might confuse other claudes that looks at the test suite

@jdutton

jdutton commented Jun 17, 2026

Copy link
Copy Markdown
Owner

@daviddgonzalez you can merge this whenever you are ready

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rag: over-broad catch in loadPipeline mislabels all failures as '@xenova/transformers is not installed'

2 participants