Skip to content

Fix source messages silently dropping updates from mutable sources - #19

Merged
pufit merged 1 commit into
ClickHouse:mainfrom
groeneai:fix/source-messages-upsert-on-metadata-change
Mar 30, 2026
Merged

pufit merged 1 commit into
ClickHouse:mainfrom
groeneai:fix/source-messages-upsert-on-metadata-change

Conversation

@groeneai

Copy link
Copy Markdown
Contributor

Summary

  • GitHub notifications are mutable — when someone @mentions you on a PR you authored, GitHub updates the existing notification's reason from "author" to "mention" (same notification ID)
  • The previous INSERT OR IGNORE silently dropped these updates since the (source, id) primary key already existed, making mentions/tags invisible to consumer cursors
  • Now detects when an existing record's metadata or content has changed, deletes the old row, and re-inserts with a new rowid — so consumers see it as a new unread message
  • Unchanged records are still silently skipped (no extra queries for the common case of no changes)

Problem

The source_messages table uses PRIMARY KEY (source, id). GitHub notification IDs are stable per thread — when a notification's reason changes (e.g. author → mention), the API returns the same ID with updated fields. INSERT OR IGNORE skipped these entirely.

Before fix: 55 stored messages — 51 author, 3 comment, 1 assign, 0 mention
Live GitHub API: 10 mention notifications (same IDs as stored author records)

Implementation

In insert_source_messages():

  1. Before inserting, check if (source, id) already exists
  2. If it exists with identical metadata + content → skip (current behavior, no regression)
  3. If it exists with different metadata or content → DELETE old row, then INSERT new one
  4. The new row gets a higher rowid, making it visible to consumer cursors that already read the old version

Test plan

  • All 326 existing tests pass
  • Deployed and verified: Nerve restarted, GitHub source sync registered, next run scheduled
  • Verified via DB inspection that the 10 "mention" notifications will be re-inserted on next sync cycle

🤖 Generated with Claude Code

GitHub notifications are mutable — when someone @mentions you on a PR
you authored, GitHub updates the existing notification's `reason` field
from "author" to "mention" (same notification ID). The previous
INSERT OR IGNORE silently dropped these updates since the (source, id)
primary key already existed, making mentions invisible to consumers.

Now checks if an existing record has different metadata or content
before inserting. If changed, deletes the old record and re-inserts
with a new rowid so consumer cursors see it as a new unread message.
Unchanged records are still silently skipped (no noise).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants