-
Notifications
You must be signed in to change notification settings - Fork 522
fix: Resolve #1507 - fix(memory-write): preserve provenance and reject failed updates (#770) #1519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||||||
| ```python | ||||||||||||||
| import re | ||||||||||||||
| from enum import Enum | ||||||||||||||
|
|
||||||||||||||
| class MemoryStatus(Enum): | ||||||||||||||
| SUCCESSFUL_UPLOAD_STATUSES = ['success', 'ok', 'uploaded', 'uploaded successfully'] | ||||||||||||||
|
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win Fix Enum type error and align with upstream canonical statuses. There are two issues with
Consider importing the canonical set directly to avoid duplication and crashes, or correctly using the 🐛 Proposed fix (using direct import)-class MemoryStatus(Enum):
- SUCCESSFUL_UPLOAD_STATUSES = ['success', 'ok', 'uploaded', 'uploaded successfully']
+from memanto.app.services.memory_write_service import SUCCESSFUL_UPLOAD_STATUSES🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| class Memory: | ||||||||||||||
| def __init__(self, id, provenance, content): | ||||||||||||||
| self.id = id | ||||||||||||||
| self.provenance = provenance | ||||||||||||||
| self.content = content | ||||||||||||||
| self.status = None | ||||||||||||||
|
|
||||||||||||||
| def update(self, new_content, new_provenance=None, new_status=None): | ||||||||||||||
| if new_status and new_status.lower() not in MemoryStatus.SUCCESSFUL_UPLOAD_STATUSES: | ||||||||||||||
| raise MemoryError("Failed update") | ||||||||||||||
|
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win Enforce validation for missing/null upload statuses. The condition Additionally, iterating over an Enum member directly raises a 🐛 Proposed fix- if new_status and new_status.lower() not in MemoryStatus.SUCCESSFUL_UPLOAD_STATUSES:
+ if not new_status or new_status.lower() not in MemoryStatus.SUCCESSFUL_UPLOAD_STATUSES.value:
raise MemoryError("Failed update")(Note: If you adopt the direct import of 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| if new_provenance: | ||||||||||||||
| self.provenance = new_provenance | ||||||||||||||
| self.content = new_content | ||||||||||||||
| if new_status: | ||||||||||||||
| self.status = new_status | ||||||||||||||
|
|
||||||||||||||
| def update_memory(memory, new_content, new_provenance=None, new_status=None): | ||||||||||||||
| memory.update(new_content, new_provenance, new_status) | ||||||||||||||
| return memory | ||||||||||||||
|
|
||||||||||||||
| # Example usage: | ||||||||||||||
| memory = Memory(1, "initial provenance", "initial content") | ||||||||||||||
| updated_memory = update_memory(memory, "new content", "new provenance", "success") | ||||||||||||||
| print(updated_memory.provenance) # Output: new provenance | ||||||||||||||
| print(updated_memory.status) # Output: success | ||||||||||||||
|
|
||||||||||||||
| try: | ||||||||||||||
| update_memory(memory, "new content", new_status="failed") | ||||||||||||||
| except MemoryError as e: | ||||||||||||||
| print(e) # Output: Failed update | ||||||||||||||
| ``` | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win Remove markdown closing tick. This will cause a 🐛 Proposed fix-```📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Remove markdown formatting and import the domain exception.
This file contains markdown code block syntax (````python
) which will cause aSyntaxError`.Additionally, `import re` is unused, and the domain-specific `MemoryError` is not imported, causing the code to raise Python's built-in out-of-memory exception instead.
🐛 Proposed fixes
📝 Committable suggestion
🤖 Prompt for AI Agents