Retry validator-agent/prober registration; show validator hostname

Both binaries registered with control-api exactly once at startup and
exited (os.Exit(1)) on any failure — including control-api simply not
being up yet (no ordering guarantee between the two at boot/redeploy) or
the admin not having added this validator_id/site_id to the config yet.
Run() now retries registration with capped exponential backoff (3s->30s)
until it succeeds or the process is asked to shut down, instead of
crashing; registerWithRetry is identical in agentcore and probercore
since their Run/register shape already was.

Separately, the admin dashboard's Validators page had no hostname column
even though the agent already reports one on register (mirroring the
prober) and control-api already persists it — only the admin-config read
DTO (validatorDTO in httpapi and dashboard) dropped it before it reached
the template. Added hostname + last_heartbeat_at to that DTO end-to-end
and a Хост/Heartbeat column to validators.html, matching sites.html.

Rebuilt bin/{control-api,admin-dashboard,prober,validator-agent} and
bin/SHA256SUMS per docs/SETUP.md's documented build recipe.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5 committed 2026-09-18 10:43:00 +03:00
1 parent 399c64e801
commit 95f8066eed
15 files changed
+320 -23

No files matched your search

+40 -5
View File
@@ -30,6 +30,13 @@ type Agent struct {
log *slog.Logger
lastHandledIPID int64
// registerRetryInitial/Max govern the backoff used while waiting for a
// successful registration (see registerWithRetry): control-api may not
// be up yet at agent boot, or may come and go across a redeploy, and the
// agent should keep waiting rather than exit.
registerRetryInitial time.Duration
registerRetryMax time.Duration
}
func New(cfg *config.ValidatorAgent, log *slog.Logger) *Agent {
@@ -38,17 +45,19 @@ func New(cfg *config.ValidatorAgent, log *slog.Logger) *Agent {
timeout = 10 * time.Second
}
return &Agent{
cfg: cfg,
client: apiclient.New(cfg.ControlAPIURL, timeout+5*time.Second),
log: log,
cfg: cfg,
client: apiclient.New(cfg.ControlAPIURL, timeout+5*time.Second),
log: log,
registerRetryInitial: 3 * time.Second,
registerRetryMax: 30 * time.Second,
}
}
// Run registers with the Control API and polls forever until ctx is
// cancelled.
func (a *Agent) Run(ctx context.Context) error {
if err := a.register(ctx); err != nil {
return fmt.Errorf("register: %w", err)
if err := a.registerWithRetry(ctx); err != nil {
return err
}
interval := time.Duration(a.cfg.PollIntervalSeconds) * time.Second
@@ -88,6 +97,32 @@ func (a *Agent) register(ctx context.Context) error {
return nil
}
// registerWithRetry retries register with capped exponential backoff until
// it succeeds or ctx is cancelled. Control-api may not be reachable yet at
// agent boot (started before control-api, or a network blip), or may reject
// the request until an admin adds this validator_id to its config — either
// way the agent should keep waiting rather than exit, since both conditions
// can resolve on their own after the agent has already started.
func (a *Agent) registerWithRetry(ctx context.Context) error {
delay := a.registerRetryInitial
for {
err := a.register(ctx)
if err == nil {
return nil
}
a.log.Warn("registration failed, will retry", "err", err, "retry_in", delay)
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(delay):
}
delay *= 2
if delay > a.registerRetryMax {
delay = a.registerRetryMax
}
}
}
type heartbeatReq struct {
LocalState string `json:"local_state"`
}