feat(storage): atomic setIfAbsent primitive (client)#119
Draft
Zmatarasso wants to merge 1 commit into
Draft
Conversation
Adds a race-free "write only if the key is not already set" command to plugin
storage: storage.setIfAbsent(key, value, { ttlSeconds? }) plus the pipeline
set_if_absent command. Resolves to the stored item on a win, or { value: undefined }
when the key already existed (claim lost) — mirroring the get-miss convention.
This is the client half; the platform (envoy-web PluginStorageService) must learn
the set_if_absent action for it to resolve. See docs/proposals/atomic-set-if-absent.md.
Motivation: integrations that provision from two concurrent paths (e.g. an event
webhook + an app-extension render, possibly on different pods) need a real
mutual-exclusion primitive. Today's get-then-set is a TOCTOU race and set_unique
overwrites. setIfAbsent lets exactly one caller win, resolved server-side against
the existing unique index.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Platform companion PR: envoy/envoy-web#21455 (adds the |
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.
Summary
Adds a race-free "write only if the key is not already set" primitive to plugin storage — the client half of a cross-repo change (platform companion PR in
envoy-web).storage.setIfAbsent(key, value, { ttlSeconds? })+ pipelineset_if_absentcommand.{ value: undefined }when the key already existed (claim lost) — same convention asget-miss /setUnique-exhaustion, so no new result shape.set_if_absentaction.Why
Some integrations provision from two concurrent paths for the same entity — e.g. an event webhook and an app-extension render — that can run at the same instant and on different pods. Both do
get → (missing) → create, and the idempotency record is only written after the external calls, so both see "missing" and both create (duplicate external records). This is a check-then-act (TOCTOU) race that a better read can't fix and that in-process de-duplication can't cover across pods.setoverwrites (last-write-wins) andset_uniqueguarantees a unique value (not key ownership), so neither can elect a single winner.setIfAbsentcan: the winner is decided atomically at the write, server-side, against the existing unique index onplugin_storage_items.Motivating case:
pacs-integration-service#202(By The Bay / Habitap credential provisioning).What's here
EnvoyStorageCommand— newset_if_absentaction +EnvoySetIfAbsentStorageCommand.EnvoyPluginStoragePipeline.setIfAbsent(...)andEnvoyPluginStorage.setIfAbsent(...).EnvoyPluginStoragePipelineMock(single-threaded existence check; TTL not modelled).docs/proposals/atomic-set-if-absent.md.tsc --noEmit,eslint, andjest(76 passing, +4 new) are green.Depends on
Platform companion PR in
envoy-webadding theset_if_absentaction toPlatform::PluginStorageService. This SDK method is a no-op until that lands. The two can merge in either order.🤖 Generated with Claude Code