Skip to content

[Task]: Deregister agents from the registry on graceful shutdown #91

Description

@grantfox-oss

Each specialist agent registers with the registry at startup and then stays status: active in registry.json for its whole lifetime. When an agent process stops cleanly — a Render redeploy, a SIGTERM, a local Ctrl-C — it never tells the registry it's going away. The record lingers as active, the orchestrator's planner can still select it, and the failure is only caught later by the executor's runtime health check — wasting a planning cycle and adding task latency. Clean shutdowns should not require the registry to discover the agent is gone.

Goal

On graceful shutdown, an agent tells the registry it's leaving (deregister, or mark itself inactive) before the process exits.

Requirements & constraints

  • Add a registry endpoint to deregister / mark-inactive an agent, scoped to the agent's own identity (an agent must not be able to deregister a different agent). If a suitable endpoint doesn't exist, adding it is part of this work.
  • Each agent installs SIGTERM and SIGINT handlers that call it, then close the HTTP server and exit 0.
  • The shutdown call must be timeout-bounded so a slow or unreachable registry can never hang the process exit.
  • This pairs with the stale-agent TTL expiry work (draft issue [Task]: Add unit tests for the CleverVault contract #10): graceful shutdown handles the clean case, TTL expiry handles crashes. They're complementary and independent — neither blocks the other.

Design decisions left to the implementer

Edge cases to consider

  • Registry unreachable at shutdown → log a warning and exit anyway within the timeout (don't hang, don't crash-loop).
  • Double signal (two SIGTERMs) → deregister once, exit once.
  • Deregistering an unknown/already-removed id → handled gracefully by the endpoint.

Acceptance criteria

  • Registry exposes an identity-scoped deregister/mark-inactive endpoint
  • Each agent's SIGTERM/SIGINT handler calls it, then closes the server and exits 0
  • The call is timeout-bounded; an unreachable registry never hangs exit
  • Double-signal and unknown-id cases handled
  • Tests cover the endpoint (happy path, unknown id, wrong-identity rejection) and the shutdown wiring
  • npm test passes

Relevant files

  • packages/registry/src/server.ts, packages/registry/src/server.test.ts, each packages/agents/*/src/server.ts (or shared startup helper)

Notes for contributors

If you'd like to work on this, comment below so we can assign it to you.
Questions welcome — see CONTRIBUTING.md for setup
and workflow.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions