From 4246e37384cea058b75cf2c0002f95abc543b7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Sun, 29 Nov 2026 16:37:08 +0100 Subject: [PATCH] fix(agent): apply agent settings as they are when jobs are handed out The jobs endpoint read the agent, and with it allow_private, before its long poll of up to 20 seconds, so jobs handed out afterwards could carry a setting changed in the meantime and the change only applied a poll later. It now reads the agent again when the poll returns jobs. TestCheckerNetwork also waits for two runs at most: the next run after a monitor's first one is on its phase now, up to one and a half intervals later. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- internal/api/agent.go | 20 +++++++++++++++++++- internal/api/checkernet_test.go | 4 +++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/api/agent.go b/internal/api/agent.go index 4988943..26e9d7a 100644 --- a/internal/api/agent.go +++ b/internal/api/agent.go @@ -227,7 +227,25 @@ func (s *Server) agentJobs(c *gin.Context) { internalError(c, err) return } - jobs, orgs, err := s.resolveJobs(ctx, agentOf(c), entries) + agent := agentOf(c) + if len(entries) > 0 { + // The long poll may have waited for a while: settings such as + // allow_private apply to the jobs as they are now. + err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + var err error + agent, err = q.GetAgentByHash(ctx, HashToken(bearerToken(c))) + return err + }) + if errors.Is(err, pgx.ErrNoRows) { + fail(c, http.StatusUnauthorized, "unauthenticated") + return + } + if err != nil { + internalError(c, err) + return + } + } + jobs, orgs, err := s.resolveJobs(ctx, agent, entries) if err != nil { internalError(c, err) return diff --git a/internal/api/checkernet_test.go b/internal/api/checkernet_test.go index 6052d2c..86d2188 100644 --- a/internal/api/checkernet_test.go +++ b/internal/api/checkernet_test.go @@ -85,7 +85,9 @@ func TestCheckerNetwork(t *testing.T) { } waitResult := func(id string, ok bool, what string) { t.Helper() - waitFor(t, 20*time.Second, what, func() bool { + // Two runs at most: the one already handed out, then the next on + // the monitor's phase, up to one and a half intervals later. + waitFor(t, 30*time.Second, what, func() bool { got, msg, seen := latestOf(owner, id) return seen && got == ok && (ok || strings.Contains(msg, "non-public")) }) -- 2.54.1