Skip to content

fix(provider): serve OpenRouter's variable-frame-rate readiness video on GLM-5.3-Flash - #1559

Closed
jonathan308 wants to merge 3 commits into
masterfrom
fix/glm-video-invalid-media
Closed

jonathan308 wants to merge 3 commits into
masterfrom
fix/glm-video-invalid-media

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

OpenRouter's provider-readiness test for glm-5.3-flash fails input-video-base64 with HTTP 400 {"error":{"code":"invalid_request_error","message":"invalid media input"}}. The coordinator sends that message only for the provider failure code invalid_media.

Root cause, proven with the real OpenRouter clip. input-video-base64.mov is a variable-frame-rate (VFR) QuickTime movie: 211 frames in 10.833 s with 31 different sample durations. Frame 1 is at 0.342 s, but 1 / nominalFrameRate predicts 0.051 s. GLM5NextProcessor.decodeFrames required every timestamp to be within a quarter frame of index / nominalFrameRate, so it threw unsupported("variable-frame-rate video"). The provider then mapped it:

EngineV2VisionPrefill.prepareGLM5NextMedia
  GLM5NextProcessor.prepareDetailed → decodeFrames            ✘ unsupported("variable-frame-rate video")
  glm5NextInputError                → EngineV2VisionPrefillError.unsupportedMedia
MultiModelBatchSchedulerEngine      → multimodalRejected("multimodal_rejected: GLM media input: variable-frame-rate video")
ProviderLoop.sanitizedInferenceFailure → invalid_media → coordinator 400 "invalid media input"

