Skip to content

Retried UPGRADE acks overload Elasticsearch; record upgrade results from check-in upgrade_details #8274

In review

Description

@ycombinator

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)
Loading

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
Loading

Changes

  • Added: on a POST /checkin with upgrade_details: UPG_FAILED, create the result with error = metadata.error_msg (no refresh, 409 ignored) and clear upgrade_started_at.
  • Added: on a POST /checkin with upgrade_details: UPG_ROLLBACK, create the result with a synthesized error built from metadata.reason (e.g. upgrade rolled back: watch failed) and clear upgrade_started_at. UPG_ROLLBACK carries no error_msg, so the UPG_FAILED validation does not apply. This is how a failure during the watch period is reported; UPG_FAILED there only occurs if the rollback itself fails.
  • Added: when a check-in without upgrade_details completes a stored upgrade (existing markUpgradeComplete), create the success result for the stored upgrade_details.action_id (no refresh, 409 ignored). If there is no stored action_id (for example the fast-upgrade race or the stale upgrade_started_at self-heal), no result is written here and the ack remains responsible for it.
  • Changed: on a POST /acks, if the stored upgrade_details.action_id equals 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-agents update keeps its refresh.
  • Changed: the success result for an upgrade with upgrade_details is written when the watch period ends, not at the ack. In Kibana, agents stay Updating (upgrade_started_at set, upgraded_at empty) and the action stays in progress in Agent activity through UPG_WATCHING.
  • Changed: failed and rolled-back upgrades are counted as failures in Agent activity. Today they are acked without error and counted as successes.
  • Changed: @timestamp of 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 predate upgrade_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 an error.

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

  1. added
    enhancement
    Team:Elastic-Agent-Control-Plane
    on Nov 18, 2026
  2. kpollich commented on Nov 20, 2026

    @kpollich
    Member

    🤖 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 sets upgraded_at. Recording the failure from upgrade_details fixes that, so I'd treat the change in failure counts as a bug fix.

    A couple of notes, neither blocking:

    • Agents will show as Updating for longer. When the ack matches the stored upgrade_details it no longer writes, so upgraded_at is only set once the details clear after the upgrade watcher's grace period. Kibana reports updating while upgrade_started_at is set and upgraded_at is 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?
    • Some failures will still count as successes. The result create ignores 409s, so a failure or rollback during the watch period keeps the success written at WATCHING. A failure that happens before any upgrade_details are 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_id matches, no result is ever written and the action stays in progress in Agent activity. Should the skip path check that the result exists first?

  3. ycombinator commented on Nov 20, 2026

    @ycombinator
    ContributorAuthor

    Thanks for the thorough review, @kpollich.

    can you add it to the Changed list so it isn't a surprise?

    Yes, I'll add it. The result and upgraded_at will 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) through UPG_WATCHING.

    Should a later UPG_FAILED update the existing result instead of being dropped?

    .fleet-actions-results is a data stream, so an existing result can't be updated: only op_type=create is allowed, and a second doc would skew Kibana's per-action_id counts. Instead, the result will now be written once the outcome is known: on UPG_FAILED, on UPG_ROLLBACK (what a watch-period revert actually reports, with an error built from metadata.reason), or when the check-in with no upgrade_details ends the watch period, i.e. the upgrade was successful. I've updated the sequence diagram to show this.

    Should the skip path check that the result exists first?

    No. Because the result will not be written at UPG_WATCHING anymore, it wouldn't exist yet at the ack, and it no longer matters which Fleet Server version stored UPG_WATCHING. The ack skip is safe because the result is written later from the stored upgrade_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.

  4. added a commit that references this issue on Nov 20, 2026
    6a6b672
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Team:Elastic-Agent-Control-Planeenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions