[Bounty proposal] fix(preference-tools): guard None replace_memory_id and validate non-empty preference ($50 proposed)
Summary
In backend/utils/retrieval/tools/preference_tools.py, save_user_preference_tool() records learned preferences and corrections into the knowledge ledger or canonical memory store.
Runtime Crashes & Vulnerabilities
-
Fatal
AttributeError: 'NoneType' object has no attribute 'strip': At line 218:replacement = replace_memory_id.strip()When optional parameter
replace_memory_idis supplied asNone(standard for LangChain tools when optional arguments are not explicitly given a string),replace_memory_id.strip()crashes with an unhandledAttributeErroroutside any exception boundary, terminating the tool call. -
AttributeError: 'NoneType' object has no attribute 'split'in_write_provenance(): At line 111:normalized_preference = ' '.join(preference.split())If
preferenceisNone, calling.split()raisesAttributeError. -
Writing Empty / Whitespace-only Preferences: Empty or whitespace strings passed as
preferenceare currently not validated upfront, allowing blank or meaningless memory items to be written to Firestore and the knowledge ledger.
Fix
- Defensively normalize
replace_memory_idviastr(replace_memory_id or '').strip(). - Validate
preferenceupfront (if not preference or not isinstance(preference, str) or not preference.strip(): return "Error: Preference content cannot be empty"). - In
_write_provenance(), normalizepreferencesafely viastr(preference or '').split(). - Annotate
replace_memory_id: Optional[str] = ""for typing correctness. - Add comprehensive hermetic unit tests in
backend/tests/unit/test_preference_tools.py.
Bounty Proposal
- Proposed tier: $50 (Targeted bug fix + unit test coverage)
- Settlement: Base Mainnet USDC / Stripe / Singapore Card
Resolved in PR #23135.
Guarded replace_memory_id against None values, added upfront non-empty validation for preference, ensured robust user_id resolution, and added full hermetic unit test coverage (8/8 passing) in backend/tests/unit/test_preference_tools.py.
Payout address (Base USDC): 0xb95e2AD8E9D9e9BF902c7531577Cd0E1ceB203D4
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! 🙏