Repository navigation
fix(init): fail fast when model init blocks instead of hanging forever - #2014
Merged
Merged
Conversation
Model/connection initialization had no wall-clock cap: if embeddings, the cross-encoder, or LLM verification blocked (e.g. an offline HuggingFace download or an unreachable provider), `asyncio.gather` in `MemoryEngine.initialize()` never returned and the daemon hung in a third state — neither started nor errored. The lazy reranker path (`CrossEncoderReranker.ensure_initialized()`) had the same problem on the first request. Wrap both with `asyncio.wait_for` capped by a new static config `HINDSIGHT_API_MODEL_INIT_TIMEOUT` (default 300s, generous enough for first-time model downloads). On timeout, raise a clear RuntimeError that names the likely cause and points at the env var — no silent fallback. Fixes #1897
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.
Fixes #1897
Problem
Model/connection initialization had no wall-clock cap. If embeddings, the cross-encoder, or LLM verification blocked — e.g. an offline HuggingFace download or an unreachable provider —
asyncio.gatherinMemoryEngine.initialize()(memory_engine.py:2313) never returned. The daemon got stuck in a third state: not started, not errored, just hung. From the caller's side the memory operation hangs forever with no way to recover.The lazy reranker path
CrossEncoderReranker.ensure_initialized()(reranking.py:156) had the same gap, surfacing the hang on the first recall instead of at startup.Fix — fail fast, no silent fallback
HINDSIGHT_API_MODEL_INIT_TIMEOUT(default 300s — generous enough for legitimate first-time model downloads on slow connections).gatherand the lazy reranker init withasyncio.wait_for. On timeout, raise aRuntimeErrorthat names the likely cause and points at the env var.Deliberately kept minimal-scope: did not add the diagnostic
_embeddings_initialized/_reranker_initializedstate fields the issue floated — the reranker already tracks_initializedand they aren't needed for the fix.Note: env var follows the project's
HINDSIGHT_API_*convention (the issue suggestedHINDSIGHT_MODEL_INIT_TIMEOUT).Tests
tests/test_model_init_timeout.py:RuntimeErrorLint, format,
tytype-check, and existing reranker-timeout tests all pass.