[PR #407] [MERGED] Ensure async txtai readiness, improve HF fallback variants, and add SSE timeout in orchestrator #715

Closed
opened 2026-03-13 21:05:21 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/407
Author: @AJaySi
Created: 3/10/2026
Status: Merged
Merged: 3/10/2026
Merged by: @AJaySi

Base: mainHead: codex/fix-hugging-face-model-not-found-errors-y1qoah


📝 Commits (1)

  • 3a88d09 Make SIF agent workflows non-blocking and guard SSE hangs

📊 Changes

4 files changed (+82 additions, -58 deletions)

View changed files

📝 backend/services/intelligence/sif_agents.py (+18 -12)
📝 backend/services/intelligence/txtai_service.py (+14 -31)
📝 backend/services/llm_providers/huggingface_provider.py (+28 -12)
📝 frontend/src/services/contentPlanningOrchestrator.ts (+22 -3)

📄 Description

Motivation

  • Ensure the txtai intelligence service is asynchronously initialized before SIF agents perform searches/indexing to avoid blocking the event loop or operating on uninitialized embeddings.
  • Make embedding operations in agents non-blocking by offloading blocking calls to threads and centralize a robust readiness check.
  • Improve model fallback behavior in the Hugging Face provider and prevent the frontend AI orchestration from hanging when SSE streams never finish.

Description

  • Added SIFBaseAgent._ensure_intelligence_ready and replaced synchronous is_initialized() checks in multiple agents with await self._ensure_intelligence_ready() to safely gate operations.
  • Updated TxtaiIntelligenceService to await self._ensure_initialized_async() in index_content, search, get_similarity, cluster, and classify, changed initialization logging and failure handling, and kept indexing flow but now warns and optionally raises when uninitialized.
  • Made embedding calls in _fetch_index_documents thread-safe by calling embeddings.count and embeddings.search via asyncio.to_thread, and normalized metadata processing.
  • Added _candidate_model_variants and integrated it into the HF fallback sequence to try provider-suffixed and base model ids, and adjusted logging and retry behavior in huggingface_provider.
  • Frontend ContentPlanningOrchestrator.loadAIAnalytics now has a hard timeout and a finished guard to ensure SSE-based strategic intelligence resolves or times out and clears the timeout on completion.

Testing

  • Ran backend unit tests (pytest) covering intelligence and agent flows and they passed.
  • Ran frontend unit tests (jest) for the orchestrator and SSE handling and they passed.
  • Ran static checks/linting (flake8/mypy) on modified modules and they passed.

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/407 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 3/10/2026 **Status:** ✅ Merged **Merged:** 3/10/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/fix-hugging-face-model-not-found-errors-y1qoah` --- ### 📝 Commits (1) - [`3a88d09`](https://github.com/AJaySi/ALwrity/commit/3a88d09af87525614098a00f4da997a4a84f03e6) Make SIF agent workflows non-blocking and guard SSE hangs ### 📊 Changes **4 files changed** (+82 additions, -58 deletions) <details> <summary>View changed files</summary> 📝 `backend/services/intelligence/sif_agents.py` (+18 -12) 📝 `backend/services/intelligence/txtai_service.py` (+14 -31) 📝 `backend/services/llm_providers/huggingface_provider.py` (+28 -12) 📝 `frontend/src/services/contentPlanningOrchestrator.ts` (+22 -3) </details> ### 📄 Description ### Motivation - Ensure the txtai intelligence service is asynchronously initialized before SIF agents perform searches/indexing to avoid blocking the event loop or operating on uninitialized embeddings. - Make embedding operations in agents non-blocking by offloading blocking calls to threads and centralize a robust readiness check. - Improve model fallback behavior in the Hugging Face provider and prevent the frontend AI orchestration from hanging when SSE streams never finish. ### Description - Added `SIFBaseAgent._ensure_intelligence_ready` and replaced synchronous `is_initialized()` checks in multiple agents with `await self._ensure_intelligence_ready()` to safely gate operations. - Updated `TxtaiIntelligenceService` to await `self._ensure_initialized_async()` in `index_content`, `search`, `get_similarity`, `cluster`, and `classify`, changed initialization logging and failure handling, and kept indexing flow but now warns and optionally raises when uninitialized. - Made embedding calls in `_fetch_index_documents` thread-safe by calling `embeddings.count` and `embeddings.search` via `asyncio.to_thread`, and normalized metadata processing. - Added `_candidate_model_variants` and integrated it into the HF fallback sequence to try provider-suffixed and base model ids, and adjusted logging and retry behavior in `huggingface_provider`. - Frontend `ContentPlanningOrchestrator.loadAIAnalytics` now has a hard timeout and a `finished` guard to ensure SSE-based strategic intelligence resolves or times out and clears the timeout on completion. ### Testing - Ran backend unit tests (`pytest`) covering intelligence and agent flows and they passed. - Ran frontend unit tests (`jest`) for the orchestrator and SSE handling and they passed. - Ran static checks/linting (`flake8`/`mypy`) on modified modules and they passed. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69afb132c9248328b2cb4ca08e8d382c) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-13 21:05:21 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#715
No description provided.