[Control Plane] Graceful shutdown not implemented (literal TODO)
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)inrunServer. - Thread the cancellable context through
server.Startso 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
// TODOcomment.
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/shutdownendpoint — nice-to-have but not part of this fix.
Files
control-plane/cmd/agentfield-server/main.go:38,234— replacewaitForShutdownFuncstub with real signal handling and shutdown sequencecontrol-plane/internal/server/server.go— expose aShutdown(ctx)method on theServerstruct if not already presentcontrol-plane/internal/config/config.go— addShutdownTimeoutSeconds intconfig 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
SIGTERMto 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 shutdowncomment 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.
shall i do this ????
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 #427in the description
Happy coding! :rocket:
shall i do this ????
assigned it to you
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:
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!
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:
@AbirAbbas im working on this