Fix: document title fallback - #1572
Open
addyCooks wants to merge 3 commits into
Open
Conversation
… messages supermemoryai#1406 shipped the API-error unwrapping and the status-aware handleError fallbacks with a test file that had already been deleted in supermemoryai#1397, so SupermemoryClient - every outbound API call, extractApiErrorMessage, and all of handleError - had no coverage at all. Restores src/server/client/index.test.ts with 53 cases covering the SDK wiring, space scoping, result normalisation, forgetMemory's exact-match and similarity fallbacks, the raw-fetch endpoints, and the full status table. Two of those cases failed against the untested code: - A 403 whose body is {"error": ""} leaked the raw JSON envelope to the user, because extractApiErrorMessage falls through to the raw string when the recognised key holds an empty value. An envelope we parsed but that carries no message now yields undefined so the caller reaches its scope-aware fallback. - A status outside the mapped switch (409, 413, ...) with an empty body reached the user as an Error with an empty message. Unmapped statuses with no message now report the status instead.
Documents saved through the MCP connector have been landing with a null title, so every surface fell back to "Untitled Document". The titling step runs server-side, but the content itself almost always carries a usable title, and the ingest API has no title field for a caller to set. Resolve a display title from metadata.title, then the stored title, then the content itself (YAML frontmatter, a markdown heading, or a short opening line), and let add_memory pin a title through metadata. Fixes supermemoryai#1425
Pin the three content shapes from the issue - a markdown H1, a YAML frontmatter title block, and a title line followed by prose - plus repairing a card by pinning metadata.title over a null or paraphrased title.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1425
What's happening
Auto-titling runs server-side during ingestion. When it fails,
documents.titlestays null and every surface falls back to "Untitled Document" even though the
content itself opens with a perfectly good title. The reporter's three test cards
(markdown H1, YAML frontmatter, plain title line) all processed to
status: donewith a null title.
This does not fix the server-side titling regression, which lives outside this
repo. It makes the null title recoverable, and gives callers the title control
the issue asks for.
What this does
resolveDocumentTitle()resolves a display title in order:metadata.titlethe caller's explicit choice, so it outranks auto-titlingtitletitle:, a markdown heading, or ashort standalone opening line
Derivation is deliberately conservative: list/quote/table openers, code fences,
horizontal rules, bare URLs, punctuation-only lines, and long opening paragraphs
all decline rather than produce a bad title.
Wired into the document modal, memory grid, MCP/note cards, dashboard recents,
brain-home recents, and the command palette.
Title control
The ingest API has no
titlefield, soadd_memorynow takes an optionaltitleand pins it throughmetadata.title, which the app and the MCPlist_documents/get_documentoutput both read back. No API change neededthis works against the API as it ships today.
A real
titlefield onPOST /v3/documentsstill needs a server-side change.Tests
apps/web/lib/document-title.test.ts22 cases covering precedence and thederivation edge cases (CRLF, BOM, setext headings, nested frontmatter keys,
truncation, blank/non-string metadata)
apps/mcp/src/server/format.test.ts5 cases for pinned titles in MCP outputapps/mcp/src/server/client/index.test.ts2 cases for title pinning