Skip to content

feat: import AVIF workflow metadata from XMP#13757

Open
austintraver wants to merge 4 commits into
Comfy-Org:mainfrom
austintraver:codex/avif-xmp-import
Open

feat: import AVIF workflow metadata from XMP#13757
austintraver wants to merge 4 commits into
Comfy-Org:mainfrom
austintraver:codex/avif-xmp-import

Conversation

@austintraver

@austintraver austintraver commented Jul 17, 2026

Copy link
Copy Markdown

Summary

Dragging an AVIF that stores ComfyUI workflow or prompt metadata in an XMP MIME item currently accepts the image but does not restore its workflow. This extends the reader introduced by Add the ability to parse workflows from AVIF images to import that metadata while preserving existing EXIF behavior.

Changes

  • Recognize infe items with type mime and content type application/rdf+xml, resolve their declared 0/4/8-byte iloc fields and extents, and read workflow and prompt from RDF elements or attributes.
  • Parse EXIF first, then replace only matching keys whose XMP values contain syntactically valid JSON. Absent or malformed XMP leaves EXIF metadata intact.
  • Validate extent ranges before allocation and join multiple extents before decoding the XMP packet.

Review Focus

  • XMP item extraction is limited to self-contained file offsets (construction_method=0, data_reference_index=0). idat-stored items using construction method 1 remain out of scope.
  • XMP overrides EXIF per key; semantic workflow validation remains in the shared loading path rather than this format reader.

Testing

  • pnpm test:unit src/scripts/metadata/avif.test.ts --maxWorkers=2 — 25/25 passed
  • pnpm typecheck
  • pnpm lint
  • pnpm format:check
  • pnpm knip
  • Encoded and decoded a libavif 1.4.2 canary containing a 460-byte XMP item; the existing AVIF reader returned its exact workflow and prompt.

@austintraver
austintraver requested a review from a team July 17, 2026 10:38
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 17, 2026
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

✅ All contributors have signed the CLA. Thank you! This PR is ready to be merged.
Posted by the CLA Assistant Lite bot.

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

🎨 Storybook: 🚧 Building...

🎭 Playwright: ⏳ Running...

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

AVIF metadata parsing now extracts XMP workflow and prompt values alongside EXIF. Test fixtures support multiple metadata items, configurable iloc layouts, and computed offsets, with coverage for XMP import, precedence, and malformed metadata handling.

Changes

AVIF XMP Metadata Support

Layer / File(s) Summary
AVIF item parsing and XMP extraction
src/scripts/metadata/avif.ts, src/types/metadataTypes.ts
Bounds item parsing, records construction_method, decodes variable-width iloc fields, assembles item bytes, and maps XMP RDF/XML properties into metadata.
EXIF and XMP metadata integration
src/scripts/metadata/avif.ts
Supports EXIF-only and XMP-only metadata, conditionally parses EXIF, warns when TIFF data is unavailable, and merges XMP values.
Multi-item AVIF fixtures and workflow tests
src/scripts/metadata/avif.test.ts
Generates AVIF files with optional EXIF and XMP items, configurable extents and field sizes, and tests workflow/prompt import, precedence, and malformed XMP handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AVIFFile
  participant parseAvifMetadata
  participant getIlocItemData
  participant EXIFParser
  participant parseXmpMetadata
  AVIFFile->>parseAvifMetadata: provide AVIF metadata boxes
  parseAvifMetadata->>getIlocItemData: extract EXIF and XMP item bytes
  getIlocItemData-->>parseAvifMetadata: return assembled item data
  parseAvifMetadata->>EXIFParser: parse EXIF item when present
  EXIFParser-->>parseAvifMetadata: return EXIF metadata
  parseAvifMetadata->>parseXmpMetadata: parse RDF/XML item when present
  parseXmpMetadata-->>parseAvifMetadata: return workflow and prompt metadata
  parseAvifMetadata-->>AVIFFile: return merged metadata
Loading

