Skip to content

fix: disable transformers progress bar on Windows#2368

Merged
goldmedal merged 3 commits into
Canner:mainfrom
Federicorao:codex/issue-2366-1781271202
Jun 22, 2026
Merged

fix: disable transformers progress bar on Windows#2368
goldmedal merged 3 commits into
Canner:mainfrom
Federicorao:codex/issue-2366-1781271202

Conversation

@Federicorao

@Federicorao Federicorao commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #2366.

Disable transformers progress bar before loading sentence-transformers to prevent OSError on Windows due to sys.stderr.flush() failure. On Windows, the tqdm progress bar used by transformers/huggingface internally calls sys.stderr.flush() which can raise OSError: [WinError 1] Incorrect function in certain terminals (e.g., Git Bash). Calling transformers.logging.disable_progress_bar() before importing sentence-transformers or lancedb.embeddings eliminates this crash without changing any other behavior.

I checked that the changed Python files still parse correctly.

Summary by CodeRabbit

  • Bug Fixes
    • Reduced noisy console output by disabling Transformers/Hugging Face progress bar display during embedding function initialization and warm-up.
  • Chores
    • Kept embedding startup behavior the same while ensuring initialization runs without extra progress logging.

@github-actions github-actions Bot added python Pull requests that update Python code core labels Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 32e4ad6f-d5ef-41da-bc94-254bfc4da68a

📥 Commits

Reviewing files that changed from the base of the PR and between 8d5ddb5 and c8fd5df.

📒 Files selected for processing (1)
  • core/wren/src/wren/memory/embeddings.py

Walkthrough

A private helper _disable_transformers_progress_bar() is added and invoked at two embedding initialization points: before the sentence-transformers embedding is created in get_embedding_function(), and before the embedding probe in warm_up(). This disables HuggingFace Transformers progress bar output to resolve Windows OSError failures during model loading.

Changes

Transformers progress bar disable to fix Windows OSError

Layer / File(s) Summary
Progress bar disable helper and integration points
core/wren/src/wren/memory/embeddings.py
Introduces private _disable_transformers_progress_bar() helper that calls transformers.utils.logging.disable_progress_bar(), and invokes it before embedding creation in get_embedding_function() and before the warmup probe in warm_up() to prevent stderr flush errors on Windows.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 Progress bars were causing strife,
On Windows—quite the frantic life!
A helper small, so lean and neat,
Makes stderr flush again complete! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'fix: disable transformers progress bar on Windows' accurately describes the main change: disabling the transformers progress bar to fix an OSError on Windows.
Linked Issues check ✅ Passed The PR implements the requested fix from issue #2366 by disabling transformers progress bar before loading sentence-transformers, allowing memory initialization on Windows.
Out of Scope Changes check ✅ Passed All changes are scoped to the embeddings.py module and directly address the Windows OSError issue. No unrelated changes were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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.

Actionable comments posted: 4

🧹 Nitpick comments (3)
core/wren/src/wren/memory/embeddings.py (3)

28-29: 💤 Low value

Hard-coded model assumptions in docstring are unverified.

The docstring claims the default model is "all-MiniLM-L6-v2" with "1024-dimensional" embeddings, but there's no code to verify or enforce this. The actual model and dimension depend on LanceDB's registry defaults, which could change between versions or be configured differently.

Remove the hard-coded model name and dimension from the docstring, or query them from the created embedding function to ensure accuracy.

🤖 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 `@core/wren/src/wren/memory/embeddings.py` around lines 28 - 29, The docstring
in core/wren/src/wren/memory/embeddings.py hardcodes a model name and embedding
dimension; remove those specific claims or make them dynamic by querying the
actual embedding function/instance at runtime. Update the module-level docstring
(and any references in functions or classes that mention the model or dimension)
to either omit the specific model/dimension or retrieve them from the created
embedding function (e.g., from the embedding factory/instance used when creating
embeddings) and include that information only after verifying its attributes.
Ensure you reference and adjust any code that assumes "all-MiniLM-L6-v2" or
"1024-dimensional" so behavior matches the actual embedding provider.

38-38: ⚡ Quick win

Redundant get_registry() call.

The registry is already obtained at module import time (line 14) and stored in the module-level registry variable. Calling get_registry() again is unnecessary. Reuse the module-level registry or cache it.

