8000 File handling refactor breaks loading of PNGs with NaN values in metadata · Issue #4199 · Comfy-Org/ComfyUI_frontend · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
File handling refactor breaks loading of PNGs with NaN values in metadata #4199
Open
@christian-byrne

Description

@christian-byrne

File handling refactor breaks loading of PNGs with NaN values in metadata

Background

PR #3955 refactored file handling to centralize the logic into a new fileHandlers.ts module. This PR was reverted due to issues reported in:

Root Cause: NaN in Workflow Metadata

When ComfyUI executes a workflow, the backend adds an is_changed field to track node state. If a node's IS_CHANGED method throws an exception, the backend sets this field to float("NaN"):

# From ComfyUI/execution.py, lines 52-60
try:
    is_changed = _map_node_over_list(class_def, input_data_all, "IS_CHANGED")
    node["is_changed"] = [None if isinstance(x, ExecutionBlocker) else x for x in is_changed]
except Exception as e:
    logging.warning("WARNING: {}".format(e))
    node["is_changed"] = float("NaN")  # This creates invalid JSON!
finally:
    self.is_changed[node_id] = node["is_changed"]

This modified node data gets saved in the PNG metadata. Example from an affected PNG:

{
  "prompt": {"16": {"inputs": {"image": "animated_webp.webp"}, "class_type": "DevToolsLoadAnimatedImageTest", "_meta": {"title": "Load Animated Image"}, "is_changed": NaN}, "17": {...}},
  "workflow": {"id": "cffcce2d-a13c-4a5f-929b-82f274bacc36", "nodes": [...], ...}
}

Note: The workflow field contains valid JSON, but the prompt field contains invalid JSON with literal NaN.

Why the Refactor Broke This

Before (app.ts):

if (pngInfo?.workflow) {
  await this.loadGraphData(JSON.parse(pngInfo.workflow), true, true, fileName)
} else if (pngInfo?.prompt) {
  this.loadApiJson(JSON.parse(pngInfo.prompt), fileName)
}

The if-else structure meant that if a valid workflow existed, the prompt was never parsed.

After (fileHandlers.ts):

return {
  workflow: pngInfo?.workflow ? JSON.parse(pngInfo.workflow) : undefined,
  prompt: pngInfo?.prompt ? JSON.parse(pngInfo.prompt) : undefined,
}

Both workflow and prompt are parsed eagerly, causing JSON.parse() to fail on the invalid prompt JSON.

Next Steps

  1. Immediate fix: Re-implement the file handler refactor with lazy evaluation:

    return {
      workflow: pngInfo?.workflow ? () => JSON.parse(pngInfo.workflow) : undefined,
      prompt: pngInfo?.prompt ? () => JSON.parse(pngInfo.prompt) : undefined,
    }
  2. Defensive parsing: Add try-catch blocks and/or sanitize NaN values before parsing

  3. Backend fix: Create issue in ComfyUI repo to use None or valid JSON instead of float("NaN")

Related Issues

┆Issue is synchronized with this Notion page by Unito

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0