Skip to content

fix: assistant prefill prevents malformed harvest/refresh responses#5

Merged
EdgeCaser merged 2 commits intomainfrom
fix/spaces-in-project-key
Mar 26, 2026
Merged

fix: assistant prefill prevents malformed harvest/refresh responses#5
EdgeCaser merged 2 commits intomainfrom
fix/spaces-in-project-key

Conversation

@EdgeCaser
Copy link
Copy Markdown
Owner

Summary

  • Adds assistant prefill to both harvest_memory_content and refresh_memory_content API calls, forcing the model to continue in memory-file format instead of drifting into narrative summaries
  • Prints the raw malformed response on harvest failure for easier debugging
  • Updates test mocks to simulate real API behavior with prefill (response is continuation only, not full text)

Context

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_file check 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

  • All 328 tests pass, 87% coverage maintained
  • Manual: run memsync harvest against a session that previously triggered the malformed response

🤖 Generated with Claude Code

EdgeCaser and others added 2 commits March 25, 2026 18:47
…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>
@EdgeCaser EdgeCaser merged commit f9fd140 into main Mar 26, 2026
7 checks passed
@EdgeCaser EdgeCaser deleted the fix/spaces-in-project-key branch March 26, 2026 01:50
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant