Skip to content

Conversation

Copy link

Copilot AI commented Nov 21, 2025

_service_running() only checked for tasks in running state, causing false negatives during container startup/restart. This triggered premature demo shutdowns via the idle monitor when services were actually healthy but transitioning.

Changes

  • _service_running(): Accept tasks in transitional states (new, pending, assigned, preparing, starting) in addition to running
  • Edge case: Return True when replicas > 0 but no tasks exist yet (brief window during scale-up)
  • Maintainability: Extract active states to ACTIVE_TASK_STATES constant

Before/After

# Before: Only checked running tasks
tasks = svc.tasks(filters={"desired-state": "running"})
return any(t.get("Status", {}).get("State") == "running" for t in tasks)

# After: Accept all non-terminal states
tasks = svc.tasks()
if not tasks and replicas > 0:
    return True  # Service scaling up
return any(t.get("Status", {}).get("State") in ACTIVE_TASK_STATES for t in tasks)

This prevents the heartbeat system from incorrectly detecting service failures during normal Docker Swarm lifecycle events.

Original prompt

This section details on the original issue you should resolve

<issue_title>API doesnt read well demo's status</issue_title>
<issue_description>Sometimes when a demo is launched, ws stops, camera stops, as if the heartbeat went unsuccessful</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 21, 2025 10:39
The function now checks for preparing/starting states in addition to running,
preventing false negatives during container startup or restart.

Co-authored-by: Balmine <[email protected]>
- Add ACTIVE_TASK_STATES constant for maintainability
- Check all tasks (not just desired-state=running) to handle rapid transitions
- Handle edge case when replicas>0 but no tasks exist yet
- Add comprehensive documentation

Co-authored-by: Balmine <[email protected]>
Copilot AI changed the title [WIP] Fix API to read demo's status correctly Fix service status detection during container transitions Nov 21, 2025
Copilot AI requested a review from Balmine November 21, 2025 10:44
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.

API doesnt read well demo's status

2 participants