PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

BUG: Memory curator misses upcoming anniversaries across year boundaries and on leap days

Open akhilmodi29 opened this issue 2 weeks ago • 4 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

What happened?

Description

In backend/app/utils/memory_curator.py, _semantic_surface_date() computes whether a semantic event's anniversary is within EVENT_ANNIVERSARY_LOOKAHEAD_DAYS (3 days) of the reference date.

However, the calculation only evaluates event_start.date().replace(year=reference.year):

  1. Year Boundary: If the reference date is in late December (e.g. Dec 30) and an event happened on January 1, the upcoming anniversary on Jan 1 of the following year (2 days away) is calculated as Jan 1 of the current year (delta = -363). This causes the lookahead condition 0 <= delta <= 3 to evaluate to False, prematurely surfacing the memory today instead of on its upcoming anniversary.
  2. Leap Day (Feb 29): When an event occurred on Feb 29, evaluating it in a non-leap year raises a ValueError, which immediately returns reference.isoformat(), discarding the lookahead window instead of falling back to Feb 28.

Steps to Reproduce

  1. Call _semantic_surface_date(reference=date(2026, 12, 30), event_start=datetime(2024, 1, 1)).
  2. Notice the anniversary is 2 days away (January 1, 2027), which is within the 3-day lookahead window.
  3. Observe output is "2026-12-30" (today) instead of "2027-01-01".

Expected Behavior

The function should evaluate the next upcoming anniversary in reference.year + 1 when the current year's date has passed, and map leap day anniversaries to Feb 28 in non-leap years.

Proposed Fix

Check reference.year + 1 if anniversary < reference, and catch ValueError to map Feb 29 to Feb 28.

Record

  • [x] I agree to follow this project's Code of Conduct

akhilmodi29 avatar Nov 15 '26 16:11 akhilmodi29

👋 Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)

github-actions[bot] avatar Nov 15 '26 16:11 github-actions[bot]

⚠️ Potential Duplicate Issue (Semantic Match)

This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:

  1. BUG: On Jan 1, "On this day" shows last night's New Year's Eve photos as "1 year ago today" (#1632, open) https://github.com/AOSSIE-Org/PictoPy/issues/1632 Similarity: 66.5%

  2. fix: date-based memories are misclassified as location memories (#1229, open) https://github.com/AOSSIE-Org/PictoPy/issues/1229 Similarity: 59.7%

Please review before proceeding.

github-actions[bot] avatar Nov 15 '26 16:11 github-actions[bot]

Link your account with Gitcord

Thanks for opening this issue, @akhilmodi29!

To receive Discord notifications and contributor tracking for this organization:

  1. Join Discord: https://discord.gg/hjUhu33uAn
  2. In Discord, run /link akhilmodi29
  3. Paste the verification code into your GitHub bio (or a public gist)
  4. Click Verify in Discord (or run /verify-link akhilmodi29)

Once linked, Gitcord can notify you about assignments, mentions, and more.

— Posted by Gitcord

gitcordapp[bot] avatar Nov 15 '26 16:11 gitcordapp[bot]

Hey @rohan-pandeyy, I would like to work on this issue. I have successfully reproduced the errors and have a fix ready. I have also tested the fix, and it is working as expected.

Could you please assign this issue to me?

My proposed solution:

Modify the existing _semantic_surface_date() function inside backend/app/utils/memory_curator.py.

The updated function would look like this:

def _semantic_surface_date(reference: date, event_start: datetime) -> str:
    """
    Surface on the event's upcoming anniversary, else today.

    An anniversary within the next few days is worth waiting for; anything
    else is a rediscovery and should show now.
    """
    try:
        anniversary = event_start.date().replace(year=reference.year)

        if anniversary < reference:
            anniversary = event_start.date().replace(year=reference.year + 1)
    except ValueError:
        # Feb 29 in a non-leap reference year.
        anniversary = event_start.date().replace(year=reference.year, day=28)

    delta = (anniversary - reference).days
    if 0 <= delta <= EVENT_ANNIVERSARY_LOOKAHEAD_DAYS:
        return anniversary.isoformat()
    return reference.isoformat()

sayxnn17 avatar Nov 15 '26 20:11 sayxnn17