[Bug] _validate rejects LLM replies wrapped in a markdown code fence; json_object/prompt_only unusable with fence-emitting models
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 22/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 13.3k
- Fork
- 926
- Merge trung bình
- 1 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 57
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của EverMind-AI/EverOS
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
EverMind-AI/EverOS#414 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
EverMind-AI/EverOS#629 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
EverMind-AI/EverOS#558 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
memorize(): make delivery resumable per memcell so retries and replays are idempotentCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
EverMind-AI/EverOS#516 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
EverMind-AI/EverOS#485 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của EverMind-AI/EverOS
Issue tương tự
-
bug docs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
mesa/mesa#4223 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
ActivityWatch/docs#223 ·
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier captureCó thể đã có người làm @jianyx1 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
volcengine/OpenViking#8354 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
comp/tools P2 tool/skills type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NousResearch/hermes-agent#159541 ·
Maintainer thường phản hồi trong vòng 1 ngày