fix(agent): preload jiter native parser - #33692
Merged
Merged
Conversation
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-import |
1 |
First entries
agent/jiter_preload.py:29: [unresolved-import] unresolved-import: Cannot resolve imported module `jiter`
✅ Fixed issues: none
Unchanged: 5017 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
Collaborator
19 tasks
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvage of #33665 by @helix4u onto current main.
Summary
Preloads the OpenAI SDK's native
jiterstreaming parser duringagentpackage import, so the first DeepSeek/OpenAI-compatible streaming request on Windows doesn't hitModuleNotFoundError: No module named 'jiter.jiter'.Root cause
OpenAI SDK lazy-imports
openai.lib.streaming.chat._completionsthe first time a streaming response is consumed, from inside the SSE worker thread. That module doesfrom jiter import from_json, which triggersjiter/__init__.py→from .jiter import *→ load of the native.pyd. On some Windows installs this thread-load fails (likely an AV / file-lock / loader-state race), even though the sameimport jiter.jitersucceeds when run synchronously from the Hermes venv at a REPL.Reproduced live by a Discord user (Lucien) on Windows + DeepSeek: direct
import jiter.jiterprintedjiter ok, but every streaming chat request failed withModuleNotFoundError: No module named 'jiter.jiter'. Confirmed workaround:That preloads the native extension on the main thread before any Hermes code starts. The PR makes Hermes do the same automatically.
Changes
agent/jiter_preload.py: best-effortimportlib.import_module("jiter.jiter")+from jiter import from_json, runs at module import. Swallows exceptions so a truly missing/broken install still surfaces via the normal SDK error path.agent/__init__.py: importsjiter_preloadso the side effect runs on firstimport agent.*(which happens very early in CLI/gateway startup viaagent.portal_tags,agent.secret_sources, etc.).tests/agent/test_jiter_preload.py: happy path + ModuleNotFoundError fallback.Validation
scripts/run_tests.sh tests/agent/test_jiter_preload.py→ 2/2 passed.python3 -c "import agent; from agent import jiter_preload; print(jiter_preload._JITER_PRELOADED)"→True,jiter.jiterinsys.modules.scripts/release.py.Closes #33665. helix4u authorship preserved via rebase-merge.
Infographic