fix: assistant prefill prevents malformed harvest/refresh responses#5
fix: assistant prefill prevents malformed harvest/refresh responses#5
Conversation
…tive instead of memory file The model sometimes ignores the "return only the memory file" instruction and outputs a session summary, which the malformed-response check correctly rejects. Adding an assistant prefill that starts with the first line of the current memory file forces the model to continue in the expected format. Also prints the raw malformed response on failure for easier debugging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a558d5e8e1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ) | ||
|
|
||
| updated_content = _strip_model_wrapper(response.content[0].text) | ||
| updated_content = _strip_model_wrapper(prefill + response.content[0].text) |
There was a problem hiding this comment.
Strip response wrappers before adding prefill
Calling _strip_model_wrapper on prefill + response.content[0].text makes fence stripping ineffective, because _strip_model_wrapper only removes fences when the string starts with ; after this change it always starts with `#` or `<!--` from prefill. If Claude returns a wrapped continuation (for example starting with `\nmarkdown), the fences survive cleanup, _looks_like_memory_filestill passes due to the prefill line, and malformed fenced content can be written toGLOBAL_MEMORY.md` (same pattern appears in both harvest and refresh code paths).
Useful? React with 👍 / 👎.
Summary
harvest_memory_contentandrefresh_memory_contentAPI calls, forcing the model to continue in memory-file format instead of drifting into narrative summariesContext
The model occasionally ignores the "return only the memory file" instruction and returns a session summary (e.g., a checklist of completed tasks). The
_looks_like_memory_filecheck catches this, but the user gets a cryptic error with no way to see what went wrong. The prefill technique is the standard Anthropic fix for steering output format.Test plan
memsync harvestagainst a session that previously triggered the malformed response🤖 Generated with Claude Code