Skip to content

fix(video): recover playback after surface stalls - #15

Merged
programmersd21 merged 1 commit into
programmersd21:mainfrom
Luquatic:fix/video-resume-timeout
Aug 11, 2026
Merged

fix(video): recover playback after surface stalls#15
programmersd21 merged 1 commit into
programmersd21:mainfrom
Luquatic:fix/video-resume-timeout

Conversation

@Luquatic

@Luquatic Luquatic commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • retry video presentation after compositor timeouts instead of permanently stopping decoding
  • reconfigure and retry lost or outdated swapchains after resume
  • keep fatal surface errors on the existing stop path

Root cause

During suspend, get_current_texture() can time out while the compositor is not presenting. Wallr treated every non-presented frame as fatal and stopped the decoder, leaving the last frame frozen after resume.

Validation

  • cargo fmt --all --check
  • cargo check --workspace
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace (47 passed)
  • regression coverage for timeout, outdated, and lost surface actions

Summary by Sourcery

Improve video playback resilience to compositor surface stalls by recovering from non-fatal presentation failures instead of permanently stopping playback.

Bug Fixes:

  • Prevent video playback from freezing after suspend when surface acquisition times out by treating timeouts and certain surface errors as recoverable.

Enhancements:

  • Extend frame status reporting to distinguish timed-out, outdated, and lost surfaces for more granular recovery handling during video presentation.
  • Add logic to retry or reconfigure swapchains on recoverable video present failures while keeping fatal errors on the existing stop path.

Tests:

  • Add unit tests verifying that recoverable frame statuses map to retry or reconfigure actions in the video presentation flow.

Summary by CodeRabbit

  • Bug Fixes

    • Improved video playback recovery when frames time out or become outdated.
    • Automatically reconfigures the display surface when recovery is needed.
    • Stops playback cleanly for unrecoverable frame errors.
    • Transition rendering now stops when a frame is not successfully presented.
  • Reliability

    • Added clearer handling for lost and outdated frames.
    • Improved retry behavior for temporary playback interruptions.

@sourcery-ai

sourcery-ai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR changes video playback to treat compositor timeouts and recoverable surface errors as non-fatal, adding a small retry/reconfigure loop and extending FrameStatus and renderer surface error handling so playback can recover after stalls while still stopping on fatal errors.

Sequence diagram for the new video playback recovery loop

sequenceDiagram
    participant play_video
    participant Surface
    participant LivePacer
    participant VideoPlayback

    play_video->>play_video: video_present_action(status)
    alt Presented
        play_video->>play_video: continue playback loop
    else Retry
        play_video->>LivePacer: wait_until(Instant + 100ms)
    else Reconfigure
        play_video->>Surface: configure(device, SurfaceConfiguration)
        play_video->>LivePacer: wait_until(Instant + 100ms)
    else [Err]
        play_video->>VideoPlayback: stop()
    end
Loading

File-Level Changes

Change Details Files
Introduce a VideoPresentAction state machine and use it in the video playback loop to retry or reconfigure the surface instead of stopping on timeouts and recoverable errors.
  • Add VideoPresentAction enum with Presented, Retry, and Reconfigure variants.
  • Add video_present_action helper that maps FrameStatus values to appropriate VideoPresentAction.
  • Update play_video loop to map renderer status through VideoPresentAction, reconfigure the surface on Outdated/Lost, wait briefly via LivePacer on non-presented frames, and only stop playback on fatal errors.
wallr-core/src/daemon/mod.rs
Extend FrameStatus and renderer surface acquisition logic to distinguish timeout, outdated, and lost swapchain states as recoverable conditions.
  • Update Renderer::present to return FrameStatus::Outdated and FrameStatus::Lost for the corresponding wgpu::SurfaceError cases.
  • Extend FrameStatus enum to include Outdated and Lost variants and adjust its documentation to cover recovery semantics.
wallr-core/src/renderer/mod.rs
Broaden video rendering transition and tests to account for non-presented frames and the new recovery behavior.
  • Change render_transition loop break condition to continue until a Presented frame instead of treating TimedOut as terminal.
  • Thread LivePacer into render_transition so it can be passed to play_video for pacing retries.
  • Add unit test verifying that video_present_action maps TimedOut to Retry and Outdated/Lost to Reconfigure, alongside existing viewport tests.
wallr-core/src/daemon/mod.rs

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 Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Frame status recovery

Layer / File(s) Summary
Renderer status contract
wallr-core/src/renderer/mod.rs
FrameStatus now includes Outdated and Lost. render_frame returns these statuses for the matching surface errors.
Video recovery flow
wallr-core/src/daemon/mod.rs
Video playback retries timeouts, reconfigures outdated or lost surfaces, waits before retries, and stops on render errors. Transition rendering stops for every non-Presented status. Tests cover the new classification.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant VideoPlayback
  participant render_frame
  participant Surface
  participant LivePacer
  VideoPlayback->>render_frame: render video frame
  render_frame-->>VideoPlayback: FrameStatus
  alt TimedOut
    VideoPlayback->>LivePacer: wait 100 ms
    LivePacer-->>VideoPlayback: retry timing
  else Outdated or Lost
    VideoPlayback->>Surface: reconfigure surface
    Surface-->>VideoPlayback: reconfigured surface
  else Presented
    VideoPlayback-->>VideoPlayback: continue playback
  end
Loading

Suggested reviewers: programmersd21

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: recovering video playback after compositor surface stalls.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@sourcery-ai sourcery-ai Bot 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@wallr-core/src/daemon/mod.rs`:
- Around line 1297-1308: Update the surface recovery configuration in play_video
to use the current surface dimensions rather than the stale commit.width and
commit.height values from CommitData. Reuse the live output dimensions
maintained by update_output, or restart playback when that output changes, while
preserving the existing format and recovery behavior.

In `@wallr-core/src/renderer/mod.rs`:
- Around line 426-432: Add #[non_exhaustive] to the public FrameStatus enum so
future variants do not break external exhaustive matches; otherwise mark this
API change as breaking before release.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 30031ded-9266-42fd-88ed-11fa5e0dbaa9

📥 Commits

Reviewing files that changed from the base of the PR and between 7052017 and dc1152c.

📒 Files selected for processing (2)
  • wallr-core/src/daemon/mod.rs
  • wallr-core/src/renderer/mod.rs

Comment on lines +1297 to +1308
surface.configure(
&renderer.device,
&wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: commit.format,
width: commit.width,
height: commit.height,
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: wgpu::CompositeAlphaMode::Opaque,
view_formats: vec![],
desired_maximum_frame_latency: 2,
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Map surface configuration and RenderState update paths.
ast-grep outline wallr-core/src/daemon/mod.rs --items all --type impl,function
rg -n -C8 '\.configure\s*\(|SurfaceConfiguration|self\.(format|width|height)\s*=|commit\.(format|width|height)' wallr-core/src

Repository: programmersd21/wallr

Length of output: 200


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- candidate files ---'
git ls-files 'wallr-core/src/*' | sed -n '1,120p'
printf '%s\n' '--- surface-related code ---'
rg -n -C10 '(\.configure\s*\(|SurfaceConfiguration|commit\.(format|width|height)|format\s*=|width\s*=|height\s*=|alpha_mode|present_mode)' wallr-core/src/daemon/mod.rs wallr-core/src 2>/dev/null | sed -n '1,320p'

Repository: programmersd21/wallr

Length of output: 23742


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- RenderState and CommitData definitions ---'
rg -n -C12 'struct (RenderState|CommitData)|enum VideoPresentAction|fn (play_video|render_video|video_present_action)' wallr-core/src/daemon/mod.rs
printf '%s\n' '--- relevant implementation sections ---'
sed -n '300,540p' wallr-core/src/daemon/mod.rs
sed -n '680,875p' wallr-core/src/daemon/mod.rs
sed -n '1180,1335p' wallr-core/src/daemon/mod.rs

Repository: programmersd21/wallr

Length of output: 28056


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- complete RenderState fields ---'
sed -n '635,675p' wallr-core/src/daemon/mod.rs
printf '%s\n' '--- render-state creation and format selection ---'
rg -n -C18 'create_render_state_for_output_sync|SurfaceCapabilities|formats|RenderState \{' wallr-core/src/daemon/mod.rs wallr-core/src/renderer/mod.rs
printf '%s\n' '--- frame status and surface acquisition ---'
rg -n -C20 'enum FrameStatus|fn render_frame|SurfaceError|surface\.get_current_texture|SurfaceConfiguration' wallr-core/src/renderer/mod.rs

Repository: programmersd21/wallr

Length of output: 34068


🏁 Script executed:

set -euo pipefail
python3 - <<'PY'
from pathlib import Path
s = Path("wallr-core/src/daemon/mod.rs").read_text()

checks = {
    "commit snapshots dimensions": "width: self.width,\n                height: self.height," in s,
    "play_video renders with snapshot dimensions": "width: commit.width,\n                height: commit.height," in s,
    "recovery config uses snapshot dimensions": "format: commit.format,\n                            width: commit.width,\n                            height: commit.height," in s,
    "resize path updates live state dimensions": "lock.width = new_width;\n                            lock.height = new_height;" in s,
    "resize path configures current dimensions": "width: new_width,\n                                height: new_height," in s,
    "resize path does not bump playback generation": "lock.playback_gen" not in s[s.find("fn update_output"):s.find("fn output_destroyed")],
}
for name, result in checks.items():
    print(f"{name}: {'YES' if result else 'NO'}")
if not all(checks.values()):
    raise SystemExit("unexpected source shape")
PY

Repository: programmersd21/wallr

Length of output: 431


Use current surface dimensions during video recovery.

update_output can reconfigure the surface while play_video still uses the snapshot in CommitData. A resize can therefore make recovery restore stale dimensions and repeat Outdated or Lost errors. Use live dimensions or restart playback when the output changes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@wallr-core/src/daemon/mod.rs` around lines 1297 - 1308, Update the surface
recovery configuration in play_video to use the current surface dimensions
rather than the stale commit.width and commit.height values from CommitData.
Reuse the live output dimensions maintained by update_output, or restart
playback when that output changes, while preserving the existing format and
recovery behavior.

