fix(agent): persist agent ID after auth to prevent crashloop duplicates#6543
Merged
6543 merged 3 commits intoMay 7, 2026
Merged
Conversation
When the agent crashes before completing registration, it loses its assigned ID. On restart, it authenticates as a new agent (ID 0) and gets a fresh server entry, leading to infinite agent entries during crashloop. Persist the agent ID immediately after successful authentication so subsequent restarts reuse the same server-side entry. Closes woodpecker-ci#6527 Signed-off-by: wucm667 <stevenwucongmin@gmail.com>
Contributor
Account with automation patterns detected 🤖We analyzed recent public events and found several patterns that are frequently associated with automated scripts or AI agents. Human? 0% likely to be a human.
Have thoughts about this account? Let the community know. 🕵🏽 Analyzed 199 public events via AgentScan |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6543 +/- ##
==========================================
- Coverage 41.53% 41.52% -0.01%
==========================================
Files 431 431
Lines 28725 28727 +2
==========================================
Hits 11930 11930
- Misses 15721 15724 +3
+ Partials 1074 1073 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6543
approved these changes
May 7, 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.
Fixes #6527
Bug
When the Woodpecker agent is unable to query Docker, it crashes and restarts. Each restart creates a new agent entry on the server, leading to an infinite number of agent entries during crashloop.
Root Cause
The agent receives its assigned ID during authentication but only persists it after completing registration. If the agent crashes between auth and registration (e.g., Docker connection failure), the ID is lost. On restart, it authenticates as a new agent (ID 0) and gets a fresh server-side entry.
Fix
Persist the agent ID immediately after successful authentication in
cmd/agent/core/agent.go. This ensures subsequent restarts reuse the same server-side entry viaAgentUpdateinstead of creating new ones.Added
AgentID()method toAuthClientto expose the agent ID received during auth.Verification
go build ./cmd/agent/...passesgo test ./cmd/agent/... ./agent/...passesgo test ./server/rpc/... -run TestRegisterAgentpasses