Skip to content

fix: show the newest turns first on the Memories page - #305

Merged
cmdaltctr merged 1 commit into
mainfrom
fix/memories-timeline-pairing
Nov 21, 2026
Merged

cmdaltctr merged 1 commit into
mainfrom
fix/memories-timeline-pairing

Conversation

@cmdaltctr

@cmdaltctr cmdaltctr commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

What was wrong

Since skill learning, capture stores the host message ID in a memory's metadata.promptId, not the prompt row ID. The Memories list paired memory and prompt only on that field, so no memory since early November found its prompt. Unpaired items sorted after every pair, so page 1 stopped at 4 November.

Fix

  • Pair on user_prompts.linked_memory_id; keep metadata.promptId as fallback for older rows.
  • Sort pairs and single items together by time.
  • Cascade delete of a memory also deletes the prompt linked to it (same root cause left prompts behind).

Evidence

  • 3 new regression tests in tests/memory-timeline-orphan.test.ts; each failed before the fix.
  • Same pairing rule applied read-only to a real store: paired memories 234 → 4,147, page 1 opens on the newest turns.
  • bun run ci:local passed (exit 0).

Summary by CodeRabbit

  • Bug Fixes
    • Memory timelines now place linked memories and prompts together, ordered by the memory’s creation time. Standalone memories and prompts appear in order by their own creation times, rather than being grouped after linked items.
    • Deleting a memory with cascade enabled now also removes prompts linked to it, including when the prompt ID is not recorded in the memory’s metadata.

Since skill learning, capture stores the host message ID in a memory's
metadata.promptId instead of the prompt row ID. The Memories list paired a
memory with its prompt only on that field, so no new memory found its
prompt. Unpaired items sorted after every pair, and page 1 stopped at the
last pair from early November.

- Pair on user_prompts.linked_memory_id, with metadata.promptId as a
  fallback for older rows.
- Sort pairs and single items together by time.
- Cascade delete of a memory also deletes the prompt linked to it, so
  newer memories no longer leave their prompt behind.
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Memory timelines now pair and order linked memories and prompts using their linked identifiers. Cascade deletion also removes prompts linked to a memory and reports whether a prompt was deleted.

Changes: Memory and prompt linkage

Layer / File(s) Summary
Timeline pairing and ordering
src/services/api/memory-list.ts, tests/memory-timeline-orphan.test.ts
Timeline listing pairs memories and prompts through their linked identifiers. It sorts paired and standalone items by timestamp. Tests cover linked-pair and standalone-item ordering.
Cascade deletion of linked prompts
src/services/storage/user-prompts.ts, src/services/api/memory-write.ts, tests/memory-timeline-orphan.test.ts, tests/web-api-memory-characterisation.test.ts
Cascade deletion removes prompts linked to a memory and reports whether a prompt was deleted. Tests cover linked-prompt deletion and stub restoration.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: Minimal · up to 6c75e

The change fixes memory timeline ordering and removes linked prompts when a memory is deleted. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: show the newest turns first on the Memories page" matches the main change. The objectives and file summaries show the Memories timeline now pairs memories with prompts via linked_memor…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: show the newest turns first on the Memories page" matches the main change. The objectives and file summaries show the Memories timeline now pairs memories with prompts via linked_memory_id and sorts paired and unpaired items together by time, so the newest turns appear first. The title is specific and does not name files or use vague terms. It does not mention the cascade-delete change, but that is secondary to the main fix.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 87c7421 and 6c75e9d.

Files selected for processing: 5

  • src/services/api/memory-list.ts
  • src/services/api/memory-write.ts
  • src/services/storage/user-prompts.ts
  • tests/memory-timeline-orphan.test.ts
  • tests/web-api-memory-characterisation.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@cmdaltctr
cmdaltctr merged commit 1c4851f into main Nov 21, 2026
5 of 6 checks passed
@cmdaltctr
cmdaltctr deleted the fix/memories-timeline-pairing branch November 21, 2026 23: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