Skip to content

Fix: document title fallback - #1572

Open
addyCooks wants to merge 3 commits into
supermemoryai:mainfrom
addyCooks:fix/document-title-fallback
Open

Fix: document title fallback#1572
addyCooks wants to merge 3 commits into
supermemoryai:mainfrom
addyCooks:fix/document-title-fallback

Conversation

@addyCooks

Copy link
Copy Markdown

Fixes #1425

What's happening

Auto-titling runs server-side during ingestion. When it fails, documents.title
stays 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: done
with 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:

  1. metadata.title the caller's explicit choice, so it outranks auto-titling
  2. the stored title
  3. derived from content YAML frontmatter title:, a markdown heading, or a
    short 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 title field, so add_memory now takes an optional
title and pins it through metadata.title, which the app and the MCP
list_documents / get_document output both read back. No API change needed
this works against the API as it ships today.

A real title field on POST /v3/documents still needs a server-side change.

Tests

  • apps/web/lib/document-title.test.ts 22 cases covering precedence and the
    derivation edge cases (CRLF, BOM, setext headings, nested frontmatter keys,
    truncation, blank/non-string metadata)
  • apps/mcp/src/server/format.test.ts 5 cases for pinned titles in MCP output
  • apps/mcp/src/server/client/index.test.ts 2 cases for title pinning

… 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.
@addyCooks addyCooks changed the title Fix/document title fallback Fix: document title fallback Aug 20, 2026
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.

Auto-titling regression: most MCP-connector saves land as "Untitled Document" since ~Aug 6

1 participant