Repository navigation
feat(runtimehost): make instance state writes conditional - #60
Conversation
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 59 minutes. View limit details
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Every API server runs its own process of a plugin against one shared instance state, so two read-modify-write cycles can lose a change. Hosts now return a version with each read and honor expected_version on a write, failing with ABORTED when the key changed. The client adds ReadInstanceStateVersion, WriteInstanceStateIf and UpdateInstanceState, which repeats the change after a conflict. On a host that doesn't keep versions they return ErrInstanceStateUnversioned, and UpdateInstanceState writes nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es it WriteInstanceStateIf sent the write first and only then noticed the host keeps no versions, so on an older host it overwrote the value unconditionally. It now learns whether the host keeps versions before the first conditional write, from a read it makes once per client or one the plugin already made, and writes nothing on such a host. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdateInstanceState retried a conflicting write at once, so servers that collided on a key tended to collide again. It now waits a random time in a window that doubles from 10 ms to 500 ms between attempts, and stops when the context ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5fddad7 to
03b2f1a
Compare
Problem
Every API server runs its own process of a plugin against one shared instance state, so two
read-modify-write cycles on the same key can lose an update. Plugins work around it with sharded
keys and hand-written leases.
Approach
A read returns the key's
version, andversionedtells the plugin the host keeps versions. Awrite may set
expected_version(0: the key must not exist); the host refuses it with ABORTED whenthe key changed. The client adds
ReadInstanceStateVersion,WriteInstanceStateIfandUpdateInstanceState, which reads, applies the change, and retries after a conflict, up to 8attempts. Between attempts it waits a random time in a window that doubles from 10 ms to 500 ms, so
servers that collided don't collide again at once, and it stops when the context ends.
On a host without versions these return
ErrInstanceStateUnversionedand write nothing.WriteInstanceStateIflearns whether the host keeps versions before its first conditional write,so it never sends one to a host that would apply it unconditionally.
Compatibility and release
Additive proto fields. An unset
expected_versionkeeps today's unconditional write.Related changes
buf generate.Validation
go test ./...,go vet ./...and every example build: pass.gofmt -l .lists onlypkg/pluginsdk/runtime/scan_source_test.go, which is unformatted onmainand not touched here.
bufleaves it unchanged.make protoitself stopsat its
protoccheck on this machine, though generation doesn't useprotoc.UpdateInstanceStateraised the version on each write; a write at astale version and a create-only write of an existing key were both refused as conflicts.
Evidence
Evidence: https://evidence.siloserver.org/r/silo-plugin-sdk/pr-60/
AI Disclosure
WriteInstanceStateIfwrotefirst and checked for version support afterwards, so an older host overwrote the value; it now
checks first.
mainand applied the fixes; claude-opus-5-5 and gpt-6.2-sol (Codex) each reviewed it independently. No findings on this change.🤖 Generated with Claude Code
Note
Add versioned, conditional instance-state writes to
runtimehost.ClientReadInstanceStateVersion,WriteInstanceStateIf, andUpdateInstanceStatein instance_state_version.go.UpdateInstanceStaterereads and reruns its callback after a conflict, up to 8 attempts with full-jitter exponential backoff.version/versionedread fields, optionalexpected_versionon writes, and aversionin the write response. Regenerated bindings in runtime_host.pb.go.ErrUnversionedHosterror when the host lacks version support. Conflicting gRPCAbortedresponses map to a package conflict error.UpdateInstanceStatecallback may run repeatedly and must not have side effects.version/expected_versionfields getErrUnversionedHostfromWriteInstanceStateIfandUpdateInstanceState; existing unconditionalWriteInstanceStatebehavior is unchanged.Macroscope summarized 03b2f1a.