feat(backend): implement agent heartbeat monitoring and automatic dead-agent cleanup (#170) - #211
Merged
Conversation
…anup (Epta-Node#170) - Add POST /api/agents/:id/heartbeat endpoint with rate limiting - Add updateLastSeen, markStaleAgents, and deleteOfflineAgents DB queries - Add heartbeat cleanup service (mark offline after 5m, delete after 24h) - Add environment configuration variables - Update frontend useAgentRegistry for real-time auto-refresh - Add unit tests for heartbeat endpoint and cleanup service
|
@morelucks is attempting to deploy a commit to the Jaja's projects Team on Vercel. A member of the Team first needs to authorize it. |
devJaja
self-requested a review
July 29, 2026 20:22
devJaja
approved these changes
Jul 29, 2026
devJaja
left a comment
Contributor
There was a problem hiding this comment.
Solid Implementation @morelucks
LGTM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements agent heartbeat monitoring and automatic dead-agent cleanup so that the agent registry reflects real-time online/offline status.
Closes #170
Key Changes
POST /api/agents/:id/heartbeatendpoint inbackend/src/api/routes/agents.tswith per-IP rate limiting (heartbeatRateLimitMiddleware).updateLastSeen(agentId),markStaleAgents(staleThresholdMinutes), anddeleteOfflineAgents(offlineThresholdHours)methods tobackend/src/db/agents.ts.backend/src/services/heartbeat.tsto periodically mark agents offline when inactive for 5 minutes and automatically delete offline agents after 24 hours.HEARTBEAT_INTERVAL_MS,HEARTBEAT_STALE_THRESHOLD_MINUTES, andAGENT_OFFLINE_DELETE_HOURSinbackend/src/config/index.tsandbackend/.env.example.createAppand graceful shutdown handlers inbackend/src/api/app.ts.useAgentRegistry.tsandagentRegistry.tsto auto-refresh status on window focus and status transitions.backend/tests/heartbeat.test.tsverifying all heartbeat and cleanup operations.Verification