Repository navigation
feat(api): the decisions of an agent rollout, and reading a release (part of #240) - #446
Merged
Merged
Conversation
Release versions with the agent's rules, the servers a rollout lists, and the pure decision for the server whose turn it is: send, wait, skip, move on, or stop with a reason (ADR 0028). Signed-off-by: samuel mbabhazi <[email protected]>
Signed-off-by: samuel mbabhazi <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 24, 2026
… (#447) ## Task Part of #240, step 1c of ADR 0028: the control plane rolls `UpgradeAgent` out to an organization's servers, one at a time. It is stacked on #446, which adds the decisions and the release reader. It uses the version from each hello, added by #445; until #445 merges, a turn sees the new version at the agent's next `CollectFacts`. The web UI is the next pull request. ## What changed **The rollout's table (`agent_upgrades`):** - It holds: - the version, which is the control plane's own; - the servers, in turn order; - the position, and the action of the current turn; - when the turn started; - the failure: server, reason, and the action's reason. - Constraints: - at most one running rollout per organization, through a partial unique index; - a version pattern; - between 1 and 1,000 servers; - known failure reasons; - a failure exactly when failed, an end time exactly when ended. - Forced row security, and the table is in `TENANT_TABLES`. - The runtime role may select, insert and update it, never delete: rollouts are kept as their history. **The rollout's runs (`AgentUpgrades.advance`, a pg-boss queue and its worker):** - Each run reads the turn under the tenant scope and decides with `nextUpgradeStep` (#446). - It ends every turn it can right away: skipped servers, servers already on the version. It returns when a turn has to wait. - **Sending.** The release's digest and bundle are read outside any transaction. `UpgradeAgent` is then enqueued under the key `au:<rollout>:<node>`, with a 30-minute deadline, and the turn's new start is written in the same transaction. - **Concurrency.** Every write is a compare-and-swap on the position and action just read, so a concurrent run rolls back instead of doing a turn twice. - **Wake-ups.** - A finished action wakes its rollout through the key. - `fleet.node.agent_version_changed` (#445) and `fleet.node.ready` wake the organization's running rollout. - Otherwise the rollout looks again every 15 seconds. - **Audit:** `fleet.agent_upgrade.started` with the actor, then `node_upgraded` or `node_skipped`, then `succeeded` or `failed` with the server and the reasons. **HTTP (`node.manage`):** - `GET /organizations/{organizationId}/agent-upgrades`: - the control plane's version; - the servers on an older release; - the newest rollout. - `POST /organizations/{organizationId}/agent-upgrades` with `{version}`, answering 202: - **The version must still be the control plane's.** The client names the version it saw, so a control plane upgraded in the meantime refuses the rollout. This also keeps the route-role matrix's rule that an empty body stops at validation. - **The release is read first.** The release of each needed architecture must be readable before anything starts. - **Errors** are stable 409 codes: `agent_upgrade_unavailable`, `agent_upgrade_version_changed`, `agent_upgrade_running`, `agent_upgrade_not_needed`, `agent_upgrade_too_many` and `agent_release_unavailable`. **Docs:** a SPEC section on the routes, the turns, the timings and the audit events. The route-role matrix and `openapi.json` are regenerated. ## Why ADR 0028, section 2. The control plane sends `UpgradeAgent` to one server at a time. It never sends it while a deployment touches that server, which shows as any other unfinished action there. It waits for that agent to report the new version, and stops at the first failure. ## How it was tested - **Unit (`agent-upgrades.spec.ts`):** - **Start:** - candidates are listed by name, and the releases are read for both architectures; - every refusal leaves nothing behind. - **A full rollout:** A, then B. No second action goes out while A's runs, the action carries the release, and every audit event is checked. - **The other turns:** - stopping at the first failure, with the agent's reason; - skipped servers; - waiting while another action runs; - a release unavailable at a server's turn; - the overview. - Coverage: 97 % of lines. - **Integration (`agent-upgrades.integration.spec.ts`, real PostgreSQL, through HTTP and the restricted runtime role):** - **Access:** the overview, 404 for roles without `node.manage`, 400 for an empty or malformed version. - **The rollout:** 202, then 409 for a second one. The run puts the `upgradeAgent` action in the database; after the agent's success and new version, the rollout succeeds with its three audit events, and a new start answers `agent_upgrade_not_needed`. - **The table itself:** through the admin login, the partial unique index, the failure check and the version pattern. - **Local checks:** - `pnpm nx run-many -t lint,typecheck,test -p api` passes, and so does the web typecheck. - The whole API integration suite passes locally on PostgreSQL 18, except the three known 23001 tests and two files that need Docker. A first run caught the missing runtime grant: the queue reads the table inside the agent stream. **Size:** about 1,050 lines of code and 600 of tests, over the 500-line target. The table, the queue and the routes only make sense together, and the decisions are already in their own pull request. ## Security considerations - **No URL from a client.** The rollout's target is the control plane's own version, never one a client supplies; the body only confirms it. - **What the control plane relays.** It sends only what the release published. The agent rebuilds the address, checks the digest and verifies the bundle offline (#441, #442). - **No new outside service.** The control plane reaches GitHub's release hosts, which ADR 0028 names. - **No secret moves.** The bundle and the digest are public. - **Every state change is audited, and rollouts cannot be deleted.** <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Organization administrators can start agent upgrades and check the rollout’s status, target version, and pending servers. * Upgrades proceed server by server, with progress and success or failure details recorded. Servers that are already up to date or otherwise ineligible may be skipped. * **Documentation** * Added specification details for the upgrade endpoints, rollout behavior, and retained rollout history. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: samuel mbabhazi <[email protected]>
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.
Task
Part of #240, step 1c of ADR 0028 (#436). The building blocks of the agent rollout: what it decides for each server, and how the control plane reads a release. Nothing calls them yet. The next pull request adds the rollout's table, queue, API and audit events on top.
What changed
Release versions (
fleet/domain/agent-upgrade.ts), with the agent's rules (agent/internal/upgrade):parseReleaseVersionacceptsMAJOR.MINOR.PATCHwith an optional prerelease. It refuses build metadata, leading zeros, numbers over 9 digits, texts over 64 characters, anddev.compareVersionsfollows semantic versioning precedence, prereleases included.agentArchiveandreleaseFilegive the names and addresses thatrelease.ymlpublishes.The rollout's decisions, pure:
upgradeCandidateslists the servers to upgrade: not removed, on a release older than the target, onamd64orarm64. Adevagent is left out, since the agent refuses to upgrade one.nextUpgradeStepdecides, for the server whose turn it is:send,wait,skip,done,finish, orfailwith a reason:node_unavailable). A server with any other unfinished action, which is how a deployment touching it shows, gets 30 minutes (node_busy). This is ADR 0028's "never while a deployment touches that server".action_failed, with the action's reason). An action that never ends, because the server never came back, stops it after 35 minutes (not_confirmed).done. A heartbeat recorded more than 150 seconds after the success, still on the previous version, meansrolled_back: the previous binary stops within 2 minutes of its result (the agent'srestartWithin), so a later heartbeat comes from a process started after it, and the guard put the previous binary back. With no new version within 25 minutes, the rollout stops withnot_confirmed.Reading a release (
fleet/infrastructure/github-agent-releases.ts):checksums.txt: one line, lowercase hex, listed once..sigstore.jsonbundle: a JSON object with a Sigstore bundle media type.nullon any failure, and logs only the kind of failure.Why
ADR 0028 section 2: the control plane names the version, relays the digest and the bundle, sends
UpgradeAgentto one server at a time, waits for that agent to report the new version, and stops at the first failure. The decisions are pure so they can be tested on their own, including every timing.How it was tested
agent-upgrade.spec.ts, 16 tests:nextUpgradeStep, at each timing boundary.github-agent-releases.spec.ts:file:;checksums.txtparser.pnpm nx run-many -t lint,typecheck,test -p apipasses.Security considerations
upgrade_unverified).