Repository navigation
Description
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]).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn review
Activity
fix(action-items): coerce naive and string timestamps in sort keys to…
fix(action-items): coerce naive and string timestamps in sort keys to…
fix(action-items): coerce naive and string timestamps in sort keys to…
fix(action-items): coerce naive and string timestamps in sort keys to…
fix(backend): coerce raw ISO-string timestamps on action-item read (#…
fix(action-items): coerce timestamps in apple reminders sync and get_…
undivisible commentedon Oct 22, 2026
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! 🙏
fix(action-items): coerce naive and ISO string timestamps in sort key…
fix(action-items): coerce naive and ISO string timestamps in sort key…