Problem: User-provided tags in POST /api/bookmarks were being overwritten by LLM-generated tags
Root Cause Flow:
- User sends tags in POST request → Tags saved to DB (line 87 in route.ts)
processBookmark()runs → LLM generates tags (line 120-121 in bookmark-processor.ts)updateBookmarkTags()DELETES all existing tags and replaces with LLM tags (line 123-125 in bookmark-utils.ts)- Result: User tags lost
Key Functions Involved:
app/api/bookmarks/route.ts:84-88- Saves user-provided tagslib/bookmark-processor.ts:118-122- Calls LLM and updates tagslib/bookmark-utils.ts:117-136- Deletes and replaces tags (problem)
Solution: Modified updateBookmarkTags() to merge tags instead of replacing:
// Old: Delete all → Insert new
// New: Fetch existing → Merge with new → Delete all → Insert mergedPattern to Remember: When building APIs that combine user input with automated enrichment:
- Always check if functions downstream are destructive (delete/replace) vs additive
- Tag systems should merge by default, not replace
- Consider idempotency - what happens if the same function is called multiple times?