agentfield icon indicating copy to clipboard operation
agentfield copied to clipboard

[Control Plane] Graceful shutdown not implemented (literal TODO)

Open santoshkumarradha opened this issue 7 months ago • 7 comments

Summary

Graceful shutdown is not implemented — runServer blocks on a select {} loop and the codebase contains a literal // TODO: Implement graceful shutdown comment, so SIGTERM during a rolling deploy kills in-flight requests immediately.

Context

main.go:234 ends runServer by calling waitForShutdownFunc() which is defined at line 38 as func() { select {} }. There is no signal.NotifyContext, no http.Server.Shutdown, and no draining of in-flight agent executions, presence sweeps, or webhook dispatchers. A rolling deploy or pod eviction sends SIGTERM which terminates the process mid-request, leaving executions in an indeterminate state in storage and potentially corrupting in-progress workflow DAGs. This is classified CRITICAL because it affects every production deployment on every restart.

Scope

In Scope

  • Install signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM) in runServer.
  • Thread the cancellable context through server.Start so background goroutines (presence manager, status forwarder, webhook dispatcher) stop cleanly.
  • Call http.Server.Shutdown(ctx) with a configurable drain timeout (default 30s) to let in-flight HTTP requests complete.
  • Replace the select {} no-op with the real shutdown sequence.
  • Remove the // TODO comment.

Out of Scope

  • Implementing execution checkpointing or resuming interrupted workflows — that is a larger feature.
  • Changing how the server starts or how routes are registered.
  • Adding a /healthz/shutdown endpoint — nice-to-have but not part of this fix.

Files

  • control-plane/cmd/agentfield-server/main.go:38,234 — replace waitForShutdownFunc stub with real signal handling and shutdown sequence
  • control-plane/internal/server/server.go — expose a Shutdown(ctx) method on the Server struct if not already present
  • control-plane/internal/config/config.go — add ShutdownTimeoutSeconds int config field (default 30)
  • control-plane/cmd/agentfield-server/main_test.go — integration test: send SIGTERM, verify server drains and exits within timeout

Acceptance Criteria

  • [ ] Sending SIGTERM to the server initiates a clean shutdown that waits for in-flight HTTP requests to complete (up to the configured timeout)
  • [ ] Background goroutines (presence manager, at minimum) are stopped before the process exits
  • [ ] The literal // TODO: Implement graceful shutdown comment is removed
  • [ ] Server exits with code 0 on clean shutdown, non-zero on timeout exceeded
  • [ ] Tests pass (go test ./control-plane/...)
  • [ ] Linting passes (make lint)

Notes for Contributors

Severity: CRITICAL

This is the highest-priority correctness fix. Use golang.org/x/net/context signal helpers or the stdlib signal.NotifyContext (Go 1.16+). The drain timeout must be configurable so teams with long-running executions can adjust it. Check internal/services/presence_manager.go and any goroutine launched in main.go or server.Start — each needs a ctx.Done() exit path.

santoshkumarradha avatar Apr 12 '26 03:04 santoshkumarradha

shall i do this ????

dinzz005 avatar May 01 '26 08:05 dinzz005

Thanks for picking this up, @dinzz005! :tada:

Here's what to expect:

  • We'll check in after 7 days if we haven't heard an update
  • After 14 days, we'll send a second reminder
  • After 21 days without activity, we'll unassign to let others contribute

Tips for success:

  • Drop a comment when you start working on it
  • Share any blockers - we're here to help!
  • Link your PR with Fixes #427 in the description

Happy coding! :rocket:

github-actions[bot] avatar May 02 '26 13:05 github-actions[bot]

shall i do this ????

assigned it to you

AbirAbbas avatar May 02 '26 13:05 AbirAbbas

Hey @dinzz005! :wave:

Just a friendly reminder that you're assigned to this issue. It's been about a week since assignment.

How's it going? We'd love to hear:

  • Any progress updates?
  • Running into any blockers we can help with?
  • Need more time? (Totally fine!)

A quick comment helps us know you're still interested. If your plans have changed, no worries at all - just let us know and we can find another contributor.

Thanks for contributing to AgentField! :rocket:

github-actions[bot] avatar May 08 '26 10:05 github-actions[bot]

Hi @dinzz005,

Just checking in again! It's been 14 days since we last heard from you on this issue.

Quick options:

  • :speech_balloon: Drop a comment with a progress update
  • :link: Link a draft PR if you've started working on it
  • :wave: Let us know if you'd like to be unassigned (no judgment!)

If we don't hear back in 7 days, we'll unassign this issue to give other contributors a chance to help.

Thanks for understanding!

github-actions[bot] avatar May 15 '26 11:05 github-actions[bot]

Hi @dinzz005,

It's been 21 days since the last update on this issue. To keep the project moving, we've unassigned this issue so other contributors can pick it up.

No worries at all! Life happens, and we totally understand. If you'd like to continue working on this, just comment here and we'll reassign it to you.

This issue is now available for anyone who'd like to contribute. Check out our contribution guidelines if you're interested!

Thanks for your interest in AgentField! :heart:

github-actions[bot] avatar May 22 '26 11:05 github-actions[bot]

@AbirAbbas im working on this

7vignesh avatar Jul 03 '26 20:07 7vignesh