fix: idle demo job loop while admission is off
Gate ready-job publication and build deadlines on admission while keeping claim recovery active. Cover ready jobs and mid-claim recovery with the targeted compatibility test.
2 files changed,
+50
−14
internal/console/demo_claim_e2e_test.go+35 −10internal/console/demo_jobs.go+15 −4
Intent
Attributed to this commit: 16.7 g CO₂e (2,185,350 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on agent-start-demo-3, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/demo_claim_e2e_test.go b/internal/console/demo_claim_e2e_test.go| index 5997a416d..b684ece54 100644 |
| --- a/internal/console/demo_claim_e2e_test.go |
| +++ b/internal/console/demo_claim_e2e_test.go |
| @@ -7,6 +7,7 @@ import ( |
| "encoding/hex" |
| "errors" |
| "io" |
| + "log" |
| "net" |
| "net/http" |
| "net/http/httptest" |
| @@ -444,16 +445,40 @@ func TestDemoClaimOffCompatibility(t *testing.T) { |
| } |
| }) |
| t.Run("admissionOffIdle", func(t *testing.T) { |
| - s, _, _ := claimTestServer(t) |
| - s.demoClaimTestEnabled = false |
| - s.cfg.Demo.Enabled = false |
| - counted := &demoDisabledStore{demoCountingStore: &demoCountingStore{Store: s.cfg.Releases}} |
| - s.cfg.Releases = counted |
| - ctx, cancel := context.WithTimeout(t.Context(), 50*time.Millisecond) |
| - defer cancel() |
| - s.RunDemoJobs(ctx, nil) |
| - if counted.gets.Load()+counted.puts.Load()+counted.lists.Load()+counted.polls.Load()+counted.deletes.Load() != 0 { |
| - t.Fatal("admission-off idle recovery added store requests") |
| + for _, ready := range []bool{false, true} { |
| + t.Run(strconv.FormatBool(ready), func(t *testing.T) { |
| + var s *Server |
| + if ready { |
| + s, _, _, _ = demoPublishFixture(t) |
| + next, err := s.nextDemoJobDeadline(t.Context()) |
| + if err != nil || !next.Valid { |
| + t.Fatalf("ready job has no publication deadline: %+v %v", next, err) |
| + } |
| + } else { |
| + s, _, _ = claimTestServer(t) |
| + } |
| + s.demoClaimTestEnabled = false |
| + s.cfg.Demo.Enabled = false |
| + counted := &demoDisabledStore{demoCountingStore: &demoCountingStore{Store: s.cfg.Releases}} |
| + s.cfg.Releases = counted |
| + next, err := s.nextDemoJobDeadline(t.Context()) |
| + if err != nil || next.Valid { |
| + t.Fatalf("admission off scheduled publication: %+v %v", next, err) |
| + } |
| + var logs bytes.Buffer |
| + old := log.Writer() |
| + log.SetOutput(&logs) |
| + defer log.SetOutput(old) |
| + ctx, cancel := context.WithTimeout(t.Context(), 50*time.Millisecond) |
| + defer cancel() |
| + s.RunDemoJobs(ctx, nil) |
| + if strings.Contains(logs.String(), "demo publication") { |
| + t.Fatalf("admission off attempted publication: %s", &logs) |
| + } |
| + if counted.gets.Load()+counted.puts.Load()+counted.lists.Load()+counted.polls.Load()+counted.deletes.Load() != 0 { |
| + t.Fatal("admission-off idle recovery added store requests") |
| + } |
| + }) |
| } |
| }) |
diff --git a/internal/console/demo_jobs.go b/internal/console/demo_jobs.go| index 769099a6b..a7288020f 100644 |
| --- a/internal/console/demo_jobs.go |
| +++ b/internal/console/demo_jobs.go |
| @@ -469,8 +469,10 @@ func (s *Server) RunDemoJobs(ctx context.Context, watch *release.ChangeWatch) { |
| if err := s.ObserveDemoJobs(ctx, watch); err != nil { |
| log.Printf("console: demo changes: %v", err) |
| } |
| - if err := s.publishReadyDemos(ctx); err != nil { |
| - log.Printf("console: demo publication: %v", err) |
| + if s.cfg.Demo.Enabled { |
| + if err := s.publishReadyDemos(ctx); err != nil { |
| + log.Printf("console: demo publication: %v", err) |
| + } |
| } |
| if err := s.ReconcileDemoClaims(ctx, false); err != nil { |
| log.Printf("console: %s: %v", demoClaimPending, err) |
| @@ -481,8 +483,7 @@ func (s *Server) RunDemoJobs(ctx context.Context, watch *release.ChangeWatch) { |
| // A busy upload may leave an overdue operation for the next pass. |
| claimNext.Int64 = max(claimNext.Int64, time.Now().Add(time.Second).UnixNano()) |
| } |
| - var next sql.NullInt64 |
| - err := s.store.db.QueryRowContext(ctx, `SELECT min(CASE state WHEN 'queued' THEN deadline WHEN 'ready' THEN ? ELSE result_by END) FROM demo_jobs WHERE state IN ('queued','picked','ready')`, time.Now().Add(time.Second).UnixNano()).Scan(&next) |
| + next, err := s.nextDemoJobDeadline(ctx) |
| if claimNext.Valid && (!next.Valid || claimNext.Int64 < next.Int64) { |
| next = claimNext |
| } |
| @@ -511,6 +512,16 @@ func (s *Server) RunDemoJobs(ctx context.Context, watch *release.ChangeWatch) { |
| } |
| } |
| +// Admission controls build publication and its timer; claim recovery has its own timer. |
| +func (s *Server) nextDemoJobDeadline(ctx context.Context) (sql.NullInt64, error) { |
| + var next sql.NullInt64 |
| + if !s.cfg.Demo.Enabled { |
| + return next, nil |
| + } |
| + err := s.store.db.QueryRowContext(ctx, `SELECT min(CASE state WHEN 'queued' THEN deadline WHEN 'ready' THEN ? ELSE result_by END) FROM demo_jobs WHERE state IN ('queued','picked','ready')`, time.Now().Add(time.Second).UnixNano()).Scan(&next) |
| + return next, err |
| +} |
| + |
| func (s *Server) demoJobsWake() chan struct{} { |
| s.demoJobs.mu.Lock() |
| defer s.demoJobs.mu.Unlock() |