[9.4](backport #7712) feat: add synchronous enrollment write strategy to prevent ghost agents - #7721
Merged
Merged
Conversation
…ts (#7712) * feat: add synchronous enrollment write strategy to prevent ghost agents Introduce inputs[].server.feature_flags.sync_enrollment_write (default false). When true, createFleetAgent writes the agent document directly with op_type=create&refresh=wait_for so the document is committed and visible to search before the enrollment response is sent. Any retry on any pod finds the existing document immediately, eliminating ghost agents caused by the async bulk queue / EOF race. The existing async path is unchanged when the flag is false. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor: rename feature flag to _sync_enrollment_write to signal temporary status Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test: fix createFleetAgent call to pass syncWrite argument Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test: add unit tests for sync enrollment write path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs: spell out full config key in SyncEnrollmentWrite comment The config tag uses an underscore prefix (_sync_enrollment_write) but the doc comment didn't make the exact key explicit, causing inconsistency with the PR description. Spell out the full key in the comment. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: remove changelog fragment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: fix spelling behaviour -> behavior in comment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test: assert op_type=create and refresh=wait_for in sync enrollment tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> (cherry picked from commit d6324c7)
mergify
Bot
requested review from
blakerouse and
ycombinator
and removed request for
a team
August 29, 2026 00:43
4 tasks
ycombinator
approved these changes
Aug 29, 2026
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.
What is the problem this PR solves?
When an enrollment write is committed to fleet-server's in-memory bulk queue but the HTTP response is lost before it reaches the agent (network drop, EOF), the agent retries enrollment. If the retry lands on a different pod, that pod's
FindAgentsearch finds nothing — the write hasn't been flushed to Elasticsearch yet — and creates a second agent document. These duplicate documents ("ghost agents") accumulate and do not resolve on their own.The batched pre-refresh dedup approach in #7662 cannot prevent this: cross-pod retries are never in the same flush batch, so in-batch dedup never fires. Evidence from the 30k serverless checkin scale test: 35 ghost agents with
enrolled_attimestamps clustered in a 21-second window (11:53:42–11:54:03 UTC), zeroErrEnrollDuplicate429s — confirming in-batch dedup never triggered for any of the 35 retries.How does this PR solve the problem?
A new feature flag,
inputs[].server.feature_flags._sync_enrollment_write(default:false), selects the enrollment write strategy.When
false(default), the existing async bulk queue path is unchanged.When
true,createFleetAgentwrites the agent document directly to Elasticsearch usingop_type=create&refresh=wait_for. ES blocks until the document is committed and visible to search on all shards before returning. The enrollment response is not sent until this write completes, so any retry on any pod finds the existing document immediately. A 409 fromop_type=createis treated as success.The
_prefix on the flag name signals that it is internal and temporary. The intent is to enable it in Staging via serverless-gitops, validate with the 30k checkin scale test, and then remove the flag entirely — making the sync path the permanent enrollment write path.How to test this PR locally
Enable the flag and run the 30k Fleet Server checkin scale test against Staging. Confirm ghost agent count is 0 after enrollment completes.
Design Checklist
Checklist
./changelog/fragmentsusing the changelog toolRelated issues
This is an automatic backport of pull request feat: add synchronous enrollment write strategy to prevent ghost agents #7712 done by Mergify.