comfyinst

package
v0.206.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package comfyinst stops the ComfyUI instances a GPU lease's runners kept alive (plan P13).

A runner told to keep the ComfyUI it launched (render/comfy-lifecycle.mjs, keep:true) leaves it running after the runner exits: spawned detached, console in a log file, so a batch of items under one lease pays the model load once. That instance must live no longer than the lease it was launched under: the launch marker (.offload-launch-<key>.json) records the lease epoch, and the HOLDER of that lease stops the instance when it releases it (`gpu reserve` when its wrapped command ends, the pipeline when a media lease is released). That bounds the process. What the instance keeps in models and caches (ComfyUI unloads its models itself when a prompt ends under --disable-smart-memory, so that is a warm session's executor cache, or the models of a hand-started instance run with smart memory) is bounded sooner by the instance itself, without a watcher here: a kept or warm launch carries the idle pack (render/comfyui-ext/idle-nodes), which frees it after 300 s with an empty queue (run live on 2026-10-14).

AN INSTANCE THAT BOUNDS ITSELF (ADR 0097, 2026-10-24). Since then the runners keep the ComfyUI they launch after every good job, and the same pack ends the process after 300 s with no prompt and no runner holding it; the marker says so (idleExitSec). The pipeline's routine release of a media lease (StopForRelease) leaves such an instance running, so the next job on its cards reuses it instead of paying the launch again. Every explicit end of a lease (`gpu reserve` when its command ends, its detached holder, `gpu release`) still stops it with StopForLease.

WHAT IT WILL AND WILL NOT STOP. Only a keyed instance whose marker names exactly this lease epoch. A marker with no epoch (the default instance, an instance launched outside a lease) is never touched: it belongs to whoever kept it. Before anything is signalled the instance is shown to be the harness's own, the same proof the launcher applies before it reuses one: its pid is alive, the process did not begin after the marker was written (a recycled pid), and the endpoint on the marker's port reports exactly the argv the launcher recorded. Anything short of that is left running and reported, never killed: a foreign process on the port is not ours to stop. Nothing here is a timer or a watcher; it runs once, in the releasing process, at release.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PIDsOfOtherLeases

func PIDsOfOtherLeases(comfyDir string, epoch uint64, alive func(int) bool, start func(int) (int64, bool)) []int

PIDsOfOtherLeases lists the live processes the launch markers in comfyDir tie to a lease other than epoch. A wrapper that lost its lease stops its own tree and must spare these: an instance it kept and another lease reused is that lease's job now. A marker that names no lease (the default instance, or one kept outside any lease) is nobody else's and is not listed. start is the process start time (Unix ms; nil = not checked): a pid that began after its marker was written was recycled and is not listed.

Types

type Deps

type Deps struct {
	// Alive reports whether pid is a live process.
	Alive func(pid int) bool
	// Start reports when pid began, in Unix milliseconds; false when the platform cannot say.
	Start func(pid int) (int64, bool)
	// Kill stops pid.
	Kill func(pid int) error
	// Sleep pauses between the checks that the instance is gone after a kill.
	Sleep func(time.Duration)
	// QuietPolls is how many times the process is re-checked after a kill before it is
	// reported as still running.
	QuietPolls int
	// HTTPTimeout bounds each request to the instance.
	HTTPTimeout time.Duration
	// ProofAttempts is how many times the launch fingerprint (GET /system_stats) is asked for before
	// the instance is reported as not answering; 0 = once. An instance in the middle of a prompt
	// (the qwen-image prompts in the field run 550 to 585 seconds) answers late, and a lease holder
	// that read one slow answer as "not shown to be ours" left the instance running with its models
	// for the next lease's family to be loaded beside (render/comfy-family.mjs says how that ends).
	ProofAttempts int
	// Client is the HTTP client; nil means one with HTTPTimeout.
	Client *http.Client
}

Deps are the process and network seams.

func RealDeps

func RealDeps() Deps

RealDeps is the production wiring.

type Marker

type Marker struct {
	StartedAt  int64    `json:"startedAt"`
	PID        int      `json:"pid"`
	OwnerPID   int      `json:"ownerPid"`
	Args       []string `json:"args"`
	Key        string   `json:"key"`
	Port       int      `json:"port"`
	LeaseEpoch *uint64  `json:"leaseEpoch"`
	// IdleExitSec is the process bound the instance carries (its idle pack exits it after that many seconds with no prompt and no
	// runner holding it); 0 = none, the lease's holder ends it.
	IdleExitSec int `json:"idleExitSec"`
}

Marker is the launch record render/comfy-ownership.mjs writes for a keyed instance.

type Outcome

type Outcome struct {
	Key     string `json:"key"`
	PID     int    `json:"pid"`
	Port    int    `json:"port"`
	Stopped bool   `json:"stopped"`
	// Spared is true when a routine release left an instance that bounds its own process (StopForRelease).
	Spared bool `json:"spared,omitempty"`
	// Why is empty when the instance was stopped; otherwise it says why it was left, or why its
	// marker was only cleared.
	Why string `json:"why,omitempty"`
}

Outcome is what happened to one instance of the lease.

func StopForLease

func StopForLease(ctx context.Context, comfyDir string, epoch uint64, d Deps) []Outcome

StopForLease stops every keyed instance in comfyDir whose launch marker records lease epoch `epoch`, and reports one Outcome per such instance, in key order. An empty comfyDir, an epoch of 0 and a directory that cannot be read are no-ops.

func StopForRelease

func StopForRelease(ctx context.Context, comfyDir string, epoch uint64, d Deps) []Outcome

StopForRelease is StopForLease for the pipeline's routine release of a media lease after its job: an instance that bounds its own process (IdleExitSec > 0) is left running for the next job and reported, unsignalled, with why; every other instance of the lease is stopped exactly as StopForLease stops it.

func StopMarker

func StopMarker(ctx context.Context, comfyDir, key string, port int, d Deps) Outcome

StopMarker stops the instance a launch marker names, whatever lease launched it: the primitive an explicit takeover uses (plan P10, used by P11) for a ComfyUI instance that is not a descendant of the lease's wrapper. key "" is the default instance's marker (.offload-launch.json, which records no port: port names it, and is used only when the marker has none). It asks the instance to stop the prompt it is running (POST /interrupt), drops its models (POST /free) and kills the marker's pid, but only after the same proof the lease's own holder gives: the pid is alive, it did not begin after the marker was written, and the endpoint reports exactly the argv the launcher recorded. Anything short of that is left running and reported, never killed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL