Skip to content
Open
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
3 changes: 1 addition & 2 deletions api/routers/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ async def _run_generation(job_id: str, image_bytes: bytes, params: dict, collect
job.status = "running"

def progress_cb(pct: int, step: str = "") -> None:
if pct > job.progress:
job.progress = pct
job.progress = pct
if step:
job.step = step

Expand Down
2 changes: 1 addition & 1 deletion api/services/extension_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _read_loop(self, proc: subprocess.Popen, msg_queue: queue.Queue) -> None:
try:
msg_queue.put(json.loads(line))
except json.JSONDecodeError:
print(f"[{self.MODEL_ID}] {line}", file=sys.stderr)
print(f"[{self.MODEL_ID}] bad JSON: {line}", file=sys.stderr)
finally:
msg_queue.put(None) # sentinel: process is done

Expand Down
32 changes: 31 additions & 1 deletion src/areas/generate/components/WorkflowPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ function EmbeddedCanvas({ workflow, allExtensions }: {
const [edges, setEdges, onEdgesChange] = useEdgesState(workflow.edges as FlowEdge[])
const { updateNodeData } = useReactFlow()
const { navigate } = useNavStore()
const saveTimer = useRef<ReturnType<typeof setTimeout> | null>(null)

// Direct patch into controlled nodes state — no React Flow store dependency
const patchNode = useCallback<PatchFn>((nodeId, patch) => {
Expand All @@ -458,6 +459,36 @@ function EmbeddedCanvas({ workflow, allExtensions }: {
))
}, [setNodes])

// ─── Tab sync ──────────────────────────────────────────────────────────────
const lastSyncedAtRef = useRef<string>(workflow.updatedAt)
const didMountRef = useRef(false)

// Sync local state when Workflows tab saves to the store (Workflows→Generate)
useEffect(() => {
if (workflow.updatedAt === lastSyncedAtRef.current) return
setNodes(workflow.nodes as FlowNode[])
setEdges(workflow.edges as FlowEdge[])
lastSyncedAtRef.current = workflow.updatedAt
}, [workflow.updatedAt])

// Debounced save to the store when local state changes (Generate→Workflows)
// No cleanup return — lets the timer fire even if user navigates away
useEffect(() => {
if (!didMountRef.current) { didMountRef.current = true; return }
if (saveTimer.current) clearTimeout(saveTimer.current)
saveTimer.current = setTimeout(() => {
const now = new Date().toISOString()
const updated: Workflow = {
...workflow,
nodes: nodes as WFNode[],
edges: edges as WFEdge[],
updatedAt: now,
}
lastSyncedAtRef.current = now
useWorkflowsStore.getState().save(updated)
}, 500)
}, [nodes, edges])

const currentMeshUrl = useAppStore((s) => s.currentJob?.outputUrl)
const showToast = useAppStore((s) => s.showToast)
const { runState, run, cancel } = useWorkflowRunStore()
Expand Down Expand Up @@ -659,7 +690,6 @@ export default function WorkflowPanel() {
{workflow ? (
<ReactFlowProvider>
<EmbeddedCanvas
key={workflow.id + workflow.updatedAt}
workflow={workflow}
allExtensions={allExtensions}
/>
Expand Down
23 changes: 19 additions & 4 deletions src/areas/workflows/WorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@ function WorkflowCanvasInner({
const historyRef = useRef<Snapshot[]>([{ nodes: workflow.nodes as Node[], edges: workflow.edges as Edge[], name: workflow.name }])
const histIdxRef = useRef(0)
const [histIdx, setHistIdx] = useState(0)
const skipPushRef = useRef(true) // skip the initial autosave-triggered push
const skipPushRef = useRef(true) // skip the initial autosave-triggered push
const lastSavedAtRef = useRef<string>(workflow.updatedAt)

// Re-sync when workflow switches
useEffect(() => {
Expand All @@ -818,19 +819,34 @@ function WorkflowCanvasInner({
histIdxRef.current = 0
setHistIdx(0)
skipPushRef.current = true
lastSavedAtRef.current = workflow.updatedAt
}, [workflow.id])

// Auto-save + history push debounced
// Re-sync when Generate tab (or another external source) saves param changes
useEffect(() => {
if (workflow.updatedAt === lastSavedAtRef.current) return
setNodes(workflow.nodes as Node[])
setEdges(workflow.edges as Edge[])
setName(workflow.name)
skipPushRef.current = true
lastSavedAtRef.current = workflow.updatedAt
}, [workflow.updatedAt])

// Auto-save + history push debounced.
// No cleanup return — lets the timer fire even if the user navigates away
// before the debounce expires, keeping both tabs in sync.
useEffect(() => {
if (saveTimer.current) clearTimeout(saveTimer.current)
saveTimer.current = setTimeout(() => {
const now = new Date().toISOString()
const updated: Workflow = {
...workflow,
name,
nodes: nodes as WFNode[],
edges: edges as WFEdge[],
updatedAt: new Date().toISOString(),
updatedAt: now,
}
lastSavedAtRef.current = now
onSave(updated)

if (!skipPushRef.current) {
Expand All @@ -844,7 +860,6 @@ function WorkflowCanvasInner({
}
skipPushRef.current = false
}, 500)
return () => { if (saveTimer.current) clearTimeout(saveTimer.current) }
}, [nodes, edges, name])

const preflightIssues = useMemo(() => {
Expand Down