Skip to content

idea: texture-band drift measurement across chain segments (assess/compare_outputs) #1152

Closed
1 of 1 issue completed

Description

@dkackman

Add a texture-band measurement that an agent can run across chain segments, so "drift compounds per seam" becomes a number instead of an eyeball judgement.

Source

knoic/ComfyUI-MiniMaxH3-PrefixStream (MIT): engine/texture_diagnostics.py (~35 lines), tools/analyze_texture_drift.py, and the method in docs/DEGRADATION_ANALYSIS_CN.md.

What it measures

For one RGB region: convert to luma and two chroma differences (R−G, B−G), remove a linear lighting gradient, apply a 2D Hann window, FFT, then report the RMS energy in three wavelength bands: 2–8, 8–32 and 32–128 px. Compare the same static region (a flat background, or the same patch of skin in a similar pose) across segments 1, 3, 5... Rising mid-band energy is a candidate sign of the blotches and stripes that build up over continuations.

Their method around it is worth adopting as-is for any drift A/B:

  • Branch every arm from one clean first segment, with the same per-segment seed sequence, prompts, references and settings.
  • Change one variable at a time. Combine fixes only after each has been shown to work alone.
  • Measure decoded frames before any stitch or MP4 encode. If a PNG already shows the artifact, the encoder is not to blame.

Shape it could take here

Either a region + texture_bands option on assess_output, or a mode of compare_outputs that reports per-band ratios between two outputs over the same box. compare_outputs already reads frames and handles video, so the second is probably the smaller change. Output stays a measurement, never a quality score.

Caveats (theirs, and they matter)

  • It is not a quality score. Higher mid-band energy can be blotching or real detail. Lower energy in every band can just mean the frame got blurrier.
  • Only valid on comparable framing and lighting. A moving camera or a misaligned skin region makes the numbers meaningless, so the agent has to pick a static region, and the guide text has to say so.
  • MP4 compression adds its own flat-area texture: measure the same frame before and after encode.

Why now

#1150 (latent-tail continuation) and #1151 (continuation LoRA) both need a drift metric to judge their A/Bs.

Filed by Don, 2026-11-01, from a review of PrefixStream.

Activity

  1. added
    enhancementNew feature or request
    ideaAn idea for the researcher agent to assess
    owner:leadFeature lead's turn (harnest R11)
    on Nov 2, 2026
  2. dkackman commented on Nov 2, 2026

    @dkackman
    OwnerAuthor

    Lead: claude-opus-5-5 (anthropic). Design against develop at 4dd4d21.

    Verdict: build smaller. One opt-in parameter on compare_outputs, no new tool, no assess probe

    Add texture_bands=true to compare_outputs. It reports RMS energy in the 2–8, 8–32 and 32–128 px bands for each output at each at moment, over the shared crop box, plus each band's ratio to the baseline. It is one build stage of about $4–6. It adds one MCP parameter and one CompareRequest field, and no workflow syntax, dependency or download.

    Cut, and what would bring each back:

    • region + bands on assess_output. That would be a fourth name for the crop concept, a second full-resolution decode, and a break in the "exactly three probes" invariant pinned across five test files and ARCHITECTURE.md:144. Comes back if agents need bands inside an unattended assess pass (for example a seam rule), shown by a field report.
    • Pre-encode PNG export of chain segments (a hook in dw/pipeline_processors/chain.py). The issue's rule "measure decoded frames before any encode" can't be followed in dw today, because chains only ever write MP4. Comes back if an A/B under this tool lands on a 2–8 px difference that encoding could explain. That is the band the encoder touches.
    • Any rule, threshold or verdict on the bands. The output stays a measurement (the issue's own caveat).

    Sweep (step 2) conclusions

    • compare_outputs is at dw_mcp/tools_media.py:212-240 and dw_mcp/media.py:337-354. It calls POST /api/gallery/compare (dw/server/routes/media.py:643-664, :697+), which runs dw/media_compare.py. A shared crop [x,y,w,h] in source pixels already exists and is the measured box (check_request :85, crop_box :116). So do at moments (resolve_moments :129) and full-resolution PyAV frames (_frames :247, dw/media_readers.py:93). Must change because every metric there is pairwise against baseline (_metrics_for :268-303), while bands are measured on each output on its own. The baseline row needs cells too.
    • check_request :89 requires 2–8 names. Must change because the issue's main use is one chain's segments 1, 3, 5, which is one output at several moments.
    • dw_mcp/media.py:357-395 compare_summary hard-codes the three metric keys (:375) and reads ssim is None as "no metrics" (:372). Breaks because a bands-only call (one name) would print as "no metrics".
    • assess_output (dw/server/assess.py:97-149, dw/tasks/assess.py:127) only keeps grey thumbnails, has no region, and runs no probes on stills (:62). Its probe set is pinned to three in tests/test_assessment_rules.py:109-117, tests/test_server_assess.py:129-220, tests/test_mcp_twins.py:151-154, tests/test_mcp_media.py:1126-1164 and docs/ARCHITECTURE.md:144. This is why the issue's first shape is cut.
    • tests/test_mcp_server.py:865-887 pins the exact compare payload, so the new field must be sent only when true. :1293-1327 requires the wrapper and handler defaults to match.
    • tests/test_api_contract.py:132-143: the new CompareRequest field means regenerating ui/src/lib/generated/openapi.json and api-schema.ts (CI ci.yml:82). ComparePage.svelte never calls the route.
    • Surface budget (tests/test_mcp_server.py:1577): 16,000 tokens. The last measurement was about 15,052 (2026-10-19), leaving about 950. That headroom is inferred, not re-measured. One parameter plus about one sentence fits.
    • Nothing in dw measures wavelength bands today. The nearest is look_stats "detail" (dw/tasks/assess.py:165), one broadband number at thumbnail size. Code to reuse: band energy from one rfft (dw/dsp.py:368-485) and image rfft2 (dw/tasks/stabilize.py:30-34). numpy and scipy are already direct dependencies (pyproject.toml:79,92).
    • No pre-encode frames. save_segments (chain.py:694) writes trimmed segment MP4s, deleted unless keep_segments (:279-288, :695). Every measurement includes encoder texture, mostly in 2–8 px.
    • Guidance homes: docs/WORKFLOW_GUIDE.md:1120-1135 "Comparing outputs", docs/MCP.md:248, docs/SERVER.md:642+, plugins/dw/skills/minimax-h3/SKILL.md:57-70,179-183, references/cuts.md:92-127 (drift is measured today as lightness, saturation and contrast only).

    Demand (step 3)

    The axes (step 4)

    Design

    Problem: H3 chain texture drift (blotches, stripes, coarsening, or over-smoothing from a fix) has no number, so A/Bs on it rest on eyeballing alone.

    Non-goals: a quality score or verdict; an assess probe or seam rule; pre-encode frame export; automatic choice of a static region (the agent picks the box).

    Corrections to the proposal:

    • The issue leans to compare_outputs as the smaller change. The sweep agrees, but its metrics are all pairwise. Bands are per output, so the baseline row gets values too, and the change adds a ratio-to-baseline per band.
    • compare_outputs needs 2+ names today. The within-chain use (segments 1, 3, 5 of one video) needs one, so texture_bands=true lowers the minimum to 1. One name with texture_bands off is still refused as now.
    • "Measure before encode" isn't possible in dw (see Cut). The guide says so and tells the agent to read 2–8 px with that in mind.

    Surfaces:

    • MCP: compare_outputs(..., texture_bands: bool = False). The docstring gets one added clause, along the lines of "texture_bands adds per-output FFT band energy over crop (a measurement, not a score; see the workflows guide, Comparing outputs)".
    • REST: CompareRequest.texture_bands: bool = False on POST /api/gallery/compare. The reply cell gains texture: {luma: {fine, mid, coarse}, chroma_rg: {...}, chroma_bg: {...}} per output per moment. Non-baseline cells also get texture_ratio with the same shape (output / baseline, null where the baseline band is 0). Band keys are fine (2–8 px), mid (8–32) and coarse (32–128); the px ranges are stated in the reply's texture_bands header.
    • Engine: a new pure function in a new module, dw/texture_bands.py, called from dw/media_compare.py per decoded frame: texture_bands(rgb_uint8_array) -> dict. It computes Y plus R−G and B−G, removes a least-squares plane (linear lighting gradient), applies a 2D Hann window, takes numpy.fft.rfft2, and reports RMS over the radial frequency annuli matching each wavelength band. Bands longer than the box's short side are reported null. Credit knoic/ComfyUI-MiniMaxH3-PrefixStream (MIT) in docs/ATTRIBUTIONS.md for the method.
    • Refusals: texture_bands without a shared crop measures the full frame (allowed: the guide says to crop). A per-name crop list with texture_bands is refused ("texture bands need one shared box"), because per-name boxes are display-only today. A box smaller than 16 px on a side is refused ("too small for the 2–8 px band"). Images are measured too; one moment.
    • Syntax: none.

    Stages

    Stage 1: texture bands on compare_outputs

    • Builds: dw/texture_bands.py; the media_compare.check_request and compare changes; the CompareRequest field; the MCP wrapper and handler parameter (sent only when true); compare_summary printing a bands line per output per moment and no longer reading "no SSIM" as "no metrics"; the regenerated OpenAPI and UI schema.
    • Unit tests: tests/test_texture_bands.py:
      • a synthetic stripe image at period 4, 16 and 64 px puts its energy in fine, mid and coarse respectively;
      • a pure linear gradient measures about 0 in every band (detrend works);
      • a blurred copy is lower in every band;
      • a pure grey-hue change moves chroma but not luma.
        Extend tests/test_media_compare.py and tests/test_compare_route.py (one name allowed only with bands, per-name crops refused, tiny box refused, ratio null on a zero baseline) and tests/test_mcp_server.py (payload omits the field when false, defaults match).
    • Docs: a docs/WORKFLOW_GUIDE.md "Comparing outputs" subsection, "Texture bands". It covers what each band suggests; the issue's caveats verbatim in substance (not a score, mid up can be detail, all down can be blur, static framing only, encoder texture lives in fine); and the A/B method (branch from one clean first segment, same seeds and prompts, one variable at a time). Also docs/MCP.md:248, docs/SERVER.md compare body, and docs/ATTRIBUTIONS.md. Plugin: one line in minimax-h3/references/cuts.md drift section and SKILL.md:68 pointing at the guide subsection.
    • Deploy: server, plus a plugin docs bump.
    • Estimate: $4–6.
    • Acceptance intent (over MCP):
      • compare_outputs with two H3 chain outputs, at at three moments, one shared crop, and texture_bands=true returns the grid and, per output per moment, nine numbers (3 bands × luma/R−G/B−G). Each non-baseline output also gets nine ratios.
      • The same call with names of one chain output and three at moments returns bands for each moment and no pairwise metrics, with no "no metrics" message.
      • The same output named twice gives ratios of 1.0.
      • Without texture_bands, the reply and summary are unchanged from today.
      • A one-name call without texture_bands is refused as today. A per-name crop list with texture_bands is refused, naming the shared-box rule. A crop under 16 px a side is refused.
      • A still image works, with one moment.
      • The guide section get_guide("workflows", section="Comparing outputs") carries the caveats.

    Order and dependencies: one stage, no blockers. #1151 can use it once it lands; nothing waits on it.

    Risks

    • Misread as a score. An agent may treat "mid up" as worse, or "all down" as better. Mitigations: the docstring says "not a score", the guide carries the caveats, and there are no thresholds.
    • Encoder texture. All measurement is post-encode. The guide says to read fine-band changes with that in mind (see Cut for the trigger).
    • Budget headroom is inferred (about 950 tokens). If the clause doesn't fit, it moves entirely to the guide and the docstring keeps only the pointer.
    • Moving content makes the numbers meaningless. The agent has to choose a static box, and the guide has to say so.

    Questions

    • Q1 [scope] Build smaller as above (one opt-in compare_outputs parameter, one stage), cutting the assess_output region and the pre-encode PNG hook. Default: build it. If otherwise: "defer" keeps judging idea: H3 Anti-Burn LoRA on chain continuation segments only #1151 by eye and parks this on idea: H3 Anti-Burn LoRA on chain continuation segments only #1151's outcome; "build the assess shape too" adds a second stage touching the three-probe invariant.
    • Q2 [scope] Allow compare_outputs with one name when texture_bands=true (for one chain's segments). Default: yes. If otherwise: single-chain drift needs the chain named twice; this changes nothing else.
    • Q3 [none] Names: parameter texture_bands, band keys fine/mid/coarse, new module dw/texture_bands.py. Default: as written.

    Reply in comments and hand back with owner:lead. Approve by adding status:plan-approved yourself. No agent may set it.

    Decision for Don: build texture_bands as one opt-in compare_outputs parameter (one stage, about $4–6), cutting the assess and pre-encode shapes?
    Kind: scope Default: one stage builds the parameter as designed, including one-name calls (Q2)
    If otherwise: defer (judge #1151 by eye), or widen to the assess probe as a second stage Reversible: with a breaking-change (removing an MCP parameter)

  3. added
    featureWork bigger than a fix: designed with Don, built in stages (harnest R11)
    owner:donParked for human decision
    status:plan-reviewA feature plan is posted and waiting for Don
    and removed
    ideaAn idea for the researcher agent to assess
    owner:leadFeature lead's turn (harnest R11)
    on Nov 2, 2026
  4. dkackman commented on Nov 2, 2026

    @dkackman
    OwnerAuthor

    Rulings on plan v1 (Don, 2026-11-01)

    • Q1 [scope]: build it. One stage, texture_bands as an opt-in compare_outputs parameter. The assess_output region shape, the pre-encode PNG export and any threshold or verdict on the bands stay cut, each with the trigger the plan names.
    • Q2 [scope]: yes. One name is allowed with texture_bands=true; without it, a single name is still refused.
    • Q3: names as written: texture_bands, fine/mid/coarse, dw/texture_bands.py.

    Approved as written. If the docstring clause doesn't fit the surface budget once it's re-measured, move it to the guide as the plan says, rather than raising the budget.

  5. added
    owner:leadFeature lead's turn (harnest R11)
    and removed
    owner:donParked for human decision
    status:plan-reviewA feature plan is posted and waiting for Don
    on Nov 2, 2026
  6. 6 remaining items

  7. dkackman commented on Nov 2, 2026

    @dkackman
    OwnerAuthor

    Spec for #1152's plan v1, by tester claude-opus-5-5 (anthropic). Cases were written from the plan alone. Nothing was run or verified; the only MCP calls were read-only (get_guide, list_tasks, the compare_outputs schema).

    #1160, stage 1: texture bands on compare_outputs. All cases are in regression-suite-complete.md and marked pending: #1160.

    • C-F662: two H3 shots, three moments, one shared crop. Nine bands per output per moment, nine ratios on the non-baseline output only, pairwise metrics kept, the px-range header, a bands line in the summary, no verdict wording, and a repeat call that matches exactly.
    • C-F663: one name with three moments gives bands, no ratios, no pairwise metrics and no "no metrics" text. One name without texture_bands (left out or false) is still refused.
    • C-F664: the same output named twice gives all 27 ratios at 1.0. baseline= moves the ratios and leaves the band values unchanged.
    • C-F665: without bands (left out or false) the reply is unchanged and has no texture keys. Per-name crops without bands still work.
    • C-F666: refusals and boundaries. A per-name crop list is refused, including a one-entry list. Boxes of 15×64, 64×15 and 15×15 are refused. 16×16 is accepted with coarse null. The full frame is accepted. The 9-name cap still holds. A 15 px box without bands is still accepted.
    • C-F667: greyscale QR stills (CPU only). One moment. Chroma bands are 0 and their ratios null, never inf or NaN. A rerun gives luma ratios of 1.0. A 4× down-up blurred copy has a fine ratio below 1.
    • C-F668: a past-end moment gets no bands or ratios and doesn't break the other cells. That includes a baseline that is past its end.
    • C-F669: the tool description ("not a score" or a pointer to the guide), the guide subsection and its caveats, and the pointers from the minimax-h3 SKILL.md and cuts.md.

    Notes. None of these stops a case from being written.

    • get_guide("workflows", section="Comparing outputs") is refused today: the workflows guide has no section by that name, and its sections are How the catalog is organised … Type System. The plan's guide target (WORKFLOW_GUIDE.md:1120-1135) may sit under a different heading, or in a guide other than workflows. C-F669 requires that the heading resolves once the stage is built.
    • Two edges the plan leaves open are recorded rather than asserted. One is whether mid (8–32 px) is null or a number in a 16 px box. The other is whether a one-entry per-name crop list counts as the refused list form. A two-entry list must be refused.
  8. added
    owner:leadFeature lead's turn (harnest R11)
    and removed
    status:needs-specTester writes acceptance cases for the plan's stages
    on Nov 2, 2026
  9. added 2 commits that reference this issue on Nov 2, 2026
  10. dkackman commented on Nov 2, 2026

    @dkackman
    OwnerAuthor

    Close-out of #1152. Lead: claude-opus-5-5 (anthropic).

    Closed: stage #1160 (texture bands on compare_outputs). It was verified on develop @ 768400da after one bounce (C-F669, the Texture bands guide heading).

    Design record: docs/proposals/complete/texture-bands-complete.md. The todo.md "Shipped since the ranking" entry is added. These are docs only, merged to develop @ 06f08f37, with no deploy. No partial design doc existed to retire, and the stage's own commits already updated the user-facing docs (guide, MCP.md, SERVER.md, ARCHITECTURE.md, ATTRIBUTIONS.md, the minimax-h3 skill).

    verify: run every case whose source: names one of this feature's stages, and close the parent if they all pass.

  11. added and removed
    owner:leadFeature lead's turn (harnest R11)
    on Nov 2, 2026
  12. dkackman commented on Nov 2, 2026

    @dkackman
    OwnerAuthor

    Feature-parent verify of #1152. Tester: claude-opus-5-5 (anthropic), against develop @ 06f08f37 on lem.

    I ran all 8 cases whose source: names stage #1160 (C-F662 to C-F669 in regression-suite-complete.md) over MCP, as written. All 8 pass.

    • C-F662: two ep3 shots, frames 10/60/120, crop [352,144,256,256]. Each output has 9 bands per moment, none null. Only the non-baseline row has ratios, and a spot check matches the division (Y fine 3.7985/10.956 = 0.3467). PSNR/SSIM/MAD are kept. The header gives the px ranges and says "a measurement not a score". No verdict wording. A repeat call matches to every digit.
    • C-F663: one name (ep25) at 3 moments gives 3 band lines, with no ratios, no pairwise metrics and no "no metrics" text. One name without texture_bands (left out, or false) is refused: "compare takes 2 to 8 (or 1 with texture_bands)".
    • C-F664: the same output twice at frames 0/60/123 gives all 27 ratios at 1 and identical PSNR. Frame 123 is measured. With baseline= set to shot 2, the ratios move to shot 1 and the frame-60 bands equal C-F662's exactly.
    • C-F665: a call without bands and one with texture_bands=false give identical replies, with no texture lines. Per-name crops without bands are still accepted (full-frame metrics, display-only crops).
    • C-F666: a per-name crop list is refused, both the 2-entry and the 1-entry form ("texture bands need one shared box"). Boxes of 15×64, 64×15 and 15×15 are refused ("too small for the 2-8 px band ... at least 16 px a side"). The 16×16 box is accepted, with fine numeric and coarse null; mid is also null (recorded, as the case asks). The full frame is accepted with 9 numbers per cell. 9 names are refused ("takes 1 to 8"). A 15 px box without bands is accepted.
    • C-F667: I ran the fixture runs A, A2 and Bl (4× down-up blur). Every chroma band is 0 and every chroma ratio is null (-), with no inf or NaN. A2's luma ratios are 1/1/1. Bl's luma ratios are fine 0.2314 (< 1), mid 0.8524, coarse 0.9706. One name with a still gives one row and one column, with no ratios. The runs were cleaned up with delete_output(job_id=…).
    • C-F668: where shot 1 runs past its end at frame 200, its cell reads "no bands - past end" while ep25's frame-200 bands are reported. With the short clip as baseline, ep25's frame-200 bands are reported with "baseline past end: no ratio". Neither call errored.
    • C-F669: the texture_bands boolean defaults to false. The description says "a measurement, not a score" and points to the guide. get_guide("workflows", section="Comparing outputs") and section="Texture bands" both resolve, and the text covers each band's meaning, not-a-score, mid rising as possible detail and all bands falling as possible blur, static framing, measurement after encode with encoder texture in fine, the A/B method, the shared 16 px box rule and the one-name use. The minimax-h3 SKILL.md (chains bullet) and references/cuts.md (lines 129-131, the drift section) both point to Comparing outputs, Texture bands.

    No pending: #1160 lines remain. Closing as completed.

  13. added
    status:verifiedTester confirmed the fix via a real MCP call
    and removed on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend:sharedenhancementNew feature or requestfeatureWork bigger than a fix: designed with Don, built in stages (harnest R11)owner:testerTester's turn to actstatus:plan-approvedDon approved the feature plan (Don only)status:verifiedTester confirmed the fix via a real MCP calltarget:lem

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions