Skip to content

Keep a webhook's flags when a thread reads after an older poll - #1151

Open
jnunemaker wants to merge 6 commits into
mainfrom
nunes/webhook-poll-replay
Open

jnunemaker wants to merge 6 commits into
mainfrom
nunes/webhook-poll-replay

Conversation

@jnunemaker

@jnunemaker jnunemaker commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Why

In webhook mode (1.5), every process still polls Cloud every 5 minutes, and the shared poller keeps its last snapshot. A thread or new instance that hadn't read since that poll synced the snapshot on its first read, over the newer flags a webhook had just synced. Built-in adapters refuse the older snapshot by sync version. A local adapter whose sync_version returns nil (third-party adapters) rolled back until the next poll:

  • FLIPPER_CLOUD_MEMORY_READS on (default): that process's Memory kept the new flags, but the local adapter was rolled back, so processes that boot or restart read the old flags.
  • FLIPPER_CLOUD_MEMORY_READS=false: every read got the old flags for up to ~5 minutes.

What changed

Size: code +47 −13 · tests +89 −6 · docs +1 −1

  • Configuration#sync (webhook or forced sync) fetches one snapshot and imports it into the poller's Memory adapter before syncing the local adapter. Later Poll reads then sync the fresh flags. Memory#import refuses an older version, so a poll that was in flight can't put the old snapshot back.
  • Poll's default synchronizer, and Cloud's memory-reads sync, read the poller's flags and version together through a new Memory#snapshot (a shallow copy taken under the lock). Without it, a reader could pair one import's flags with another's version. This came up in Codex review. The same window also existed between two ordinary polls, so it now covers every Poll user whose poller adapter is a Memory (as Flipper::Poller's is).
  • In memory-reads mode, the snapshot is copied only when a thread actually syncs, and the version is checked again if a forced sync replaced the poll in the meantime.
  • README: the "other processes reload every 10 seconds" line now says it needs an adapter that stores the sync version.

Proof

Failing then passing (spec/flipper/cloud/memory_reads_spec.rb. The local adapter is wrapped to drop sync_version, then a poll at v1 with the flag off, a webhook at v2 with the flag on, then a new reader):

Spec Before Branch
another thread reads after an older poll main: database...[:boolean] expected "true", got nil pass
another instance reads after an older poll, memory reads off main: enabled? expected true, got false pass
poll's flags and version read together while a webhook imports 61b8fe7: expected "true", got nil pass
3 examples, 0 failures

Focused: spec/flipper/cloud, cloud_spec, poller_spec, adapters/poll_spec, adapters/memory_spec, engine_spec, named_instances_spec, middleware:

520 examples, 0 failures

CI covers the full suite and the other adapters.

Performance & compatibility

  • Performance: each forced sync (webhook) does one extra in-memory import into the poller. After a poll, a thread takes a shallow copy of the flag hash only when it actually syncs, about once per thread per changed poll. Unchanged polls do the same version-only check as before. No new queries or requests.
  • Compatibility: additive. Adds a public Flipper::Adapters::Memory#snapshot. Poll syncs from a snapshot only when the poller's adapter is a Memory. Other poller adapters behave as before. Without memory reads, a forced sync now syncs from a fetched snapshot (same flags, same Synchronizer). No stored data changes.

Review

/nunebot-review was run with the focus on Codex review. Simplify, QA and the security-review skill were not run as skills. A manual security pass found nothing: no auth, input parsing or secrets are touched, and the webhook signature check is unchanged.

Codex (gpt-6.2-sol):

  1. Whole branch. Fixed the [P1] torn read of the poller's flags and version (Memory#snapshot). Rejected [P3] "non-memory forced sync no longer emits synchronizer_exception on fetch failure": the default memory-reads path has fetched outside the synchronizer since 1.5.0, and the error still raises. Rejected [P3] "README needs shared storage": the section already means your shared adapter.
  2. 858e8e4. Fixed [P2] copying every flag per thread before the unchanged check, and [P3] syncing into a different adapter object than Poll reads. Rejected [P2] "versionless storage can still lose to a single in-flight sync": storage without a version can't order two concurrent writers. The deterministic 5-minute rollback is fixed.
  3. 3738c98. Fixed [P2]: recheck when a forced sync replaced the poll during the check.
  4. 8ccdd34. Rejected [P2] "serves v2 until refresh if another process stored v3 meanwhile": in webhook mode, Memory reloads from storage every 10 s, and storage holding v3 stores versions, so the reload picks it up.

Then /simplify, with four review angles (8b1ce894):

  • Moved the consistent snapshot read into Poll's default synchronizer for every caller. Cloud's non-memory path is back to the plain Poll, as on main.
  • Memory#snapshot is now a shallow copy.
  • Removed the unused synchronize options parameter and added a shared poll_cloud spec helper.
  • Skipped deleting the sync_poll recheck, because it prevents undoing an explicit enable.
  • Skipped Wrapper for the test adapter, because it would forward sync_version.

Codex on that commit:

  • Fixed (ab663c27): snapshot only a Memory poller adapter, never an unrelated snapshot method.
  • Rejected "no sync instrumentation without memory reads": same as main.
  • Rejected "a shallow snapshot shares gate hashes": Memory#get already hands those out as read-only.
  • Rejected, on the follow-up review, "a SimpleDelegator-wrapped Memory poller adapter gets no atomic read": that's no worse than main.

Risk and rollback

Touches Cloud's sync paths in both read modes. To roll back, revert the PR, which restores the 1.5.0 behaviour.

Changelog (1.5.1)

  • Fixed: in Cloud webhook mode, a thread or instance that read after the 5-minute backstop poll could sync that poll's older flags over a newer webhook sync when the local adapter doesn't store a sync version.

🤖 Generated with Claude Code

jnunemaker and others added 6 commits November 29, 2026 16:38
In webhook mode the poller still polls every 5 minutes and keeps its last
snapshot. A thread or instance that hadn't read since that poll synced the
snapshot on its next read, over the newer flags a webhook had just synced.
Built-in adapters refuse it by sync version, but a local adapter that can't
store one rolled back until the next poll.

A forced sync now imports its snapshot into the poller's Memory adapter too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A forced sync now imports into the poller's adapter while threads sync from
it. Reading its flags and version in separate calls could pair a poll's flags
with the webhook's version and write the older flags back. Cloud's poll syncs
now read a snapshot of both, taken under the adapter's lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Most reads after a poll find it synced, so check the version before copying
every flag. Without memory reads, sync into the adapter Poll reads from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Poll's default synchronizer now reads the poller's flags and version together,
since a poll imports while threads sync from it, so Cloud's non-memory path is
back to the plain Poll. Memory#snapshot makes a shallow copy. Drops the
unused synchronize options and shares the spec's poll setup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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