Skip to content

feat(BA-8643): add compare_and_replace_prefixes to AbstractKVStore - #15988

Merged
HyeockJinKim merged 4 commits into
mainfrom
feat/BA-8643-etcd-compare-and-replace
Oct 22, 2026
Merged

HyeockJinKim merged 4 commits into
mainfrom
feat/BA-8643-etcd-compare-and-replace

Conversation

@jopemachine

@jopemachine jopemachine commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Part of the AppProxy worker Ingress work (epic BA-8433). Independent of the coordinator stack; #15893 (TraefikWorkerClient) builds on it and carries these commits until this merges. Replaces #15916, whose branch was recreated.

Resolves #15914 (BA-8643)

Summary

  • AbstractKVStore.compare_and_replace_prefixes(replacements, *, guards) replaces the subtrees as atomic_replace_prefixes does, only when every guard key holds its given value at commit (None: the key is absent).
    • Returns True when the replacement landed and False when a guard failed, leaving the subtrees as they were.
    • AsyncEtcd runs it through _request(..., conditional=True) like the existing conditional writes.
    • AgentEtcdClientView forwards it with the agent's scope prefixes, as it does compare_and_put and compare_and_delete.
  • atomic_replace_prefixes and the new method share _replacement_ops, which builds the deletes of stale keys and the puts of new ones.

Test plan

  • pants check / pants test on tests/unit/common/test_etcd.py and tests/unit/agent/test_etcd.py
  • tests/unit/common/test_etcd.py — the subtree is replaced while the guard holds, left alone when the guard moved, and a None guard holds for an absent key
  • tests/unit/agent/test_etcd.py — through AgentEtcdClientView, the guard and the subtree resolve in the same agent scope: replaced while the guard holds, left alone when it moved

🤖 Generated with Claude Code

jopemachine and others added 2 commits October 22, 2026 14:33
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jopemachine
jopemachine requested a review from a team as a code owner October 22, 2026 05:33
Copilot AI balanced review requested due to automatic review settings October 22, 2026 05:33
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused addition preserves existing replacement logic, follows conditional-write patterns, and has no identified blocking defects.

No open issues 🎉

What changed in this PR

Adds guarded subtree replacement to the shared AsyncEtcd client, enabling conditional configuration updates for the AppProxy Traefik ingress work.

Changes:

  • Adds compare_and_replace_prefixes, which commits replacements only when every guard matches, with None checking key absence.
  • Shares replacement-operation construction with atomic_replace_prefixes.
  • Adds tests for matching, changed, and absent guards, plus a feature changelog entry.
File Description
tests/​unit/​common/​test_etcd.py Tests successful replacement and preservation when a guard fails.
src/​ai/​backend/​common/​etcd.py Adds guarded transactions and extracts the shared replacement helper.
changes/​15988.feature.md Documents the new guarded replacement method.

Review effort: Balanced

@jopemachine
jopemachine marked this pull request as draft October 22, 2026 05:40
AgentEtcdClientView forwards it with the agent's scope prefixes, as it does the other
conditional writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the comp:agent Related to Agent component label Oct 22, 2026
@jopemachine jopemachine changed the title feat(BA-8643): add compare_and_replace_prefixes to AsyncEtcd feat(BA-8643): add compare_and_replace_prefixes to AbstractKVStore Oct 22, 2026
@jopemachine
jopemachine marked this pull request as ready for review October 22, 2026 06:12

@HyeockJinKim HyeockJinKim left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems like there are a few more etcd calls than usual, but let's put this task aside for now and address it in a follow-up issue.

@HyeockJinKim
HyeockJinKim merged commit 4688c90 into main Oct 22, 2026
41 of 43 checks passed
@HyeockJinKim
HyeockJinKim deleted the feat/BA-8643-etcd-compare-and-replace branch October 22, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:agent Related to Agent component comp:common Related to Common component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a guarded prefix replacement to AsyncEtcd

3 participants