Skip to content

fix(images): a local A1111 edit reports the checkpoint the server rendered with - #279

Merged
jddunn merged 2 commits into
masterfrom
fix/a1111-reports-loaded-checkpoint
Oct 11, 2026
Merged

jddunn merged 2 commits into
masterfrom
fix/a1111-reports-loaded-checkpoint

Conversation

@jddunn

@jddunn jddunn commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

What this fixes

A finding of a code review of #261.

An edit on a local Stable Diffusion server (AUTOMATIC1111) that names no model sends no checkpoint override, so the server renders with the checkpoint it has loaded. The result's model, and with it the span and the usage record, named defaultModelId, which initialization takes from the first entry of /sdapi/v1/sd-models. On a server with several checkpoints the first one listed need not be the loaded one.

The server says what it used: the response's info is a JSON string with sd_model_name (Processed.js, returned by /sdapi/v1/txt2img and /sdapi/v1/img2img). The result now reads the name from there, and falls back to the listed checkpoint when the response carries none. A model the call names is reported as named, as before.

Test

image-operation-default-models.e2e: a server that lists two checkpoints and answers with sd_model_name of the second; the edit reports the second.

Summary by Sourcery

Report the model actually used for local image generation and keep related usage and tracing metadata accurate.

Bug Fixes:

  • Report the checkpoint actually used by a local AUTOMATIC1111 server when an image request does not specify a model, falling back to the listed default when the response provides no checkpoint.

Enhancements:

  • Propagate the provider and model returned by image generation results to usage metadata and tracing spans, including fallback-provider responses.

Tests:

  • Add coverage for AUTOMATIC1111 responses that identify a rendered checkpoint different from the first listed checkpoint, as well as fallback behavior and explicitly named models.

…dered with

With no model named, an edit leaves the server on the checkpoint it has
loaded, and the result named the first checkpoint the server lists, which
need not be the loaded one. The result now takes the name from the
response's own `info` (`sd_model_name`), and falls back to the listed one
when the response carries none. A model the call names is reported as
named.
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 11, 2026 00:36
@sourcery-ai

sourcery-ai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 hour and 26 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T00:38:15.338939Z 46c2276 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sourcery-ai

sourcery-ai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

The local Stable Diffusion provider now derives the reported model from A1111’s info.sd_model_name when the request does not specify a model, while preserving explicit-model and fallback behavior; an end-to-end test covers a loaded checkpoint that is not first in the server’s model list.

Sequence diagram for reported A1111 checkpoint selection

sequenceDiagram
    participant Caller
    participant StableDiffusionLocalProvider
    participant A1111
    Caller->>StableDiffusionLocalProvider: image operation
    StableDiffusionLocalProvider->>A1111: POST /sdapi/v1/img2img or /sdapi/v1/extra-single-image
    A1111-->>StableDiffusionLocalProvider: response with info
    alt request.modelId is specified
        StableDiffusionLocalProvider->>StableDiffusionLocalProvider: use request.modelId
    else response info contains sd_model_name
        StableDiffusionLocalProvider->>StableDiffusionLocalProvider: renderedCheckpoint(data.info)
    else no rendered checkpoint
        StableDiffusionLocalProvider->>StableDiffusionLocalProvider: use defaultModelId or unknown
    end
    StableDiffusionLocalProvider-->>Caller: result with modelId and usage
Loading

File-Level Changes

Change Details Files
Report the checkpoint actually rendered by local A1111 when no model is explicitly requested.
  • Parse sd_model_name from the response info JSON string, ignoring malformed or empty values.
  • Prefer the explicitly requested model, then the rendered checkpoint, then the configured default or unknown fallback for both image-generation paths.
src/io/media/images/providers/StableDiffusionLocalProvider.ts
Add end-to-end coverage for servers whose loaded checkpoint differs from the first listed checkpoint.
  • Mock multiple listed checkpoints and an A1111 response identifying the second checkpoint.
  • Verify an unqualified local edit reports the checkpoint named by the response.
src/api/runtime/__tests__/image-operation-default-models.e2e.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 4 billable files and costs up to $1.00.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 5 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: framerslab/agentos/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 2c5c30b2-907f-428a-9352-36eb3264780b

📥 Commits

Reviewing files that changed from the base of the PR and between d4d3c6d and 61942f9.


📒 Files selected for processing (4)
  • src/api/generateImage.ts
  • src/api/runtime/__tests__/image-operation-default-models.e2e.test.ts
  • src/io/media/images/__tests__/StableDiffusionLocalProvider.test.ts
  • src/io/media/images/providers/StableDiffusionLocalProvider.ts

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Report the checkpoint used by local A1111 image renders

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Read A1111's rendered checkpoint from its response instead of assuming the first listed
 checkpoint.
• Preserve explicitly named models and fall back to the listed default when response metadata is
 unavailable.
• Test an edit where the rendered checkpoint is second in the server's model list.
Diagram

graph TD
  A["Image request"] --> B["A1111 render"] --> C{"Explicit model?"} -->|Yes| D["Named model"] --> H["Result model"]
  C -->|No| E{"Response checkpoint?"} -->|Yes| F["Rendered model"] --> H
  E -->|No| G["Default or unknown"] --> H
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Query the currently loaded checkpoint
  • ➕ Could identify the loaded checkpoint independently of render response metadata.
  • ➖ Adds a server request and may observe a different checkpoint if it changes between the query and render.

Recommendation: Prefer the PR's per-render response metadata: it identifies the checkpoint for that specific operation without another request. Retaining the existing default fallback and explicit-model precedence limits behavior changes.

Files changed (2) +42 / -2

Bug fix (1) +22 / -2
StableDiffusionLocalProvider.tsUse A1111 response metadata for the reported model +22/-2

Use A1111 response metadata for the reported model

• Adds guarded parsing of 'sd_model_name' from the response's JSON 'info' string. Generation and editing now use that name when no model was requested, retaining the provider default and 'unknown' fallbacks.

src/io/media/images/providers/StableDiffusionLocalProvider.ts

Tests (1) +20 / -0
image-operation-default-models.e2e.test.tsCover edits rendered with a non-first A1111 checkpoint +20/-0

Cover edits rendered with a non-first A1111 checkpoint

• Adds an end-to-end test with two listed checkpoints and response metadata naming the second. Verifies that a model-unspecified edit reports the checkpoint the server says it used.

src/api/runtime/tests/image-operation-default-models.e2e.test.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Generated model reporting goes untested ✓ Resolved
Description
The new renderedCheckpoint(data.info) call in the generation result has no integration test for a
server that renders with a checkpoint other than the first one listed. The added real-path test
calls editImage only, so the corresponding generateImage result is not checked for the behavior
this change introduces.
Code

src/io/media/images/providers/StableDiffusionLocalProvider.ts[325]

+      modelId: request.modelId || renderedCheckpoint(data.info) || this.defaultModelId || 'unknown',
Evidence
Rule 5 requires integration coverage for new observable behavior. The changed generation result
reads the response checkpoint, while the added second-checkpoint integration case invokes only the
edit path.

AGENTS.md: Test Observable Behavior Through Real Paths: AGENTS.md: Test Observable Behavior Through Real Paths: AGENTS.md: Test Observable Behavior Through Real Paths: AGENTS.md: Test Observable Behavior Through Real Paths
src/io/media/images/providers/StableDiffusionLocalProvider.ts[301-325]
src/api/runtime/tests/image-operation-default-models.e2e.test.ts[243-261]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new checkpoint reporting behavior is exercised through editImage but not through generateImage.
## Fix Focus Areas
- src/api/runtime/__tests__/image-operation-default-models.e2e.test.ts[243-261]
- src/io/media/images/providers/StableDiffusionLocalProvider.ts[325-325]
## Recommended Fix
Add a real-path generateImage test with two listed checkpoints and an A1111 txt2img response whose sd_model_name is the second checkpoint; assert the returned model names the second checkpoint.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Generated images get the wrong usage model ✓ Resolved
Description
generateViaA1111 now returns the checkpoint from data.info when the request has no modelId,
but generateImage records usage and sets its span from the model resolved before the request. When
a fallback proxy is present, it passes no model ID to A1111, so a server loaded with a different
checkpoint returns that checkpoint to the caller while the usage record and span retain the resolved
default.
Code

src/io/media/images/providers/StableDiffusionLocalProvider.ts[325]

+      modelId: request.modelId || renderedCheckpoint(data.info) || this.defaultModelId || 'unknown',
Evidence
The fallback proxy forwards an undefined model ID, allowing the changed A1111 return expression to
select the response checkpoint. The generation API returns that value, but assigns its telemetry
model before the call and does not replace it afterward.

src/api/generateImage.ts[139-181]
src/api/generateImage.ts[416-437]
src/io/media/images/FallbackImageProxy.ts[347-361]
src/io/media/images/providers/StableDiffusionLocalProvider.ts[238-240]
src/io/media/images/providers/StableDiffusionLocalProvider.ts[321-325]
src/api/generateImage.ts[474-502]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
When local A1111 generation runs through a fallback proxy, its returned checkpoint can differ from the model recorded in the usage ledger and span.
## Fix Focus Areas
- src/io/media/images/providers/StableDiffusionLocalProvider.ts[323-325]
- src/api/generateImage.ts[416-420]
- src/api/generateImage.ts[469-483]
## Recommended Fix
After generation succeeds, use `result.modelId` to update the generation span and `metricModelId` before recording usage. Add a test with a fallback proxy and an A1111 response whose rendered checkpoint differs from the resolved default.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

…1 generation path is tested

The usage record and the span of generateImage named the provider and
model resolved before the request. A fallback provider that served the
image after the first one failed, and a local server's own checkpoint,
were recorded under the first choice. Both now come from the result, as
editImage's already did.

The provider-level tests cover the generation path of the checkpoint
report: the name the response gives when the request names no model, the
named model when it names one, and the first listed checkpoint when the
response names none.
@jddunn
jddunn merged commit 3744044 into master Oct 11, 2026
9 checks passed
@jddunn
jddunn deleted the fix/a1111-reports-loaded-checkpoint branch October 11, 2026 00:53
github-actions Bot pushed a commit that referenced this pull request Oct 11, 2026
## [0.13.40](v0.13.39...v0.13.40) (2026-10-11)

### feat

* **auth:** OAuth for a web server: a redirect flow, sealed secrets and a sealed token store (#242) ([59a20d1](59a20d1))
* **voice-pipeline:** build a speech-to-text chain from provider entries (#176) ([29046f2](29046f2))

### fix

* **images:** a local A1111 edit reports the checkpoint the server rendered with (#279) ([3744044](3744044))
* **images:** the untrusted image fetch closes six gaps a security review found (#278) ([b99ecbc](b99ecbc))
* **memory:** the guarded fetch's deadline covers decoding, and a network refusal names no resolver detail (#280) ([7d8bc9e](7d8bc9e))

### docs

* eleventh round of audit follow-ups (two pages published, the agent() and gmi() guides aligned) (#264) ([d4d3c6d](d4d3c6d))
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