Repository navigation
Keep a webhook's flags when a thread reads after an older poll - #1151
Open
jnunemaker wants to merge 6 commits into
Open
jnunemaker wants to merge 6 commits into
jnunemaker wants to merge 6 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_versionreturns nil (third-party adapters) rolled back until the next poll:FLIPPER_CLOUD_MEMORY_READSon (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#importrefuses 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 newMemory#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 everyPolluser whose poller adapter is aMemory(asFlipper::Poller's is).Proof
Failing then passing (
spec/flipper/cloud/memory_reads_spec.rb. The local adapter is wrapped to dropsync_version, then a poll at v1 with the flag off, a webhook at v2 with the flag on, then a new reader):database...[:boolean]expected"true", gotnilenabled?expectedtrue, gotfalse"true", gotnilFocused:
spec/flipper/cloud,cloud_spec,poller_spec,adapters/poll_spec,adapters/memory_spec,engine_spec,named_instances_spec,middleware:CI covers the full suite and the other adapters.
Performance & compatibility
Flipper::Adapters::Memory#snapshot.Pollsyncs from a snapshot only when the poller's adapter is aMemory. 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-reviewwas 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):
Memory#snapshot). Rejected [P3] "non-memory forced sync no longer emitssynchronizer_exceptionon 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.Then
/simplify, with four review angles (8b1ce894):Poll's default synchronizer for every caller. Cloud's non-memory path is back to the plainPoll, as on main.Memory#snapshotis now a shallow copy.synchronizeoptions parameter and added a sharedpoll_cloudspec helper.sync_pollrecheck, because it prevents undoing an explicit enable.Wrapperfor the test adapter, because it would forwardsync_version.Codex on that commit:
ab663c27): snapshot only aMemorypoller adapter, never an unrelatedsnapshotmethod.Memory#getalready hands those out as read-only.SimpleDelegator-wrappedMemorypoller 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)
🤖 Generated with Claude Code