Skip to content

Stop ComfyUI while it is idle, so it holds no VRAM - #20

Merged
shivanshtalwar0 merged 1 commit into
masterfrom
feat/idle-gate
Oct 7, 2026
Merged

shivanshtalwar0 merged 1 commit into
masterfrom
feat/idle-gate

Conversation

@shivanshtalwar0

Copy link
Copy Markdown

Problem. On the 5090 rig an idle ComfyUI held ~776 MB of VRAM, although every render already frees its models. What stays is the CUDA context, which only goes away when the process exits. The card is shared with VoxMin (7.8 GB idle) and OmniVoice, so that memory was missing from every job they ran (januscaler/VoxMin has the matching change).

Change.

  • With COMFYUI_IDLE_STOP_SECONDS set (compose default: 120), docker/entrypoint.sh execs docker/idle_gate.py in place of ComfyUI. The gate owns port 8188 and runs ComfyUI on COMFYUI_PORT+1. It starts ComfyUI on the first request that needs it (~5 s on the rig) and stops it once the queue has been empty and nothing has asked for that long.
  • Without starting ComfyUI, the gate answers:
    • /system_stats (healthcheck) and /queue with fixed answers;
    • /api/wrapper/workflows (voxmin-backend's 10 s probe) from ComfyUI's last answer;
    • /ws with 503 until something real starts ComfyUI.
  • When WRAPPER_AUTH_TOKEN is set, those answers go only to requests that carry it; anything else reaches ComfyUI itself.
  • Every request gets its own connection to ComfyUI, so the gate counts each one. X-Forwarded-For carries the real client.
  • Unset (RunPod, vast, serverless) or with sequence parallelism, nothing changes.
  • The gate is stdlib only. VoxMin ships an identical copy for its own API and the OmniVoice sidecar.

Tests.

  • 20 new tests: test_idle_gate.py runs the real gate against a stand-in server; test_docker.py covers the entrypoint wiring and validates its flags against the gate's parser.
  • tests-unit/wrapper_api_test: 308 passed. The 3 TestGraphValidation failures also fail on master here (no model files locally).
  • ruff check . is clean.
  • On the rig, the published :latest image ran with this entrypoint and gate mounted. /queue and /system_stats were answered with ComfyUI down. The first workflows probe started it (4.8 s) and was cached. ComfyUI exited 20 s later, taking its GPU process with it, and the cached probe did not wake it. A real request started it again (4.8 s), and the Docker healthcheck stayed healthy.

After merge: on the rig, docker compose pull comfyui && docker compose up -d comfyui.

🤖 Generated with Claude Code

On the 5090 rig ComfyUI kept ~776 MB of the card while idle, although every
render already frees its models: what stays is the CUDA context, which no
API gives back while the process lives. The card is shared with VoxMin and
OmniVoice, so that memory was missing from every job they ran.

With COMFYUI_IDLE_STOP_SECONDS set (compose: 120), the entrypoint execs
docker/idle_gate.py in place of ComfyUI. The gate owns the port, starts
ComfyUI on the first request that needs it (~5 s on the rig) and stops it
once its queue has been empty and nothing has asked for that long. It
answers the probes that run all day without starting it: the healthcheck's
/system_stats and /queue as fixed answers, voxmin-backend's 10 s
/api/wrapper/workflows probe from ComfyUI's last answer; /ws is a 503 until
something real starts it. Stubs and the cache are only served to a request
carrying WRAPPER_AUTH_TOKEN when one is set. Each request gets its own
connection to ComfyUI, so the gate sees every one; X-Forwarded-For carries
the real client.

Unset (RunPod, vast, serverless) or with sequence parallelism, ComfyUI
runs as before. The gate is stdlib-only; VoxMin ships the same file.

Tested: 20 new tests (the gate against a stand-in server, the entrypoint
wiring in test_docker.py); on the rig, the published image with this
entrypoint answered probes without starting ComfyUI, freed its VRAM 20 s
after the last request, and started again on the next one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shivanshtalwar0
shivanshtalwar0 merged commit 75f948d into master Oct 7, 2026
13 of 17 checks passed
@shivanshtalwar0
shivanshtalwar0 deleted the feat/idle-gate branch October 24, 2026 16:55
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.

2 participants