Skip to content

fix(storage): 按事件循环隔离异步客户端#2168

Merged
zhoujh01 merged 1 commit into
mainfrom
fix/loop-scoped-async-clients
May 21, 2026
Merged

fix(storage): 按事件循环隔离异步客户端#2168
zhoujh01 merged 1 commit into
mainfrom
fix/loop-scoped-async-clients

Conversation

@qin-ctx
Copy link
Copy Markdown
Collaborator

@qin-ctx qin-ctx commented May 21, 2026

Description

修复异步 Embedding/VLM 客户端在多线程、多事件循环场景下复用同一个 async client 的问题,并调整语义刷新链路,让 memory 文件向量化和 resource temp -> target 同步都在语义队列处理中保持一致。

Related Issue

Fixes #2135

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • 新增 LoopScopedAsyncClientCache,让 httpx.AsyncClient、OpenAI/Ark 等异步客户端按当前事件循环缓存,避免跨 worker thread/event loop 复用导致运行时错误。
  • 将 memory 写入后的单文件向量刷新收敛到 SemanticProcessor,使用生成后的 summary 对变更文件向量化,并保留目录级向量刷新。
  • 在 resource 语义任务中传递 target_preexistingsync_to_target,确保 full update 仍可在语义生成持有资源锁时完成 temp -> target 同步,同时保留已有 target 的 incremental 判断。

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

执行过:

.venv/bin/python -m pytest tests/unit/test_async_client_cache.py tests/unit/test_extra_headers_embedding.py tests/unit/test_extra_headers_vlm.py tests/storage/test_semantic_processor_target_preexisting.py tests/storage/test_semantic_dag_incremental_missing_summary.py tests/storage/test_semantic_queue_memory_dedupe.py tests/misc/test_resource_processor_mv.py tests/server/test_content_write_service.py

结果:78 passed, 4 warnings in 8.55s。warnings 为现有依赖/Pydantic deprecation 类提示。

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

不适用

Additional Notes

本地 pre-commit hook 绑定的系统 Python 和当前 .venv 都没有安装 pre_commit 模块,因此提交时使用了 --no-verify;相关测试已在本地通过。

Cache async SDK clients per event loop to avoid cross-loop reuse in worker threads.
Move memory vectorization into semantic queue refresh and preserve target sync state for resource updates.
@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🏅 Score: 90
🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@zhoujh01 zhoujh01 merged commit cfb19a5 into main May 21, 2026
4 of 5 checks passed
@zhoujh01 zhoujh01 deleted the fix/loop-scoped-async-clients branch May 21, 2026 09:24
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

OpenAIVLM.get_async_client() caches AsyncOpenAI across event loops, breaking background semantic processing

2 participants