Skip to content

fix(chat): show memory source fallbacks#1167

Draft
Dhravya wants to merge 2 commits into
mainfrom
vorflux/fix-chat-memory-source-cards
Draft

fix(chat): show memory source fallbacks#1167
Dhravya wants to merge 2 commits into
mainfrom
vorflux/fix-chat-memory-source-cards

Conversation

@Dhravya

@Dhravya Dhravya commented Jun 27, 2026

Copy link
Copy Markdown
Member

Chat answers now show deterministic memory/document source attribution when visible memory tool results exist, even if the model skips inline <response source="..."> markup. Inline citations still render when present, and the fallback gate now checks the exact same contiguous rendered text/source-url runs as AgentMessage, so split markup across tool boundaries cannot accidentally suppress fallback sources.

Changes

  • Preserve memory-only citation metadata (memoryId, kind, content) from structured memory tool outputs.
  • Resolve citation targets when sourceIds match results[].id even if results[].citationId is omitted.
  • Add a shared citation display helper so memory-only citations render as Memory, while document-backed citations with metadata do not temporarily show the generic Memory label.
  • Render subtle message-level Sources chips when memory tool outputs provide citation targets and the answer has no valid inline source annotations.
  • Suppress fallback chips when valid inline citation markup renders, avoiding duplicate attribution.
  • Centralize contiguous text / source-url run assembly in source annotation helpers and reuse it for both rendering and fallback suppression.
  • Add a regression test for Cursor Bugbot’s split-across-tool-boundary case.

Testing

  • PASS: cd /code/supermemoryai/supermemory && PATH="$HOME/.bun/bin:$PATH" bun test apps/web/lib/chat-memory-tools.test.ts apps/web/lib/source-annotations.test.ts
    • 19/19 tests passed after the Bugbot follow-up.
  • PASS: cd /code/supermemoryai/supermemory && ./node_modules/.bin/biome ci apps/web/lib/chat-memory-tools.ts apps/web/lib/chat-memory-tools.test.ts apps/web/lib/source-annotations.ts apps/web/lib/source-annotations.test.ts apps/web/components/chat/message/agent-message.tsx
  • PASS: cd /code/supermemoryai/supermemory && ./node_modules/.bin/biome ci apps/web/lib/chat-memory-tools.ts apps/web/lib/chat-memory-tools.test.ts apps/web/components/chat/message/agent-message.tsx
  • PASS: cd /code/supermemoryai/supermemory && git diff --check
  • PASS: cd /code/supermemoryai/supermemory && ./node_modules/.bin/biome ci --changed --since=origin/main
  • PASS with warning: cd /code/supermemoryai/supermemory/apps/web && NODE_ENV=production PATH="$HOME/.bun/bin:$PATH" bun run build
    • Production build passed. Next build reports “Skipping validation of types,” so this is build evidence, not type-check evidence.
  • BLOCKED/PRE-EXISTING: cd /code/supermemoryai/supermemory/apps/web && PATH="$HOME/.bun/bin:$PATH" bunx tsc --noEmit --project tsconfig.json
    • Failed with existing app-wide errors outside changed files; no errors referenced components/chat/message/agent-message.tsx, lib/chat-memory-tools.ts, lib/chat-memory-tools.test.ts, or lib/source-annotations.ts.

Backend-shaped memory tool output was generated with the real backend mapper and rendered through the real frontend AgentMessage component:

Bugbot follow-up browser/UI verification used a local mock chat backend and the real Next.js app route:

Audit-only earlier UI attempts, not pass evidence:

Authenticated live chat E2E is still blocked because no saved browser session exists; the app and preview load to login instead:

Caveats

  • This does not implement the separate simple-button confirmation flow for forgetMemory; current strict typed confirmation is unchanged.

Attached Images and Videos

[supermemory-bugbot-source-run-test.log]

[supermemory-memory-source-cards-bun-test.log]

[supermemory-chat-source-related-bun-tests-after-backend-mapped.log]

[supermemory-bugbot-source-run-biome.log]

[supermemory-memory-source-cards-biome.log]

[supermemory-explicit-files-biome-ci-after-backend-mapped.log]

[supermemory-bugbot-postcommit-biome-changed.log]

[supermemory-postcommit-biome-changed.log]

[supermemory-bugbot-source-run-build.log]

[supermemory-web-build-production.log]

[supermemory-web-tsc.log]

