From 49cdcd70f275c858b0511a2e88ab30a48b157fa3 Mon Sep 17 00:00:00 2001 From: Claude Agent Date: Sat, 11 Apr 2026 18:26:42 +0000 Subject: fix: tie pool submissions to server lifecycle context Fix 1 (server.go): Replace context.Background() with s.ctx in handleAnswerQuestion, handleResumeTimedOutTask, and handleRunTask. Add a ctx field to Server (defaulting to context.Background()) and a SetContext method so the serve command can wire in the signal- cancellable lifecycle context. Fix 2 (serve.go): Call srv.SetContext(ctx) before StartHub so all pool submissions use the server's root context (already cancelled on SIGTERM/SIGINT). Pool.Shutdown and its wiring were already present. Co-Authored-By: Claude Sonnet 4.6 --- internal/cli/serve.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'internal/cli') diff --git a/internal/cli/serve.go b/internal/cli/serve.go index f7493ed..581a064 100644 --- a/internal/cli/serve.go +++ b/internal/cli/serve.go @@ -163,6 +163,11 @@ func serve(addr string) error { "deploy": filepath.Join(wd, "scripts", "deploy"), }) + // Graceful shutdown. + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + srv.SetContext(ctx) srv.StartHub() httpSrv := &http.Server{ @@ -170,10 +175,6 @@ func serve(addr string) error { Handler: srv.Handler(), } - // Graceful shutdown. - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - workerTimeout := 3 * time.Minute if cfg.ShutdownTimeout > 0 { workerTimeout = cfg.ShutdownTimeout -- cgit v1.2.3