[Bounty proposal] fix(database): prevent read mutation and harden date boundaries in action item codec ($50 proposed)
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:
- In-place Input Mutation on Reads:
prepare_action_item_for_readdirectly 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. - 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. - Status String Whitespace:
prepare_action_item_for_writedoes not strip whitespace from stringstatusvalues (e.g.' completed '), leading to spurious validation errors or desynchronizedcompletedbooleans. - Provenance Array Type Invariant: Neither read nor write normalizers safeguard
provenanceagainst non-list inputs (e.g. string or dict values), which breaks downstream consumers expecting list iterables. - Zero Dedicated Unit Tests:
backend/database/action_item_codec.pycurrently has zero unit test coverage inbackend/tests/unit/test_action_item_codec.py.
Proposed Solution
- Input Immutability: Shallow-copy
action_item_data = dict(action_item_data)inprepare_action_item_for_read, protecting caller dictionaries from in-place mutation. - 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. - Status Sanitization: Strip
statusstrings inprepare_action_item_for_write. - Provenance Type Defense: Coerce malformed/non-list
provenancevalues to[]. - Comprehensive Unit Tests: Add 17 dedicated unit tests in
backend/tests/unit/test_action_item_codec.pycovering immutability, default injection, status/completed inference, date parsing boundaries, and write validation.
Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])
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!
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! 🙏