Skip to content

[Bounty proposal] fix(action-items): sort and score aggregation crashes with TypeError / AttributeError on ISO string or naive timestamps ( proposed) #22181

Closed as not planned

Description

@Dragonire9

Product impact

  • Primary loop layer: action items listing and scoring (GET /v1/action-items, GET /v1/dev/user/action-items, GET /v2/integrations/{app_id}/user/tasks, MCP get_action_items, get_scores, and get_pending_apple_reminders_sync).
  • When an action item document in Firestore contains an ISO string due_at or created_at (from client integrations, webhook syncs, or batch migrations) or an offset-naive datetime, calling _action_item_list_sort_key in �ackend/database/action_items.py raises an unhandled exception:
    • TypeError: '<' not supported between instances of 'datetime.datetime' and 'str' when comparing ISO string due_at with datetime objects.
    • TypeError: can't compare offset-naive and offset-aware datetimes when comparing naive datetime due_at with aware datetime / default.
    • AttributeError: 'str' object has no attribute 'timestamp' when attempting to invoke .timestamp() on string created_at.
  • These crashes fatal-crash all caller endpoints with an unhandled HTTP 500 for the user.
  • Additionally, get_pending_apple_reminders_sync crashes with TypeError when sorting synced_items on string updated_at, and get_scores drops string/naive timestamps from daily/weekly scores because of strict isinstance(..., datetime).

Describe the bug
On main:
In �ackend/database/action_items.py:
python def _action_item_list_sort_key(item: Dict[str, Any]) -> tuple: return ( bool(item.get('completed')), item.get('due_at') is None, item.get('due_at') or datetime.max.replace(tzinfo=timezone.utc), -((item.get('created_at') or datetime.min.replace(tzinfo=timezone.utc)).timestamp()), )
If item['due_at'] is an ISO formatted string or offset-naive datetime, sorting a list containing mixed datetime and string timestamps immediately crashes with TypeError.
If item['created_at'] is an ISO string, .timestamp() throws AttributeError.

To reproduce (offline, synthetic data)
`python
from datetime import datetime, timezone
from database.action_items import _action_item_list_sort_key

1. TypeError on string due_at vs datetime

items = [
{'id': '1', 'completed': False, 'due_at': '2026-10-25T14:00:00Z', 'created_at': datetime.now(timezone.utc)},
{'id': '2', 'completed': False, 'due_at': datetime(2026, 10, 26, 14, 0, tzinfo=timezone.utc), 'created_at': datetime.now(timezone.utc)},
]
sorted(items, key=_action_item_list_sort_key)

TypeError: '<' not supported between instances of 'str' and 'datetime.datetime'

2. AttributeError on string created_at

item = {'id': '3', 'completed': False, 'due_at': None, 'created_at': '2026-10-25T14:00:00Z'}
_action_item_list_sort_key(item)

AttributeError: 'str' object has no attribute 'timestamp'

`

Expected behavior
_action_item_list_sort_key, synced_items.sort, and get_scores coerce due_at, created_at, and updated_at to timezone-aware UTC datetimes using coerce_utc_datetime so that mixed representations (ISO strings, naive datetimes, aware datetimes) sort stably without raising exceptions.

Fix

  • Coerce due_at and created_at in _action_item_list_sort_key with coerce_utc_datetime.
  • Coerce updated_at in get_pending_apple_reminders_sync with coerce_utc_datetime.
  • Coerce due_at and created_at in get_scores.
  • Comprehensive hermetic regression unit tests in ests/unit/test_action_items_null_timestamps.py.
    PR follows immediately.

Proposed bounty: US. Claim to: https://paypal.me/Dragonire9 ([email protected]).

Activity

  1. moved this from Someday to In progress in omi TODO / bountieson Oct 18, 2026
  2. undivisible commented on Oct 22, 2026

    @undivisible
    Collaborator

    We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now. The fix already landed in #22359 — thanks for the fix! 🙏

  3. moved this from In progress to In review in omi TODO / bountieson Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions