[Bug] _validate rejects LLM replies wrapped in a markdown code fence; json_object/prompt_only unusable with fence-emitting models
维护者通常 1 天内回复
评估
调研方向
Start in src/everos/component/llm/openai_provider.py, at _validate and the existing _strip_trailing_commas repair step it calls. Fence stripping (a leading json or and a trailing ```) would be added as an extra repair before validation. Work is already under way in linked PR #628, so check that PR before starting. Done means a fenced JSON reply validates against _EpisodeReply in json_object and prompt_only modes.
由索引模型根据 Issue 内容生成。
描述
Summary
OpenAIProvider._validate rejects LLM replies wrapped in a markdown code fence (json ... ), so non-OpenAI-native models (glm, deepseek, etc.) that habitually wrap JSON in a fence fail validation in json_object / prompt_only mode, returning EXTERNAL_SERVICE_UNAVAILABLE on every /add and /flush.
Reproduce
Model: glm-5.2 (and any model that wraps JSON in ```json fences), via an OpenAI-compatible endpoint.
everos.toml:
[llm]
model = "glm-5.2"
api_key = "..."
base_url = "..."
response_format_mode = "prompt_only" # or "json_object"
curl -X POST http://localhost:8000/api/v2/memory/add \
-H "Content-Type: application/json" \
-d '{"session_id":"s1","messages":[{"sender_id":"A","role":"user","timestamp":1737900000000,"content":"C likes basketball"},{"sender_id":"C","role":"user","timestamp":1737900006000,"content":"yes I do"}]}'
curl -X POST http://localhost:8000/api/v2/memory/flush \
-H "Content-Type: application/json" -d '{"session_id":"s1"}'
Response:
{"error":{"code":"EXTERNAL_SERVICE_UNAVAILABLE","message":"no usable reply in 2 attempts (model='glm-5.2', response_format_mode='prompt_only'): reply failed validation against _EpisodeReply"}}
Actual LLM reply (raw)
The model returns valid JSON wrapped in a fence:
```json {"title": "...", "content": "..."} ```
Root cause
src/everos/component/llm/openai_provider.py _validate runs response_format.model_validate_json(text) on the full reply text. A reply starting with ```json is not valid JSON, so validation fails. The only repair attempted is _strip_trailing_commas, which does not strip a markdown fence:
def _validate(text: str, response_format: type[BaseModel]) -> str:
try:
response_format.model_validate_json(text)
except ValidationError as exc:
repaired = _strip_trailing_commas(text)
if repaired != text and _validates(repaired, response_format):
return repaired
raise _AttemptFailedError(
f"reply failed validation against {response_format.__name__}", ...
) from exc
return text
Why this is a gap (not already covered)
- #564 / PR #580 fixed trailing commas but did not add fence stripping.
- #515 / PR #538 removed the old brace-balanced
_extract_json_object(which happened to skip fences by starting at the first{) in favor of strictmodel_validate_json, dropping the implicit fence tolerance. - The config docs (
default.toml:87) explicitly offerjson_object/prompt_onlyfor endpoints that "do not accept a strict schema". In those modes the endpoint is not enforcing a schema, so a model wrapping JSON in a fence is a common, expected behavior — yet_validatecannot parse it.
So a user who follows the documented fallback (prompt_only) for a non-strict endpoint still gets every extraction rejected.
Expected
_validate strips a leading (with optional language tag) and a trailing before validating, the same way the old _extract_json_object implicitly skipped fences by starting at the first {. Or: strip the fence as an additional repair step alongside _strip_trailing_commas.
Environment
- EverOS 1.7.1 (main, commit e5778ed)
- everalgo-user-memory 0.10.1
- LLM: glm-5.2 via OpenAI-compatible endpoint,
response_format_mode = "prompt_only" - Python 3.12, Linux
- 主要语言
- Python
- 星标
- 13.3k
- 派生
- 926
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 57
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
EverMind-AI/EverOS 的其他 Issue
-
难度 2/5 半天 新手友好度 62/100
EverMind-AI/EverOS#414 ·
维护者通常 1 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 18/100
EverMind-AI/EverOS#629 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
EverMind-AI/EverOS#558 · 1 条评论 ·
维护者通常 1 天内回复
-
memorize(): make delivery resumable per memcell so retries and replays are idempotent可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 5/5 一周以上 新手友好度 35/100
EverMind-AI/EverOS#516 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 35/100
EverMind-AI/EverOS#485 ·
维护者通常 1 天内回复
查看 EverMind-AI/EverOS 的全部 Issue
相似的 Issue
-
bug docs
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
ActivityWatch/docs#223 ·
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier capture可能已有人在做 @jianyx1 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
volcengine/OpenViking#8354 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
维护者通常 1 天内回复
-
comp/tools P2 tool/skills type/bug
难度 2/5 1-3 小时 新手友好度 78/100
NousResearch/hermes-agent#159541 ·
维护者通常 1 天内回复