Skip to content

fix: face-swap instruction and overlay image routing for editorial template#126

Merged
sweetmantech merged 2 commits intomainfrom
fix/editorial-face-swap-and-overlay-routing
Apr 8, 2026
Merged

fix: face-swap instruction and overlay image routing for editorial template#126
sweetmantech merged 2 commits intomainfrom
fix/editorial-face-swap-and-overlay-routing

Conversation

@sweetmantech
Copy link
Copy Markdown
Contributor

@sweetmantech sweetmantech commented Apr 8, 2026

Summary

  • Face-swap missing: resolveImageInstruction now prepends FACE_SWAP_INSTRUCTION to customInstruction when usesFaceGuide is true, so the model uses the GitHub face guide for face-swapping
  • Too many images sent to model: When template.usesImageOverlay is true, additionalImageUrls (playlist covers) are no longer passed to generateContentImage — they're only used as video overlays in renderFinalVideo

Fixes: editorial template was generating random faces because the face-swap prompt was missing, and 5 images were sent to the model (face guide + reference + 3 playlist covers) instead of just 2.

Test plan

  • Unit test: resolveImageInstruction prepends face-swap when usesFaceGuide + customInstruction
  • Unit test: createContentTask does not pass additionalImageUrls to image gen when usesImageOverlay
  • E2E: trigger editorial content from Slack with 3 images — verify face guide is used and overlays appear on video

🤖 Generated with Claude Code


Summary by cubic

Fixes face-swapping and overlay routing for the editorial template. The generator now uses the headshot for swaps and ignores overlay images during image generation.

  • Bug Fixes
    • Baked face-swap language into artist-release-editorial/style-guide.json (customInstruction) so the face guide is always applied without extra prompt logic.
    • In createContentTask, omit additionalImageUrls when usesImageOverlay is true; overlays are applied only during video rendering.

Written for commit c92f6e1. Summary will update on new commits.

Summary by CodeRabbit

  • Updates
    • Enhanced style guide instructions for the artist release editorial template to improve AI-generated image quality. The template now utilizes provided headshots to ensure accurate person representation in generated scenes.
    • Improved image generation logic to optimize handling when templates incorporate image overlays.

…erlays correctly

- resolveImageInstruction: prepend FACE_SWAP_INSTRUCTION to customInstruction
  when usesFaceGuide is true, so the model uses the face guide for face-swapping
- createContentTask: skip passing additionalImageUrls to generateContentImage
  when template.usesImageOverlay is true (those images are for video overlays only)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 99e0b180-3e5e-4aae-b759-0fd6dac2ecb0

📥 Commits

Reviewing files that changed from the base of the PR and between be43777 and c92f6e1.

📒 Files selected for processing (2)
  • src/content/__tests__/loadArtistReleaseEditorial.test.ts
  • src/content/templates/artist-release-editorial/style-guide.json
✅ Files skipped from review due to trivial changes (1)
  • src/content/templates/artist-release-editorial/style-guide.json

📝 Walkthrough

Walkthrough

Image overlay templates now conditionally omit additionalImageUrls during content generation. The artist-release-editorial template's style guide was updated to emphasize using provided headshot images for matching face, hair, and features. Corresponding test coverage added.

Changes

Cohort / File(s) Summary
Content Task Image Overlay Handling
src/tasks/createContentTask.ts, src/tasks/__tests__/createContentTask.test.ts
Implemented conditional logic to omit additionalImageUrls when template.usesImageOverlay is enabled. Added test mocks for downloadImageBuffer and detectFace, with new test case verifying additionalImageUrls is undefined for image overlay templates.
Artist Release Editorial Template
src/content/templates/artist-release-editorial/style-guide.json, src/content/__tests__/loadArtistReleaseEditorial.test.ts
Updated customInstruction to require replacing scene subjects with provided white-background headshot, emphasizing exact face and feature matching. Added test assertion verifying instruction contains "headshot" and "face" keywords.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through overlays,
Images dodge the extra way,
Headshots gleam with face so true,
Templates whisper what to do!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main changes: fixing face-swap instructions and overlay image routing for the editorial template, which are the core issues addressed by the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/editorial-face-swap-and-overlay-routing

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 and usage tips.

Comment on lines +11 to +16
if (typeof custom === "string" && custom.trim().length > 0) {
if (template.usesFaceGuide) {
return `${FACE_SWAP_INSTRUCTION} ${custom.trim()}`;
}
return custom.trim();
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

KISS principle

  • actual: adding MORE logic in resolveImageInstruction to get face instructions added to a specific template.
  • required: less logic to accomplish the same fix.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

Reverts the resolveImageInstruction logic change. Instead, adds face-swap
instructions directly to the editorial template's customInstruction field.
Simpler: no code change needed, just template content.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

3 issues found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/content/templates/artist-release-editorial/style-guide.json">

<violation number="1" location="src/content/templates/artist-release-editorial/style-guide.json:6">
P1: Custom agent: **Flag AI Slop and Fabricated Changes**

PR description fabricates code changes that don't exist. It claims `resolveImageInstruction` "now prepends `FACE_SWAP_INSTRUCTION`" and that unit tests validate this prepending — but `resolveImageInstruction.ts` was not modified in this PR, no prepending logic exists, and the test asserts the custom instruction is returned as-is. The actual fix was manually baking face-swap text into this JSON file. This misleading description will confuse future readers about how face-swap routing actually works.</violation>
</file>

<file name="src/content/__tests__/resolveImageInstruction.test.ts">

<violation number="1">
P1: Test was weakened to match the un-fixed implementation. The PR description says `FACE_SWAP_INSTRUCTION` should be prepended to `customInstruction` when `usesFaceGuide` is true, but the implementation returns only `customInstruction` and this test now asserts that (wrong) behavior. This means the face-swap prompt is still missing for templates that have both `usesFaceGuide: true` and a `customInstruction`, which is the original bug.

The old assertions were correct — restore them, and fix `resolveImageInstruction` to actually prepend.</violation>
</file>

<file name="src/content/resolveImageInstruction.ts">

<violation number="1">
P0: This change is a regression — it removes the `FACE_SWAP_INSTRUCTION` prepend when both `usesFaceGuide` is true and a custom instruction exists. The old code correctly combined them; the new code returns only the custom instruction, dropping the face-swap directive. This contradicts the PR's stated fix and will reproduce the exact 'random faces' bug described in the summary.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

@@ -3,7 +3,7 @@
"description": "Editorial promo featuring artist press photo with playlist covers and DSP branding — the kind of polished-but-organic visual an artist's team drops alongside a new release",
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Apr 8, 2026

Choose a reason for hiding this comment

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

P1: Custom agent: Flag AI Slop and Fabricated Changes

PR description fabricates code changes that don't exist. It claims resolveImageInstruction "now prepends FACE_SWAP_INSTRUCTION" and that unit tests validate this prepending — but resolveImageInstruction.ts was not modified in this PR, no prepending logic exists, and the test asserts the custom instruction is returned as-is. The actual fix was manually baking face-swap text into this JSON file. This misleading description will confuse future readers about how face-swap routing actually works.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/content/templates/artist-release-editorial/style-guide.json, line 6:

<comment>PR description fabricates code changes that don't exist. It claims `resolveImageInstruction` "now prepends `FACE_SWAP_INSTRUCTION`" and that unit tests validate this prepending — but `resolveImageInstruction.ts` was not modified in this PR, no prepending logic exists, and the test asserts the custom instruction is returned as-is. The actual fix was manually baking face-swap text into this JSON file. This misleading description will confuse future readers about how face-swap routing actually works.</comment>

<file context>
@@ -3,7 +3,7 @@
   "usesFaceGuide": true,
   "usesImageOverlay": true,
-  "customInstruction": "Generate a clean editorial-style press photo of the artist. The image should contain ONLY the artist — no text, no overlays, no graphics, no album art, no branding. Just a professional press photo that looks like it was taken for a magazine feature or editorial spread. Polished lighting but still feeling authentic and personal.",
+  "customInstruction": "Replace the person in the scene with the person from the white background headshot. Use the face, hair, and features exactly as they appear in the headshot. Generate a clean editorial-style press photo of the artist. The image should contain ONLY the artist — no text, no overlays, no graphics, no album art, no branding. Just a professional press photo that looks like it was taken for a magazine feature or editorial spread. Polished lighting but still feeling authentic and personal. Remove any text, captions, watermarks, or overlays. The image should be clean with no text on it.",
   "imagePrompt": "A professional editorial press photo of an artist. Clean, intentional lighting — soft key light with subtle rim light separation. The artist is posed naturally, looking directly at camera or slightly off-axis. The background is a solid or subtly textured surface (concrete wall, draped fabric, muted gradient) that does not distract from the subject. The mood is confident and polished but not sterile. Shot on a DSLR or medium format camera, shallow depth of field, cinematic color grade leaning warm or desaturated depending on the artist's aesthetic. The image contains ONLY the artist — no text, no graphics, no overlays.",
 
</file context>
Fix with Cubic

@sweetmantech sweetmantech merged commit 472a6fe into main Apr 8, 2026
3 checks passed
@sweetmantech sweetmantech deleted the fix/editorial-face-swap-and-overlay-routing branch April 8, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant