Skip to content

BUG: Incorrect tagging on memory cards for 'Dates' & 'Location' issue #1178#1267

Open
codex-yv wants to merge 4 commits into
AOSSIE-Org:mainfrom
codex-yv:main
Open

BUG: Incorrect tagging on memory cards for 'Dates' & 'Location' issue #1178#1267
codex-yv wants to merge 4 commits into
AOSSIE-Org:mainfrom
codex-yv:main

Conversation

@codex-yv
Copy link
Copy Markdown

@codex-yv codex-yv commented May 12, 2026

Addressed Issues: #1178

BUG: Incorrect tagging on memory cards for 'Dates' & 'Location'

Screenshots/Recordings:

TODO: Before and after screen shots are added at issue #1178

Additional Notes:

Please refer to the issue number #1178 for detailed description and implementation of the issue.

AI Usage Disclosure:

I used Antigravity to modify the frontend code and thoroughly reviewed the changes it made.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: TODO

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced memory type detection to accurately distinguish location-based memories from date-based ones.
    • Improved handling and display of memories that lack location information.
  • New Features

    • Added a location memory count metric to API responses, providing better insights into the distribution of your memories.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

Warning

Rate limit exceeded

@codex-yv has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 50 minutes and 39 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e3d54b03-9195-4c14-bd38-1aabf7a15307

📥 Commits

Reviewing files that changed from the base of the PR and between 4c42528 and 4f64a0e.

📒 Files selected for processing (7)
  • backend/app/routes/memories.py
  • backend/app/utils/memory_clustering.py
  • docs/backend/backend_python/openapi.json
  • frontend/src/api/api-functions/memories.ts
  • frontend/src/api/apiEndpoints.ts
  • frontend/src/components/Memories/MemoriesPage.tsx
  • frontend/src/hooks/useMemories.tsx

Walkthrough

This pull request refactors how memories are classified as date-based or location-based. The backend now uses location_name nullability instead of geographic coordinates and adds a total_location aggregate to API responses. Frontend types and components are updated to match the new classification method throughout the memories UI.

Changes

Memory Classification via Location Name Nullability

Layer / File(s) Summary
Backend memory data model with nullable location_name
backend/app/utils/memory_clustering.py
Introduces find_total_location_memories utility to count memories with non-null location_name, and changes _create_simple_memory to assign None instead of empty string when location data is absent.
Backend API response with total_location aggregate
backend/app/routes/memories.py
Imports and uses the new utility to compute a total_location count from generated memories and extends the /api/memories/generate response with this aggregate field.
Frontend type contracts for nullable location_name
frontend/src/api/api-functions/memories.ts
Updates Memory.location_name and LocationCluster.location_name TypeScript field types from string to string | null.
Frontend components using location_name classification
frontend/src/components/Memories/MemoryCard.tsx, frontend/src/components/Memories/MemoriesPage.tsx
Refactors MemoryCard to determine date-based status via location_name === null; updates MemoriesPage to consume the new total_location aggregate, reclassify memories in filter logic using location_name nullability, and reconstruct onThisDayMeta conditionally.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client (Frontend)
  participant API as API /generate
  participant Cluster as Memory Clustering
  participant Response as Response Builder
  
  Client->>API: Request memory generation
  API->>Cluster: Generate clustered memories
  Cluster->>Cluster: Create memory with location_name: string | null
  Cluster->>Response: Return memories array
  Response->>Response: Compute total_location via find_total_location_memories()
  Response->>Client: Return {memories, total_location}
  Client->>Client: Use total_location for location count
  Client->>Client: Classify memories by location_name !== null
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

Python, TypeScript/JavaScript

🐰 Hopping through the code with glee,
Location names now null or be,
No more geo coordinates to check,
Nullability flows from back to tech,
Memories sorted without a speck!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing incorrect tagging of memory cards for 'Dates' and 'Location', which is the core objective addressed across all modified files.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/app/routes/memories.py (1)

166-183: 🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

Add regression tests for total_location and null-based classification.

This endpoint now depends on location_name nullability for classification/counting. Please add API-level tests that cover mixed memories and assert total_location, memory_count, and date/location split consistency.

