Skip to content

fix: replicate harness test and gemini extra param - #5527

Merged
akshaydeo merged 1 commit into
devfrom
07-24-fix_replicate_harness_test_and_gemini_extra_param
Jul 24, 2026
Merged

akshaydeo merged 1 commit into
devfrom
07-24-fix_replicate_harness_test_and_gemini_extra_param

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two silent data-loss bugs are fixed: generationConfig.mediaResolution was dropped during the Gemini → Bifrost → Gemini round-trip on the GenAI generateContent path, causing image token counts to ignore the field entirely; and input_images was dropped on the Replicate /v1/images/generations path because the model-specific field mapping (image_prompt / input_image / image / input_images) was only applied on the edits path, so image-to-image requests silently generated from the prompt alone.

Changes

  • Gemini mediaResolution round-trip fix: convertGenerationConfigToResponsesParameters now writes config.MediaResolution into ExtraParams["media_resolution"] on the inbound leg, and convertParamsToGenerationConfigResponses reads it back out on the outbound leg. Previously neither leg handled the field, so MEDIA_RESOLUTION_LOW/HIGH had no effect on prompt token billing.
  • Replicate input_images on generations path: The model-specific field mapping that routes input_images to the correct per-model field (input_image for kontext models, image_prompt for flux-pro variants, image for flux-dev/fill/krea, input_images array for unknown models) is now applied on the /v1/images/generations path in addition to the edits path.
  • Gemini test: TestGenAIMediaResolution_PreservedThroughBifrostRoundTrip verifies that MEDIA_RESOLUTION_LOW survives a full Gemini → Bifrost → Gemini round-trip via ExtraParams.
  • Replicate tests: The three flat InputImages_* table cases are replaced by TestReplicateImageGenerationInputImagesFieldMapping, a structured test that covers every model in the mapping table, the default fallback, version-suffix stripping, case-insensitive model name matching, raw base64 → data URL normalization, invalid URL rejection, and the no-input-images baseline.
  • E2E harness: Two new test groups are added. Group 30 sends a real landscape image to flux-kontext-pro via /v1/images/generations with aspect_ratio: match_input_image and asserts the output preserves the landscape aspect ratio (a square output proves the image was dropped). Group 31 sends the same 1024×1024 JPEG with MEDIA_RESOLUTION_LOW and MEDIA_RESOLUTION_HIGH to both the GenAI and Vertex routes and asserts the HIGH request reports more prompt tokens than LOW (equal counts prove the field was dropped).
  • E2E filter: replicate is added as a named provider keyword so the collection runner can target Replicate-specific cases in isolation.

Type of change

  • Bug fix

Affected areas

  • Core (Go)
  • Providers/Integrations

How to test

# Unit tests
go test ./core/providers/gemini/... -run TestGenAIMediaResolution_PreservedThroughBifrostRoundTrip -v
go test ./core/providers/replicate/... -run TestReplicateImageGenerationInputImagesFieldMapping -v

# Full suite
go test ./...

For E2E validation, run the provider harness collection against a live environment with {{genaiKey}} and a Replicate-enabled {{baseUrl}}. Group 30 requires a Replicate API key; group 31 requires a Gemini/GenAI key. Group 31.3 and 31.4 additionally require Vertex credentials and will skip cleanly if not configured.

Breaking changes

  • No

Related issues

Fixes silent mediaResolution drop on Gemini GenAI path. Fixes silent input_images drop on Replicate image generations path.

Security considerations

No new auth surfaces, secrets, or PII handling introduced. The E2E fixture image is a public JPEG from Google's generative AI downloads bucket.

Checklist

  • I added/updated tests where appropriate
  • I verified builds succeed (Go and UI)

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


tejas ghatte seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Gemini media resolution now survives conversion through Bifrost response parameters. Replicate input image mapping gains broader regression coverage, provider-harness validation, and provider filtering keywords.

Changes

Gemini media resolution

Layer / File(s) Summary
Preserve media resolution through conversion
core/providers/gemini/utils.go, core/providers/gemini/responses.go
Maps MediaResolution into and out of Bifrost extra parameters.
Round-trip regression coverage
core/providers/gemini/gemini_test.go
Verifies media resolution remains unchanged across Gemini-to-Bifrost-to-Gemini conversion.
Provider-harness validation
tests/e2e/api/collections/provider-harness.json
Compares low and high media-resolution prompt token counts for GenAI and Vertex routes.

Replicate input image mapping

Layer / File(s) Summary
Expanded mapping coverage
core/providers/replicate/replicate_test.go
Tests model-specific field selection, normalization, fallback behavior, invalid URLs, and absent inputs.
Native endpoint validation
tests/e2e/api/collections/provider-harness.json
Validates Replicate input_images handling and landscape output from the native generations endpoint.
Provider filtering
tests/e2e/api/runners/filter-collection.mjs
Adds Replicate, Flux, and Black Forest Labs provider keywords.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: akshaydeo, sammaji

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning PR #123 is about Files API support, but these changes only fix Gemini mediaResolution and Replicate image mapping. Implement or describe the Files API endpoint and provider file-upload support required by #123, including the intended workflow and integration details.
Out of Scope Changes check ⚠️ Warning All substantive changes target Gemini/Replicate bugs and E2E harness updates, which are unrelated to the linked Files API support request. Remove the unrelated Gemini/Replicate fixes and harness changes, or retarget the PR to the Files API scope from #123.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title mentions the two main areas changed: Replicate harness testing and the Gemini extra parameter fix.
Description check ✅ Passed The PR follows the template well and includes summary, changes, type, affected areas, testing, and other required sections.
✨ 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 07-24-fix_replicate_harness_test_and_gemini_extra_param

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

TejasGhatte commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

@TejasGhatte
TejasGhatte marked this pull request as ready for review July 24, 2026 10:49
@coderabbitai
coderabbitai Bot requested review from akshaydeo and sammaji July 24, 2026 10:51

akshaydeo commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • Jul 24, 12:46 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 24, 12:47 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo merged commit 68426b1 into dev Jul 24, 2026
13 of 14 checks passed
@akshaydeo
akshaydeo deleted the 07-24-fix_replicate_harness_test_and_gemini_extra_param branch July 24, 2026 12:47
akshaydeo pushed a commit that referenced this pull request Jul 24, 2026
## Summary

Two silent data-loss bugs are fixed: `generationConfig.mediaResolution` was dropped during the Gemini → Bifrost → Gemini round-trip on the GenAI `generateContent` path, causing image token counts to ignore the field entirely; and `input_images` was dropped on the Replicate `/v1/images/generations` path because the model-specific field mapping (`image_prompt` / `input_image` / `image` / `input_images`) was only applied on the edits path, so image-to-image requests silently generated from the prompt alone.

## Changes

- **Gemini `mediaResolution` round-trip fix**: `convertGenerationConfigToResponsesParameters` now writes `config.MediaResolution` into `ExtraParams["media_resolution"]` on the inbound leg, and `convertParamsToGenerationConfigResponses` reads it back out on the outbound leg. Previously neither leg handled the field, so `MEDIA_RESOLUTION_LOW`/`HIGH` had no effect on prompt token billing.
- **Replicate `input_images` on generations path**: The model-specific field mapping that routes `input_images` to the correct per-model field (`input_image` for kontext models, `image_prompt` for flux-pro variants, `image` for flux-dev/fill/krea, `input_images` array for unknown models) is now applied on the `/v1/images/generations` path in addition to the edits path.
- **Gemini test**: `TestGenAIMediaResolution_PreservedThroughBifrostRoundTrip` verifies that `MEDIA_RESOLUTION_LOW` survives a full Gemini → Bifrost → Gemini round-trip via `ExtraParams`.
- **Replicate tests**: The three flat `InputImages_*` table cases are replaced by `TestReplicateImageGenerationInputImagesFieldMapping`, a structured test that covers every model in the mapping table, the default fallback, version-suffix stripping, case-insensitive model name matching, raw base64 → data URL normalization, invalid URL rejection, and the no-input-images baseline.
- **E2E harness**: Two new test groups are added. Group 30 sends a real landscape image to `flux-kontext-pro` via `/v1/images/generations` with `aspect_ratio: match_input_image` and asserts the output preserves the landscape aspect ratio (a square output proves the image was dropped). Group 31 sends the same 1024×1024 JPEG with `MEDIA_RESOLUTION_LOW` and `MEDIA_RESOLUTION_HIGH` to both the GenAI and Vertex routes and asserts the HIGH request reports more prompt tokens than LOW (equal counts prove the field was dropped).
- **E2E filter**: `replicate` is added as a named provider keyword so the collection runner can target Replicate-specific cases in isolation.

