[Bug]: parse_error in memory extraction — the validator rejects exactly the forms the contract teaches (edit() on [replace] fields, sdk.existing() bindings)
Issue Origin
Observed or reproduced in a real environment
Bug Description
Memory extraction fails terminally with failure_kind=parse_error. On one self-hosted instance this is the dominant remaining failure class: 18 session_commit tasks over one week (after the thinking + forced tool_choice 400s were mitigated).
I matched the validator's error text against captured request/response pairs for those 18 windows and found two violation patterns. Both are cases where the form the validator rejects is the form the contract teaches.
Pattern 1 — content.edit(search=..., replace=...) on merge_op=replace fields (57 occurrences)
ERROR extract_loop:run:428 - Failed to parse memory operations (iteration 2/2)
failure_kind=parse_error error=Line 1: field 'content' does not support edit()/drop():
merge_op=replace requires the complete new value, including unchanged text;
use `experiences_1.content.update("""complete new value""")` instead.
The contract already says this (#5180 aligned the guidance), yet models keep choosing the patch idiom — unsurprising on the patch merge task, whose stated purpose is patching. Captured offending program:
experiences_1.content.edit(
search="""- 跑提交前门禁:定向用例 + 全量离线回归 + review nits(仅注释/文档可省)""",
replace="""- 跑提交前门禁:定向用例 + 全量离线回归 + review nits(仅注释/文档可省)
- 打包前先跑 pnpm -r test 全量,失败先修""")
Pattern 2 — sdk.existing(...) (4 occurrences)
The contract renders existing-object bindings in the reserved call form, models copy it, and the compiler rejects it — this is #5650. Both patterns can co-occur in one response:
sdk.existing(memory_type='experiences', experience_name='单仓范围提交推送').content.edit(
search="""- 跑提交前门禁…""", replace="""…""")
Impact: the failure is terminal (single format retry; max_iterations=1 in policy_optimizer.py / streaming_memory_updater.py), the archive keeps .failed.json, and a later commit never covers it (#6227) — that window's memories are lost silently. On this instance that has accumulated to 253 failed archives vs 3,188 completed (≈7.4%).
Steps to Reproduce
- Self-hosted OpenViking 0.4.23, OpenAI-compatible endpoint (OpenRouter via a local proxy),
deepseek/deepseek-v4.1-flashor-1017,extra_request_body: {"reasoning": {"effort": "low"}}. - Use sessions long enough that memory patch merges run (profile/preferences/experiences updates).
- Watch
GET /api/v1/tasksforsession_committasks failing withfailure_kind=parse_error; grep the server log fordoes not support edit()/drop(). - Match the error text against the captured response body in that time window to see the offending program.
Expected Behavior
A semantically correct program that uses edit(search, replace) on a [replace] string field should be applied (or repaired) rather than failing the whole archive — the compiler already has a StrPatch → _validate_patch_operations → patch-repair path for patch-mode fields, and the comment in python_protocol.py says edits are deliberately stored as StrPatch so that path can handle them. At minimum, a validation failure should be recoverable and observable.
Actual Behavior
Terminal failure, invisible to the integrating client (the commit call already returned 200 with a task id), archive not recoverable, memories from that window never extracted.
Error Logs
10:57:10.689 | ERROR | openviking.session.memory.extract_loop:run:428 - Failed to parse memory operations
(iteration 2/2) failure_kind=parse_error error=Line 1: field 'content' does not support edit()/drop():
merge_op=replace requires the complete new value, including unchanged text
10:57:10,695 | WARNING | openviking.session.utils.streaming_batcher - [openviking-streaming-policy-trainer]
background flush failed: Final response could not be parsed as operations after 2 iterations (failure_kind=parse_error)
10:57:10,762 | ERROR | openviking.session.session - Phase 2 step long_term failed: ...
.failed.json left behind:
{"stage": "memory_extraction", "failed_at": "...", "skipped": true,
"error": "Final response could not be parsed as operations after 2 iterations (failure_kind=parse_error)",
"completed_memory_steps": {"long_term": ["..."]}}
Failure classes on this instance (168 tasks / 103 failed): 77 × provider 400 on thinking + forced tool_choice (now mitigated by #5636 + provider fallback), 18 × parse_error, 7 × request timeout, 1 × empty_response, 1 × proxy 502.
OpenViking Version
0.4.23. The relevant code is identical in 0.5.0 (PyPI wheel) and current main — python_protocol.py (md5 match) and the validator that raises does not support edit()/drop().
Python Version
3.14.6
Operating System
Ubuntu 24.04 (Linux x86_64)
Model Backend
OpenAI-compatible endpoint (OpenRouter through a local proxy); deepseek/deepseek-v4.1-flash and deepseek/deepseek-v4.1-flash-1017; reasoning.effort=low. Model/provider choice does not change the failure rate — 0910 and 1017, and three different providers, all produce it.
Additional Context
Three concrete changes that would close this, in order of leverage:
- Accept
edit(search=..., replace=...)on[replace]string fields by routing it through the existing patch-application path instead of erroring. This is the one that removes ~57 of the 61 observed violations. - Fix the binding rendering so the contract does not display a call form its own compiler rejects (#5650).
- Make the retry budget configurable and observable:
max_iterationsis hard-coded to 1, and a validation failure only keeps a ~200-charresponse_preview, which is why this had to be reconstructed from proxy captures.
Cross-references: #5650 (open, pattern 2), #5176 / #5180 (closed, contract guidance), #5514, #5894, #5527 (other parse_error variants), #6227 (failed archives are not recoverable), #6096 / #6104 (a separate cause of the same terminal state).
Adding a second, distinct failure level inside the same terminal state — worth separating because it needs a different fix.
While re-checking today's failures I hit a program whose Python does not even parse. The trigger is a single extra quote:
supersedes="""",
^ four quotes where an empty triple-quoted string was intended
Python reads the first """ as an opening delimiter and the fourth " as content, so the string runs on and swallows the following code. tokenize shows exactly that:
STRING lines 53-57: '"""", | ) | | new_config_hierarchy = sdk.create_experiences( | experience_name="""'
STRING lines 57-58: '""", content="""'
The reported error lands six lines later and points at the symptom, not the cause:
ERROR extract_loop:run:428 - Failed to parse memory operations (iteration 2/2)
failure_kind=parse_error error=Line 59: invalid Python syntax: invalid character '(' (U+FF08)
It is not truncation: finish_reason=stop, completion_tokens=7,599 of max_tokens=32,768, and the program is complete (146 lines, ends with sdk.commit()). The model simply miscounted quotes.
Rough split across the 20 parse_error windows on this instance (per-response, windows include unrelated concurrent sub-calls, so indicative rather than exact attribution):
| Class | Count |
|---|---|
| Parses; no known violation | 261 |
Parses; uses content.edit()/drop() on [replace] |
58 |
| Does not parse (this class) | 15 |
Parses; uses sdk.existing(...) |
4 |
One caveat for the protocol design: the contract is not wrong here — it says to leave supersedes empty — but an empty value has to be written as """, and a single miscount derails the whole program, with an error message that misdirects. memory.extraction_output_format: json avoids this class entirely (no quote nesting), which is worth considering as a mitigation while the contract-level fixes land.
Also feeds back into ask #3 in the opening post: full model output on validation failure plus the offending line would have made this a two-minute diagnosis instead of a six-line trace through the token stream.
Thanks for pointing this out. The bug has fixed in https://github.com/volcengine/OpenViking/pull/6286 and https://github.com/volcengine/OpenViking/pull/6347