omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(database): prevent read mutation and harden date boundaries in action item codec ($50 proposed)

Open Dragonire9 opened this issue 1 month ago • 2 comments

Problem Description

The action item normalization layer (backend/database/action_item_codec.py) processes task payloads across all database reads and writes (prepare_action_item_for_read and prepare_action_item_for_write). However, it has several critical safety and testability issues:

  1. In-place Input Mutation on Reads: prepare_action_item_for_read directly mutates the passed dictionary (action_item_data.pop(...), action_item_data.setdefault(...), key assignment). Callers passing cached document dictionaries or immutable mappings experience unexpected side effects and cache pollution.
  2. Unhandled Exceptions in Read Date Parsing: In prepare_action_item_for_read, converting timestamp objects using .timestamp() can raise unhandled (OverflowError, ValueError, OSError) on boundary dates or platform C-runtime limits. Furthermore, ISO string dates stored in Firestore are left as raw strings rather than normalized to UTC datetimes.
  3. Status String Whitespace: prepare_action_item_for_write does not strip whitespace from string status values (e.g. ' completed '), leading to spurious validation errors or desynchronized completed booleans.
  4. Provenance Array Type Invariant: Neither read nor write normalizers safeguard provenance against non-list inputs (e.g. string or dict values), which breaks downstream consumers expecting list iterables.
  5. Zero Dedicated Unit Tests: backend/database/action_item_codec.py currently has zero unit test coverage in backend/tests/unit/test_action_item_codec.py.

Proposed Solution

  1. Input Immutability: Shallow-copy action_item_data = dict(action_item_data) in prepare_action_item_for_read, protecting caller dictionaries from in-place mutation.
  2. Resilient Read Date Normalization: Parse ISO strings, Firestore timestamp objects, and datetimes into timezone-aware UTC datetimes, wrapped in a try/except (OverflowError, ValueError, OSError, TypeError) boundary to prevent read endpoint 500s.
  3. Status Sanitization: Strip status strings in prepare_action_item_for_write.
  4. Provenance Type Defense: Coerce malformed/non-list provenance values to [].
  5. Comprehensive Unit Tests: Add 17 dedicated unit tests in backend/tests/unit/test_action_item_codec.py covering immutability, default injection, status/completed inference, date parsing boundaries, and write validation.

Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])

Dragonire9 avatar Oct 16 '26 17:10 Dragonire9

Hi @josancamon19 @kodjima33 — is the full change in this issue still available as a paid contribution?

I mean all five parts together: read-input immutability, UTC date normalization and exception boundaries, whitespace-safe write status, list-only provenance on reads and writes, and the 17 dedicated unit tests described above.

I see another contributor has a PR open, so I want to avoid overlapping an agreed assignment. If there is remaining work, could you confirm the target branch and acceptance criteria, whether the proposed $50 is approved and in which currency, and who can take it on?

I'm based in mainland China. Is a lawful same-name fiat payout available, and who covers payment fees? With those details I can confirm scope and timing before starting. Thanks!

ayqy avatar Oct 16 '26 22:10 ayqy

Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏

undivisible avatar Oct 22 '26 12:10 undivisible