Skip to content

fix: prevent stale header rules with versioned storage meta#88

Open
Kirrrusha wants to merge 2 commits into
mainfrom
fix/update-request-with-tab-windows
Open

fix: prevent stale header rules with versioned storage meta#88
Kirrrusha wants to merge 2 commits into
mainfrom
fix/update-request-with-tab-windows

Conversation

@Kirrrusha
Copy link
Copy Markdown
Collaborator

@Kirrrusha Kirrrusha commented Jan 23, 2026

Summary

Исправляет Windows-специфичную гонку, когда при переключении вкладок и редактировании заголовков могли применяться устаревшие значения (старый снапшот из storage), перезаписывая актуальную конфигурацию.

Changes

  • Атомарное обновление DNR-правил: применяем declarativeNetRequest.updateDynamicRules({ removeRuleIds, addRules }) одним вызовом, чтобы избежать гонки remove→add.
  • Сериализация применения в background: добавлена очередь (single-flight), которая склеивает параллельные триггеры и гарантирует "latest wins".
  • Строгая версия конфигурации: сохраняем headersConfigMetaV1 (seq, монотонный updatedAt) и в background пропускаем устаревшие снапшоты, даже если события приходят не по порядку.
  • Убрано лишнее применение на смене вкладки: DNR-правила глобальные, поэтому пересборка на tabs.onActivated только увеличивала вероятность гонок.
  • Убран legacy reload-путь: удалены updateOverrideHeaders/runtime reload message; обновления теперь идут через storage.onChanged.

Why this works

На Windows из-за другой латентности и планирования событий чаще происходили перекрывающиеся триггеры применения правил. Версионирование + очередь не позволяют применить старую конфигурацию "после" новой.

Test plan

  • pnpm test:unit
  • Ручная проверка (Windows):
    • Менять значения заголовков в popup и быстро переключать вкладки (несколько раз).
    • Проверить, что запросы уходят с последними значениями заголовков.
    • В логах background убедиться, что устаревшие снапшоты пропускаются (Apply skipped (stale meta)), а применения идут последовательно.

Notes

  • seq — best-effort при конкурентных записях; updatedAt принудительно монотонный и используется как tie-breaker.

github-actions Bot added a commit that referenced this pull request Jan 23, 2026
github-actions Bot added a commit that referenced this pull request Jan 23, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 23, 2026

