Skip to content

fix(node-sdk): prevent stale fallback snapshot writes - #868

Open
roncohen wants to merge 4 commits into
mainfrom
fix/node-fallback-snapshot-order
Open

roncohen wants to merge 4 commits into
mainfrom
fix/node-fallback-snapshot-order

Conversation

@roncohen

@roncohen roncohen commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Prevent late saves from rolling back the fallback snapshot used at startup. The file provider checks flagStateVersion under a writer lock. The SDK-created Redis client checks and writes in a single Lua script.

Snapshot formats and storage keys are unchanged. The SDK-created Redis client needs EVAL, GET, and SET permissions. Existing custom clients with get and set still work: they check the version before writing, but that check is not atomic. Custom clients can opt into atomic writes with the new eval option. The README also explains how to clear a file lock left behind by a crash. This is a patch changeset.

Verification

  • Node SDK build, type tests, lint, formatting, and 292 tests passed.
  • Separate writer processes preserved the highest version in the file provider.
  • Against Redis 7.4.11, four competing writers retained the highest version with both the SDK-created client and custom eval. A legacy get/set client rejected sequential stale writes without sending EVAL.

@reflag-review reflag-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium

no actionable findings

@roncohen
roncohen enabled auto-merge December 2, 2026 19:00
@roncohen
roncohen disabled auto-merge December 2, 2026 19:01
@roncohen
roncohen enabled auto-merge December 2, 2026 19:01

@reflag-review reflag-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium

no actionable findings

@reflag-review reflag-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium

1 actionable finding.

local current = redis.call('GET', KEYS[1])
if current then
local ok, snapshot = pcall(cjson.decode, current)
if ok and type(snapshot) == 'table' and snapshot.version == 2 then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Validate the stored envelope before preserving its version

The Lua guard trusts any decoded object with version == 2 and a valid counter, but load() requires the full isFlagsFallbackSnapshot() envelope. For example, a stored snapshot with flagStateVersion: 100 but missing segments is rejected on load, yet this script silently refuses a valid version-99 replacement. Previously, saving repaired that value; SDK-created Redis clients and custom clients using eval now leave startup fallback unavailable until a sufficiently high version is saved or the key is cleared. Apply the stale-write guard only to envelopes accepted by the loader, and allow valid incoming snapshots to replace invalid stored values atomically.

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