spine-parts 2.30.2 → 2.30.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.ts +3 -3
- package/package.json +1 -1
- package/src/comfy/client.ts +162 -39
- package/src/comfy/matte.ts +1 -1
- package/src/comfy/painting.ts +1 -1
- package/src/comfy/plate.ts +1 -1
- package/src/comfy/seethrough.ts +1 -1
package/cli.ts
CHANGED
|
@@ -2021,7 +2021,7 @@ async function cmdComfyPlate(v: Map<string, string>): Promise<number> {
|
|
|
2021
2021
|
console.log(`rig-parts comfy plate: background (${graph}) ${painting} -> ${out}`);
|
|
2022
2022
|
// Every local refusal (no source mask, the checksum, the grid) comes before the host is resolved.
|
|
2023
2023
|
const r = await runBackground(
|
|
2024
|
-
() => new ComfyClient(resolveHost(v.get('--host'), process.env.COMFY_HOST), { poll: poll as number, request: 30 }),
|
|
2024
|
+
() => new ComfyClient(resolveHost(v.get('--host'), process.env.COMFY_HOST), { poll: poll as number, request: 30, wait: wait as number }),
|
|
2025
2025
|
{ painting, maskFrom: v.get('--mask-from'), out, graph, model: v.get('--model'), checkpointSha256: v.get('--checkpoint-sha256'), seed: seed as number, growPx: grow as number, steps: steps as number, ...(v.has('--cfg') ? { cfg } : {}), prompt: v.get('--prompt'), negative: v.get('--negative'), wait: wait as number, timeout: timeout as number },
|
|
2026
2026
|
(l) => console.log(l),
|
|
2027
2027
|
);
|
|
@@ -2044,7 +2044,7 @@ async function cmdComfyMatte(v: Map<string, string>): Promise<number> {
|
|
|
2044
2044
|
for (const n of [resolution, threshold, wait, timeout, poll]) if (typeof n === 'string') return usage(n);
|
|
2045
2045
|
try {
|
|
2046
2046
|
const receipt = await runMatte(
|
|
2047
|
-
() => new ComfyClient(resolveHost(v.get('--host'), process.env.COMFY_HOST), { poll: poll as number, request: 30 }),
|
|
2047
|
+
() => new ComfyClient(resolveHost(v.get('--host'), process.env.COMFY_HOST), { poll: poll as number, request: 30, wait: wait as number }),
|
|
2048
2048
|
{ painting, out, node: v.get('--node'), model: v.get('--model'), checkpointSha256: v.get('--checkpoint-sha256'), resolution: resolution as number, threshold: threshold as number, wait: wait as number, timeout: timeout as number },
|
|
2049
2049
|
line => console.log(line),
|
|
2050
2050
|
);
|
|
@@ -2081,7 +2081,7 @@ async function cmdComfy(args: string[]): Promise<number> {
|
|
|
2081
2081
|
if (sub === 'seethrough' && depthConfig !== undefined && depthRun !== 'full' && depthRun !== 'head') return usage('active config.depth requires --depth-run <full|head>; the source run is not inferred');
|
|
2082
2082
|
if (sub === 'seethrough' && depthConfig === undefined && depthRun !== undefined) return usage('--depth-run requires --config with an explicit depth block');
|
|
2083
2083
|
const host = resolveHost(v.get('--host'), process.env.COMFY_HOST);
|
|
2084
|
-
const client = new ComfyClient(host, { poll: poll as number, request: 30 });
|
|
2084
|
+
const client = new ComfyClient(host, { poll: poll as number, request: 30, wait: wait as number });
|
|
2085
2085
|
if (sub === 'seethrough') {
|
|
2086
2086
|
const image = v.get('--image');
|
|
2087
2087
|
if (image === undefined) return usage('comfy seethrough needs --image <png>');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spine-parts",
|
|
3
|
-
"version": "2.30.
|
|
3
|
+
"version": "2.30.3",
|
|
4
4
|
"description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/comfy/client.ts
CHANGED
|
@@ -37,11 +37,19 @@ export function resolveHost(flag: string | undefined, env: string | undefined):
|
|
|
37
37
|
return host.replace(/\/+$/, '');
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export const OBJECT_INFO_REQUEST_FACTOR = 4;
|
|
41
|
+
|
|
40
42
|
export interface ClientTiming {
|
|
41
43
|
/** Seconds between two polls of /queue or /history. */
|
|
42
44
|
poll: number;
|
|
43
45
|
/** Seconds one plain request may take. */
|
|
44
46
|
request: number;
|
|
47
|
+
/** Seconds GET /object_info may take (default: 4x `request`, bounded by `wait` when given). */
|
|
48
|
+
objectInfo?: number;
|
|
49
|
+
/** Seconds the run allows before a queued job starts (`--wait`), used to bound `/object_info`. */
|
|
50
|
+
wait?: number;
|
|
51
|
+
/** Milliseconds per nominal second (default: 1000); tests may inject a smaller unit to scale waits down. */
|
|
52
|
+
unitMs?: number;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
export interface OutputImage {
|
|
@@ -55,7 +63,18 @@ export interface HistoryEntry {
|
|
|
55
63
|
status: { status_str?: string; completed?: boolean; messages?: unknown[] } | null;
|
|
56
64
|
}
|
|
57
65
|
|
|
58
|
-
|
|
66
|
+
function isTimeoutError(err: unknown): boolean {
|
|
67
|
+
return err instanceof Error && (err.name === 'TimeoutError' || err.name === 'AbortError');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isTimeoutRefusal(err: unknown): boolean {
|
|
71
|
+
return (
|
|
72
|
+
err instanceof PartsError &&
|
|
73
|
+
err.problems.length === 1 &&
|
|
74
|
+
err.problems[0].code === 'COMFY_REACHABLE' &&
|
|
75
|
+
err.problems[0].detail.startsWith('did not answer within ')
|
|
76
|
+
);
|
|
77
|
+
}
|
|
59
78
|
|
|
60
79
|
function asObject(v: unknown): Record<string, unknown> | null {
|
|
61
80
|
return typeof v === 'object' && v !== null && !Array.isArray(v) ? (v as Record<string, unknown>) : null;
|
|
@@ -72,19 +91,54 @@ export class ComfyClient {
|
|
|
72
91
|
readonly timing: ClientTiming,
|
|
73
92
|
) {}
|
|
74
93
|
|
|
94
|
+
private get unitMs(): number {
|
|
95
|
+
return this.timing.unitMs ?? 1000;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private nowSeconds(): number {
|
|
99
|
+
return Date.now() / this.unitMs;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private sleepSeconds(s: number): Promise<void> {
|
|
103
|
+
return s <= 0 ? Promise.resolve() : new Promise((r) => setTimeout(r, s * this.unitMs));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Seconds `GET /object_info` may take: `timing.objectInfo` when set, else
|
|
108
|
+
* four times `timing.request` (120 s at the 30 s default, since a real box's
|
|
109
|
+
* multi-megabyte `/object_info` takes 24.5–36.5 s), bounded by `--wait`.
|
|
110
|
+
*/
|
|
111
|
+
objectInfoSeconds(wait?: number): number {
|
|
112
|
+
const cap = this.timing.objectInfo ?? this.timing.request * OBJECT_INFO_REQUEST_FACTOR;
|
|
113
|
+
const bound = wait ?? this.timing.wait;
|
|
114
|
+
return bound === undefined ? cap : Math.min(cap, bound);
|
|
115
|
+
}
|
|
116
|
+
|
|
75
117
|
private async call(method: 'GET' | 'POST', path: string, body?: string | FormData, headers?: Record<string, string>, seconds = this.timing.request): Promise<Response> {
|
|
118
|
+
const label = Number(seconds.toFixed(1));
|
|
119
|
+
try {
|
|
120
|
+
return await fetch(`${this.host}${path}`, { method, body, headers, signal: AbortSignal.timeout(Math.max(1, seconds * this.unitMs)) });
|
|
121
|
+
} catch (err) {
|
|
122
|
+
const e = err as Error;
|
|
123
|
+
const what = isTimeoutError(e) ? `did not answer within ${label} s` : `could not be reached (${e.message})`;
|
|
124
|
+
return refuse('COMFY_REACHABLE', `${method} ${this.host}${path}`, `${what}; a running ComfyUI at this host is required`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private async readText(res: Response, method: 'GET' | 'POST', path: string, seconds: number): Promise<string> {
|
|
76
129
|
try {
|
|
77
|
-
return await
|
|
130
|
+
return await res.text();
|
|
78
131
|
} catch (err) {
|
|
79
132
|
const e = err as Error;
|
|
80
|
-
const
|
|
133
|
+
const label = Number(seconds.toFixed(1));
|
|
134
|
+
const what = isTimeoutError(e) ? `did not answer within ${label} s` : `could not be reached (${e.message})`;
|
|
81
135
|
return refuse('COMFY_REACHABLE', `${method} ${this.host}${path}`, `${what}; a running ComfyUI at this host is required`);
|
|
82
136
|
}
|
|
83
137
|
}
|
|
84
138
|
|
|
85
|
-
private async json(method: 'GET' | 'POST', path: string, body?: string | FormData, headers?: Record<string, string
|
|
86
|
-
const res = await this.call(method, path, body, headers);
|
|
87
|
-
const text = await
|
|
139
|
+
private async json(method: 'GET' | 'POST', path: string, body?: string | FormData, headers?: Record<string, string>, seconds = this.timing.request): Promise<unknown> {
|
|
140
|
+
const res = await this.call(method, path, body, headers, seconds);
|
|
141
|
+
const text = await this.readText(res, method, path, seconds);
|
|
88
142
|
if (!res.ok) refuse('COMFY_REQUEST_OK', `${method} ${this.host}${path}`, `answered HTTP ${res.status}: ${brief(text)}; HTTP 200 is required`);
|
|
89
143
|
try {
|
|
90
144
|
return JSON.parse(text);
|
|
@@ -94,8 +148,8 @@ export class ComfyClient {
|
|
|
94
148
|
}
|
|
95
149
|
|
|
96
150
|
/** `GET /system_stats`, or a refusal naming the host. */
|
|
97
|
-
async systemStats(): Promise<Record<string, unknown>> {
|
|
98
|
-
const s = asObject(await this.json('GET', '/system_stats'));
|
|
151
|
+
async systemStats(seconds = this.timing.request): Promise<Record<string, unknown>> {
|
|
152
|
+
const s = asObject(await this.json('GET', '/system_stats', undefined, undefined, seconds));
|
|
99
153
|
if (s === null) refuse('COMFY_REQUEST_OK', `GET ${this.host}/system_stats`, 'answered with something that is not an object');
|
|
100
154
|
return s;
|
|
101
155
|
}
|
|
@@ -110,8 +164,8 @@ export class ComfyClient {
|
|
|
110
164
|
}
|
|
111
165
|
|
|
112
166
|
/** Free VRAM per device in GB (two decimals), keyed by the device name's first word; empty when the box does not say. */
|
|
113
|
-
async vramFree(): Promise<Record<string, number>> {
|
|
114
|
-
const s = await this.systemStats();
|
|
167
|
+
async vramFree(seconds = this.timing.request): Promise<Record<string, number>> {
|
|
168
|
+
const s = await this.systemStats(seconds);
|
|
115
169
|
const out: Record<string, number> = {};
|
|
116
170
|
const devices = Array.isArray(s.devices) ? s.devices : [];
|
|
117
171
|
for (const d of devices) {
|
|
@@ -122,14 +176,23 @@ export class ComfyClient {
|
|
|
122
176
|
return out;
|
|
123
177
|
}
|
|
124
178
|
|
|
179
|
+
private async vramFreeBestEffort(seconds = this.timing.request): Promise<Record<string, number>> {
|
|
180
|
+
try {
|
|
181
|
+
return await this.vramFree(seconds);
|
|
182
|
+
} catch (err) {
|
|
183
|
+
if (isTimeoutRefusal(err)) return {};
|
|
184
|
+
throw err;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
125
188
|
/**
|
|
126
189
|
* Where a queued prompt stands: `running` when the box is running it,
|
|
127
190
|
* `pending` with its 1-based place among the pending jobs (and how many are
|
|
128
191
|
* ahead of it, running included), or `absent` when the queue no longer lists
|
|
129
192
|
* it (finished, or never queued).
|
|
130
193
|
*/
|
|
131
|
-
async queuePlace(id: string): Promise<{ state: 'running' } | { state: 'pending'; place: number; pending: number; ahead: number } | { state: 'absent' }> {
|
|
132
|
-
const q = asObject(await this.json('GET', '/queue'));
|
|
194
|
+
async queuePlace(id: string, seconds = this.timing.request): Promise<{ state: 'running' } | { state: 'pending'; place: number; pending: number; ahead: number } | { state: 'absent' }> {
|
|
195
|
+
const q = asObject(await this.json('GET', '/queue', undefined, undefined, seconds));
|
|
133
196
|
if (q === null || !Array.isArray(q.queue_running) || !Array.isArray(q.queue_pending)) {
|
|
134
197
|
refuse('COMFY_REQUEST_OK', `GET ${this.host}/queue`, 'answered without queue_running and queue_pending arrays');
|
|
135
198
|
}
|
|
@@ -147,37 +210,79 @@ export class ComfyClient {
|
|
|
147
210
|
* Wait for a prompt queued behind other jobs (it was appended, never put in
|
|
148
211
|
* front, and nothing here reorders or cancels anyone's job): at most `wait`
|
|
149
212
|
* seconds while it is still pending, then at most `timeout` seconds once the
|
|
150
|
-
* box is running it. A
|
|
151
|
-
*
|
|
213
|
+
* box is running it. A timed-out `/queue` poll is retried while time remains
|
|
214
|
+
* in the active bound. A wait past either bound is refused naming `prompt <id>`
|
|
215
|
+
* and its place in the queue; the job is left on the box.
|
|
152
216
|
*/
|
|
153
217
|
async waitBehind(id: string, wait: number, timeout: number, say: (line: string) => void): Promise<{ entry: HistoryEntry; vramLow: Record<string, number>; elapsed: number }> {
|
|
154
|
-
const t0 =
|
|
218
|
+
const t0 = this.nowSeconds();
|
|
155
219
|
let started: number | null = null;
|
|
156
220
|
let lastPlace = -1;
|
|
221
|
+
let lastPending: { place: number; pending: number; ahead: number } | null = null;
|
|
222
|
+
let pollTimeouts = 0;
|
|
157
223
|
// The minimum free VRAM while this job runs: sampled on every running poll,
|
|
158
224
|
// then merged with what `waitHistory` reads, so it is not a post-run reading.
|
|
159
225
|
const vramLow: Record<string, number> = {};
|
|
160
226
|
for (;;) {
|
|
161
|
-
const
|
|
227
|
+
const phaseStart = started ?? t0;
|
|
228
|
+
const phaseBound = started === null ? wait : timeout;
|
|
229
|
+
const remaining = phaseBound - (this.nowSeconds() - phaseStart);
|
|
230
|
+
const pollCap = this.timing.request * 2 ** pollTimeouts;
|
|
231
|
+
const reqSeconds = remaining > 0 ? Math.min(pollCap, remaining) : Math.min(this.timing.request, Math.max(0.001, phaseBound));
|
|
232
|
+
let place: Awaited<ReturnType<ComfyClient['queuePlace']>>;
|
|
233
|
+
try {
|
|
234
|
+
place = await this.queuePlace(id, reqSeconds);
|
|
235
|
+
pollTimeouts = 0;
|
|
236
|
+
} catch (err) {
|
|
237
|
+
if (!isTimeoutRefusal(err)) throw err;
|
|
238
|
+
pollTimeouts++;
|
|
239
|
+
const now = this.nowSeconds();
|
|
240
|
+
if (started !== null) {
|
|
241
|
+
const runningFor = now - started;
|
|
242
|
+
if (runningFor >= timeout) {
|
|
243
|
+
refuse('COMFY_HISTORY_WITHIN', `prompt ${id}`, `was still running ${runningFor.toFixed(1)} s after it started; it is required within --timeout ${timeout} s (the job was left on the box, not cancelled)`);
|
|
244
|
+
}
|
|
245
|
+
await this.sleepSeconds(Math.min(this.timing.poll, Math.max(0, timeout - runningFor)));
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
const waited = now - t0;
|
|
249
|
+
if (waited >= wait) {
|
|
250
|
+
const where =
|
|
251
|
+
lastPending !== null
|
|
252
|
+
? `, at place ${lastPending.place} of ${lastPending.pending} pending with ${lastPending.ahead} job(s) ahead of it`
|
|
253
|
+
: ` (GET ${this.host}/queue timed out while waiting)`;
|
|
254
|
+
refuse(
|
|
255
|
+
'COMFY_QUEUE_BEHIND',
|
|
256
|
+
`prompt ${id}`,
|
|
257
|
+
`was still pending after ${waited.toFixed(1)} s${where}; it is required to start within --wait ${wait} s — the job was left in its place on the box, not moved and not cancelled, and no one else's job was touched`,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
await this.sleepSeconds(Math.min(this.timing.poll, Math.max(0, wait - waited)));
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
162
263
|
if (place.state === 'absent') {
|
|
163
|
-
const
|
|
264
|
+
const spentRunning = started === null ? 0 : this.nowSeconds() - started;
|
|
265
|
+
const historyBudget = Math.max(timeout - spentRunning, Math.min(this.timing.request, timeout), this.timing.poll * 2);
|
|
266
|
+
const done = await this.waitHistory(id, historyBudget, timeout);
|
|
164
267
|
for (const [k, v] of Object.entries(done.vramLow)) if (!(k in vramLow) || v < vramLow[k]) vramLow[k] = v;
|
|
165
|
-
return { entry: done.entry, vramLow, elapsed:
|
|
268
|
+
return { entry: done.entry, vramLow, elapsed: this.nowSeconds() - t0 };
|
|
166
269
|
}
|
|
167
|
-
const now =
|
|
270
|
+
const now = this.nowSeconds();
|
|
168
271
|
if (place.state === 'running') {
|
|
169
|
-
for (const [k, v] of Object.entries(await this.
|
|
272
|
+
for (const [k, v] of Object.entries(await this.vramFreeBestEffort())) if (!(k in vramLow) || v < vramLow[k]) vramLow[k] = v;
|
|
170
273
|
if (started === null) {
|
|
171
274
|
started = now;
|
|
172
275
|
say(` prompt ${id} is running`);
|
|
173
276
|
}
|
|
174
|
-
if (
|
|
175
|
-
refuse('COMFY_HISTORY_WITHIN', `prompt ${id}`, `was still running ${(
|
|
277
|
+
if (now - started >= timeout) {
|
|
278
|
+
refuse('COMFY_HISTORY_WITHIN', `prompt ${id}`, `was still running ${(now - started).toFixed(1)} s after it started; it is required within --timeout ${timeout} s (the job was left on the box, not cancelled)`);
|
|
176
279
|
}
|
|
280
|
+
await this.sleepSeconds(Math.min(this.timing.poll, Math.max(0, timeout - (this.nowSeconds() - started))));
|
|
177
281
|
} else {
|
|
282
|
+
lastPending = place;
|
|
178
283
|
if (place.place !== lastPlace) say(` prompt ${id} queued behind ${place.ahead} job(s) (pending place ${place.place} of ${place.pending})`);
|
|
179
284
|
lastPlace = place.place;
|
|
180
|
-
const waited =
|
|
285
|
+
const waited = now - t0;
|
|
181
286
|
if (waited >= wait) {
|
|
182
287
|
refuse(
|
|
183
288
|
'COMFY_QUEUE_BEHIND',
|
|
@@ -185,14 +290,14 @@ export class ComfyClient {
|
|
|
185
290
|
`was still pending after ${waited.toFixed(1)} s, at place ${place.place} of ${place.pending} pending with ${place.ahead} job(s) ahead of it; it is required to start within --wait ${wait} s — the job was left in its place on the box, not moved and not cancelled, and no one else's job was touched`,
|
|
186
291
|
);
|
|
187
292
|
}
|
|
293
|
+
await this.sleepSeconds(Math.min(this.timing.poll, Math.max(0, wait - (this.nowSeconds() - t0))));
|
|
188
294
|
}
|
|
189
|
-
await sleep(this.timing.poll);
|
|
190
295
|
}
|
|
191
296
|
}
|
|
192
297
|
|
|
193
298
|
/** `GET /object_info`: every node class the box has, with its inputs. */
|
|
194
|
-
async objectInfo(): Promise<Record<string, unknown>> {
|
|
195
|
-
const o = asObject(await this.json('GET', '/object_info'));
|
|
299
|
+
async objectInfo(wait?: number): Promise<Record<string, unknown>> {
|
|
300
|
+
const o = asObject(await this.json('GET', '/object_info', undefined, undefined, this.objectInfoSeconds(wait)));
|
|
196
301
|
if (o === null) refuse('COMFY_REQUEST_OK', `GET ${this.host}/object_info`, 'answered with something that is not an object of node classes');
|
|
197
302
|
return o;
|
|
198
303
|
}
|
|
@@ -212,7 +317,7 @@ export class ComfyClient {
|
|
|
212
317
|
/** `POST /prompt`; returns the prompt id. A rejection is refused with the box's own error text. */
|
|
213
318
|
async submit(graph: unknown, clientId: string): Promise<string> {
|
|
214
319
|
const res = await this.call('POST', '/prompt', JSON.stringify({ prompt: graph, client_id: clientId }), { 'Content-Type': 'application/json' });
|
|
215
|
-
const text = await res.
|
|
320
|
+
const text = await this.readText(res, 'POST', '/prompt', this.timing.request);
|
|
216
321
|
if (!res.ok) refuse('COMFY_PROMPT_ACCEPTED', `POST ${this.host}/prompt`, `rejected the graph with HTTP ${res.status}: ${brief(text, 1500)}`);
|
|
217
322
|
let id: unknown;
|
|
218
323
|
try {
|
|
@@ -226,24 +331,42 @@ export class ComfyClient {
|
|
|
226
331
|
|
|
227
332
|
/**
|
|
228
333
|
* Poll `/history/<id>` until the job is there, for at most `timeout`
|
|
229
|
-
* seconds, and check the box is still answering between polls.
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
334
|
+
* seconds, and check the box is still answering between polls. A timed-out
|
|
335
|
+
* poll is retried while time remains in `timeout`. Returns the entry and the
|
|
336
|
+
* lowest free VRAM seen per device. An entry whose status is an error is
|
|
337
|
+
* refused with the box's messages; so is an entry with no outputs at all,
|
|
338
|
+
* because a finished job that saved nothing is not a result.
|
|
233
339
|
*/
|
|
234
|
-
async waitHistory(id: string, timeout: number): Promise<{ entry: HistoryEntry; vramLow: Record<string, number>; elapsed: number }> {
|
|
235
|
-
const t0 =
|
|
340
|
+
async waitHistory(id: string, timeout: number, reportedTimeout = timeout): Promise<{ entry: HistoryEntry; vramLow: Record<string, number>; elapsed: number }> {
|
|
341
|
+
const t0 = this.nowSeconds();
|
|
236
342
|
const vramLow: Record<string, number> = {};
|
|
343
|
+
let pollTimeouts = 0;
|
|
237
344
|
for (;;) {
|
|
238
|
-
|
|
239
|
-
const
|
|
345
|
+
const remaining = timeout - (this.nowSeconds() - t0);
|
|
346
|
+
const pollCap = this.timing.request * 2 ** pollTimeouts;
|
|
347
|
+
const reqSeconds = remaining > 0 ? Math.min(pollCap, remaining) : Math.min(this.timing.request, Math.max(0.001, timeout));
|
|
348
|
+
for (const [k, v] of Object.entries(await this.vramFreeBestEffort(reqSeconds))) if (!(k in vramLow) || v < vramLow[k]) vramLow[k] = v;
|
|
349
|
+
let h: Record<string, unknown> | null;
|
|
350
|
+
try {
|
|
351
|
+
h = asObject(await this.json('GET', `/history/${encodeURIComponent(id)}`, undefined, undefined, reqSeconds));
|
|
352
|
+
pollTimeouts = 0;
|
|
353
|
+
} catch (err) {
|
|
354
|
+
if (!isTimeoutRefusal(err)) throw err;
|
|
355
|
+
pollTimeouts++;
|
|
356
|
+
const waited = this.nowSeconds() - t0;
|
|
357
|
+
if (waited >= timeout) {
|
|
358
|
+
refuse('COMFY_HISTORY_WITHIN', `prompt ${id}`, `was not in /history after ${waited.toFixed(1)} s; it is required within --timeout ${reportedTimeout} s (the job was left on the box, not cancelled)`);
|
|
359
|
+
}
|
|
360
|
+
await this.sleepSeconds(Math.min(this.timing.poll, Math.max(0, timeout - waited)));
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
240
363
|
const raw = h === null ? null : asObject(h[id]);
|
|
241
364
|
if (raw !== null) {
|
|
242
365
|
const entry: HistoryEntry = {
|
|
243
366
|
outputs: (asObject(raw.outputs) ?? {}) as HistoryEntry['outputs'],
|
|
244
367
|
status: asObject(raw.status) as HistoryEntry['status'],
|
|
245
368
|
};
|
|
246
|
-
const elapsed =
|
|
369
|
+
const elapsed = this.nowSeconds() - t0;
|
|
247
370
|
if (entry.status?.status_str === 'error') {
|
|
248
371
|
refuse('COMFY_RUN_OK', `prompt ${id}`, `ended with status "error": ${brief(JSON.stringify(entry.status.messages ?? []), 2000)}`);
|
|
249
372
|
}
|
|
@@ -256,11 +379,11 @@ export class ComfyClient {
|
|
|
256
379
|
}
|
|
257
380
|
return { entry, vramLow, elapsed };
|
|
258
381
|
}
|
|
259
|
-
const waited =
|
|
382
|
+
const waited = this.nowSeconds() - t0;
|
|
260
383
|
if (waited >= timeout) {
|
|
261
|
-
refuse('COMFY_HISTORY_WITHIN', `prompt ${id}`, `was not in /history after ${waited.toFixed(1)} s; it is required within --timeout ${
|
|
384
|
+
refuse('COMFY_HISTORY_WITHIN', `prompt ${id}`, `was not in /history after ${waited.toFixed(1)} s; it is required within --timeout ${reportedTimeout} s (the job was left on the box, not cancelled)`);
|
|
262
385
|
}
|
|
263
|
-
await
|
|
386
|
+
await this.sleepSeconds(Math.min(this.timing.poll, Math.max(0, timeout - waited)));
|
|
264
387
|
}
|
|
265
388
|
}
|
|
266
389
|
|
package/src/comfy/matte.ts
CHANGED
|
@@ -30,7 +30,7 @@ export async function runMatte(connect: () => ComfyClient, run: MatteRun, say: (
|
|
|
30
30
|
const client = connect();
|
|
31
31
|
const gpu = gpuName(await client.systemStats(), client.host);
|
|
32
32
|
const prefix = `rig_parts_matte_${crypto.randomUUID().slice(0, 8)}`;
|
|
33
|
-
const info = await client.objectInfo();
|
|
33
|
+
const info = await client.objectInfo(run.wait);
|
|
34
34
|
refuseIfAny(checkGraph(matteGraph(`${prefix}.png`, prefix), info, client.host, new Set(['1.image'])));
|
|
35
35
|
const files = await client.modelFiles('RMBG');
|
|
36
36
|
if (!files.some(f => f.replaceAll('\\', '/') === MATTE_MODEL_FILE)) refuse('MATTE_MODEL_INSTALLED', MATTE_MODEL_FILE, 'is absent from /models/RMBG; a selector entry alone does not establish installed weights, and automatic download is not permitted');
|
package/src/comfy/painting.ts
CHANGED
|
@@ -74,7 +74,7 @@ export async function runPainting(client: ComfyClient, run: PaintRun, say: (line
|
|
|
74
74
|
const drawn = control === null ? null : controlImage(control.skeleton, run.pose, w, h);
|
|
75
75
|
const skeletonName = drawn === null ? null : `spine_parts_${drawn.label}_${w}x${h}.png`;
|
|
76
76
|
const probe = paintingGraph(g, seeds[0], prompts, `spine_parts_${run.config.key}_${seeds[0]}`, skeletonName);
|
|
77
|
-
refuseIfAny(checkGraph(probe, await client.objectInfo(), client.host, new Set(['30.image'])));
|
|
77
|
+
refuseIfAny(checkGraph(probe, await client.objectInfo(run.wait), client.host, new Set(['30.image'])));
|
|
78
78
|
say(' box: every node, input and model of the painting graph is on its /object_info');
|
|
79
79
|
|
|
80
80
|
let skeletonRef: string | null = null;
|
package/src/comfy/plate.ts
CHANGED
|
@@ -106,7 +106,7 @@ export async function runBackground(connect: () => ComfyClient, run: BackgroundR
|
|
|
106
106
|
|
|
107
107
|
const client = connect();
|
|
108
108
|
const gpu = gpuName(await client.systemStats(), client.host);
|
|
109
|
-
const info = await client.objectInfo();
|
|
109
|
+
const info = await client.objectInfo(run.wait);
|
|
110
110
|
refuseIfAny(checkGraph(build(`${prefix}_painting.png`, `${prefix}_mask.png`), info, client.host, new Set(['1.image', '2.image'])));
|
|
111
111
|
say(` box: every node, input and model of the ${run.graph} graph is on its /object_info; GPU ${gpu}`);
|
|
112
112
|
|
package/src/comfy/seethrough.ts
CHANGED
|
@@ -92,7 +92,7 @@ export async function runSeeThrough(client: ComfyClient, run: SeeThroughRun, say
|
|
|
92
92
|
const uploadName = `${prefix}_input.png`;
|
|
93
93
|
const template: unknown = JSON.parse(readFileSync(SEETHROUGH_WORKFLOW, 'utf8'));
|
|
94
94
|
const params: SeeThroughParams = { image: uploadName, seed: run.seed, resolution: run.resolution, steps: run.steps, quant: run.quant, offload: run.offload, lama: run.lama, prefix };
|
|
95
|
-
const info = await client.objectInfo();
|
|
95
|
+
const info = await client.objectInfo(run.wait);
|
|
96
96
|
refuseIfAny(checkGraph(fillSeeThrough(template, params), info, client.host, new Set(['1.image'])));
|
|
97
97
|
say(` box: every node and input of workflows/seethrough.json is on its /object_info`);
|
|
98
98
|
|