Skip to content

feat(latency): name the inputs behind a mixer's latency failure - #1073

Merged
srperens merged 1 commit into
mainfrom
feat/latency-diagnosis
Oct 21, 2026
Merged

srperens merged 1 commit into
mainfrom
feat/latency-diagnosis

Conversation

@srperens

@srperens srperens commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1072. This PR uses the warning gate from #1072, which is merged; the branch is rebased onto main.

Problem

When a mixer's inputs disagree on latency, GStreamer posts:

GStreamer error: clock problem. (debug: ... Impossible to configure latency: max 0:00:01.000000000 < min 0:00:02.000000000. Add queues or other buffering elements.), source: <mixer>:audiomixer

It names only the aggregator, not which input is slow or which input cannot wait for it. On the production flow behind #1072 it took the debug graph, the flow JSON and local GStreamer experiments to find out that an SRT input at 2000 ms and a WHIP guest were the two sides. An operator has nothing to act on.

Change

When the bus handler lets an "Impossible to configure latency" warning from an aggregator through, it asks each live sink pad of that aggregator for its latency (a peer latency query, the same thing the aggregator does). It then appends the input that arrives latest and the input that can be held back the least, by block name:

GStreamer error: clock problem. 'SRT Input (V0)' arrives 2000 ms late, but 'WHIP Input (V15)' can only be held back 1000 ms.
  • The logic follows gst_aggregator_query_latency_unlocked (1.26): the aggregator compares the largest minimum among its inputs against the smallest maximum. min-upstream-latency raises both by the same amount, so it never causes the failure and is left out.
  • An input's origin is found by walking upstream while each element has exactly one linked input. The walk stops at a source or at an element that combines several inputs. Elements named block_id:element are shown by their block's name; elements placed directly in the flow by their id.
  • The query runs only for warnings the fix(latency): bridge appsrcs report the latency they can hold, gate repeated bus warnings #1072 gate lets through, so at most once per 10 s per aggregator. It runs on the bus-watch thread, not a streaming thread.
  • The PipelineWarning event shape is unchanged; only its text carries the diagnosis.

Rejected: a new StromEvent variant with structured min/max per input. That is a WebSocket contract change for what is, today, a message to read. It can come later if the UI wants to highlight the blocks.

