Skip to content

Add correlated V2 runtime latency profiles - #574

Open
ZenAlexa wants to merge 26 commits into
NVIDIA:mainfrom
ZenAlexa:contrib/538-api-user-input-latency-instrumentation
Open

ZenAlexa wants to merge 26 commits into
NVIDIA:mainfrom
ZenAlexa:contrib/538-api-user-input-latency-instrumentation

Conversation

@ZenAlexa

@ZenAlexa ZenAlexa commented Sep 3, 2026 •

Copy link
Copy Markdown

Current head (ca1c2303)

Closed the disconnected-track admission gap identified in review. _VideoTrack now rejects frames while the peer media state is disconnected, clears queued frames at the transition, and records the discarded count. The server updates this gate on connection-state transitions and peer release. Added a focused CPU regression for reject-before-connect, accept-while-connected, reject-after-disconnect, and queue-discard accounting.

Local validation: git diff --check and Python compileall pass. The optional aiortc dependency is not installed in this checkout, so the focused runtime test is pending the project runner.

November 16 mainline integration

Merged main@5b23817a1edd into dff962932f54 through a normal merge. Kept the current contributor guide and both profiling sections, including the source-input clock and completion boundaries. All 13 contribution Python source and test files retain their previous contents. The eight existing skill metadata checks passed, and the locked Zensical 0.0.67 documentation build completed without issues. Runtime, GPU and end-to-end latency checks were not rerun for this documentation-only mainline delta. Earlier runtime measurements remain tied to their recorded revisions.

Summary

Closes #538.

Measure UserInputEvent.timestamp at the two host checkpoints discussed in the issue: when the UI loop claims the input, and when the first subsequent window.write returns successfully in the same generation.

Merged main at 1448d5a1 and moved these measurements into the shared IProfiler and InputLatencyProfiler from #634. Removed this branch's separate profiler, jsonl writer, and --profile-path. The existing --stats-path now exports both measurements alongside the existing model-input metrics.

  • Native-window uses its monotonic input clock. WebRTC uses the server receipt clock, rebased for each replacement session. Custom sources can expose the same clock origin through TimestampedInputSource.
  • Pending input count, timestamp sum, and endpoints use constant storage. Integer nanoseconds preserve precision before conversion to the exported mean and maximum.
  • Reset discards pending inputs from the previous generation. Empty UI ticks retain pending inputs. Failed writes leave completion unreported.
  • Stats metadata identifies the window type, frame rates, resolution, presentation mode, and backpressure mode. The profiling guide explains collection, replacement sessions, and endpoint meanings.

Endpoint scope

These are host checkpoints. Native-window completion includes the presenter call. WebRTC completion includes host output handling and sender admission when a track exists. A held frame may be written after input claim, so this metric does not establish a causal visual response, transport delivery, browser decode, or physical display latency. The existing model-input metrics keep their separate meaning.

Current validation (2026-11-04)

Merged main@34ce7b7f (#772) into 65c724d3 at 50f18c69. #772 adds browser_focused to the WebRTC server at the same place this PR adds input_timestamp_origin_ns, and both stay. It also restates the last known viewport focus as a FocusUserInputEvent at the session origin when a session opens. That event carries state from before the session, so 20a4cd85 skips a focus event at session timestamp 0 in ui_claim and window_write, otherwise every replacement session would report open-to-first-write as an input latency. The WebRTC client already clamps pre-origin timestamps to 0, other sources emit no focus events, and in-session focus changes keep their latency. The profiling guide and runtime README note the rule.

On macOS arm64 the V2 runtime and profiler ci_cpu selection passed 450 tests with seven skipped, including test_ui_input_latency_skips_focus_restated_at_session_open, which fails without the skip and checks that a later focus change is still measured. Ruff 0.12.7 check and format pass on the changed files. GPU generation, browser display and end-to-end latency weren't exercised.

Previous validation (2026-11-02)

Merged main@f6ed7e3fec72 into 65c724d310b8, retaining WebM mode support and the host-side profiling boundaries. The eight profiler and input-clock implementation files are byte-for-byte unchanged from fdf75fb7aba3.

Main removed the WebRTC test module in #741. The session-clock replacement scenario now lives in the existing client-window suite, with deterministic server-relative timestamps and the real server open, reopen and close lifecycle. It checks exact session-relative and absolute event times across replacement, along with discarding events from the old session. The retired module stays removed.

On macOS arm64 with Python 3.12.14, PyTorch 2.9.1, NumPy 2.4.6, pytest 9.2.0, aiortc 1.15.0 and aiohttp 3.14.5, the V2 runtime and profiler selection passed 447 tests with three GPU tests outside the ci_cpu selection. The separate step-agreement suite passed 19 tests, including two-process Gloo execution. The final clock-fixture refinement then passed both client-window tests. Ruff 0.12.7 import-order and formatting checks, Python 3.10 syntax checks and contribution whitespace checks passed. The environment differs from the complete Linux lockfile matrix.

GPU generation, native presentation, browser display, WebM encoding and end-to-end latency were not exercised in this integration. Earlier performance and device evidence retain their recorded revisions.

Earlier validation (2026-11-01)

Revision fdf75fb7aba3 already contains main 9d98934d9652, so no additional merge or code change was needed. The input source retains put_user_input_event alongside the timestamp extension, and native and WebRTC event submission preserve their session-clock ownership.

On macOS arm64 with Python 3.12.14, PyTorch 2.9.1, NumPy 2.4.6, pytest 9.2.0, aiortc 1.15.0 and aiohttp 3.14.5, the actual V2 runtime and profiler suite passed 549 tests with four tests outside the ci_cpu selection. No selected cases failed or skipped. The separate existing step-agreement suite passed 19 tests, including two-process Gloo execution. This environment satisfies the exercised dependencies' declared version ranges and differs from the complete Linux lockfile matrix. Scoped Ruff 0.12.7 import-order and formatting checks, Python syntax and contribution whitespace checks passed.

GPU generation, native presentation, browser display and end-to-end latency were not rerun. Earlier performance and device evidence retain their recorded revisions.

Earlier validation

On d8e26d5b:

  • 378 v2 and profiler CPU cases passed, with 4 deselected. This includes source timestamps, successful and failed writes, absent clock origins, collection, reset, and replacement.
  • The source-input runner scenario fails on current main because the source-input metrics are absent.
  • A delayed-output scenario retained all 100000 inputs across empty UI ticks and an intermediate collection. The first successful write's count, mean, and maximum matched independently calculated values.
  • Two application sessions reported 3 and 2 inputs. The final stats file retained the second session, with both sessions closed and the shared window closed once.
  • 3 stats-consumer cases and 2 documentation-link cases passed. Documentation build and pinned formatting and lint checks passed.
  • The pinned typechecker reports the same 3 missing slangpy imports on main and this revision.

GPU generation, the native presenter, and browser display have not been run on this revision.

Earlier main integration (2026-10-23)

Merged main cb4f8527 into 4bff09ed, retaining the 0.2 release and packaging changes. The contribution implementation is unchanged.

On macOS arm64 with Python 3.12.14 and PyTorch 2.9.1, the V2, profiler and two-process Gloo suite passed 515 tests with four deselected. A separate 100,000-input source-loaded profiler scenario checked collection between inputs, empty UI ticks, generation reset and session reset. Count, mean and maximum matched independently calculated values at the first successful window write.

GPU generation, native presentation, browser display and end-to-end latency were not rerun. Earlier performance measurements retain their recorded revisions. Contribution whitespace checks passed.

Project CI: Please run the current-head GPU generation, native presenter, and WebRTC window integration on the project setup. The recorded host checkpoints keep the endpoint meanings described above.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Copilot AI lite review requested due to automatic review settings September 3, 2026 16:46
@copy-pr-bot

copy-pr-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge, with no new actionable issues found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues found.

Summary

Adds source-input timing at UI claim and successful window-write return.

  • The V2 runtime measures input time up to the UI claim and window write.
  • WebRTC video tracks accept frames only while the peer is connected.

Diagram

sequenceDiagram
    participant Source as Input source
    participant UI as UI loop
    participant Profiler
    participant Window
    participant Stats
    Source->>UI: Events and shared clock origin
    UI->>Profiler: Record UI claim
    UI->>Window: Write frame
    Window-->>UI: Successful return
    UI->>Profiler: Complete pending inputs
    Profiler->>Stats: Collected host measurements
Loading

Reviews (22) · Last reviewed commit: "Merge main into the contribution branch" · Reviewed by Greptile

Linearize peer availability and frame admission under the track state lock.
Preserve negotiation queuing and reopen admission after peer recovery.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>

@ArielG-NV ArielG-NV left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment

Keep the timestamp clock bridge on a dedicated input-source extension.
Measure IUILoop claim and the first following window write.
Remove transport-specific and duplicated stage instrumentation.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Define WebRTC timing at the existing single-slot sender mailbox write.
Keep active-peer delivery and display timing in matching client telemetry.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa

ZenAlexa commented Sep 3, 2026

Copy link
Copy Markdown
Author

Good catch to check this race. input_to_window_write_s deliberately ends at the existing IClientWindow.write return; for WebRTC that is the host's single-slot sender-mailbox write. Active-peer delivery, RTP transit, browser decode, composition, and display live beyond this host-side sample and need client telemetry. _sender_available changes transport queuing behavior; client telemetry supplies the presentation timestamp, so that state stays outside this profiling patch.

…r-input-latency-instrumentation

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>

# Conflicts:
#	flashdreams/flashdreams/runtime_v2/application_runner.py
#	flashdreams/flashdreams/runtime_v2/cli.py
#	flashdreams/flashdreams/runtime_v2/session_runner.py
#	flashdreams/flashdreams/runtime_v2/webrtc_client_window.py
@ZenAlexa

ZenAlexa commented Sep 3, 2026

Copy link
Copy Markdown
Author

Pulled #548's multi-session lifecycle into 5a90e4e9 and followed its new session ownership through the profiler path.

Each replacement now gets a fresh clock binding and an independent JSONL segment, with WebRTC's rebased timestamps mapped back to the correct monotonic session origin. The complete V2 CPU suite passes: 211 passed, 3 deselected. The two metrics remain anchored at IUILoop claim and the first following window write (ง •̀_•́)ง

@ZenAlexa

ZenAlexa commented Sep 3, 2026

Copy link
Copy Markdown
Author

I rechecked this against current HEAD and the PR diff. input_to_window_write_s intentionally ends when the existing IClientWindow.write call returns; for WebRTC that records host-side materialization and mailbox admission, including the existing disconnected-state behavior. Active-peer delivery, RTP transit, decode, composition, and display require client timestamps, so they remain a separate telemetry continuation.

This review keeps the transport contract unchanged and keeps #574 scoped to the two host-side perceived-latency checkpoints (•̀ᴗ•́)و

…r-input-latency-instrumentation

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>

# Conflicts:
#	flashdreams/flashdreams/runtime_v2/session_runner.py
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa

ZenAlexa commented Sep 4, 2026

Copy link
Copy Markdown
Author

Synced current main through #584 in 0e007995 and resolved the new UILoopRequests flow at the profiling boundary. The V2 CPU suite completes with 215 passed / 3 deselected; Ruff, focused ty, compileall, and diff checks pass. The WebRTC endpoint description now follows #579's bounded two-frame sender queue.

@jmccaffrey-nv jmccaffrey-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the implementation against #538, including native/WebRTC clock bridging, replacement-session ownership, correlation, cleanup, path collisions, security, and profiler overhead.

The PR satisfies the narrowed host-side checkpoints discussed on the issue: event receipt to IUILoop claim, and event receipt to the next window.write return. The latter is not causal or end-to-end perceived response latency: the UI can re-render a held pre-input frame, and WebRTC stops at host queue admission before transport, decode, composition, and scanout. The documentation states these limits; please keep that distinction explicit when closing #538.

Local validation at 0e007995: 215 V2 CPU tests passed; focused Ruff formatting/import checks, ty, compileall, and git diff --check passed. The documentation build reached the new section without a new warning; its warning-as-error run still reports 10 unrelated baseline warnings. GitHub currently shows only the successful Greptile check while NVIDIA runner validation awaits vetting.

I left three inline comments on self-describing profile metadata, unbounded in-memory summary retention, and stable event-type serialization. I found no new code-execution, deserialization, dependency, or credential-handling exposure.

-- reviewed using GPT-5.6 Sol

@jmccaffrey-nv

Copy link
Copy Markdown
Collaborator

/ok to test 0e00799

…r-input-latency-instrumentation

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa

ZenAlexa commented Sep 4, 2026

Copy link
Copy Markdown
Author

Addressed the three review threads in 020fddb4: session segments now include artifact and runtime context; summary quantiles use a bounded 1,024-sample reservoir with explicit approximation metadata; input types use UserInputEvent.get_type_name(). Endpoint docs now cover WebRTC's active-track and no-track write behavior.

Validation: 185 V2 CPU tests passed, 5 skipped in the local optional-dependency environment; 88 focused tests passed, 1 skipped; Ruff, focused ty, compileall, and diff checks passed. Sphinx built all 38 sources with 10 pre-existing warnings; current main reproduces all 10. A 20,000-input JSONL probe completed at a median 6.14 µs per profiled input across three runs, with 1,024 quantile samples retained per metric.

@greptile-apps

greptile-apps Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa

Copy link
Copy Markdown
Author

I've synced the profiling change with the new model-metrics sink on main.

Both outputs keep their session lifecycle, and replacement sessions retain independent profile segments. I've updated the validation section for the current branch.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa

ZenAlexa commented Oct 8, 2026

Copy link
Copy Markdown
Author

@jmccaffrey-nv, 47fec3fe preserves the two host-side measurement boundaries and carries main's total step budget across replacement sessions. The current two-rank Gloo scenario completes two sessions with exactly two total model steps per rank, independent profile segments, and a single presenting-rank writer; the V2 CPU suite passes 311 cases. Could you recheck the session ownership changes and authorize /ok to test 47fec3fe691ac170419bf9496ce2c03792436120 for the current runner validation?

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa
ZenAlexa requested a review from a team as a code owner October 13, 2026 05:02
@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P1 Disconnected tracks admit frames flashdreams/flashdreams/runtime_v2/serving/webrtc_server.py:175 ▶

    When a peer temporarily transitions to disconnected, the connection handler clears only _media_connected, while enqueue() continues accepting frames unless the track is closed. The runtime consequently records completed window writes without an active sender, and queued frames can remain for stale delivery after reconnection, corrupting the perceived-latency profile.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Retain the input-source event submission contract and timestamp extension
through the current client-window and file-selection lifecycle.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Opening a WebRTC session now restates the last known viewport focus as a
FocusUserInputEvent at the session origin. That event carries state from
before the session, so measuring it would charge session startup to the
first window write. In-session focus changes keep their latency.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa

Copy link
Copy Markdown
Author

Pushed ca1c2303 to close the disconnected-track admission gap. _VideoTrack now accepts frames only while its peer media state is connected, clears queued frames when the state becomes disconnected, and records the discarded count; the server updates that gate on connection-state transitions and peer release. A focused CPU regression covers reject-before-connect, accept-while-connected, reject-after-disconnect, and queue discard accounting. git diff --check and compileall pass here; the optional aiortc dependency is not installed in this checkout, so the focused runtime test awaits the NVIDIA runner.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>

This branch has not been deployed

No deployments
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.

[API] User Input Latency Instrumentation

4 participants