# Badge count accurately reflects number of unread or active items

- **Pattern:** `ab-001368` (`extension-ux-performance.badge-notifications.badge-count-accurate`)
- **Severity:** medium
- **Lifecycle:** active
- **Last modified:** 2026-04-18
- **Canonical URL:** https://auditbuffet.com/patterns/ab-001368
- **License:** CC-BY-4.0 — attribute to AuditBuffet Pattern Catalog (https://auditbuffet.com/patterns/ab-001368)

## Why it matters

A badge count that drifts from reality undermines the entire notification contract. When bulk-delete actions, crash-interrupted decrements, or missed code paths leave the counter stale, users open the popup expecting unread items and find none — or worse, miss real items because the badge showed zero. ISO 25010:2011 functional-suitability.functional-correctness applies directly: the badge's job is accurate representation of state, and independent increment/decrement counters are structurally incapable of guaranteeing that.

## Severity rationale

Medium because stale badge counts cause user confusion and erode trust in the extension's reliability, but do not expose security risk or block core functionality.

## Remediation

Derive the badge count from a single source of truth on every update rather than maintaining a separate counter. Tie badge updates to `chrome.storage.onChanged` so any write to the underlying data automatically recalculates the displayed count.

```js
async function updateBadge() {
  const { items } = await chrome.storage.local.get(['items']);
  const unread = (items ?? []).filter(item => !item.read).length;
  chrome.action.setBadgeText({
    text: unread > 0 ? String(unread) : ''
  });
}

chrome.storage.onChanged.addListener(() => updateBadge());
```

Never increment or decrement a counter variable directly — every code path that modifies items must go through storage, and `onChanged` handles the badge automatically.

## Detection

**The detection method for this pattern is part of AuditBuffet Pro.**

The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the [Extension UX & Performance Audit](https://auditbuffet.com/audits/extension-ux-performance). The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.

## External references

- iso-25010 functional-suitability.functional-correctness

Taxons: data-integrity, user-experience

HTML version: https://auditbuffet.com/patterns/ab-001368