Evidence

  • The flow-level warning names both inputs and goes out once: a_mixer_latency_failure_is_reported_once_with_its_inputs (new backend/tests/latency_diagnosis_test.rs) runs a flow through PipelineManager. One input goes through rtpjitterbuffer latency=2000, the other comes from a live appsrc at its defaults; both feed an audiomixer. The test reads PipelineWarning events for 3 s.
    • With the diagnosis wiring in bus.rs removed, it fails: expected the latency warning once, got [].
    • With the gate bypassed, it fails: got ["GStreamer error: clock problem.: 'slow' arrives 2023 ms late, but 'bridge' can only be held back 1000 ms", "GStreamer error: ... (many).
  • gst::latency_diagnosis unit tests: describe picks the right pair and says nothing when every input can wait. finds_both_inputs_of_a_mixer_that_cannot_configure_latency runs diagnose_warning on a real failing audiomixer.
  • Block names in the message: unverified by a test. The integration test uses plain flow elements, so labels there are element ids. The block-name lookup is a map from BlockInstance.id to name.

Tests

Ran on macOS (GStreamer 1.28.6):

  • cargo test --lib: 983 passed, 6 ignored.
  • cargo test --test latency_diagnosis_test --test pipeline_lifecycle_test --test qos_probe_criticals_test: all passed.
  • cargo clippy --all-targets: clean.
  • The two reverts above, run and restored.

Skipped: none. The test elements (rtpL16pay, rtpjitterbuffer, rtpL16depay, audiomixer) are in gstreamer1.0-plugins-good/base, which are in the CI package list.

Not run: on a server with a real SRT/WHIP flow.

For the reviewer

  • Inside a mixer block, a bus fed by other buses (Monitor fed by Main) has an origin of the feeding bus, which is in the same block. Its message then names the mixer block itself on one side. The main bus's own warning names the real inputs, so the operator still gets the answer from that one.
  • The origin walk picks the first linked sink pad of each element, and stops on an element with several. In a flow this always reaches a source block or a mixing element.

Out of scope

  • Highlighting the two blocks in the UI.
  • Telling the operator what to change (lower one input's latency, or raise what the other can buffer). That depends on the blocks involved.

🤖 Generated with Claude Code

https://claude.ai/code/session_019c8J2sWW25auY4wAjxpoTN

@srperens srperens left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verdict: Comment. The diagnosis looks correct, and it runs only on warnings the #1072 gate lets through. I cannot approve because no check has run on this head: the PR targets fix/bridge-appsrc-latency, and CI only runs on pull requests into main (.github/workflows/ci.yml:7 — branches: [main]).

Requested changes

  1. Once #1072 merges, rebase onto main and retarget the base, so that Check (Linux) runs latency_diagnosis_test and the new unit tests.

Claims

Claim Verdict Evidence
The diagnosis runs only for warnings the gate passes CONFIRMED backend/src/gst/pipeline/bus.rs:146 — let warning_msg = match crate::gst::latency_diagnosis::diagnose_warning(. It sits after the early return at 140
The pair is max(min) vs min(max) over live inputs CONFIRMED describe takes the largest min against the smallest max; see Diagnosis
This matches gst_aggregator_query_latency_unlocked, and min-upstream-latency raises both sides equally EXTERNAL Upstream GStreamer 1.26. Assumed as the body states
The new tests ran and guard the change UNVERIFIED The author reports macOS runs and the reverts. No CI run exists for b73756b

Diagnosis. It adds no new trigger. Pads that are non-live or unlinked drop out at backend/src/gst/latency_diagnosis.rs:34 — if !pad.peer_query(&mut query) {. The diagnosis appends text to a warning that already passed the gate. The origin walk is bounded by MAX_STEPS and stops at the first element with no linked sink pad or with several. The label falls back to the element id. block_names is a snapshot taken when the handler connects, so a block added to a running flow afterwards shows its id rather than its name. That is acceptable.

Cost: the queries run on the one GLib main loop that serves every flow's bus watch (backend/src/main.rs:1290 — let main_loop = glib::MainLoop::new(None, false);). A slow latency query would therefore delay bus handling for all flows. Latency queries are answered without the streaming lock in the elements used here, and GstBin itself issues them off the streaming threads: EXTERNAL. One more point: the gate's key includes the debug text, and that text carries the min and max values. If a jitterbuffer's reported min drifts (the test sees "2023 ms"), each new value is a new key, so the query can run more often than once per 10 s.

Radius. SHARED. Every flow's handler gains the code, but it acts only on an aggregator's "Impossible to configure latency" warning. Every other warning returns None before any query. The event shape is unchanged, so this is not a WebSocket contract change.

Overlaps. This PR is stacked on #1072 (it contains f989f53) and must land after it. No other open PR touches latency_diagnosis.rs or this branch of bus.rs.

Tests & CI. gh pr checks 1073 reports no checks. The integration test drives PipelineManager::start/stop and reads PipelineWarning, so it does exercise the wiring. The block-name label is untested, as the body says. Its elements come from plugins-good and plugins-base, both in the CI package list.

Confidence: HIGH

@srperens

Copy link
Copy Markdown
Collaborator Author

Since this PR was opened, main gained shared test setup in backend/tests/common (#935, #936, #1083). After those, no test on main builds an AppState or a PipelineManager by hand except port_pool_test.

backend/tests/latency_diagnosis_test.rs:112 builds its PipelineManager by hand. Since it subscribes to its own broadcaster, it maps to build_with:

let events = EventBroadcaster::with_capacity(4096);
let mut event_rx = events.subscribe();
let mut manager =
    common::manager::build_with(&flow, events, std::env::temp_dir()).expect("build pipeline");
  • common::manager::build(&flow) builds a PipelineManager the way start_flow does (EventBroadcaster::with_capacity(10), which equals new(10, false, false), media under the system temp dir). common::manager::build_with(&flow, events, media_path) takes your own broadcaster or media path. Neither calls detect_gpu_capabilities(), so keep that call where you have it. The registry temp file is not needed after construction.

This does not block the PR: the code compiles and merges cleanly against main as it is. Please fold it in on your next rebase.

Posted by Claude (AI) for the maintainers.

@srperens
srperens force-pushed the fix/bridge-appsrc-latency branch from f989f53 to 55b5ae2 Compare October 19, 2026 11:33
@srperens
srperens force-pushed the feat/latency-diagnosis branch from b73756b to 96014e4 Compare October 19, 2026 11:35
@srperens

Copy link
Copy Markdown
Collaborator Author

Rebased onto the updated #1072 (55b5ae2), which now masks digits in the gate key. That closes the point raised here: a drifting min ("2023 ms") no longer makes a new key, so the diagnosis query runs at most once per 10 s per aggregator.

Verified the EXTERNAL claim against GStreamer 1.26 gst_aggregator_query_latency_unlocked: the default pad query folds live inputs into max(min) and min(max), and upstream_latency_min adds the same diff to both, so it never causes the failure.

Ran locally on the rebased head: latency_diagnosis_test (1 passed), cargo test --lib latency_diagnosis (3 passed). CI will run once #1072 merges and this is rebased onto main and retargeted.

An aggregator that cannot configure its latency posts "Impossible to
configure latency: max X < min Y" and names only itself. When the bus
handler lets that warning through, it now asks each live input of the
aggregator for its latency, walks each input upstream to its origin, and
appends which input arrives latest and which one cannot be held back that
long, by block name:

  GStreamer error: clock problem. 'SRT Input (V0)' arrives 2000 ms late,
  but 'WHIP Input (V15)' can only be held back 1000 ms.

The query runs only for warnings the gate lets through, so at most once
per 10 s per aggregator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019c8J2sWW25auY4wAjxpoTN
@srperens
srperens force-pushed the feat/latency-diagnosis branch from 96014e4 to f4f30ee Compare October 19, 2026 14:38
@srperens
srperens changed the base branch from fix/bridge-appsrc-latency to main October 19, 2026 14:38
@srperens srperens closed this Oct 19, 2026
@srperens srperens reopened this Oct 19, 2026

@srperens srperens left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Area: pipeline bus handling, explaining why a mixer cannot configure its latency

When the #1072 gate lets an aggregator's "Impossible to configure latency" warning through, this PR asks each live input for its latency and names the input that arrives latest and the one that can be held back least. The approach looks right and fits BLOCK_GUIDELINES "Reported Latency": it points at the input to fix, not at queue sizes. The diagnosis runs only after the gate (backend/src/gst/pipeline/bus.rs:153). The drifting-minimum point from the last review is fixed: the gate key masks digits (bus.rs:144). The closure captures only a map of block names, no GStreamer objects (bus.rs:70-80).

Neighbours: no other open PR touches bus.rs or latency_diagnosis.

  1. CI: Check (Linux) is red, but not from this PR. The failure is vision_mixer_source_resize_test::source_switch_fits_when_caps_are_stored_late (GPU pipeline never reaches PLAYING), the flake tracked in #1092, which lists this run (39274515411). In the same run the 3 new latency_diagnosis unit tests and latency_diagnosis_test executed and passed. Re-run before merge.
  2. Block names in the message are not exercised by any test (the body says so). A slip in label (bus.rs:77-80) would pass CI while operators see raw ids (inline).

let mut event_rx = events.subscribe();
let registry_file = NamedTempFile::new().unwrap();
let registry = BlockRegistry::new(registry_file.path());
let mut manager = PipelineManager::new(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The maintainer's earlier request is still open: this builds PipelineManager by hand. common::manager::build_with(&flow, events, std::env::temp_dir()) covers it, and the BlockRegistry/NamedTempFile setup can go.

.collect();
// What the operator knows an element by: its block's name, or its own
// id for an element placed in the flow directly.
let label = move |element: &str| {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No test covers this block_id:element → block-name mapping. The integration test uses plain flow elements, so it only checks the fallback to the id. Moving this into a small fn in latency_diagnosis.rs would make it unit-testable.

@srperens
srperens merged commit b24e4f0 into main Oct 21, 2026
24 of 27 checks passed
srperens added a commit that referenced this pull request Oct 27, 2026
…runners, and say why they fail (#1106)

Both tests from #1073 fail now and then on the macOS and Windows runners:
the mixer posts no "Impossible to configure latency" warning at all. In a
diag run on the macOS runner the unit test failed 1 of 12 full lib-suite
runs with CI's environment, and 0 of 25 runs on its own.

They now skip there through skip_known_ci_failure and still run on Linux
and locally. The real-pipeline test moves from the lib into
latency_diagnosis_test so it can reach that helper. When either fails, its
message now carries the pipeline state, the warnings the bus carried, and
what each mixer input answers at the deadline.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@srperens
srperens deleted the feat/latency-diagnosis branch November 3, 2026 17:32
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