Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Multi-model runtime isolation PRs also keep these CI-safe gates green:
uv run pytest tests/test_runtime_isolation_gates.py tests/test_runtime_isolation.py -q
```

Warm ACE across BatchPrompt (Rescore) is on by default for Real `ace-step-*` GenerateAudio. Disable with `GROOVY_WARM_ACE=0`. Stub CI leaves warm off (`GROOVY_INFERENCE_STUB=1`).

Then smoke one featured template in the studio: **Render** → play the **cached** preview (patch-bay audition, not live inference).

Optional for maintainer weekly notes: Settings → **Copy clean-machine report** (privacy-safe snapshot) and paste into your lab log.
Expand Down
46 changes: 46 additions & 0 deletions apps/studio/src/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,52 @@ describe("BatchPrompt helpers", () => {
}),
).toBe("exports/a.mp4");
});

it("stamps SaveVideo and SaveGenerateLog with matching -pNN take ids", async () => {
const { batchTakeFilename, patchBatchPromptPass } = await import("./workflow");
expect(batchTakeFilename("rescore-cyberpunk.mp4", 3, ".mp4")).toBe("rescore-cyberpunk-p03.mp4");
expect(batchTakeFilename("rescore-cyberpunk-log-p01.json", 2, ".json")).toBe(
"rescore-cyberpunk-log-p02.json",
);
const workflow = {
schema_version: "1.0.0",
groovy_version: "0.1.0",
id: "w",
metadata: { title: "t" },
groups: [],
nodes: [
{
id: "bp",
type: "BatchPrompt",
pos: { x: 0, y: 0 },
widgets: { prompts: "a\n---\nb", index: 0, led: "ready" },
},
{
id: "sv",
type: "SaveVideo",
pos: { x: 200, y: 0 },
widgets: { path: "exports", filename: "rescore-cyberpunk.mp4" },
},
{
id: "lg",
type: "SaveGenerateLog",
pos: { x: 200, y: 100 },
widgets: { path: "exports", filename: "rescore-cyberpunk-log.json" },
},
],
links: [],
};
const patched = patchBatchPromptPass(workflow as never, "bp", {
index: 0,
led: "processing",
saveNodeId: "sv",
});
const byId = Object.fromEntries(patched.nodes.map((n) => [n.id, n]));
expect(byId.sv.widgets.filename).toBe("rescore-cyberpunk-p00.mp4");
expect(byId.lg.widgets.filename).toBe("rescore-cyberpunk-log-p00.json");
expect(byId.bp.widgets.index).toBe(0);
expect(byId.bp.widgets.led).toBe("processing");
});
});

describe("previewTextSnippet", () => {
Expand Down
35 changes: 29 additions & 6 deletions apps/studio/src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,16 @@ export function findPromptBatchDriver(workflow: Workflow): string | null {
return null;
}

/** Stamp SaveVideo / SaveGenerateLog base names with `-pNN` for BatchPrompt passes. */
export function batchTakeFilename(base: string, index: number, fallbackExt: string): string {
const raw = base.trim() || `output${fallbackExt}`;
const dot = raw.lastIndexOf(".");
const stemRaw = dot >= 0 ? raw.slice(0, dot) : raw;
const suffix = dot >= 0 ? raw.slice(dot) : fallbackExt;
const stem = stemRaw.includes("-p") ? stemRaw.split("-p")[0]! : stemRaw;
return `${stem}-p${String(index).padStart(2, "0")}${suffix}`;
}

export function patchBatchPromptPass(
workflow: Workflow,
batchNodeId: string,
Expand All @@ -859,16 +869,29 @@ export function patchBatchPromptPass(
};
}
if (saveNodeId && node.id === saveNodeId && node.type === "SaveVideo") {
const base = String(node.widgets.filename ?? "output.mp4");
const dot = base.lastIndexOf(".");
const stemRaw = dot >= 0 ? base.slice(0, dot) : base;
const suffix = dot >= 0 ? base.slice(dot) : ".mp4";
const stem = stemRaw.includes("-p") ? stemRaw.split("-p")[0]! : stemRaw;
return {
...node,
widgets: {
...node.widgets,
filename: `${stem}-p${String(index).padStart(2, "0")}${suffix}`,
filename: batchTakeFilename(
String(node.widgets.filename ?? "output.mp4"),
index,
".mp4",
),
},
};
}
// Same -pNN stamp as SaveVideo so exports/<stem>-p00-*.mp4 ↔ *-p00-*.json.
if (node.type === "SaveGenerateLog") {
return {
...node,
widgets: {
...node.widgets,
filename: batchTakeFilename(
String(node.widgets.filename ?? "generate-log.json"),
index,
".json",
),
},
};
}
Expand Down
16 changes: 16 additions & 0 deletions nodes/ai/src/groovy/nodes/ai/inference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
import os
import tempfile
from pathlib import Path

Expand Down Expand Up @@ -1175,6 +1176,20 @@ def run_generate_audio(cache: CacheStore, kwargs: dict) -> list[dict]:
out_buffer = AudioBuffer.from_planar(pcm, sample_rate, source_node_type="GenerateAudio")
cache.write_audio(out_buffer, pcm)
frames = int(pcm.shape[-1]) if getattr(pcm, "ndim", 0) >= 1 else 0
timing_extra: dict = {}
if str(model_id).startswith("ace-step"):
try:
from groovy.nodes.ai.backends.ace_step_runner import _load_pipeline

info = _load_pipeline.cache_info()
timing_extra = {
"ace_pipeline_cache_hits": int(info.hits),
"ace_pipeline_cache_misses": int(info.misses),
"warm_ace_worker": os.environ.get("GROOVY_AI_WORKER_MODE", "").strip().lower()
== "warm",
}
except Exception:
timing_extra = {}
report = GenerateLogReport.create(
{
"node_type": "GenerateAudio",
Expand All @@ -1183,6 +1198,7 @@ def run_generate_audio(cache: CacheStore, kwargs: dict) -> list[dict]:
"timing": {
"generate_ms": elapsed_ms,
"generate_s": round(elapsed_ms / 1000.0, 3),
**timing_extra,
},
"output": {
"media_type": "audio/pcm",
Expand Down
52 changes: 47 additions & 5 deletions nodes/ai/src/groovy/nodes/ai/worker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import annotations

import json
import os
import sys
import traceback
from pathlib import Path
from typing import Any

from groovy.executor.cache import CacheStore
from groovy.nodes.ai.inference import (
Expand Down Expand Up @@ -64,10 +67,7 @@
}


def main() -> None:
import os

payload = json.loads(sys.stdin.read())
def _handle_one(payload: dict[str, Any]) -> list[dict[str, Any]]:
node_type = payload["node_type"]
project_dir = Path(payload["project_dir"])
os.environ.setdefault("GROOVY_PROJECT_DIR", str(project_dir.resolve()))
Expand All @@ -82,7 +82,49 @@ def main() -> None:
if model_id:
require_model(project_dir, str(model_id))

outputs = handler(cache, kwargs)
return handler(cache, kwargs)


def _warm_loop() -> None:
"""NDJSON request/response loop — keeps ACE pipeline cache warm across takes."""
for raw in sys.stdin:
line = raw.strip()
if not line:
continue
request_id = None
try:
payload = json.loads(line)
if not isinstance(payload, dict):
raise RuntimeError("Warm worker payload must be a JSON object")
request_id = payload.get("request_id")
if payload.get("cmd") == "shutdown":
reply = {"ok": True, "shutdown": True, "request_id": request_id}
sys.stdout.write(json.dumps(reply) + "\n")
sys.stdout.flush()
return
outputs = _handle_one(payload)
reply = {"ok": True, "outputs": outputs, "request_id": request_id}
sys.stdout.write(json.dumps(reply) + "\n")
sys.stdout.flush()
except Exception as exc: # noqa: BLE001 — per-request isolation in warm loop
traceback.print_exc(file=sys.stderr)
reply = {
"ok": False,
"error": str(exc) or type(exc).__name__,
"request_id": request_id,
}
sys.stdout.write(json.dumps(reply) + "\n")
sys.stdout.flush()


def main() -> None:
mode = os.environ.get("GROOVY_AI_WORKER_MODE", "").strip().lower()
if mode == "warm":
_warm_loop()
return

payload = json.loads(sys.stdin.read())
outputs = _handle_one(payload)
sys.stdout.write(json.dumps({"outputs": outputs}))


Expand Down
16 changes: 15 additions & 1 deletion nodes/core/src/groovy/nodes/core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import hashlib
import json
import re
import shutil
import uuid
from datetime import UTC, datetime
from pathlib import Path
from typing import Any

import numpy as np
import soundfile as sf
Expand Down Expand Up @@ -1314,14 +1316,26 @@ def run(self, **kwargs) -> tuple[str]:
relative = self._resolve_output_relative(folder, name)
if not Path(relative).suffix:
relative = f"{relative}.json"
# Capture BatchPrompt take id from widget name before UTC stamp
# (e.g. rescore-cyberpunk-log-p03.json → p03).
batch_match = re.search(r"-p(\d+)\b", Path(name).stem, flags=re.IGNORECASE)
relative = self._timestamped_relative(relative).replace("\\", "/")
out_path = self._ctx.cache.resolve_project_path(relative)
out_path.parent.mkdir(parents=True, exist_ok=True)
export_meta: dict[str, Any] = {
"path": relative,
"node_type": "SaveGenerateLog",
"filename_widget": name,
}
if batch_match:
take = f"p{int(batch_match.group(1)):02d}"
export_meta["batch_prompt_index"] = int(batch_match.group(1))
export_meta["batch_take_id"] = take
payload = {
**log_in.record,
"exported_at": datetime.now(UTC).isoformat(),
"generate_log_id": log_in.id,
"export": {"path": relative, "node_type": "SaveGenerateLog"},
"export": export_meta,
}
out_path.write_text(json.dumps(payload, indent=2) + "\n")
return (relative,)
Expand Down
Loading
Loading