## Type of change

- [x] Bug fix

## Affected areas

- [x] Core (Go)
- [x] Providers/Integrations

## How to test

```sh
# Unit tests
go test ./core/providers/gemini/... -run TestGenAIMediaResolution_PreservedThroughBifrostRoundTrip -v
go test ./core/providers/replicate/... -run TestReplicateImageGenerationInputImagesFieldMapping -v

# Full suite
go test ./...
```

For E2E validation, run the provider harness collection against a live environment with `{{genaiKey}}` and a Replicate-enabled `{{baseUrl}}`. Group 30 requires a Replicate API key; group 31 requires a Gemini/GenAI key. Group 31.3 and 31.4 additionally require Vertex credentials and will skip cleanly if not configured.

## Breaking changes

- [x] No

## Related issues

Fixes silent `mediaResolution` drop on Gemini GenAI path. Fixes silent `input_images` drop on Replicate image generations path.

## Security considerations

No new auth surfaces, secrets, or PII handling introduced. The E2E fixture image is a public JPEG from Google's generative AI downloads bucket.

## Checklist

- [x] I added/updated tests where appropriate
- [x] I verified builds succeed (Go and UI)
akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
## Summary

Two silent data-loss bugs are fixed: `generationConfig.mediaResolution` was dropped during the Gemini → Bifrost → Gemini round-trip on the GenAI `generateContent` path, causing image token counts to ignore the field entirely; and `input_images` was dropped on the Replicate `/v1/images/generations` path because the model-specific field mapping (`image_prompt` / `input_image` / `image` / `input_images`) was only applied on the edits path, so image-to-image requests silently generated from the prompt alone.

## Changes

- **Gemini `mediaResolution` round-trip fix**: `convertGenerationConfigToResponsesParameters` now writes `config.MediaResolution` into `ExtraParams["media_resolution"]` on the inbound leg, and `convertParamsToGenerationConfigResponses` reads it back out on the outbound leg. Previously neither leg handled the field, so `MEDIA_RESOLUTION_LOW`/`HIGH` had no effect on prompt token billing.
- **Replicate `input_images` on generations path**: The model-specific field mapping that routes `input_images` to the correct per-model field (`input_image` for kontext models, `image_prompt` for flux-pro variants, `image` for flux-dev/fill/krea, `input_images` array for unknown models) is now applied on the `/v1/images/generations` path in addition to the edits path.
- **Gemini test**: `TestGenAIMediaResolution_PreservedThroughBifrostRoundTrip` verifies that `MEDIA_RESOLUTION_LOW` survives a full Gemini → Bifrost → Gemini round-trip via `ExtraParams`.
- **Replicate tests**: The three flat `InputImages_*` table cases are replaced by `TestReplicateImageGenerationInputImagesFieldMapping`, a structured test that covers every model in the mapping table, the default fallback, version-suffix stripping, case-insensitive model name matching, raw base64 → data URL normalization, invalid URL rejection, and the no-input-images baseline.
- **E2E harness**: Two new test groups are added. Group 30 sends a real landscape image to `flux-kontext-pro` via `/v1/images/generations` with `aspect_ratio: match_input_image` and asserts the output preserves the landscape aspect ratio (a square output proves the image was dropped). Group 31 sends the same 1024×1024 JPEG with `MEDIA_RESOLUTION_LOW` and `MEDIA_RESOLUTION_HIGH` to both the GenAI and Vertex routes and asserts the HIGH request reports more prompt tokens than LOW (equal counts prove the field was dropped).
- **E2E filter**: `replicate` is added as a named provider keyword so the collection runner can target Replicate-specific cases in isolation.

## Type of change

- [x] Bug fix

## Affected areas

- [x] Core (Go)
- [x] Providers/Integrations

## How to test

```sh
# Unit tests
go test ./core/providers/gemini/... -run TestGenAIMediaResolution_PreservedThroughBifrostRoundTrip -v
go test ./core/providers/replicate/... -run TestReplicateImageGenerationInputImagesFieldMapping -v

# Full suite
go test ./...
```

For E2E validation, run the provider harness collection against a live environment with `{{genaiKey}}` and a Replicate-enabled `{{baseUrl}}`. Group 30 requires a Replicate API key; group 31 requires a Gemini/GenAI key. Group 31.3 and 31.4 additionally require Vertex credentials and will skip cleanly if not configured.

## Breaking changes

- [x] No

## Related issues

Fixes silent `mediaResolution` drop on Gemini GenAI path. Fixes silent `input_images` drop on Replicate image generations path.

## Security considerations

No new auth surfaces, secrets, or PII handling introduced. The E2E fixture image is a public JPEG from Google's generative AI downloads bucket.

## Checklist

- [x] I added/updated tests where appropriate
- [x] I verified builds succeed (Go and UI)
occcat pushed a commit to occcat/bifrost that referenced this pull request Sep 2, 2026
## Summary

Two silent data-loss bugs are fixed: `generationConfig.mediaResolution` was dropped during the Gemini → Bifrost → Gemini round-trip on the GenAI `generateContent` path, causing image token counts to ignore the field entirely; and `input_images` was dropped on the Replicate `/v1/images/generations` path because the model-specific field mapping (`image_prompt` / `input_image` / `image` / `input_images`) was only applied on the edits path, so image-to-image requests silently generated from the prompt alone.

## Changes

- **Gemini `mediaResolution` round-trip fix**: `convertGenerationConfigToResponsesParameters` now writes `config.MediaResolution` into `ExtraParams["media_resolution"]` on the inbound leg, and `convertParamsToGenerationConfigResponses` reads it back out on the outbound leg. Previously neither leg handled the field, so `MEDIA_RESOLUTION_LOW`/`HIGH` had no effect on prompt token billing.
- **Replicate `input_images` on generations path**: The model-specific field mapping that routes `input_images` to the correct per-model field (`input_image` for kontext models, `image_prompt` for flux-pro variants, `image` for flux-dev/fill/krea, `input_images` array for unknown models) is now applied on the `/v1/images/generations` path in addition to the edits path.
- **Gemini test**: `TestGenAIMediaResolution_PreservedThroughBifrostRoundTrip` verifies that `MEDIA_RESOLUTION_LOW` survives a full Gemini → Bifrost → Gemini round-trip via `ExtraParams`.
- **Replicate tests**: The three flat `InputImages_*` table cases are replaced by `TestReplicateImageGenerationInputImagesFieldMapping`, a structured test that covers every model in the mapping table, the default fallback, version-suffix stripping, case-insensitive model name matching, raw base64 → data URL normalization, invalid URL rejection, and the no-input-images baseline.
- **E2E harness**: Two new test groups are added. Group 30 sends a real landscape image to `flux-kontext-pro` via `/v1/images/generations` with `aspect_ratio: match_input_image` and asserts the output preserves the landscape aspect ratio (a square output proves the image was dropped). Group 31 sends the same 1024×1024 JPEG with `MEDIA_RESOLUTION_LOW` and `MEDIA_RESOLUTION_HIGH` to both the GenAI and Vertex routes and asserts the HIGH request reports more prompt tokens than LOW (equal counts prove the field was dropped).
- **E2E filter**: `replicate` is added as a named provider keyword so the collection runner can target Replicate-specific cases in isolation.

## Type of change

- [x] Bug fix

## Affected areas

- [x] Core (Go)
- [x] Providers/Integrations

## How to test

```sh
# Unit tests
go test ./core/providers/gemini/... -run TestGenAIMediaResolution_PreservedThroughBifrostRoundTrip -v
go test ./core/providers/replicate/... -run TestReplicateImageGenerationInputImagesFieldMapping -v

# Full suite
go test ./...
```

For E2E validation, run the provider harness collection against a live environment with `{{genaiKey}}` and a Replicate-enabled `{{baseUrl}}`. Group 30 requires a Replicate API key; group 31 requires a Gemini/GenAI key. Group 31.3 and 31.4 additionally require Vertex credentials and will skip cleanly if not configured.

## Breaking changes

- [x] No

## Related issues

Fixes silent `mediaResolution` drop on Gemini GenAI path. Fixes silent `input_images` drop on Replicate image generations path.

## Security considerations

No new auth surfaces, secrets, or PII handling introduced. The E2E fixture image is a public JPEG from Google's generative AI downloads bucket.

## Checklist

- [x] I added/updated tests where appropriate
- [x] I verified builds succeed (Go and UI)
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.

3 participants