~ololduck/Frogue
Fix Summary: Remote Note Attachment Bug
Problem
Incoming remote notes with attachments were being incorrectly stored. The attachments were assigned to local ap_notes instead of the actual ap_remote_notes, causing either:
- FK violations (silent failures) when no local note had that ID
- Wrong attachments appearing on unrelated local notes when IDs collided
Root Cause
The attachments table had no ap_remote_note_id column. When processing remote notes, the code used Owner::ApNote(remote_note_id), which set the ap_note_id FK (pointing to local ap_notes) to a remote note ID.
Changes Made
1. Database Migration (migration/src/m20261025_000028_add_remote_note_id_to_attachments.rs)
- Added
ap_remote_note_idcolumn with FK toap_remote_notes - Updated CHECK constraint to support
ap_remote_noteowner kind - Data migration: automatically fixes existing mislinked attachments
- Detects rows where
owner_kind='ap_note'but the ID actually referencesap_remote_notes - Moves them to the correct
ap_remote_note_idcolumn
- Detects rows where
2. Entity Update (frogue/src/entities/attachments.rs)
- Added
ap_remote_note_id: Option<i64>field - Added
ApRemoteNoterelation
3. Store Layer (frogue/src/attachments/store.rs)
- Added
Owner::ApRemoteNote(i64)variant - Updated
create(),create_remote(),list_for(),count_for()to handle the new variant
4. Bug Fix (frogue/src/activitypub/remote/notes.rs)
- Changed 3 call sites from
Owner::ApNotetoOwner::ApRemoteNote:- Line 212:
handle_createattachment creation - Line 373:
handle_updateattachment deletion - Line 398:
handle_updateattachment creation
- Line 212:
Test Results
✅ note_attachments tests: 6 passed
✅ remote_notes tests: 13 passed
✅ Code compiles successfully
Production Data Impact
The migration will automatically fix the mislinked attachment in production:
- Attachment ID 6 (currently mislinked to local
ap_notes.id=3) will be corrected toap_remote_notes.id=3 - The
owner_kindwill be updated from'ap_note'to'ap_remote_note'
Deployment
- Deploy the new code
- The migration will run automatically on startup
- Existing mislinked attachments will be fixed
- Future remote note attachments will be stored correctly