fix(L2-B): knowledge_base _is_postgres psycopg ImportError → graceful False#53
Merged
Conversation
… False
L2 baseline CI fail 子项 B: db_url 配 postgres 但 psycopg / asyncpg 未装,
get_engine 调 create_engine ImportError → _is_postgres crash → MCP tool
search_similar stack trace ("No module named 'psycopg'")。
修法 (Surgical, 单函数 try/except):
- _is_postgres() 加 try/except (ImportError / ModuleNotFoundError / Exception)
- 缺 driver 时返 False → server.py 已有 sqlite fallback 分支自然走 (L83+)
- search_similar 走 `return {"error": "...requires Postgres + pgvector..."}`
正常 MCP error response, 装饰器不再标 "tool failed"
不在范围:
- requirements 加 psycopg (依赖膨胀, CI infra 决策待用户决)
- db.py get_engine 加 try/except (公共函数, 影响面大, 由调用方各自 handle)
实测 (本地 mock get_engine ImportError):
- ImportError → False ✓ (走 sqlite fallback)
- ConnectionError → False ✓ (其他异常兜底)
- 正常 postgres → True ✓
L2 baseline 3 子项 (A docx / B psycopg / C rollout) 合后, CI L2 应通过率
≥80% 达标。
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.
范围
L2 baseline CI fail 子项 B:
runtime/mcp/knowledge_base/server.py_is_postgres()调get_engine(), postgres db_url 配但 psycopg 未装时 ImportError → MCP toolsearch_similarstack trace。1 文件 +14/-1。L2 三子项总览
generate_report.pydocx ImportError_is_postgrespsycopg ImportError三子项合后, CI L2 ≥80% 达标。
修法 (Surgical)
server.py L83+ 已有 sqlite fallback 分支自然走 (
return {"indexed": True, ..., "backend": "sqlite-no-vec"})。tool_search_similarL127-128 已正确处理not _is_postgres()→ return error dict (而非 raise)。不在范围
本地测试 (3/3 关键 case 过)
协作宪章 §1.3 六道闸自检 (f1-f6)
置信度自检 (f5)
ModuleNotFoundError: No module named 'psycopg'假阳性过滤 (f6)
唯一 finding = "_is_postgres 在 psycopg 缺时 crash":
假阳性候选数: 0
关联