docs(debug): resolve asyncio nested loop debug session
Root cause: BilibiliExtractor sync wrappers use asyncio.run() internally, which fails when called from async context in BilibiliAdapter. Fix: Call async methods directly instead of sync wrappers. Verified: Human confirmed fix works (bilibili_BV16cNMzpExh)
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
---
|
||||
status: resolved
|
||||
trigger: "kb-workflow skill fails to download Bilibili videos with asyncio nested loop error"
|
||||
created: 2026-03-15T00:00:00Z
|
||||
updated: 2026-03-15T19:00:00Z
|
||||
---
|
||||
|
||||
## Current Focus
|
||||
|
||||
hypothesis: N/A - root cause confirmed and fix verified
|
||||
test: Ran kb-workflow process command - metadata extraction succeeded
|
||||
expecting: No asyncio nested loop error, successful metadata extraction
|
||||
next_action: Await human verification to confirm fix works in their environment
|
||||
|
||||
## Symptoms
|
||||
|
||||
expected: kb-workflow skill should successfully download Bilibili videos (BV16cNMzpExh)
|
||||
actual: Download fails with asyncio nested event loop error
|
||||
errors: `asyncio.run() cannot be called from a running event loop`
|
||||
reproduction: CLI command (e.g., `/kb-workflow download <url>`)
|
||||
started: Never worked properly - this is a new feature with a bug
|
||||
|
||||
## Eliminated
|
||||
|
||||
<!-- APPEND only -->
|
||||
|
||||
## Evidence
|
||||
|
||||
- timestamp: 2026-03-15T00:00:01Z
|
||||
checked: kb-workflow/kb_workflow.py line 387
|
||||
found: process_command() calls asyncio.run(run_pipeline()) - this is the outer event loop
|
||||
implication: Creates an async context that all nested code runs within
|
||||
|
||||
- timestamp: 2026-03-15T00:00:01Z
|
||||
checked: kb_pipeline/pipeline.py line 106
|
||||
found: Pipeline.run() is an async method that calls await processor.process()
|
||||
implication: All processors run within the async event loop
|
||||
|
||||
- timestamp: 2026-03-15T00:00:01Z
|
||||
checked: kb_pipeline/processors/download.py line 66
|
||||
found: DownloadProcessor.process() calls await adapter.fetch_metadata()
|
||||
implication: BilibiliAdapter.fetch_metadata() is called from async context
|
||||
|
||||
- timestamp: 2026-03-15T00:00:01Z
|
||||
checked: kb_pipeline/platforms/bilibili.py line 173
|
||||
found: BilibiliAdapter._fetch_metadata_with_retry() calls self._extractor.extract_video_metadata(content_id) which is a SYNC method
|
||||
implication: Calls sync wrapper from async context
|
||||
|
||||
- timestamp: 2026-03-15T00:00:01Z
|
||||
checked: kb-bilibili-metadata/bilibili_extractor.py line 91
|
||||
found: BilibiliExtractor.extract_video_metadata() calls asyncio.run(self._extract_video_async(bvid)) - this is the ROOT CAUSE
|
||||
implication: asyncio.run() CANNOT be called when an event loop is already running, causing the nested loop error
|
||||
|
||||
## Resolution
|
||||
|
||||
root_cause: BilibiliExtractor provides sync wrapper methods (extract_video_metadata, extract_article_metadata, etc.) that use asyncio.run() internally. When BilibiliAdapter.fetch_metadata() (which is async) calls these sync methods, it triggers asyncio.run() from within an already-running event loop, which is forbidden in Python's asyncio model.
|
||||
fix: Modified BilibiliAdapter._fetch_metadata_with_retry() to call the underlying async methods directly (await self._extractor._extract_video_async() and await self._extractor._extract_article_async()) instead of the sync wrappers that use asyncio.run()
|
||||
verification: Self-verified - ran kb-workflow process command successfully. No asyncio nested loop error. Metadata extracted correctly including title, author, stats, description. Human-verified - user confirmed fix works (bilibili_BV16cNMzpExh executed successfully, asyncio error resolved).
|
||||
files_changed:
|
||||
- kb_pipeline/platforms/bilibili.py
|
||||
Reference in New Issue
Block a user