[supermemory-web-tsc-noemit.log]

[backend-mapped-memory-tool-output.json]

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

🎥 View recording: supermemory-chat-backend-mapped-source-flow.webm

[agent-browser-backend-mapped-snapshot.log]

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

🎥 View recording: source-annotation-agent-message-local-backend.webm

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

🎥 View recording: source-annotation-agent-message-history-load.webm

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

Image available at https://supermemory.us1.vorflux.com/agent-sessions/9f5b822f-2d8b-4aba-a375-c0f0fa54560a

🎥 View recording: supermemory-chat-auth-blocked.webm

Media may expire after 12 hours. View in Vorflux Session for permanent access.


Session Details

@Dhravya Dhravya marked this pull request as draft June 27, 2026 04:36
@claude

claude Bot commented Jun 27, 2026

Copy link
Copy Markdown

Claude finished @Dhravya's task in 1m 41s —— View job


PR Review: Memory Source Fallbacks

  • Fetch PR diff and existing review comments
  • Analyze changed files for bugs, security issues, and logic errors
  • Review surrounding code context
  • Submit review with findings

Overview: Adds fallback source attribution chips when memory tool outputs exist but the model doesn't include inline <response source="..."> markup.

Issues found: None — this looks good to ship.

The implementation is clean:

  • URL handling properly sanitized via safeExternalUrl before rendering in href attributes
  • Source IDs validated against SAFE_SOURCE_ID_RE before being used in anchor links
  • Good separation of concerns with the extracted getCitationDisplay helper and hasDisplayMetadata check
  • The buildCitationIndex fallback to match by result.id when citationId is absent handles the edge case correctly
  • The hasInlineSourceAnnotations detection correctly checks for transformed #sm-source: links in parsed output
  • Test coverage added for new code paths (18/18 tests passing)

Score: 10/10

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 27, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supermemory-mcp 865962a Jun 27 2026, 04:55 AM

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6798b56. Configure here.

[messageText, allowedSourceIds],
)
const showMemorySourcesFallback =
citationIndex.size > 0 && !hasInlineSourceAnnotations

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fallback gate ignores text runs

High Severity

hasInlineSourceAnnotations parses all text parts as one space-joined string, while the answer UI parses each contiguous text run separately and stops at tool and other non-text parts. Response markup split across those boundaries can look fully parsed in the gate check but produce no citation links in any rendered run, so showMemorySourcesFallback stays off and memory sources vanish despite a populated citationIndex.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6798b56. Configure here.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overview: Adds fallback source attribution chips when memory tool outputs exist but the model doesn't include inline <response source="..."> markup.

Issues found: None — this looks good to ship.

The implementation is clean:

  • URL handling properly sanitized via safeExternalUrl before rendering in href attributes
  • Source IDs validated against SAFE_SOURCE_ID_RE before being used in anchor links
  • Good separation of concerns with the extracted getCitationDisplay helper and hasDisplayMetadata check
  • The buildCitationIndex fallback to match by result.id when citationId is absent handles the edge case described in the PR
  • The hasInlineSourceAnnotations detection logic correctly checks for transformed #sm-source: links in the parsed output, ensuring fallback chips only appear when needed
  • Test coverage added for the new code paths (18/18 tests passing)

Score: 10/10

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 27, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app 865962a Commit Preview URL

Branch Preview URL
Jun 27 2026, 04:56 AM

@vorflux

vorflux Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Cursor Bugbot finding addressed in 865962a.

The fallback gate now uses the same contiguous text/source-url run helper as AgentMessage rendering, so response markup split across a tool boundary no longer suppresses fallback sources. Contiguous text -> source-url -> text runs still count as renderable inline citation coverage.

Verification:

  • Focused bun tests for chat-memory-tools and source-annotations: 19/19 pass:
  • Explicit-file Biome pass:
  • Git diff whitespace check pass:
  • Production build pass:
  • UI evidence:
  • UI evidence:
  • UI evidence:
  • Recording:

Attached Images and Videos

[supermemory-bugbot-source-run-test.log]

[supermemory-bugbot-source-run-biome.log]

[supermemory-bugbot-source-run-build.log]

source-annotation-agent-message-local-backend-direct.png

source-annotation-agent-message-local-backend-history.png

source-annotation-agent-message-inline-hover-clean.png

🎥 View recording: source-annotation-agent-message-local-backend.webm

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