Skip to content

fix(oauth): protect token refresh during macOS maintenance wakes - #1257

Open
mrtrotl wants to merge 1 commit into
opencloud-eu:mainfrom
mrtrotl:fix/macos-oauth-refresh-sleep
Open

mrtrotl wants to merge 1 commit into
opencloud-eu:mainfrom
mrtrotl:fix/macos-oauth-refresh-sleep

Conversation

@mrtrotl

@mrtrotl mrtrotl commented Nov 14, 2026 •

Copy link
Copy Markdown

A macOS maintenance wake can send a rotating refresh token, go back to sleep before receiving its replacement, and then retry the consumed token. The IdP rejects that retry with invalid_grant, leaving the desktop client logged out.

Keep a bounded macOS idle/network power activity alive through the refresh and asynchronous Keychain write. Reacquire the activity immediately before the token POST so slow discovery cannot exhaust the protection budget. On limited power with all online displays asleep, defer renewal without clearing credentials or consuming a retry attempt; AC-powered headless renewal remains possible. Other platforms use a no-op activity.

Validation

  • Native Apple Silicon Debug build with Qt 6.12.0 and QtKeychain 0.18.0.
  • OAuth suite: 24 passed, 0 failed; original regression failed before the fix.
  • The slow-preflight regression also failed before the pre-dispatch recheck.
  • Native test inspects both live IOKit assertion types, enabled levels and 60-second timeouts; simulated network/Keychain tests cover deferral/resumption, write completion, timeout, invalid grant and owner destruction.
  • All 36 available CTest targets passed: 35 using the offscreen backend, and the FSEvents folder-watcher target using native Cocoa (142.30 seconds). The initial offscreen folder-watcher run did not receive FSEvents and was interrupted before rerunning natively.
  • A real overnight maintenance-wake acceptance run has not been performed with the modified application.

Limits

The assertions use public macOS APIs and expire after 60 seconds. Forced sleep, critical battery, network loss, unplugging during an exchange, and an exchange outlasting that bound can still lose a response. On battery with sleeping displays, background synchronization may wait for display wake after the existing access token expires. This change prevents the observed maintenance-wake scenario; it does not make arbitrary OAuth response loss recoverable.

Raw HTTP logs contain credentials and are not attached. The incident was correlated locally across client HTTP logs, IdP issuance metadata, and macOS power logs. The patched client has subsequently been installed on the reporting Mac: the existing account renewed its token with HTTP 200 and all four configured folders completed synchronization successfully, with no Keychain write errors. Production IdP configuration is unchanged. Overnight maintenance-wake acceptance is still pending.

@mrtrotl
mrtrotl marked this pull request as ready for review November 14, 2026 10:16

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.

1 participant