Skip to content

Commit 91608df

Browse files
committed
fix(inbox-worker): don't Nak on a CountDocuments failure after the status write commits
Per PR #363 review: in UpdateUserStatus the guarded UpdateOne already commits the status write before the MatchedCount==0 branch runs. That branch's CountDocuments is only a logging aid (absent-account vs stale-event), so returning its error caused a pointless Nak that re-ran the already-applied, idempotent write. Downgrade the CountDocuments failure to a warn and continue (return nil) instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012X9qhQT4NwmCHjdndwNtFD
1 parent 249c2de commit 91608df

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

inbox-worker/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ func (s *mongoInboxStore) UpdateUserStatus(ctx context.Context, account, statusT
186186
return fmt.Errorf("update user status for %q: %w", account, err)
187187
}
188188
if res.MatchedCount == 0 {
189-
// No match means either the account isn't on this site (expected no-op for the
190-
// all-sites fan) or a stale/duplicate event lost the guard. Distinguish so a
191-
// genuinely-missing account stays visible instead of being silently swallowed.
189+
// The UpdateOne above already committed; MatchedCount==0 is a correct no-op (account not on
190+
// this site, or a stale event the guard rejected). CountDocuments only picks the warn
191+
// message, so a failure here must not Nak/retry an already-applied write — log and move on.
192192
count, cerr := s.userCol.CountDocuments(ctx, bson.M{"account": account})
193-
if cerr != nil {
194-
return fmt.Errorf("check user existence for %q: %w", account, cerr)
195-
}
196-
if count == 0 {
193+
switch {
194+
case cerr != nil:
195+
slog.WarnContext(ctx, "user existence check failed, skipping unknown-account log", "account", account, "error", cerr)
196+
case count == 0:
197197
slog.WarnContext(ctx, "user_status_updated for unknown account, skipping", "account", account)
198198
}
199199
}

0 commit comments

Comments
 (0)