feat: add append param to update_drawer#1762
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an optional append parameter to the tool_update_drawer function, allowing users to concatenate new content to an existing drawer's body instead of replacing it. It also updates the tool's schema description and adds corresponding unit tests. A review comment points out a potential TypeError if the existing drawer content (old_doc) is None when attempting to append, and suggests safely defaulting it to an empty string.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| sanitized = sanitize_content(content) | ||
| except ValueError as e: | ||
| return {"success": False, "error": str(e)} | ||
| new_doc = old_doc + sanitized if append else sanitized |
There was a problem hiding this comment.
If old_doc is None (which can happen if a drawer was created without a document or if the database is in an unexpected state), attempting to concatenate old_doc + sanitized will raise a TypeError.
To prevent this, we should safely default old_doc to an empty string if it is None.
| new_doc = old_doc + sanitized if append else sanitized | |
| new_doc = (old_doc or "") + sanitized if append else sanitized |
When append=True, content is concatenated onto the existing drawer body instead of replacing it, so a caller updating a long drawer need only send the delta rather than re-transmitting the whole body on every edit. Defaults to False (replace), preserving prior behavior. The server already fetches the existing document, so this is a minimal read-modify-write.
…2b9) Chroma can return None for a stored drawer's document body. The append path concatenated old_doc + content directly, which raises TypeError when old_doc is None. Coerce a missing body to "" before concatenating, and add a regression test driving the None-body case directly. Addresses the PR MemPalace#1762 review feedback.
Summary
Adds an
append: bool = Falseparameter totool_update_drawer(and its MCPschema entry). When
append=Trueandcontentis provided, the content isconcatenated onto the existing drawer body instead of replacing it, so a
caller updating a long drawer can send only the delta rather than
re-transmitting the whole body on every edit.
appenddefaults toFalse— existing callers and the replace-in-fullbehavior are unchanged. The handler already fetches the existing document, so
this is a minimal read-modify-write with no extra round-trip:
Motivation and the alternatives considered (a separate
append_to_drawertool, or a richer section-patch) are in the linked issue — this PR implements
the smallest form and is happy to follow a different surface if preferred.
Closes #1761
Changes
mempalace/mcp_server.pytool_update_drawer(...)gainsappend: bool = False; content path nowappends-or-replaces based on the flag.
appendflag.mempalace_update_drawerMCP schema gains anappendboolean property;tool description notes the delta-append behavior.
tests/test_mcp_server.pytest_update_drawer_append— appends a delta and asserts the original bodysurvives and the delta is concatenated (
old_doc + sanitize_content(delta)).test_update_drawer_replace_is_default— pins that the default(
append=False) still replaces, guarding the back-compat path.Verification
Test-first (RED → GREEN; visible in the commit order on this branch):
test_update_drawer_append, which fails against the currentcode with
TypeError: tool_update_drawer() got an unexpected keyword argument 'append'.CONTRIBUTING.md adherence
test:for the failing test,feat:for the param).ruffclean on the changed file (100-char limit).develop; pushed to a personal fork.