Skip to content

feat(api): the agent version from each Hello, and why an upgrade was refused (part of #240) - #445

Merged
samuelmbabhazi merged 3 commits into
mainfrom
feat/240-agent-version-hello
Nov 24, 2026
Merged

samuelmbabhazi merged 3 commits into
mainfrom
feat/240-agent-version-hello

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Task

Part of #240, the start of step 1c of ADR 0028 (#436): what the control plane must know before it sends UpgradeAgent. It does not send the action yet.

What changed

The agent's version, from each Hello:

  • NodeLiveness.hello records the heartbeat as before, then compares the version the Hello names with the node's stored agent_version fact.
  • When they differ, it stores the new version and publishes fleet.node.agent_version_changed with from and to, in the same transaction. An unchanged version records nothing.
  • This is how the control plane will see that an upgrade took, or that the guard rolled it back: the previous binary reports the previous version again.
  • A value that is not a release version or dev (^[0-9A-Za-z][0-9A-Za-z.+-]{0,63}$) is not stored, and the node keeps the last version it reported correctly.
  • It also closes the follow-up left by the maintenance gate (feat(api): enter and leave maintenance (part of #256) #422): an upgraded agent no longer reads as outdated until its next CollectFacts.

Why an upgrade was refused:

  • The six fixed texts of UpgradeAgent (SPEC 3.4, feat(agent): UpgradeAgent swaps in a verified release and the guard rolls it back (part of #240) #442) map to reason codes: upgrade_dev_build, upgrade_not_newer, upgrade_unit_outdated, upgrade_unverified, upgrade_unavailable and upgrade_in_progress.
  • They are step causes, so a compensated action keeps its reason.
  • The application's agent action history gets an English label for each, translated in fr.ts. These are labels only: no screen changes, and no upgrade action exists yet to show them.

Docs: SPEC 5.2 says what a hello records and audits.

Why

ADR 0028's rollout waits for each agent to report the new version before it moves to the next server. Until now the version was stored at enrollment and refreshed only by CollectFacts.

How it was tested

  • Unit:
    • node-liveness.spec.ts: a change is stored and audited once; the rollback's version change is audited too; a first version; malicious values (empty, spaces, a newline, ../, 65 characters, ;, a leading -) keep the stored version and still count the heartbeat; a removed node records nothing.
    • node-stream.spec.ts: the stream passes the Hello's version.
    • agent-action.spec.ts: each text maps to its reason and back, compensated or failed.
    • agent-action-rows.spec.ts: each label, and its French text.
  • Integration (fleet-administration-http.integration.spec.ts, real PostgreSQL): the node view shows the new version, and the audit log holds one fleet.node.agent_version_changed.
  • Local checks: pnpm nx run-many -t lint,typecheck,test -p api web passes, and so does pnpm format:check. The whole API integration suite passes locally against PostgreSQL 18, except the three known 23001 tests and two files that need Docker.

Security considerations

  • Nothing the agent sends is stored unless it matches the version pattern, and the event carries only the two versions.
  • The reason codes come from a fixed table, and an unknown text still reads as unknown.

A hello whose version differs from the stored agent_version fact stores it and audits fleet.node.agent_version_changed, so the control plane sees an upgrade or its rollback (ADR 0028).

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 856d90c and 4cc9d1e.

Files ignored due to path filters: 2

  • apps/api/openapi.json is excluded by !apps/api/openapi.json
  • packages/api-client/src/gen/openapi.ts is excluded by !**/gen/**, !packages/api-client/src/gen/**
Files selected for processing: 13

  • apps/api/src/modules/fleet/application/node-liveness.spec.ts
  • apps/api/src/modules/fleet/application/node-liveness.ts
  • apps/api/src/modules/fleet/domain/agent-action.spec.ts
  • apps/api/src/modules/fleet/domain/agent-action.ts
  • apps/api/src/modules/fleet/domain/events.ts
  • apps/api/src/modules/fleet/domain/node.ts
  • apps/api/src/modules/fleet/fleet-administration-http.integration.spec.ts
  • apps/api/src/modules/fleet/interface/node-stream.spec.ts
  • apps/api/src/modules/fleet/interface/node-stream.ts
  • apps/web/src/app/delivery/agent-action-rows.spec.ts
  • apps/web/src/app/delivery/agent-action-rows.ts
  • apps/web/src/app/ui/fr.ts
  • docs/SPEC.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@samuelmbabhazi
samuelmbabhazi merged commit ef4bab3 into main Nov 24, 2026
25 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/240-agent-version-hello branch November 24, 2026 11:16
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]>
samuelmbabhazi added a commit that referenced this pull request Nov 24, 2026
## Task

Part of #240, step 1c of ADR 0028: the web side of the agent rollout. It
is stacked on #447, which adds `GET` and `POST
/organizations/{organizationId}/agent-upgrades`. **UI change: waiting
for the maintainer's visual validation before merge.**

Captures, desktop and phone, English and French:
https://claude.ai/artifact/D18ej9YP9bVKXj7xWXr5mw

## What changed

**A card on the Servers page (`sk-agent-upgrades`), above the servers
table, shown only when there is something to say:**
- **Development build** (no version), or every agent already on the
control plane's version: nothing. The page looks as it does today.
- **Agents to upgrade:** "N servers run an older agent than the control
plane, X", an **Upgrade agents** button, and a note on what happens: one
server at a time, the signature checked, applications kept running.
- **Rollout running:** "server n of N, name", then one pill per server
in turn order: upgraded, upgrading, waiting.
- The card reads the overview again every 5 seconds while the rollout
runs.
  - It stops when the rollout ends, or when the page goes away.
- When the rollout ends, it refreshes the servers table, whose versions
changed.
- **Rollout stopped, with servers still waiting:** an alert naming the
server, with one sentence per reason. For `action_failed`, the agent's
own reason label from the action history is added. The pills show where
the rollout stopped, and the button comes back.
- **The button sends `{version}`,** the version the overview gave. Every
refusal code of #447 gets its own sentence, in English and French; any
other failure uses the page's usual message.

**Smaller parts:**
- `FleetApi.agentUpgrades` and `FleetApi.startAgentUpgrade`.
- `actionReasonLabel`, exported from the action history's labels. It
picks up the `upgrade_*` reasons of #445 once that merges.
- The browser fixture takes provider overrides. The tenant suite runs
with a released control plane version and a fake GitHub, so the card is
checked under the production CSP and axe.

## Why

ADR 0028 section 2: "The UI shows the version of each agent and offers
the upgrade once a release is newer." The servers table already shows
each agent's version; this card offers the upgrade and follows it.

## How it was tested

- **Unit:**
- `agent-upgrade-view.spec.ts`: every state, names falling back to ids,
a stale failure hidden once nothing waits, a French sentence for every
stop reason and every refusal code.
  - `agent-upgrades.spec.ts`:
    - hidden on a development build;
    - the POST carries the version;
- polling every 5 seconds and stopping when the rollout ends or the page
is destroyed;
    - the stopped state;
    - a refused start explained in French;
    - no rollout of one organization shown under another.
  - `servers-page.spec.ts`: the card on the real page, and its POST.
- **Checks:** `pnpm nx run-many -t lint,typecheck,test -p web api`
passes (331 web tests), and so does `pnpm format:check`.
- **Browser** (`vitest.browser.config.mts`, Chromium, production build,
PostgreSQL): 28 tests pass, including the new one. The card shows up,
axe finds nothing, the POST answers 202 with `{version}`, the card turns
into the rollout, and the console stays clean.
- **Captures:** the real app in Chromium, seeded with three servers and
an `agent_upgrades` row in each state, with no console error and Outfit
loaded. They are in the page linked above.

## Security considerations

- The page is behind `node.manage`, and the API checks it again.
- The card shows ids, names, versions and fixed sentences only: nothing
the agent sent is repeated, since reasons are codes mapped to fixed
labels.
- No inline style: the dot colors are `[style.background]` bindings,
which go through the CSSOM.

---------

Signed-off-by: samuel mbabhazi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant