[Core] Make model-agent reconciliation race-safe#680
Open
fredericsun wants to merge 1 commit into
Open
Conversation
fredericsun
requested review from
beiguo218,
pallasathena92,
slin1237 and
truddy0
as code owners
July 23, 2026 04:27
op109lvb
approved these changes
Jul 23, 2026
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.
What this PR does
This PR makes model-agent ConfigMap, in-memory cache, and periodic self-healing reconciliation safe under concurrent model updates and deletion.
Key changes:
ConflictandAlreadyExistserrors.Why we need it
Each model-agent stores multiple model entries in one node-level ConfigMap. Status, metadata, progress, deletion, and periodic self-healing can update that ConfigMap concurrently.
Previously, these operations could race because they were based on independently fetched ConfigMap snapshots.
For example:
A similar race could occur when periodic self-healing copied a cache entry before deletion, then attempted to restore it after deletion had removed the entry.
A ConfigMap update conflict during deletion could also leave the entry present because the delete path did not retry against the latest ConfigMap.
These races can leave stale node state behind, prevent model deletion from converging, and block controllers waiting for every node entry to be removed.
The new implementation retries mutations against the latest ConfigMap, limits each operation to its intended model key, and uses the model UID plus live-cache ownership to reject stale work.
It also preserves an important node-local workflow. If a CR temporarily stops matching a node and later becomes eligible again, the same CR generation must be allowed to write its state back. Therefore, only CRs with a deletion timestamp receive a persistent UID fence.
No download scheduling or Gopher queue behavior is changed by this PR.
How to test
Unit tests
Run:
go test ./pkg/modelagentThe model-agent tests cover:
Live model-agent validation
Validated in a live cluster with the PR model-agent image:
Deleted a model while Gopher was actively downloading it.
Changed a model's node selection from node A to node B and then back to node A.
Reconciled two models concurrently in the same node ConfigMap.
Readywith metadata.E2E regression validation
Created and deleted a imported model in a live cluster
Verified that:
DELETED.Checklist
make testpasses locally