fix: demo admission check ignores caller cancellation
internal/console/apidemo.go+3 −1internal/console/apidemo_test.go+48 −0
CI failed — run details
Intent
<task-notification> <task-id>bm9k8zgx2</task-id> <tool-use-id>toolu_01GfoqPomN9TsACThZLDv8cx</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/cd1b6de2-ac77-426f-a77d-fc5436969c88/tasks/bm9k8zgx2.output</output-file> <status>completed</status> <summary>Background command "Wait for Task 3 continuation" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 17.3 g CO₂e (2,082,053 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-1, 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/apidemo.go b/internal/console/apidemo.go| index f680afc6e..78c9e029f 100644 |
| --- a/internal/console/apidemo.go |
| +++ b/internal/console/apidemo.go |
| @@ -211,7 +211,9 @@ func (s *Server) demoAdmissionReady(ctx context.Context) error { |
| c.mu.Lock() |
| defer c.mu.Unlock() |
| if !c.checked || !time.Now().Before(c.expiresAt) { |
| - err := validateDemoAdmissionState(ctx, s.cfg, s.store) |
| + // The shared verdict must not cache a caller's cancellation or deadline. |
| + // Validation retains its own ten-second timeout. |
| + err := validateDemoAdmissionState(context.WithoutCancel(ctx), s.cfg, s.store) |
| previous, current := "", "" |
| if c.err != nil { |
| previous = c.err.Error() |
diff --git a/internal/console/apidemo_test.go b/internal/console/apidemo_test.go| index d9362df49..58fa58d35 100644 |
| --- a/internal/console/apidemo_test.go |
| +++ b/internal/console/apidemo_test.go |
| @@ -637,6 +637,54 @@ func expireDemoAdmissionCache(s *Server) { |
| s.demoAdmission.expiresAt = time.Now().Add(-time.Second) |
| } |
| +type demoCancelDuringListStore struct { |
| + release.Store |
| + cancel context.CancelFunc |
| + calls int |
| +} |
| + |
| +func (s *demoCancelDuringListStore) List(ctx context.Context, prefix string) ([]string, error) { |
| + if strings.HasPrefix(prefix, "apps/") { |
| + s.calls++ |
| + s.cancel() |
| + if err := ctx.Err(); err != nil { |
| + return nil, err |
| + } |
| + } |
| + return s.Store.List(ctx, prefix) |
| +} |
| + |
| +func TestDemoAdmissionCallerCancellation(t *testing.T) { |
| + s := demoTestServer(t) |
| + if err := s.demoAdmissionReady(t.Context()); err != nil { |
| + t.Fatal(err) |
| + } |
| + expireDemoAdmissionCache(s) |
| + ctx, cancel := context.WithCancel(t.Context()) |
| + defer cancel() |
| + store := &demoCancelDuringListStore{Store: s.cfg.Releases, cancel: cancel} |
| + s.cfg.Releases = store |
| + r := httptest.NewRequest("POST", "/api/demo/apps", strings.NewReader("archive")).WithContext(ctx) |
| + r.RemoteAddr = "192.0.2.1:1234" |
| + r.Header.Set("Content-Type", "application/gzip") |
| + s.mux.ServeHTTP(newDemoRecorder(), r) |
| + if !errors.Is(ctx.Err(), context.Canceled) || store.calls != 1 { |
| + t.Fatalf("request was not cancelled during refresh: context=%v, LIST calls=%d", ctx.Err(), store.calls) |
| + } |
| + // Publication is not wired yet; reaching DEMO-BUILD proves admission passed. |
| + w := demoRequest(s, "", "192.0.2.2") |
| + if w.Code != 503 || !strings.Contains(w.Body.String(), demoCopy["DEMO-BUILD"]) { |
| + t.Fatalf("fresh create refused after caller cancellation: %d %s", w.Code, w.Body.String()) |
| + } |
| + if store.calls != 1 { |
| + t.Fatalf("fresh create did not reuse the healthy verdict: LIST calls=%d", store.calls) |
| + } |
| + var attempts int |
| + if err := s.store.db.QueryRow(`SELECT count(*) FROM demo_admissions`).Scan(&attempts); err != nil || attempts != 1 { |
| + t.Fatalf("create attempts=%d, want only the fresh caller's attempt: %v", attempts, err) |
| + } |
| +} |
| + |
| func TestDemoAdmissionCacheRefresh(t *testing.T) { |
| s := demoTestServer(t) |
| counted := &demoCountingListStore{Store: s.cfg.Releases} |