Skip to content

fix(desktop): prevent black bands in Rewind window captures - #13038

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
aryanorastar:codex/11207-rewind-opaque-capture
Sep 8, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
aryanorastar:codex/11207-rewind-opaque-capture

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Fixes #11207.

Rewind's single-window capture paths allowed ScreenCaptureKit's transparent shadow/framing pixels to reach opaque JPEG and HEVC sinks, where those pixels were flattened into the wide black band stored on disk. This PR adds one shared pixel-integrity policy for both the one-shot screenshot path and the persistent window stream: exclude single-window shadows and ask ScreenCaptureKit to back any remaining transparency with opaque white before encoding.

This follows ScreenCaptureKit's documented contracts for ignoreShadowsSingleWindow and shouldBeOpaque.

Product invariants affected

none

How it was verified

  • xcrun swift test --package-path Desktop --filter 'ScreenCaptureDimensionsTests|WindowCaptureStreamPolicyTests|WindowCaptureFrameSinkTests|ScreenCaptureWebPTests' — 25 tests passed, 0 failures.
  • ./scripts/swift-format-wrapper.sh lint Desktop/Sources/ScreenCaptureService.swift Desktop/Sources/WindowCaptureStreamEngine.swift Desktop/Tests/ScreenCaptureDimensionsTests.swift — changed Swift files passed the pinned formatter.
  • ./scripts/swiftlint-wrapper.sh lint — 1,633 files linted, 0 violations.
  • python3 scripts/check_desktop_test_quality.py — test-quality ratchet passed.
  • make preflight — repository PR contracts passed.

A full named-bundle capture comparison is tracked as the final manual proof because macOS Screen Recording permission is TCC-gated per bundle identity.

Tests

ScreenCaptureDimensionsTests.testSingleWindowCaptureConfigurationProducesOpaqueContentWithoutShadowFraming constructs the real production SCStreamConfiguration, applies the shared policy, and verifies that shadow framing is excluded and the output is opaque. The same helper is called by both one-shot and persistent capture engines.

Failure class (fixes)

Failure-Class: new

Failure-class transition narrative (only when needed)

Violated contract: capture pixels that may contain alpha cannot cross into opaque persistence formats without an explicit backing policy; otherwise transparent framing becomes stored black content.

Canonical guard: both single-window capture engines now call one shared ScreenCaptureKit configuration primitive that excludes shadow framing and requests opaque backing, with a behavioral regression test against the real configuration object.

Evidence: issue #11207 measured the corruption inside the stored image rather than in presentation layout, and the production paths persist those capture frames into JPEG/HEVC formats that cannot preserve alpha. The new FC-transparent-capture-flattened-without-backing registry entry records this boundary for future capture sinks.

Review in cubic

Apply one shared ScreenCaptureKit pixel-integrity policy to both one-shot and
persistent single-window capture paths so transparent shadow margins cannot
flatten into black JPEG or HEVC pixels.

Fixes BasedHardware#11207

Failure-Class: FC-transparent-capture-flattened-without-backing
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@cubic-dev-ai cubic-dev-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.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @aryanorastar — well-scoped fix for #11207, and sharing one policy across both capture sinks is the right shape. File by file:

  • desktop/macos/Desktop/Sources/ScreenCaptureService.swift — applySingleWindowPixelIntegrityPolicy(to:) setting ignoreShadowsSingleWindow + shouldBeOpaque matches Apple's documented contracts: shouldBeOpaque presents semitransparent content backed by solid white, while the default clear backing is exactly what JPEG/HEVC sinks flatten to black. Applying it inside captureConfiguration(for:) covers both one-shot SCScreenshotManager paths (including captureWindowCGImage), and the new macOS 14 availability annotation on captureConfiguration is consistent with the file's existing gating; the release-compile check is green.
  • desktop/macos/Desktop/Sources/WindowCaptureStreamEngine.swift — routing the persistent stream through the same policy in makeConfiguration(size:) means the HEVC sink inherits it too. The filter stays SCContentFilter(desktopIndependentWindow:), so there is no privacy-surface change.
  • desktop/macos/Desktop/Tests/ScreenCaptureDimensionsTests.swift — the new test pins both flags on a real SCStreamConfiguration. It mirrors the implementation rather than exercising a live capture, but that is the contract-test style the failure-class convention asks for here, so it's fine.
  • .github/failure-classes/FC-transparent-capture-flattened-without-backing.json — schema matches the existing 220+ sibling entries (empty evidence_prs has precedent). Consider adding this PR number as evidence once it merges.
  • desktop/macos/changelog/unreleased/20260907-rewind-opaque-window-captures.json — matches the changelog convention.

Two things before merge:

  1. Root-cause confirmation. Issue Rewind screenshots are stored with a ~21% black band baked in (SCK scalesToFit + point-derived size) #11207's own analysis names a second candidate mechanism — scalesToFit = true letterboxing from point-derived config sizes vs the pixel-space source aspect on Retina. This PR removes the transparency-flattening mechanism (shadow alpha and translucent margins flattening to black), but since the final proof is a named-bundle capture comparison that is TCC-gated, please attach a before/after stored frame from a real capture showing the band is gone. If any banding remains, the scalesToFit/aspect path is the next suspect.
  2. CI. Both desktop check failures trace to AgentSyncRecoveryTests.testDelayedOldVMSyncResponseCannotCreateReplacementRecoveryEvidence — a gate-based async race test with a mock backend returning SQLite HTTP 500s — which is unrelated to this diff; the same workflow was green on main immediately before and after this run, so it looks flaky. A re-run should clear it, but the checks need to be green before merge.

Leaving for human maintainer review: the stored-frame verification needs someone with the TCC-authorized app bundle.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

The scope hint named desktop/macos/Desktop/Sources/VideoChunkEncoder.swift, which
does not exist; the encoder lives under Rewind/Core/. Failure-class prepare matches
hints with fnmatch, so the hint could never fire — the class would stay unsuggested
on exactly the future encoder change it was written to catch.

Co-Authored-By: Claude Opus 5 <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Pushed 8bfb6b3 — cubic's scope-hint path was right, and the root-cause question deserves more than a re-run, so I traced both of #11207's candidates in code first.

Hint fix. desktop/macos/Desktop/Sources/VideoChunkEncoder.swift does not exist; the encoder is at desktop/macos/Desktop/Sources/Rewind/Core/VideoChunkEncoder.swift. I checked the other two hints while I was there — both resolve. Since prepare matches hints with fnmatch, the broken one could never fire, so the class would have stayed unsuggested on exactly the future encoder change it was written to catch.

On root cause. I could not run a capture — same TCC gate — but both mechanisms #11207 names are decidable from the source, and one of them is now ruled out:

The encoder canvas is not it. VideoChunkEncoder.swift:1028 writes every frame as

context.draw(image, in: CGRect(x: 0, y: 0, width: width, height: height))

That is the full canvas rect with no aspect preservation, so a frame whose aspect no longer matches the chunk is stretched, not padded. The 20% aspectRatioChangeThreshold and 2s debounce do let a mismatched frame into an existing chunk — but the visible result would be distortion, never a band. #11207's second candidate can be closed.

"Point-derived size" alone is not it either. captureDimensions preserves the aspect exactly — configHeight = configWidth / aspectRatio, with a symmetric clamp when the other axis exceeds maxSize — so the requested box matches the window's aspect to within Int() truncation. That is sub-pixel, not 21%. Points-versus-pixels changes the scale SCK renders at, not the aspect it fits into, so scalesToFit has nothing to letterbox on that account.

What that leaves actually supports this PR, though it credits a different line than the description does. Before the fix, the captured surface is the window plus its shadow framing. That region is both transparent — flattened to black by the JPEG/HEVC sinks, the mechanism this PR names — and larger than window.frame, so the requested box no longer matches the source aspect and scalesToFit pads the difference. ignoreShadowsSingleWindow = true removes that surface outright, which closes both paths at once. On this reading shouldBeOpaque is a backstop for genuinely translucent window content rather than the main remedy, which also fits the asymmetry in the report: macOS window shadows are not symmetric.

This makes the manual check discriminating rather than just before/after. The SDK header defines shouldBeOpaque as backing "partially transparent areas on windows" with solid white — letterbox padding is not that, so it should not be whitened. So the colour of any surviving band identifies the mechanism:

  • band gone → shadow framing was the cause; the fix is complete
  • band survives, now white → residual translucent window content; shouldBeOpaque is what is carrying the fix
  • band survives, still black → scalesToFit padding from a source/box aspect mismatch that this PR does not address, and the next change is to captureConfiguration

That is inference from the header wording plus the sources, not a capture, so it is a prediction the physical test can falsify rather than a claim that it holds.

On CI: agreed the two red checks are AgentSyncRecoveryTests.testDelayedOldVMSyncResponseCannotCreateReplacementRecoveryEvidence and unrelated to this diff — nothing here touches sync or the agent runtime. This push re-runs them.

@kodjima33 kodjima33 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.

Desktop bug fix (owner-override fast lane): Rewind single-window captures leaked shadow/transparency into opaque JPEG/HEVC sinks producing black bands (#11207), confirmed distinct from prior chrome-layout fix and still present on main. Trusted contributor aryanorastar, small scoped diff, tests added.

@kodjima33
kodjima33 merged commit 5fc7d79 into BasedHardware:main Sep 8, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewind screenshots are stored with a ~21% black band baked in (SCK scalesToFit + point-derived size)

3 participants