You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Record UPGRADE results from check-in upgrade_details - #8319
Each UPGRADE ack makes Fleet Server do two refreshed Elasticsearch writes: the result in .fleet-actions-results and the update in .fleet-agents. When Elasticsearch is slow, either write can time out, so the ack returns a 500, the agent retries it up to 5 times, and every retry repeats both writes against the already loaded cluster.
Failed and rolled-back upgrades are also acked without an error, so Kibana's Agent activity counts them as successes. See #8274 for the full design discussion.
How does this PR solve the problem?
The check-in upgrade_details becomes the source of truth for UPGRADE action results, as was always planned in elastic/elastic-agent#3119, and the .fleet-actions-results doc is created once, when the outcome is known:
UPG_FAILED records error_msg once the failure is final: a download failure can be retried until metadata.retry_until, so it is recorded only after that deadline has passed (plus a one minute clock-skew grace). Failures with no retry_until, such as extract or replace failures, are recorded immediately.
UPG_ROLLBACK records an error built from metadata.reason, unless the UPGRADE action requested the rollback (data.rollback), in which case it records a success.
A check-in without upgrade_details records a success when the stored upgrade shows evidence of completion: the agent's version changed, or the stored state is UPG_WATCHING. A stored UPG_FAILED or UPG_ROLLBACK whose upgrade_started_at is still set has no result yet (creating it failed), so it is recorded with a generic error. Other stored states, for example a canceled UPG_SCHEDULED, record nothing.
An ack whose action matches the stored upgrade_details.action_id and carries no error returns 200 without writing; otherwise it writes as before, but without refreshing the result create.
Known limitation: for upgrades to SNAPSHOT versions, the Agent clears upgrade_details.metadata.retry_until after resolving the snapshot build ID, even though the artifact download keeps retrying. A transient download failure after that point is recorded as a final failure even if a later retry succeeds. Upgrades to released versions are not affected.
Scale tests
Ran /perf-tests (10k agents, serverless QA) on this PR and compared it with a baseline run on main.
Upgrade action → delivered to agent on check-in, p95
95.6 s
96.5 s
Upgrade delivered → ack, p95
601 s
380 s
Agents that sent an UPGRADE ack
10,000
4,413
Fleet Server HTTP 5xx
296
261
Fleet Server HTTP 429
61.2k
55.4k
Elasticsearch circuit breaker errors / rejections
0 / 0
0 / 0
unable to record the upgrade result, retrying on a later check-in
0
454
Upgrade step
completed in 11m37s
hit the 16 min poll limit (9,992 of 10,000 acked)
Check-in delivery latency is unchanged.
Elasticsearch load during the upgrade stalls on both: slow small writes to the single-shard .fleet-agents-7. This happened on main too, so it isn't specific to this change. Run-to-run ES sizing and autoscaling varied a lot.
The retry message only appears with this PR: slow .fleet-agents writes cancel the request context and the result is retried on a later check-in.
How to test this PR locally
Run go test ./internal/pkg/api/ ./internal/pkg/dl/ for the unit tests. The integration tests are in internal/pkg/server/upgrade_results_integration_test.go and need the docker compose environment: TEST_RUN=Test_Upgrade_Results mage test:integration.
Design Checklist
I have ensured my design is stateless and will work when multiple fleet-server instances are behind a load balancer.
I have or intend to scale test my changes, ensuring it will work reliably with 100K+ agents connected.
I have included fail safe mechanisms to limit the load on fleet-server: rate limiting, circuit breakers, caching, load shedding, etc.
Checklist
I have commented my code, particularly in hard-to-understand areas
I have added tests that prove my fix is effective or that my feature works
I have added an entry in ./changelog/fragments using the changelog tool
Create the UPGRADE action result from the check-in upgrade_details once the
outcome is known (UPG_FAILED, UPG_ROLLBACK, or the check-in without
upgrade_details that ends the watch period) instead of on every UPGRADE ack.
An ack that matches the stored upgrade_details.action_id and carries no error
returns 200 without writing; otherwise it writes as before, but without
refreshing the result create.
Failed and rolled-back upgrades are now recorded with an error, so they count
as failures in Kibana's Agent activity.
Closeselastic#8274
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This pull request does not have a backport label. Could you fix it @ycombinator? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:
backport-./d./d is the label to automatically backport to the 8./d branch. /d is the digit
backport-active-all is the label that automatically backports to all active branches.
backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Retryable upgrade failures are prematurely recorded as immutable final failures, while incorrect mock expectations cause the new upgrade tests to fail before validating the behavior.
This PR moves UPGRADE result recording to check-in upgrade_details, reducing repeated Elasticsearch writes from acknowledgments and reporting failed or rolled-back upgrades in Agent activity.
Changes:
Record results when check-ins report failure, rollback, or completion of a stored upgrade.
Skip matching, error-free UPGRADE acknowledgments and remove refreshes from UPGRADE result creates.
Extend the stored upgrade schema and add unit tests, integration tests, and a changelog entry.
File
Description
model/schema.json
Define stored upgrade action, state, and error fields.
The action cache only retains the action ID and type, so a cache hit
produced an UPGRADE result with empty namespaces.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cached actions lose namespaces needed for result visibility
internal/pkg/api/handleCheckin.go:940
GetAction returns only the action ID and type, not namespaces (internal/pkg/cache/cache.go:112–150). Progress check-ins populate this cache, so completion can create a result without the original namespaces, breaking namespace-scoped activity visibility. Fetch the full action here, or extend the cache to preserve namespaces.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Critical check-in logic can permanently suppress missing upgrade results and irreversibly record retryable download failures or successful user-requested rollbacks as terminal errors.
User-requested rollbacks are incorrectly recorded as failures
internal/pkg/api/handleCheckin.go:788
UPG_ROLLBACK also represents a successful user-requested rollback: the Agent's default-branch manual rollback path sets this state with a manual-rollback reason. When those details precede the ack for a rollback action, this branch records an immutable error result and the matching ack is skipped, counting a successful requested rollback as a failure. Inspect the action's rollback flag and distinguish requested rollbacks from watchdog-triggered reverts before selecting the result error.
Failure details are cleared before the result is recoverable
internal/pkg/api/handleCheckin.go:877
If an older Fleet Server stored UPG_FAILED or UPG_ROLLBACK but its ack never created a result, the first check-in without details skips that result here and then erases the stored action ID and error. The failure becomes unrecoverable from later check-ins, and a delayed error-free ack can record success instead. Ensure the stored terminal result exists before clearing the details, preserving enough metadata to reconstruct failure and rollback errors.
Stale failure reports can clear a newer upgrade marker
internal/pkg/api/handleCheckin.go:820
After Kibana dispatches another upgrade, a check-in can still report the previous failure—the Agent's default-branch upgrade-wait helper explicitly accounts for stale UPG_FAILED details. This unconditional write clears the new upgrade_started_at even when recorded is true, and subsequent progress check-ins do not restore it, so the new upgrade loses its Updating marker. Preserve the marker on repeated terminal reports and associate any clearing with the upgrade that actually ended.
The agent reports UPG_FAILED for each failed download attempt while it
keeps retrying until metadata.retry_until. Treat a UPG_FAILED check-in
as final only when retry_until is missing or has passed (plus a clock
skew grace), so a retried download that succeeds is not recorded as a
failure. The decision uses the check-in alone, so any Fleet Server
instance reaches the same outcome.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A check-in without upgrade_details recorded a success for any stored
upgrade, including a scheduled upgrade the agent canceled. Record a
success only for a changed version or a stored UPG_WATCHING, and settle a
stored UPG_FAILED or UPG_ROLLBACK that has not been settled yet
(upgrade_started_at still set) with an idempotent create from the stored
state. Other stored states record nothing.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved check-in handling issues can record permanent failures for retryable downloads, misclassify rollbacks as successes, and discard stored rollback reasons.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The success condition incorrectly treats a version change as proof of upgrade success even when a stored rollback is pending, permanently recording the rollback as a success in the append-only results.
…keep its reason
A rollback returns the agent to its previous version, so a changed
version does not imply a successful upgrade. Store metadata.reason in
the upgrade details model so an unsettled rollback recovered from the
stored state keeps its reason.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Discarding retryable upgrade failures can leave the stored state scheduled/requested, allowing a no-error acknowledgment to record immutable success for an upgrade that ultimately fails.
Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.
Queue this pull request once it meets the queue conditions
Ignoring a retryable UPG_FAILED left the stored upgrade at UPG_SCHEDULED
or UPG_REQUESTED, so the ack the agent sends for a failed upgrade (without
an error) was taken for a skipped upgrade and recorded a success. Store it
as UPG_DOWNLOADING with the failure as retry_error_msg instead, which also
shows the upgrade as progressed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
A failed result create with an empty upgrade timestamp leaves no pending marker, causing subsequent check-ins and acknowledgments to skip retries and permanently lose the result even after Elasticsearch recovers.
A failed action lookup or result create is logged and retried by a later
check-in, instead of failing the check-in: the agent must still report its
health and receive actions. The stored upgrade_details are kept so the
retry still has what it needs.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
A failed result creation when upgrade_started_at is already empty permanently loses the action result because subsequent check-ins and acknowledgments skip recovery.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A failed result creation after a version-inferred success loses its retry path, allowing the next unchanged-version, no-details check-in to clear the action ID without recording the result.
// Do not fail the check-in (the agent must still report its health and receive
// actions), and keep the stored upgrade_details so the next check-in tries again.
zerolog.Ctx(ctx).Error().Err(err).Str(ecs.ActionID, ud.ActionID).Str(ecs.AgentID, agent.Agent.ID).Msg("unable to record the upgrade result, retrying on a later check-in")
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
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 is the problem this PR solves?
Each UPGRADE ack makes Fleet Server do two refreshed Elasticsearch writes: the result in
.fleet-actions-resultsand the update in.fleet-agents. When Elasticsearch is slow, either write can time out, so the ack returns a 500, the agent retries it up to 5 times, and every retry repeats both writes against the already loaded cluster.Failed and rolled-back upgrades are also acked without an
error, so Kibana's Agent activity counts them as successes. See #8274 for the full design discussion.How does this PR solve the problem?
The check-in
upgrade_detailsbecomes the source of truth for UPGRADE action results, as was always planned in elastic/elastic-agent#3119, and the.fleet-actions-resultsdoc is created once, when the outcome is known:UPG_FAILEDrecordserror_msgonce the failure is final: a download failure can be retried untilmetadata.retry_until, so it is recorded only after that deadline has passed (plus a one minute clock-skew grace). Failures with noretry_until, such as extract or replace failures, are recorded immediately.UPG_ROLLBACKrecords an error built frommetadata.reason, unless the UPGRADE action requested the rollback (data.rollback), in which case it records a success.upgrade_detailsrecords a success when the stored upgrade shows evidence of completion: the agent's version changed, or the stored state isUPG_WATCHING. A storedUPG_FAILEDorUPG_ROLLBACKwhoseupgrade_started_atis still set has no result yet (creating it failed), so it is recorded with a generic error. Other stored states, for example a canceledUPG_SCHEDULED, record nothing.An ack whose action matches the stored
upgrade_details.action_idand carries no error returns 200 without writing; otherwise it writes as before, but without refreshing the result create.Known limitation: for upgrades to SNAPSHOT versions, the Agent clears
upgrade_details.metadata.retry_untilafter resolving the snapshot build ID, even though the artifact download keeps retrying. A transient download failure after that point is recorded as a final failure even if a later retry succeeds. Upgrades to released versions are not affected.Scale tests
Ran
/perf-tests(10k agents, serverless QA) on this PR and compared it with a baseline run onmain.main(#60)unable to record the upgrade result, retrying on a later check-in.fleet-agents-7. This happened onmaintoo, so it isn't specific to this change. Run-to-run ES sizing and autoscaling varied a lot..fleet-agentswrites cancel the request context and the result is retried on a later check-in.How to test this PR locally
Run
go test ./internal/pkg/api/ ./internal/pkg/dl/for the unit tests. The integration tests are ininternal/pkg/server/upgrade_results_integration_test.goand need the docker compose environment:TEST_RUN=Test_Upgrade_Results mage test:integration.Design Checklist
Checklist
./changelog/fragmentsusing the changelog toolRelated issues
upgrade_details#8274🤖 Generated with Claude Code