github-actions Bot added a commit that referenced this pull request Jan 23, 2026
github-actions Bot added a commit that referenced this pull request Jan 30, 2026
github-actions Bot added a commit that referenced this pull request Jan 30, 2026
github-actions Bot added a commit that referenced this pull request Jan 30, 2026
github-actions Bot added a commit that referenced this pull request Feb 2, 2026
github-actions Bot added a commit that referenced this pull request Feb 2, 2026
github-actions Bot added a commit that referenced this pull request Feb 2, 2026
github-actions Bot added a commit that referenced this pull request Feb 4, 2026
github-actions Bot added a commit that referenced this pull request Feb 4, 2026
github-actions Bot added a commit that referenced this pull request Feb 4, 2026
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
@Kirrrusha Kirrrusha force-pushed the fix/update-request-with-tab-windows branch from 13f91af to 1585555 Compare February 6, 2026 07:28
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
@Kirrrusha Kirrrusha force-pushed the fix/update-request-with-tab-windows branch from 1585555 to c7d6752 Compare February 6, 2026 07:56
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
@Kirrrusha Kirrrusha force-pushed the fix/update-request-with-tab-windows branch from c7d6752 to 92e9ea1 Compare February 6, 2026 08:14
github-actions Bot added a commit that referenced this pull request Feb 6, 2026
github-actions Bot added a commit that referenced this pull request Feb 13, 2026
github-actions Bot added a commit that referenced this pull request Feb 13, 2026
github-actions Bot added a commit that referenced this pull request Feb 13, 2026
github-actions Bot added a commit that referenced this pull request Feb 13, 2026
@Kirrrusha Kirrrusha force-pushed the fix/update-request-with-tab-windows branch from 1148fb8 to 6813c3a Compare February 16, 2026 14:40
github-actions Bot added a commit that referenced this pull request Feb 16, 2026
github-actions Bot added a commit that referenced this pull request Feb 16, 2026
github-actions Bot added a commit that referenced this pull request Feb 16, 2026
github-actions Bot added a commit that referenced this pull request Feb 26, 2026
github-actions Bot added a commit that referenced this pull request Feb 26, 2026
github-actions Bot added a commit that referenced this pull request Feb 26, 2026
github-actions Bot added a commit that referenced this pull request Feb 27, 2026
github-actions Bot added a commit that referenced this pull request Feb 27, 2026
github-actions Bot added a commit that referenced this pull request Feb 27, 2026
@Kirrrusha Kirrrusha force-pushed the fix/update-request-with-tab-windows branch from 86e0f30 to 386b0d7 Compare February 27, 2026 18:16
github-actions Bot added a commit that referenced this pull request Feb 27, 2026
github-actions Bot added a commit that referenced this pull request Feb 27, 2026
github-actions Bot added a commit that referenced this pull request Feb 27, 2026
github-actions Bot added a commit that referenced this pull request Mar 2, 2026
github-actions Bot added a commit that referenced this pull request Mar 2, 2026
github-actions Bot added a commit that referenced this pull request Mar 2, 2026
@Kirrrusha Kirrrusha force-pushed the fix/update-request-with-tab-windows branch from 5d6b119 to fae69b7 Compare March 2, 2026 19:33
github-actions Bot added a commit that referenced this pull request Mar 2, 2026
github-actions Bot added a commit that referenced this pull request Mar 2, 2026
github-actions Bot added a commit that referenced this pull request Mar 2, 2026
github-actions Bot added a commit that referenced this pull request Mar 3, 2026
github-actions Bot added a commit that referenced this pull request Mar 3, 2026
github-actions Bot added a commit that referenced this pull request Mar 3, 2026
Kirill Lebedenko added 2 commits May 3, 2026 14:25
## Summary
Исправляет Windows-специфичную гонку, когда при переключении вкладок и редактировании заголовков могли применяться **устаревшие** значения (старый снапшот из storage), перезаписывая актуальную конфигурацию.

## Changes
- **Атомарное обновление DNR-правил**: применяем `declarativeNetRequest.updateDynamicRules({ removeRuleIds, addRules })` одним вызовом, чтобы избежать гонки remove→add.
- **Сериализация применения в background**: добавлена очередь (single-flight), которая склеивает параллельные триггеры и гарантирует "latest wins".
- **Строгая версия конфигурации**: сохраняем `headersConfigMetaV1` (`seq`, монотонный `updatedAt`) и в background пропускаем устаревшие снапшоты, даже если события приходят не по порядку.
- **Убрано лишнее применение на смене вкладки**: DNR-правила глобальные, поэтому пересборка на `tabs.onActivated` только увеличивала вероятность гонок.
- **Убран legacy reload-путь**: удалены `updateOverrideHeaders`/runtime reload message; обновления теперь идут через `storage.onChanged`.

## Why this works
На Windows из-за другой латентности и планирования событий чаще происходили перекрывающиеся триггеры применения правил. Версионирование + очередь не позволяют применить старую конфигурацию "после" новой.

## Test plan
- `pnpm test:unit`
- Ручная проверка (Windows):
  - Менять значения заголовков в popup и быстро переключать вкладки (несколько раз).
  - Проверить, что запросы уходят с **последними** значениями заголовков.
  - В логах background убедиться, что устаревшие снапшоты пропускаются (`Apply skipped (stale meta)`), а применения идут последовательно.

## Notes
- `seq` — best-effort при конкурентных записях; `updatedAt` принудительно монотонный и используется как tie-breaker.
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.

1 participant