Fix: SDK pin 7bed8216 → 54227bab (Layr-Labs/mlx-swift-lm#340; now 6aef0a5d, see Refactor pass). The decoder now follows the reference loader: Transformers' PyAV path uses average_rate and frame count, and puts frame i at i / fps. Frames are indexed in presentation order and timed by the track's average rate. AVFoundation's nominalFrameRate for this clip is 19.447004, equal to FFmpeg's avg_frame_rate 4220/217. Timestamps must be finite and strictly increasing. The 2 FPS sampler, all limits, and constant-frame-rate clips are unchanged.

Label aliases dropped. An earlier revision of this PR also let the shared MediaIngest.decodeVideo admit data:video/mov;base64, and data:video/x-m4v;base64,. By owner decision, 8ef69dde3 removes them:

  • OpenRouter sends data:video/quicktime;base64,, which every model already admits. Nemotron Super admits only video/mp4 and video/quicktime, and it passed OpenRouter's base64 readiness test with OpenRouter's label. The recorded request size also fits that 28-character header exactly.
  • Every model again admits the same two inline-video labels as Nemotron Super. The aliases had made the shared ingest accept labels that Nemotron Super, in the provider and the coordinator, still refuses. Videos labeled video/mov or video/x-m4v get invalid_media, as on master.
  • MediaIngest.swift, MediaIngestTests.swift and docs/threat-model.yaml now match master. The routing test keeps the real video/quicktime and video/mp4 cases. The VFR fix and its regression test are unchanged.

Before

flowchart LR
  classDef bad fill:#fde2e1,stroke:#c0392b,color:#000
  classDef ok fill:#e3f4e1,stroke:#2e7d32,color:#000
  classDef io fill:#e8eefc,stroke:#3559b7,color:#000
  R["OpenRouter readiness video_url<br/>data:video/quicktime or data:video/mp4"]:::io --> I["MediaIngest.decodeVideo<br/>label ∈ {mp4, quicktime}"]
  I --> P["GLM5NextProcessor.decodeFrames<br/>|pts − i/fps| ≤ ¼ frame?"]
  P -- "VFR (input-video-base64.mov)" --> X["unsupported: variable-frame-rate video"]:::bad
  X --> E["invalid_media → 400"]:::bad
  P -- "CFR (input-video-url.mp4)" --> S["2 FPS sample → engine"]:::ok
Loading

After

flowchart LR
  classDef ok fill:#e3f4e1,stroke:#2e7d32,color:#000
  classDef io fill:#e8eefc,stroke:#3559b7,color:#000
  classDef bad fill:#fde2e1,stroke:#c0392b,color:#000
  R["OpenRouter readiness video_url<br/>data:video/quicktime or data:video/mp4"]:::io --> I["MediaIngest.decodeVideo<br/>label ∈ {mp4, quicktime}, unchanged"]
  I --> P["GLM5NextProcessor.decodeFrames<br/>pts finite and increasing?<br/>frame i at i / average fps"]
  P -- "VFR or CFR (both clips)" --> S["unchanged 2 FPS sampler → placements → engine"]:::ok
  P -- "pts not finite or not increasing" --> X["invalidInput → invalid_media → 400"]:::bad
Loading

Blue: request. Red: refusal. Green: served. Only decodeFrames changes; the label rule is the same before and after.

Evidence

The new scheduler-level test is GLM5NextMediaRoutingTests.openRouterReadinessVideosReachTheEngineInsteadOfInvalidMedia. It uses the real OpenRouter fixtures from the SDK test resources, pinned by SHA-256, and runs them through the real request decode, GLM prompt normalization, shared ingest, GLM5NextProcessor at the published processor budgets, glm5NextInputError, scheduler error mapping and ProviderLoop.sanitizedInferenceFailure. Only the tower and engine are stubbed; no weights are loaded. It sends input-video-base64.mov as data:video/quicktime and input-video-url.mp4 as data:video/mp4, the way the coordinator inlines the URL clip.

  • Before (master SDK pin, new test). This is the original run's output without the lines for the since-removed video/mov case and alias test:
    ✘ openRouterReadinessVideosReachTheEngineInsteadOfInvalidMedia()
      ↳ video/quicktime refused as invalid_media: .multimodalRejected("multimodal_rejected: GLM media input: variable-frame-rate video")
    
    The video/mp4 URL fixture already passed on master.
  • After (8ef69dde3):
    ✔ Test openRouterReadinessVideosReachTheEngineInsteadOfInvalidMedia() passed after 16.314 seconds.
    
    input-video-base64.mov → 11 temporal pairs on a 1512×560 canvas (40×108 patches, 1080 tokens per pair). input-video-url.mp4 → 5 pairs on 1288×728 (52×92, 1196 tokens per pair).

Regression suites on 8ef69dde3, run after swift build --build-tests and scripts/stage-test-metallib.sh, with isolated DARKBLOOM_STATE_FILE and DARKBLOOM_LOADED_MODELS_FILE:

../scripts/run-nested-suite.sh 'ProviderCoreTests\.vlm|GLM5NextMediaRoutingTests|EngineV2VisionRoutingTests|EngineV2VisionSpanCarvingTests|MediaKindClassificationTests|MultimodalErrorMappingTests|VLMCapReservation|VLMDecodeBomb|AudioInputRejectionTests|NemotronSuperVideoBindingTests|NemotronSuperVideoGoldenTests|GLM5NextPromptPolicyTests' --no-parallel
➜ Test realTokenizerReproducesTheReferencePromptIDs() skipped.
✔ Test run with 175 tests in 11 suites passed after 38.919 seconds.

174 passed, 1 skipped, 0 failed. Swift Testing's total counts the skipped test. The total was 176 before the alias test was removed. The skip is pre-existing: realTokenizerReproducesTheReferencePromptIDs runs only when NEMOTRON_SUPER_REFERENCE_DIR is set. Because of it, the runner's no-skip check exits 1. The existing label-refusal test, decodeVideo fails closed on a non-MP4 data URI (data:video/webm), passes.

The SDK suites GLM5NextProcessorTests|GLM5NextVisionTests passed (21 tests); see #340. The alias removal does not change the SDK pin. On 8ef69dde3, make docs-check (192 files OK), make changelog-check (2 valid fragments) and make docs-impact-check BASE=origin/master (5 changed files, coverage OK) pass.

Coordinator check, read-only against platform master f512258: the GLM estimator (mediawork.Profile.EncodedVideo) accepts both clips under any data:…;base64 label. It prices the .mov at 13,130 tokens, above the provider's bound of 11 × (1080 + 2 + 11) + 2 = 12,025, and the .mp4 at 7,256, above 5 × (1196 + 2 + 11) + 2 = 6,047. No platform change is needed for GLM.

Merge Danger

Door: two-way. No wire, protocol, persisted state or capacity-quotation change. A revert restores the refusals.

Blast Radius: GLM-5.3-Flash video decoding

  • GLM video: VFR clips that got a deterministic 400 are now served. Their prompt timestamps are index / average fps, as in the reference loader. CFR clips produce the same frames, grids and timestamps.
  • Shared ingest is unchanged. MediaIngest.decodeVideo still admits only data:video/mp4;base64 and data:video/quicktime;base64, the same two labels as NemotronSuperLocalImageBinding.admittedVideoDataURIPrefixes. The SDK change touches only GLM5NextProcessor, so Gemma, Qwen, MiMo and Nemotron Super video are unaffected.

Limitations

  • No full-checkpoint execution. The vision tower and engine are stubbed, so this does not show model answer quality on the clip. A real-weights run (GLM53_REAL_VISION lane) was not performed.
  • GLM5NextOfficialVisionReferenceTests needs GLM53_REFERENCE_FIXTURE_DIR, which is not available here, so it skipped.
  • The synthetic ordinaryFactoryRunsTextHTTPImageAndProtectedEmbeddedMTP (with DARKBLOOM_TEST_GLM5_MANAGED_SYNTHETIC=1) fails on load with metadata("tokenizer lacks the <think> tokens"). That happens in synthetic-fixture tokenizer validation, before any media code runs, and this PR does not touch it.
  • Required refactor pass (AGENTS.md): not run. This change was made by a delegated worker without a subagent tool, so the coordinating session owns that gate.

Refactor pass

This is the required refactor pass from AGENTS.md. It replaces the "Required refactor pass: not run" item under Limitations. It only cleans up code and wording and does not change behavior. It adds one signed commit, eb79154e3.

Removed afterwards: the alias part this pass reviewed was removed later in 8ef69dde3 (see Label aliases dropped). That covers Changes item 2, the MediaIngest.admittedVideoDataURIHeaders and vlmDecodeVideoLabelAliases review items, the T-050 threat-model wording and the out-of-scope finding. The removal restores master's code and did not get a separate refactor pass. Apart from two notes marked below, the record is as the pass wrote it.

Changes

  1. SDK pin 54227bab → 6aef0a5d. The pin over master is now 7bed8216 → 6aef0a5d. The new SDK commit is refactor(glm5next): drop decodeFrames' unused frame-rate parameter in Layr-Labs/mlx-swift-lm#340.
    • The VFR fix left GLM5NextProcessor.decodeFrames' fps parameter unused. Timing comes from GLM5NextDecodedVideo.framesPerSecond, which is nominalFrameRate. The commit removes the parameter.
    • It also fixes two comments that still described constant-frame-rate-only decoding: the decodeFrames doc comment and the file header's list of local changes.
    • Decoding, the presentation-order check, sampling and limits are identical.
  2. Changelog: the shared video path also serves MiMo. MiMoV26EncodedMediaIngress calls MediaIngest.decodeVideo directly, and MiMoV26OrdinaryServingPolicy admits videos. So MiMo V2.6 also admits the video/mov and video/x-m4v labels. The fragment now says "(GLM, Gemma, Qwen and MiMo)". The Blast Radius list under Merge Danger, "Shared ingest (GLM, Gemma, Qwen, Diffusion Gemma)", should also include MiMo V2.6.

Reviewed and kept

  • MediaIngest.admittedVideoDataURIHeaders. The lowercased lookup behaves like the old case-insensitive compare for these ASCII labels. MemoryBackedVideoAsset still identifies the container from the bytes. The aliases stay; dropping them is a product decision.
  • GLM5NextMediaRoutingTests helpers.
    • GLMMediaMarkerTokenizer must mirror the SDK's GLM5NextTestTokenizer, because the provider tests cannot import the SDK's test types.
    • openRouterVideo uses the repo's usual #filePath fixture lookup and keeps the SHA-256 pins.
    • PreparedCapture is small and documented.
    • Extracting any of these would only add churn.
  • vlmDecodeVideoLabelAliases, inference.md, cli-reference.md and the T-050 threat-model wording are accurate. No current doc still says that variable-frame-rate video is refused. The dated report docs/reports/2026-10-21-glm53-flash-single-mac-qualification.md still says it was refused. That report is a frozen record of that run, so it stays as written.

Out-of-scope finding, not edited

NemotronSuperLocalImageBinding.admittedVideoDataURIPrefixes is documented as "The inline movie labels MediaIngest.decodeVideo admits." After this PR decodeVideo admits four labels, so that comment is stale. The narrower two-label list for Super is intended. The file is outside this PR's diff and belongs to the Nemotron Super video work.

Note, resolved by the alias removal (8ef69dde3): decodeVideo again admits exactly those two labels, so the comment is accurate again and needs no follow-up.

Validation after the change

Note: these results predate the alias removal; the current results are under Evidence. Validation was run from provider-swift after the change, reusing the build output. Test state used a fresh temporary DARKBLOOM_STATE_FILE and DARKBLOOM_LOADED_MODELS_FILE.

swift build --build-tests                                   # Build complete
../scripts/stage-test-metallib.sh "$(swift build --show-bin-path)"
../scripts/run-nested-suite.sh 'ProviderCoreTests\.vlm|GLM5NextMediaRoutingTests|EngineV2VisionRoutingTests|EngineV2VisionSpanCarvingTests|MediaKindClassificationTests|MultimodalErrorMappingTests|VLMCapReservation|VLMDecodeBomb|AudioInputRejectionTests|NemotronSuperVideoBindingTests|NemotronSuperVideoGoldenTests|GLM5NextPromptPolicyTests' --no-parallel
✔ Test openRouterReadinessVideosReachTheEngineInsteadOfInvalidMedia() passed after 27.247 seconds.
✔ Test "decodeVideo admits MP4 and QuickTime label aliases; the bytes still decide" passed after 0.004 seconds.
➜ Test realTokenizerReproducesTheReferencePromptIDs() skipped.
✔ Test run with 176 tests in 11 suites passed after 49.461 seconds.
  • Provider suites: 176 passed, 0 failed, 1 skipped. The skip is the same one as before this pass: realTokenizerReproducesTheReferencePromptIDs needs NEMOTRON_SUPER_REFERENCE_DIR. Because of that skip, the runner's no-skip check exits 1.
  • SDK: GLM5NextProcessorTests|GLM5NextVisionTests passed, 21 tests in 4 suites with no skips; see fix(coordinator): schedule the read-cache purge janitor #340.
  • Docs: make docs-check (192 files OK), make changelog-check (2 valid fragments) and make docs-impact-check BASE=origin/master (coverage OK) pass.
  • swift-format: both changed SDK files are clean with the SDK's .swift-format. The provider has no swift-format config or gate (the pre-commit hook skips Swift), and this pass changed no provider Swift file.

ordinaryFactoryRunsTextHTTPImageAndProtectedEmbeddedMTP: the failure is pre-existing and unrelated

  • The test runs only with DARKBLOOM_TEST_GLM5_MANAGED_SYNTHETIC=1, so CI never runs it. The master CI run 39874274817 on this PR's base cf3c45107 passed, and its Provider Unit Tests log shows Test ordinaryFactoryRunsTextHTTPImageAndProtectedEmbeddedMTP() skipped.
  • GLM5NextManagedLoad throws metadata("tokenizer lacks the <think> tokens") when GLM5NextThinkingTokenizer(base:) cannot resolve both <think> and </think>.
  • The synthetic GLM5NextManagedFixture tokenizer has only <unk>, <s>, </s>, x and the six media tokens.
  • That guard and the fixture both came from GLM-5.3-Flash serving, residency safety and MiMo tool-schema parity #1516 and are unchanged here. The guard runs before the processor is constructed. The SDK pin adds only GLM5NextProcessor video-decoding commits.
  • So the test fails the same way on master. A separate master build was not run.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

… on GLM

OpenRouter's provider-readiness test input-video-base64 failed on
glm-5.3-flash with 400 invalid_media. The clip is a variable-frame-rate
QuickTime movie (211 frames in 10.833 s), and GLM5NextProcessor refused it
with unsupported("variable-frame-rate video"), which the scheduler maps to
multimodal_rejected and then invalid_media.

- Bump mlx-swift-lm to the GLM5Next decoder fix: frames are indexed in
  presentation order and timed by the track's average rate, as in the
  reference loader (Layr-Labs/mlx-swift-lm#340).
- Admit data:video/mov (OpenRouter's documented QuickTime label) and
  data:video/x-m4v on the shared media ingest. MemoryBackedVideoAsset
  still identifies MP4 or QuickTime from the bytes.
- Scheduler-level regression test with the real OpenRouter fixtures and a
  label-alias ingest test; docs and changelog fragment.
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Ready Ready Preview Oct 23, 2026 2:30am UTC
d-inference-console-ui-dev Ready Ready Preview Oct 23, 2026 2:30am UTC
d-inference-landing Ready Ready Preview Oct 23, 2026 2:30am UTC
darkbloom-status Ready Ready Preview Oct 23, 2026 2:30am UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 23, 2026 2:30am UTC

Request Review

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head 8ef69dde3fe8 against base cf3c4510722a.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
First pass completed; selected deeper review is pending

Reviewers: anthropic/claude-sonnet-5.5: first pass completed; anthropic/claude-opus-5.5: selected depth completed (4 batches); openai/gpt-6.1-sol: selected depth completed (2 batches)

Scan incomplete: 1 file(s) could not be fully read as text. Binary, Git LFS and submodule changes require manual review.
Affected files: libs/mlx-swift-lm

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Human review required: CI did not complete the security review. A maintainer must review the saved findings and remaining scope. A green advisory job is not security clearance; do not manually rerun the paid scan.

Coverage: 37/37 source units; cross-file integration complete. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

Bedrock: 21 request(s), 821523 uncached + 0 cache-read + 79449 cache-write input / 13161 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately.
Workload allowance: 22 native request(s), including one shared response repair; 500 emergency ceiling. Selected depth and integration rounds are admitted as their scope becomes known.

… the changelog

Required refactor pass; no behavior change.

- Bump libs/mlx-swift-lm 54227bab -> 6aef0a5d (Layr-Labs/mlx-swift-lm#340),
  which removes decodeFrames' frame-rate parameter left unused by the
  variable-frame-rate fix and updates two comments that still described
  constant-frame-rate-only decoding.
- The shared inline-video path also serves MiMo V2.6:
  MiMoV26EncodedMediaIngress calls MediaIngest.decodeVideo directly, so it
  admits the new video/mov and video/x-m4v labels too. Say so in the
  changelog fragment.
Owner decision. OpenRouter sends data:video/quicktime;base64, which every
model already admits: Nemotron Super passed OpenRouter's base64 readiness
test with OpenRouter's label, and the recorded request size fits that
28-character header exactly. The aliases also made the shared ingest accept
labels that Nemotron Super, in the provider and the coordinator, still
refuses.

- MediaIngest.decodeVideo again admits only data:video/mp4;base64 and
  data:video/quicktime;base64; MediaIngest.swift, MediaIngestTests.swift and
  the T-050 threat-model wording match master.
- The routing test keeps the real video/quicktime and video/mp4 readiness
  cases and drops the video/mov variant.
- Docs and the changelog fragment keep only the variable-frame-rate fix.
  The SDK pin and the GLM regression test are unchanged.
jonathan308 added a commit that referenced this pull request Oct 23, 2026
@jonathan308

Copy link
Copy Markdown
Collaborator Author

Consolidated into #1561 (one PR per model, owner decision). Merge commit 35d266d brings this branch's commits (bf77fd7, eb79154, 8ef69dd) into #1561 unchanged, so its evidence and refactor-pass record still apply. The SDK fix stays in Layr-Labs/mlx-swift-lm#340.

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