Skip to content

fix(agent): persist agent ID after auth to prevent crashloop duplicates#6543

Merged
6543 merged 3 commits into
woodpecker-ci:mainfrom
wucm667:fix/agent-crashloop-infinite-entries
May 7, 2026
Merged

fix(agent): persist agent ID after auth to prevent crashloop duplicates#6543
6543 merged 3 commits into
woodpecker-ci:mainfrom
wucm667:fix/agent-crashloop-infinite-entries

Conversation

@wucm667

@wucm667 wucm667 commented May 5, 2026

Copy link
Copy Markdown
Contributor

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 via AgentUpdate instead of creating new ones.

Added AgentID() method to AuthClient to expose the agent ID received during auth.

Verification

  • go build ./cmd/agent/... passes
  • go test ./cmd/agent/... ./agent/... passes
  • go test ./server/rpc/... -run TestRegisterAgent passes

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>
@6543 6543 added bug Something isn't working agent labels May 5, 2026
@woodpecker-bot

woodpecker-bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Account with automation patterns detected 🤖

@wucm667

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.

Signal Points Detail
Many recent forks +51 8 repositories forked in a single day
High sustained fork rate +55 9 repositories forked over 1 day (sustained high activity)

Have thoughts about this account? Let the community know.

🕵🏽 Analyzed 199 public events via AgentScan

@codecov

codecov Bot commented May 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.52%. Comparing base (97eae44) to head (dfe48b2).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@6543 6543 merged commit a7a123d into woodpecker-ci:main May 7, 2026
9 checks passed
@woodpecker-bot woodpecker-bot mentioned this pull request May 7, 2026
1 task
@wucm667 wucm667 deleted the fix/agent-crashloop-infinite-entries branch May 7, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crashlooping agent creates infinite number of agent entires

3 participants