FEAT-3: policy push from owner to agent - #35
Merged
Conversation
Add a policy-push path that rides the existing dial-home order queue, so an
owner can update an agent's supervision policy without reaching inbound.
Owner:
- AgentRegistry.queue_policy(agent_id, policy_yaml) appends a
{"type": "policy", "policy": ...} order.
- POST /agents/{agent_id}/policy validates the YAML with load_policy_str and
returns 422 on invalid input, queues the order on success.
Agent:
- latest_policy_order picks the newest policy order when several arrive at once.
- swap_supervisor validates, stops the old Supervisor, and starts a new one on
the same RemoteApprover so approvals keep flowing. An invalid push is logged
and skipped, leaving the current supervisor running so the loop never crashes.
- The report loop applies approve orders as before, then hot-swaps on a policy
order.
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
Lets an owner push a new supervision policy to a dial-home agent over the existing order channel, so a policy update reaches an agent that can never be contacted inbound.
Owner (src/spero/owner.py)
AgentRegistry.queue_policy(agent_id, policy_yaml)appends a{"type": "policy", "policy": ...}order to the agent's queue.POST /agents/{agent_id}/policy(async, token-guarded) accepts{"policy": "<yaml>"}, validates it withload_policy_str, returns 422 on invalid YAML or policy, and on success queues the order and returns{"queued": "policy"}.Agent (src/spero/agent.py)
latest_policy_order(orders)returns the YAML of the last policy order, so an agent that pulls several at once converges on the newest.swap_supervisor(sup, policy_yaml, approver)validates the YAML, stops the oldSupervisor, and starts a new one on the sameRemoteApproverso approvals keep flowing. An invalid push is logged and skipped, leaving the current supervisor running, so a bad push can never take the agent down.Tests
latest_policy_orderpicks the last push;swap_supervisorswaps to the new policy while preserving the approver state; an invalid push leaves the old supervisor running.Gates
ruff check,ruff format --check,mypy,pytestall green. 234 passed.