Skip to content

iOS: notify the ADM observer when an enable operation rolls back after will-enable - #270

Open
hiroshihorie wants to merge 1 commit into
m144_releasefrom
hiroshi/adm-enable-rollback-compensation
Open

iOS: notify the ADM observer when an enable operation rolls back after will-enable#270
hiroshihorie wants to merge 1 commit into
m144_releasefrom
hiroshi/adm-enable-rollback-compensation

Conversation

@hiroshihorie

@hiroshihorie hiroshihorie commented Jul 10, 2026

Copy link
Copy Markdown
Member

Problem

OnEngineWillEnable runs before permission and category checks, node configuration, and engine startup. If a later step fails, rollback never notifies the observer. Observers that configure or activate the audio session in willEnable can therefore retain resources for an engine state that was never applied.

Change

After a successful OnEngineWillEnable, register a rollback action that calls OnEngineDidDisable with the previous state. This covers both device and manual rendering paths. The result is ignored because rollback cannot be cancelled.

OnEngineDidDisable may now represent an attempted enable returning to the previous state, not only a completed disable.

Testing

Built framework_objc for an arm64 iOS device. Reproduced by enabling input with an incompatible playback-only category and verified that rollback now notifies the observer.

…able

OnEngineWillEnable is invoked before the fallible parts of an enable
operation: permission and category checks, node configuration, and
engine start. When any of those failed, the rollback replayed only the
constructive engine actions and never told the observer, so an observer
that configured and activated the audio session for the enable was left
holding an activation for an engine state that never materialized. It
leaked until the next retry or stop.

Push a rollback action right after a successful will-enable that fires
OnEngineDidDisable with the previous engine state. Existing observers
already implement did-disable as the release edge, so they get correct
compensation without adopting a new callback. The result is ignored
since the rollback itself cannot be aborted. Applies to both the device
and manual rendering paths.

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.

Pull request overview

This PR fixes an iOS observer lifecycle gap where OnEngineWillEnable can succeed but a later enable step fails, causing the engine to roll back without notifying the ADM observer—potentially leaking audio session activation in observers that acquire resources in willEnable.

Changes:

  • Add a rollback action immediately after successful OnEngineWillEnable that notifies the observer via OnEngineDidDisable with the previous engine state when a later enable step fails.
  • Apply the same rollback-notification behavior to both manual rendering and device rendering paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1855 to +1859
if (observer_ != nullptr) {
LOGW() << "Enable rolled back after OnEngineWillEnable, notifying observer (Manual)";
observer_->OnEngineDidDisable(engine_manual_input_, state.prev.IsOutputEnabled(),
state.prev.IsInputEnabled());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe worth doing?

Comment on lines +2297 to +2301
if (observer_ != nullptr) {
LOGW() << "Enable rolled back after OnEngineWillEnable, notifying observer";
observer_->OnEngineDidDisable(engine_device_, state.prev.IsOutputEnabled(),
state.prev.IsInputEnabled());
}
@hiroshihorie
hiroshihorie requested a review from pblazej July 15, 2026 17:06
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.

4 participants