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")) })