Repository navigation
Conversation
| 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 |
There was a problem hiding this comment.
[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.
What changed
Prevent late saves from rolling back the fallback snapshot used at startup. The file provider checks
flagStateVersionunder 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, andSETpermissions. Existing custom clients withgetandsetstill work: they check the version before writing, but that check is not atomic. Custom clients can opt into atomic writes with the newevaloption. The README also explains how to clear a file lock left behind by a crash. This is a patch changeset.Verification
eval. A legacyget/setclient rejected sequential stale writes without sendingEVAL.