As per coding guidelines: "Ensure that test code is automated, comprehensive, and follows testing best practices" and "Verify that all critical functionality is covered by tests".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/routes/memories.py` around lines 166 - 183, Add API-level tests
for the memories endpoint that exercise mixed memory records including some with
location_name set to null to verify classification and counts; call the route
(using the project's test client) with a payload or fixture containing mixed
types, then assert response["data"]["memory_count"] equals the number sent,
response["total_location"] equals the value returned by the server-side helper
(find_total_location_memories), and that the location/date breakdown in the
message and in computed counts (location_count/date_count) matches counts
derived from records where location_name nulls are treated as non-location;
ensure tests are automated, cover null-based classification, and fail if
total_location or the location/date split are inconsistent.
🧹 Nitpick comments (1)
frontend/src/components/Memories/MemoriesPage.tsx (1)

149-151: ⚡ Quick win

Replace new any casts with narrow payload typing.

The added as any usages hide API-shape drift for today, years, and total_location. A narrow local type keeps these checks compile-time safe.

Suggested refactor
+type OnThisDayPayload = {
+  today?: string;
+  years?: number[];
+};
+
+type AllMemoriesPayload = {
+  total_location?: number;
+};

-const onThisDayMeta = onThisDayQuery.data?.data
+const onThisDayData = onThisDayQuery.data?.data as OnThisDayPayload | undefined;
+const onThisDayMeta = onThisDayData
   ? {
-      today: (onThisDayQuery.data.data as any).today,
-      years: (onThisDayQuery.data.data as any).years,
+      today: onThisDayData.today,
+      years: onThisDayData.years,
     }
   : null;

+const allMemoriesPayload = allMemoriesQuery.data as AllMemoriesPayload | undefined;
 const locationCount =
-  (allMemoriesQuery.data as any)?.total_location ??
+  allMemoriesPayload?.total_location ??
   memoriesWithMultipleImages(allMemories).filter((m) => m.location_name !== null)
     .length;

As per coding guidelines: "Avoid 'any', use explicit types."

Also applies to: 224-226

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/Memories/MemoriesPage.tsx` around lines 149 - 151,
The code uses wide casts "(onThisDayQuery.data.data as any)" for fields today,
years and total_location; define a narrow TypeScript interface (e.g.,
OnThisDayPayload with typed today, years, total_location) and use it instead of
any by applying the interface to the query result (or to a local const typed as
that interface) so accesses in MemoriesPage (references: onThisDayQuery, today,
years, total_location) are compile-time checked; update the two places noted
(around the current lines and the occurrences at 224-226) to use the new type
rather than any.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/app/utils/memory_clustering.py`:
- Around line 108-113: The function find_total_location_memories currently
indexes memory["location_name"] which can raise KeyError for items missing that
key; update the loop to safely access the field (e.g., use
memory.get("location_name") or check "location_name" in memory) and only
increment tlm when the safe access returns a non-None value, leaving the rest of
the function behavior unchanged; reference the function name
find_total_location_memories and the memory variable in your change.

---

Outside diff comments:
In `@backend/app/routes/memories.py`:
- Around line 166-183: Add API-level tests for the memories endpoint that
exercise mixed memory records including some with location_name set to null to
verify classification and counts; call the route (using the project's test
client) with a payload or fixture containing mixed types, then assert
response["data"]["memory_count"] equals the number sent,
response["total_location"] equals the value returned by the server-side helper
(find_total_location_memories), and that the location/date breakdown in the
message and in computed counts (location_count/date_count) matches counts
derived from records where location_name nulls are treated as non-location;
ensure tests are automated, cover null-based classification, and fail if
total_location or the location/date split are inconsistent.

---

Nitpick comments:
In `@frontend/src/components/Memories/MemoriesPage.tsx`:
- Around line 149-151: The code uses wide casts "(onThisDayQuery.data.data as
any)" for fields today, years and total_location; define a narrow TypeScript
interface (e.g., OnThisDayPayload with typed today, years, total_location) and
use it instead of any by applying the interface to the query result (or to a
local const typed as that interface) so accesses in MemoriesPage (references:
onThisDayQuery, today, years, total_location) are compile-time checked; update
the two places noted (around the current lines and the occurrences at 224-226)
to use the new type rather than any.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c3535120-8fdb-495b-bd13-36e2f82731c6

📥 Commits

Reviewing files that changed from the base of the PR and between f8ec976 and 4c42528.

📒 Files selected for processing (5)
  • backend/app/routes/memories.py
  • backend/app/utils/memory_clustering.py
  • frontend/src/api/api-functions/memories.ts
  • frontend/src/components/Memories/MemoriesPage.tsx
  • frontend/src/components/Memories/MemoryCard.tsx

Comment on lines +108 to +113
def find_total_location_memories(data:list) -> int:
tlm = 0 # total location memories
for memory in data:
if memory["location_name"] != None:
tlm +=1
return tlm
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard aggregation against missing location_name keys.

Using memory["location_name"] can raise KeyError and fail the response build if any item is missing that key. Prefer safe access here.

Suggested fix
-def find_total_location_memories(data:list) -> int:
-    tlm = 0 # total location memories
+def find_total_location_memories(data: list) -> int:
+    tlm = 0  # total location memories
     for memory in data:
-        if memory["location_name"] != None:
-            tlm +=1
-    return tlm 
+        if memory.get("location_name") is not None:
+            tlm += 1
+    return tlm
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/utils/memory_clustering.py` around lines 108 - 113, The function
find_total_location_memories currently indexes memory["location_name"] which can
raise KeyError for items missing that key; update the loop to safely access the
field (e.g., use memory.get("location_name") or check "location_name" in memory)
and only increment tlm when the safe access returns a non-None value, leaving
the rest of the function behavior unchanged; reference the function name
find_total_location_memories and the memory variable in your change.

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