Suggested reviewers: pythongosssss


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
End-To-End Regression Coverage For Fixes ❓ Inconclusive PR title/commit subjects aren’t provided here, so I can’t safely verify the bug-fix trigger for this regression-test rule. Provide the PR title and commit subjects (or a metadata summary listing them) so I can confirm whether browser_tests coverage is required.
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Adr Compliance For Entity/Litegraph Changes ✅ Passed Changed files are limited to AVIF metadata parsing/tests and a type, with no src/lib/litegraph/, src/ecs/, or graph-entity files touched.
Title check ✅ Passed The title clearly states the main change: importing AVIF workflow metadata from XMP.
Description check ✅ Passed The description matches the template sections and includes summary, changes, review focus, and testing.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/scripts/metadata/avif.test.ts`:
- Around line 472-502: Add malformed-XMP fallback tests alongside the existing
AVIF metadata tests, covering malformed XML and schema-invalid workflow or
prompt JSON while providing valid EXIF metadata. Use getFromAvifFile and assert
the returned workflow and prompt preserve the EXIF values when XMP is missing or
invalid, while retaining the existing valid-XMP precedence coverage.

In `@src/scripts/metadata/avif.ts`:
- Around line 222-253: Update getIlocItemData to validate each extent’s source
range and accumulate totalLength before allocating itemData. Enforce an explicit
metadata-size limit during accumulation, reject invalid or overflowing ranges
and totals, then allocate only after all extents pass validation; preserve the
existing data-copy behavior for valid items.
- Around line 262-267: Validate parsed XMP prompt and workflow values in the
metadata handling block using their runtime schemas before assigning them to
metadata, leaving invalid properties unset so valid EXIF values remain
effective; update src/scripts/metadata/avif.ts lines 262-267. Add malformed-XML
and schema-invalid-JSON cases asserting EXIF fallback behavior in
src/scripts/metadata/avif.test.ts lines 472-502.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 25de46f6-61e8-4b98-aeca-c55a9338caba

📥 Commits

Reviewing files that changed from the base of the PR and between 27859cb and 5c4b919.

📒 Files selected for processing (3)
  • src/scripts/metadata/avif.test.ts
  • src/scripts/metadata/avif.ts
  • src/types/metadataTypes.ts

Comment thread src/scripts/metadata/avif.test.ts Outdated
Comment thread src/scripts/metadata/avif.ts
Comment thread src/scripts/metadata/avif.ts
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 17, 2026
@austintraver

Copy link
Copy Markdown
Author

I have read and agree to the Contributor License Agreement

comfy-legal added a commit to Comfy-Org/comfy-cla that referenced this pull request Jul 17, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/scripts/metadata/avif.test.ts`:
- Around line 214-258: Extend buildIlocBox to accept version,
construction-method, and index-size options, and encode the corresponding iloc
v1/v2 fields and extent indexes in the fixture. Add assertions that exercise
parseIlocBox’s method-0 XMP import path and confirm unsupported construction
locations retain the EXIF fallback, covering the AVIF/XMP behavior through real
parsing paths.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d1f9d7f8-c7d3-49d8-aa16-315330598ea2

📥 Commits

Reviewing files that changed from the base of the PR and between 9e6cfaa and 4535823.

📒 Files selected for processing (2)
  • src/scripts/metadata/avif.test.ts
  • src/scripts/metadata/avif.ts

Comment thread src/scripts/metadata/avif.test.ts
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 17, 2026
Use the canonical ComfyUI XMP namespace emitted by the Save Image (Advanced) AVIF writer in Comfy-Org/ComfyUI#14975. The reader matches by local name, so parsing behavior is unchanged.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/scripts/metadata/avif.test.ts (1)

415-423: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add a non-canonical XMP namespace test.

buildXmpPacket hardcodes the canonical comfy URI, so the suite does not verify the promised namespace-independent parsing. Make the namespace configurable or add a packet using a different URI/prefix, then assert workflow and prompt extraction still succeeds.

Also applies to: 582-594

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/scripts/metadata/avif.test.ts` around lines 415 - 423, Extend the AVIF
metadata tests around buildXmpPacket to cover a non-canonical XMP namespace URI
or prefix. Make the packet builder configurable as needed, generate a packet
with the alternate namespace, and assert workflow and prompt extraction still
succeed independently of the namespace choice.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/scripts/metadata/avif.test.ts`:
- Around line 415-423: Extend the AVIF metadata tests around buildXmpPacket to
cover a non-canonical XMP namespace URI or prefix. Make the packet builder
configurable as needed, generate a packet with the alternate namespace, and
assert workflow and prompt extraction still succeed independently of the
namespace choice.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0eda2fed-49fd-44f7-9b06-422bbb1066d9

📥 Commits

Reviewing files that changed from the base of the PR and between 4535823 and 8dee4bc.

📒 Files selected for processing (1)
  • src/scripts/metadata/avif.test.ts

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 18, 2026
@austintraver

Copy link
Copy Markdown
Author

This stays contained to the AVIF metadata reader and its tests, with no new dependencies (just the built-in browser parsing APIs). Existing EXIF import is untouched; XMP is layered on top of it and falls back to EXIF whenever the XMP is missing or doesn't parse.

Malformed files stay bounded too: item ranges are validated against the file size before anything is allocated, so a crafted AVIF can't force an oversized read, and anything the reader doesn't recognize is skipped rather than mis-read.

Nothing in the UI or the load flow changes; this is purely the parser behind the existing drag-to-load path. That's why the coverage is unit tests plus a real libavif round-trip rather than a browser test. The matching writer in Comfy-Org/ComfyUI#14975 produces exactly this XMP layout, so the two interoperate end to end.

Happy to add whatever would help review.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant