fix: update local state after runner assignment - #191
Merged
Merged
Conversation
assign_runner_pod uses deepcopy + replace_namespaced_custom_object to
set the runner label on an AnarchyRun, but never updates self.definition
with the result. This means runner_state (which reads from
self.definition['metadata']['labels']) returns the stale pre-assignment
value until the K8s watch fires and calls update_definition.
The Ansible runner never hit this because it processes runs in seconds,
giving the watch time to catch up. The Go runner processes runs in
~200ms, consistently beating the watch. This causes two failures:
1. POST /run/{name} (postResult) fails with 400 because the API checks
anarchy_run.runner_state \!= anarchy_runner_pod.name — stale label.
2. PATCH /run/subject/{name} (SubjectUpdate) fails with 400 because
runner_assignments (populated by update_definition via watch) is
empty — the watch hasn't fired yet.
The fix is one line: await self.update_definition(definition) after the
K8s replace. This updates self.definition immediately (fixing
runner_state) and calls update_runner_assignment (fixing
runner_assignments). When the watch eventually fires with the same
resourceVersion, handle_watch_found short-circuits (line 37).
This mirrors what AnarchyObject.replace() already does — assign_runner_pod
was the only codepath that inlined the K8s replace without updating local
state.
jkupferer
approved these changes
May 20, 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.
assign_runner_pod uses deepcopy + replace_namespaced_custom_object to set the runner label on an AnarchyRun, but never updates self.definition with the result. This means runner_state (which reads from self.definition['metadata']['labels']) returns the stale pre-assignment value until the K8s watch fires and calls update_definition.
The Ansible runner never hit this because it processes runs in seconds, giving the watch time to catch up. The Go runner processes runs in ~200ms, consistently beating the watch. This causes two failures:
The fix is one line: await self.update_definition(definition) after the K8s replace. This updates self.definition immediately (fixing runner_state) and calls update_runner_assignment (fixing runner_assignments). When the watch eventually fires with the same resourceVersion, handle_watch_found short-circuits (line 37).
This mirrors what AnarchyObject.replace() already does — assign_runner_pod was the only codepath that inlined the K8s replace without updating local state.