Repository navigation
Description
Describe the enhancement:
An UPGRADE ack makes Fleet Server do two refreshed writes in one request: the result document in .fleet-actions-results (dl.CreateActionResult) and the agent update in handleUpgrade. If either times out, the ack returns a 500, elastic-agent re-sends it (up to 5 retries, then it drops the ack), and each repeat does both writes again.
Current behavior
The agent reports progress in the check-in upgrade_details, which Fleet Server stores on every check-in with a refreshed .fleet-agents update. After the restart on the new version the agent also sends an UPGRADE ack, and each ack does two refreshed writes. A timeout in either returns a 500, and the agent's ack retrier re-sends the ack with a 1 to 5 minute backoff, which repeats both writes. The retrier gives up after 5 failed retries ("Fleet will not be notified of its completion"). It lives in memory, and the agent has already marked the upgrade as acked on disk, so a dropped ack is not re-sent after a restart.
sequenceDiagram
participant A as Elastic Agent
participant F as Fleet Server
participant E as Elasticsearch
A->>F: POST /checkin (upgrade_details: DOWNLOADING to RESTARTING)
F->>E: update .fleet-agents upgrade_details (refresh)
Note over A: restarts on the new version
A->>F: POST /acks (ack'ing the UPGRADE action)
F->>E: create .fleet-actions-results (refresh)
F->>E: update .fleet-agents upgraded_at, clear upgrade_started_at (refresh)
alt either write times out
F-->>A: 500
A->>F: retry ack after 1 to 5 min, up to 5 times, repeating both writes
else both writes succeed
F-->>A: 200
end
A->>F: POST /checkin (upgrade_details: WATCHING, then none after the upgrade watcher's grace period)
Proposed behavior
The check-in upgrade_details becomes the source of truth for UPGRADE results. The result is written once, when the outcome is known, never at UPG_WATCHING. .fleet-actions-results is a data stream (append-only: only op_type=create by _id is allowed), so a success written early could not be replaced by a later failure or rollback. The result document keeps the same _id (actionID:agentID), action_id, agent_id and namespaces.
sequenceDiagram
participant A as Elastic Agent
participant F as Fleet Server
participant E as Elasticsearch
A->>F: POST /checkin (upgrade_details: DOWNLOADING to RESTARTING)
F->>E: update .fleet-agents upgrade_details (refresh)
Note over A: restarts on the new version
A->>F: POST /checkin (upgrade_details: UPG_WATCHING)
F->>E: update .fleet-agents upgrade_details (refresh)
A->>F: POST /acks (ack'ing the UPGRADE action)
alt stored upgrade_details.action_id equals the acked action id
F-->>A: 200 (no writes)
else no matching upgrade_details
F->>E: create .fleet-actions-results (no refresh, 409 ignored)
F->>E: update .fleet-agents upgraded_at, clear upgrade_started_at (refresh)
F-->>A: 200
end
alt watch period ends
A->>F: POST /checkin (no upgrade_details)
F->>E: create .fleet-actions-results, success, using the stored upgrade_details.action_id (no refresh, 409 ignored)
F->>E: update .fleet-agents upgraded_at, clear upgrade_started_at and upgrade_details
else watcher rolls back
A->>F: POST /checkin (upgrade_details: UPG_ROLLBACK, metadata.reason)
F->>E: create .fleet-actions-results with error (no refresh, 409 ignored)
end
Changes
- Added: on a
POST /checkinwithupgrade_details: UPG_FAILED, create the result witherror=metadata.error_msg(no refresh, 409 ignored) and clearupgrade_started_at. - Added: on a
POST /checkinwithupgrade_details: UPG_ROLLBACK, create the result with a synthesizederrorbuilt frommetadata.reason(e.g.upgrade rolled back: watch failed) and clearupgrade_started_at.UPG_ROLLBACKcarries noerror_msg, so theUPG_FAILEDvalidation does not apply. This is how a failure during the watch period is reported;UPG_FAILEDthere only occurs if the rollback itself fails. - Added: when a check-in without
upgrade_detailscompletes a stored upgrade (existingmarkUpgradeComplete), create the success result for the storedupgrade_details.action_id(no refresh, 409 ignored). If there is no storedaction_id(for example the fast-upgrade race or the staleupgrade_started_atself-heal), no result is written here and the ack remains responsible for it. - Changed: on a
POST /acks, if the storedupgrade_details.action_idequals the acked action id, return 200 and write nothing. - Changed: when the ack does write (no matching
upgrade_details), the result create is no longer refreshed. The.fleet-agentsupdate keeps its refresh. - Changed: the success result for an upgrade with
upgrade_detailsis written when the watch period ends, not at the ack. In Kibana, agents stay Updating (upgrade_started_atset,upgraded_atempty) and the action stays in progress in Agent activity throughUPG_WATCHING. - Changed: failed and rolled-back upgrades are counted as failures in Agent activity. Today they are acked without
errorand counted as successes. - Changed:
@timestampof a result created from a check-in is Fleet Server's receive time, not the agent's clock. - Unchanged: the ack writes as today whenever there is no matching
upgrade_details: agents that predateupgrade_details, fast upgrades between check-ins, same-version or replayed upgrades, an ack before the check-in that stores the details, and acks that carry anerror.
This extends the upgrade_details work in elastic/elastic-agent#3119 (shipped in 8.12), which kept the UPGRADE ack "for backwards compatibility" and left removing it to later, and elastic/kibana#176910, where the Fleet UI began relying on upgrade_details instead of a fixed wait.
Describe a specific use case for the enhancement or feature:
When many Elastic Agents are upgraded at once, each agent acks the UPGRADE action right after it restarts on the new version. If Elasticsearch is slow at that moment, Fleet Server answers the ack with a 500. The agent retries the ack up to 5 times with a 1 to 5 minute backoff and then drops it, so Fleet is never told the upgrade finished. In the meantime every retry makes Fleet Server repeat the same two writes against the already loaded cluster.
With this change the agent's upgrade result does not depend on the ack. Fleet Server records it once, from the upgrade_details the agent already sends on its check-ins, and answers the ack with a cheap 200 so the agent has nothing to retry. An agent whose ack is dropped still gets its result recorded.
An agent whose upgrade fails asynchronously currently acks the action without an error, so Kibana counts the failed upgrade as acknowledged. Instead, with the proposed change, a check-in with upgrade_details in the state UPG_FAILED would record the result with its error set to the error_msg from that upgrade_details, and a check-in in the state UPG_ROLLBACK (what the agent reports when the upgrade watcher reverts a bad upgrade) would record it with an error built from metadata.reason. This would change those failure counts in Kibana's Agent activity. I believe this change makes the failure counts in Kibana's Agent activity more accurate than they are today. @elastic/streams-ui would you be OK with this change?
Activity
kpollich commentedon Nov 20, 2026
🤖 Written with help from Claude
Yes, this is fine from the Streams UI side. Today an agent whose upgrade fails before the restart acks the action with no
error, so Agent activity counts it as a success, and the ack also setsupgraded_at. Recording the failure fromupgrade_detailsfixes that, so I'd treat the change in failure counts as a bug fix.A couple of notes, neither blocking:
upgrade_detailsit no longer writes, soupgraded_atis only set once the details clear after the upgrade watcher's grace period. Kibana reportsupdatingwhileupgrade_started_atis set andupgraded_atis empty, so agents stay Updating through WATCHING instead of going healthy at the ack. I think that's more accurate, but can you add it to the Changed list so it isn't a surprise?upgrade_detailsare stored can also lose the race to the ack. Both behave the same as today, so this is still an improvement. Should a later UPG_FAILED update the existing result instead of being dropped?Open question on mixed Fleet Server versions during a rolling upgrade. If an older Fleet Server stores WATCHING without creating the result, and a newer one then gets the ack and skips it because
upgrade_details.action_idmatches, no result is ever written and the action stays in progress in Agent activity. Should the skip path check that the result exists first?ycombinator commentedon Nov 20, 2026
Thanks for the thorough review, @kpollich.
Yes, I'll add it. The result and
upgraded_atwill now be written when the watch period ends, not at the ack, so agents stay Updating (and the action stays in progress in Agent activity) throughUPG_WATCHING..fleet-actions-resultsis a data stream, so an existing result can't be updated: onlyop_type=createis allowed, and a second doc would skew Kibana's per-action_idcounts. Instead, the result will now be written once the outcome is known: onUPG_FAILED, onUPG_ROLLBACK(what a watch-period revert actually reports, with an error built frommetadata.reason), or when the check-in with noupgrade_detailsends the watch period, i.e. the upgrade was successful. I've updated the sequence diagram to show this.No. Because the result will not be written at
UPG_WATCHINGanymore, it wouldn't exist yet at the ack, and it no longer matters which Fleet Server version storedUPG_WATCHING. The ack skip is safe because the result is written later from the storedupgrade_details.action_id. One narrow limitation remains: in a deployment with more than one Fleet Server instance, during a rolling upgrade of Fleet Server that overlaps an in-flight Agent upgrade, an older Fleet Server can handle the check-in that ends the watch period without writing the result. That leaves the action in progress in Agent activity until it expires. Most deployments have a single Fleet Server instance and aren't affected, so I think we can live with this.Record UPGRADE results from check-in upgrade_details