Skip to content

fix(soul): a merge deleted the title a person gave their own memory - #19

Merged
tentpegbob merged 1 commit into
mainfrom
fix/the-merge-kept-only-the-entries
Oct 25, 2026
Merged

tentpegbob merged 1 commit into
mainfrom
fix/the-merge-kept-only-the-entries

Conversation

@tentpegbob

Copy link
Copy Markdown

What

POST /api/soul/documents/memory/merge rewrites the document from its parsed
entries:

merged = merge_memory_logs(before, *request.logs)
content = format_memory_log(merged.entries)
write_identity_document(document, content)

and the parser says plainly what it leaves out:

Anything before the first entry heading — a title, a paragraph explaining
what the file is — is not an entry and is not returned.

So every merge deleted it. That preamble is the only part of MEMORY.md a
person writes by hand
; the entries are all machine-written.

Why it matters now

It mattered little while merging was an explicit cross-backend sync the user
triggered. It matters now: Canvas files a correction through this route
(OpenHands#83, which moved it off a read-modify-write that could drop the
previous entry), so a single thumbs-down was enough to delete the title a
person had put on their own memory.

That is the opposite of what milestone 2 asks of this document — "nothing is
overwritten and nothing is lost"
.

How

The target's preamble is kept, read back by a new memory_log_preamble:

content = memory_log_preamble(before) + format_memory_log(merged.entries)

An incoming log's preamble stays on the machine it was written on, because two
of them is exactly the three-way merge this format exists to avoid. The
docstring's original argument is right about reconciling preambles and was
being used to justify dropping one.

Convergence is unaffected and now pinned by a test: the preamble is local, the
entries are the union, so merging twice changes nothing.

A log with no entries at all is treated as all preamble rather than as
nothing, so a file someone has started but not yet logged into is not emptied
by the first merge.

Verification

The route test fails without the fix:

E   AssertionError: assert False
+    where False = '## 2026-10-20T08:00:00Z — Judge on a second runtime\n…'.startswith('# What I keep forgetting\n\n')
tests/sdk/context/           441 passed  (+2 new)
tests/agent_server/         2670 passed, 3 failed  (+1 new)
ruff check / format          clean

The three failures are test_cleanup_stale_tmux_sessions_* in
tests/agent_server/test_api.py, which fail on this machine on a clean
checkout as well — tmux socket paths, unrelated to this change.

Follow-up, not done here

Canvas now depends on this behaviour, so compatibility.minimumAgentServer
should be raised when the release carrying it lands. Bumping it against an
unreleased version would break every local stack today, so it belongs with
the release rather than with the fix. An older server still files the
correction; it just loses the preamble, which is the behaviour this fixes.

HUMAN:

Issue Number

None. Issues are disabled on this fork.

🤖 Generated with Claude Code

The memory merge rewrites the whole document from its parsed entries, and the
parser deliberately returns only entries — so anything above the first
heading was dropped on every merge. That is the one part of MEMORY.md a
person writes by hand.

It mattered little while merging was an explicit cross-backend sync. It
matters now: filing a correction goes through this route, so a single
thumbs-down was enough to delete it.

The target's preamble is kept, read back by `memory_log_preamble`. An
incoming log's preamble stays on the machine it was written on, because two
of them is exactly the three-way merge this format exists to avoid — and the
merge still converges: the preamble is local, the entries are the union, and
running it twice changes nothing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@tentpegbob
tentpegbob merged commit 3bb8c6e into main Oct 25, 2026
3 checks passed
@tentpegbob
tentpegbob deleted the fix/the-merge-kept-only-the-entries branch October 25, 2026 21:45
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