♻️ Proposed fix to reuse module-level registry
 def get_embedding_function():
     """
     Return a LanceDB-compatible embedding function for sentence-transformers.

     Returns:
         A callable that accepts a batch of strings and returns a list of embeddings.
-        Each embedding is a list of floats (1024-dimensional for the default
-        all-MiniLM-L6-v2 model).

     Raises:
         ImportError: If sentence-transformers or lancedb is not installed.
     """
     if not _SENTENCE_TRANSFORMERS_AVAILABLE:
         raise ImportError(
             "sentence-transformers not available. Install with: pip install 'wrenai[memory]'"
         )
-    registry = get_registry()
     return registry.get("sentence-transformers").create()
🤖 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 `@core/wren/src/wren/memory/embeddings.py` at line 38, The duplicate call to
get_registry() (the local "registry = get_registry()" at the shown location) is
redundant because a module-level registry variable is already created at import
time; remove the extra call and reuse the module-level registry variable instead
(ensure you don't shadow it with a new local assignment in functions or classes
such as any function referencing registry in this file), keeping references to
registry as-is so the module-level cached instance is used.

39-39: ⚖️ Poor tradeoff

No way to configure which sentence-transformers model to use.

The old API accepted a model_name parameter to select different models (e.g., multilingual vs. English). The new API calls registry.get("sentence-transformers").create() with no arguments, using only LanceDB's default model. This removes the ability to customize the embedding model, which may be needed for different languages or performance requirements.

Consider adding back model selection capability, either as a function parameter or through the registry create method.

🤖 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 `@core/wren/src/wren/memory/embeddings.py` at line 39, The current call to
registry.get("sentence-transformers").create() in embeddings.py removes the
ability to pick a specific sentence-transformers model; update the embeddings
factory to accept a model_name parameter and pass it through to the registry
creator (e.g., change the function that returns
registry.get("sentence-transformers").create() to accept model_name and call
registry.get("sentence-transformers").create(model_name=model_name) or similar),
or alternatively update the registry implementation to support
create(model_name=...) so callers can select multilingual/English models via the
model_name argument; ensure the parameter name (model_name) is exposed in the
public function signature that currently returns
registry.get("sentence-transformers").create() so existing call sites can opt
into custom models.
🤖 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.

Inline comments:
In `@core/wren/src/wren/memory/embeddings.py`:
- Around line 34-39: The change removed the ability to obtain the vector
dimension needed by Arrow schema creation (formerly via _DEFAULT_DIM/warm_up),
so update the sentence-transformers embedding API to expose dimension
information: modify the code path that returns
registry.get("sentence-transformers").create() (embedding factory) so the
created object exposes a stable dimension attribute or method (e.g.,
embedding.dim or embedding.get_dimension()) or return a tuple (embedding, dim);
ensure callers like store.py can call that attribute/method (or unpack the
tuple) to obtain the integer used for pa.list_(pa.float32(), dim).
- Around line 13-19: The current bare except around get_registry() masks all
errors; update the block that sets _SENTENCE_TRANSFORMERS_AVAILABLE (the call to
get_registry() and the membership check for "sentence-transformers") to only
catch the expected exceptions (e.g., ImportError, KeyError, possibly
RuntimeError) that indicate the embedding backend or package is unavailable, and
let other exceptions bubble up (or log and re-raise) so real bugs in
get_registry() are not silently swallowed; reference the get_registry() call and
the _SENTENCE_TRANSFORMERS_AVAILABLE assignment when making this change.
- Line 22: The embeddings module must match the MemoryStore API: change
get_embedding_function to accept a model_name parameter (def
get_embedding_function(model_name=None)), export _DEFAULT_MODEL, _DEFAULT_DIM,
and warm_up, and ensure _SENTENCE_TRANSFORMERS_AVAILABLE remains defined; update
the function to use a single get_registry() call (remove the duplicate call at
module import or inside the function) and compute or set _DEFAULT_DIM
dynamically rather than hardcoding "1024" in the docstring—either derive the
dimension from the resolved model metadata or remove the specific dimension
text; ensure imports in store.py (get_embedding_function, _DEFAULT_MODEL,
_DEFAULT_DIM, warm_up) succeed with these symbols exported.
- Around line 5-7: The module-level call to
transformers_logging.disable_progress_bar() in wren.memory.embeddings causes a
global side effect; remove that import-time call and instead call
disable_progress_bar() only around the specific code paths that instantiate or
warm up the transformer embedding model (e.g., inside the warm_up function or
the embedding model creation function/class in wren.memory.embeddings),
optionally guarded by an opt-out config/env flag, and restore or avoid disabling
globally afterward (implement a small helper or context-like toggle around model
creation to localize the effect rather than calling
transformers_logging.disable_progress_bar() at import time).