Comment on lines +426 to +432
/// Whether a frame was presented or the surface needs recovery.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FrameStatus {
Presented,
TimedOut,
Outdated,
Lost,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Inspect internal uses and public exports of FrameStatus.
rg -n -C3 '\bFrameStatus\b|\brender_frame\s*\(' wallr-core/src

# Inspect package versioning and release policy metadata.
fd -a '^Cargo\.toml$' . -E target -0 |
  xargs -0 -r -n1 sh -c 'printf "\n--- %s ---\n" "$1"; sed -n "1,180p" "$1"' sh

Repository: programmersd21/wallr

Length of output: 17757


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- public module/export surface ---'
rg -n -C4 '^(pub\s+)?mod renderer|pub\s+use.*renderer|FrameStatus|non_exhaustive' wallr-core/src wallr-core/README.md README.md

printf '%s\n' '--- change introducing the enum variants ---'
git diff -- wallr-core/src/renderer/mod.rs wallr-core/src/lib.rs

printf '%s\n' '--- release and compatibility guidance ---'
rg -n -i -C3 'semver|breaking|release|api|public|library|version' README.md wallr-core/README.md .github 2>/dev/null || true

printf '%s\n' '--- package metadata ---'
sed -n '1,100p' wallr-core/Cargo.toml

Repository: programmersd21/wallr

Length of output: 16294


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
import re

path = Path("wallr-core/src/renderer/mod.rs")
text = path.read_text()
match = re.search(r'pub enum FrameStatus\s*\{(.*?)\n\}', text, re.S)
if not match:
    raise SystemExit("FrameStatus declaration not found")
body = match.group(1)
variants = re.findall(r'^\s*([A-Z][A-Za-z0-9_]*)\s*,', body, re.M)
print("FrameStatus variants:", variants)
print("has #[non_exhaustive]:", bool(re.search(r'#\[non_exhaustive\]\s*pub enum FrameStatus', text)))
PY

Repository: programmersd21/wallr

Length of output: 255


Add #[non_exhaustive] or release this as a breaking API change.

wallr-core exposes renderer publicly. Adding variants to FrameStatus breaks external exhaustive matches.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@wallr-core/src/renderer/mod.rs` around lines 426 - 432, Add #[non_exhaustive]
to the public FrameStatus enum so future variants do not break external
exhaustive matches; otherwise mark this API change as breaking before release.

@programmersd21
programmersd21 merged commit 22b6e3e into programmersd21:main Aug 11, 2026
3 checks passed
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.

2 participants