Skip to content

feat(backend): implement agent heartbeat monitoring and automatic dead-agent cleanup (#170) - #211

Merged
devJaja merged 1 commit into
Epta-Node:mainfrom
morelucks:feat/heartbeat-monitoring
Jul 29, 2026
Merged

feat(backend): implement agent heartbeat monitoring and automatic dead-agent cleanup (#170)#211
devJaja merged 1 commit into
Epta-Node:mainfrom
morelucks:feat/heartbeat-monitoring

Conversation

@morelucks

Copy link
Copy Markdown
Contributor

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

  • Heartbeat Endpoint: Implemented POST /api/agents/:id/heartbeat endpoint in backend/src/api/routes/agents.ts with per-IP rate limiting (heartbeatRateLimitMiddleware).
  • Database Queries: Added updateLastSeen(agentId), markStaleAgents(staleThresholdMinutes), and deleteOfflineAgents(offlineThresholdHours) methods to backend/src/db/agents.ts.
  • Background Cleanup Service: Created backend/src/services/heartbeat.ts to periodically mark agents offline when inactive for 5 minutes and automatically delete offline agents after 24 hours.
  • Config & Environment: Documented and parsed HEARTBEAT_INTERVAL_MS, HEARTBEAT_STALE_THRESHOLD_MINUTES, and AGENT_OFFLINE_DELETE_HOURS in backend/src/config/index.ts and backend/.env.example.
  • Server Lifecycle: Integrated heartbeat background service into createApp and graceful shutdown handlers in backend/src/api/app.ts.
  • Frontend Real-Time Refresh: Updated useAgentRegistry.ts and agentRegistry.ts to auto-refresh status on window focus and status transitions.
  • Automated Tests: Added complete test coverage in backend/tests/heartbeat.test.ts verifying all heartbeat and cleanup operations.

Verification

  • Ran full backend test suite: 19 test suites passed, 212 tests passed.

…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
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

@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
devJaja self-requested a review July 29, 2026 20:22

@devJaja devJaja left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid Implementation @morelucks

LGTM

@devJaja
devJaja merged commit 97d99d4 into Epta-Node:main Jul 29, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Implement Agent Heartbeat Monitoring and Automatic Dead-Agent Cleanup

2 participants