---

Nitpick comments:
In `@core/wren/src/wren/memory/embeddings.py`:
- Around line 28-29: The docstring in core/wren/src/wren/memory/embeddings.py
hardcodes a model name and embedding dimension; remove those specific claims or
make them dynamic by querying the actual embedding function/instance at runtime.
Update the module-level docstring (and any references in functions or classes
that mention the model or dimension) to either omit the specific model/dimension
or retrieve them from the created embedding function (e.g., from the embedding
factory/instance used when creating embeddings) and include that information
only after verifying its attributes. Ensure you reference and adjust any code
that assumes "all-MiniLM-L6-v2" or "1024-dimensional" so behavior matches the
actual embedding provider.
- Line 38: The duplicate call to get_registry() (the local "registry =
get_registry()" at the shown location) is redundant because a module-level
registry variable is already created at import time; remove the extra call and
reuse the module-level registry variable instead (ensure you don't shadow it
with a new local assignment in functions or classes such as any function
referencing registry in this file), keeping references to registry as-is so the
module-level cached instance is used.
- Line 39: The current call to registry.get("sentence-transformers").create() in
embeddings.py removes the ability to pick a specific sentence-transformers
model; update the embeddings factory to accept a model_name parameter and pass
it through to the registry creator (e.g., change the function that returns
registry.get("sentence-transformers").create() to accept model_name and call
registry.get("sentence-transformers").create(model_name=model_name) or similar),
or alternatively update the registry implementation to support
create(model_name=...) so callers can select multilingual/English models via the
model_name argument; ensure the parameter name (model_name) is exposed in the
public function signature that currently returns
registry.get("sentence-transformers").create() so existing call sites can opt
into custom models.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 54678a6b-c6bb-4001-8fe5-3dc309dcca6f

📥 Commits

Reviewing files that changed from the base of the PR and between 6e150e2 and 8d5ddb5.

📒 Files selected for processing (1)
  • core/wren/src/wren/memory/embeddings.py

Comment thread core/wren/src/wren/memory/embeddings.py Outdated
Comment thread core/wren/src/wren/memory/embeddings.py Outdated
Comment thread core/wren/src/wren/memory/embeddings.py Outdated
Comment thread core/wren/src/wren/memory/embeddings.py Outdated
@goldmedal goldmedal changed the title Disable transformers progress bar before loading sentence-transformers to prevent OSError on Windows due to sys.stderr.f fix(wren): disable transformers progress bar before loading sentence-transformers to prevent OSError on Windows due to sys.stderr.f Jun 15, 2026
@goldmedal

Copy link
Copy Markdown
Collaborator

Hi @Federicorao, thanks for you working on this. There are some CI fails. Could you fix them?

@Federicorao Federicorao changed the title fix(wren): disable transformers progress bar before loading sentence-transformers to prevent OSError on Windows due to sys.stderr.f fix: disable transformers progress bar on Windows Jun 18, 2026
Federicorao and others added 2 commits June 18, 2026 12:31
transformers only ships with the optional memory extra, so importing
transformers.utils.logging at module top level makes wren.memory.embeddings
unimportable when that extra is not installed. Move the import into
_disable_transformers_progress_bar (lazy, matching the existing lazy lancedb
import) so the module stays importable without the extra.
@Federicorao

Copy link
Copy Markdown
Contributor Author

Thanks @goldmedal — went back through the change and fixed a real issue: the new from transformers.utils import logging was at module top level, which makes wren.memory.embeddings fail to import whenever the optional memory extra (transformers) isn't installed. That's a likely cause of the import-time CI failures.

I moved it into _disable_transformers_progress_bar as a lazy import, matching the existing lazy lancedb import in this module, and verified the module now imports cleanly with transformers absent. The model_name parameter and defaults are unchanged.

The only check that ran here is labeler (green); the test workflows look like they're waiting on maintainer approval for this fork PR — could you re-trigger them so I can confirm against the full CI? Thanks!

@goldmedal goldmedal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Federicorao 👍

@goldmedal goldmedal merged commit f91529b into Canner:main Jun 22, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: wren memory fetch fails with OSError: [WinError 1] Incorrect function while loading sentence-transformers model

2 participants