Skip to content

10648 persist audiocom multiple windows - #10689

Merged
embarc-gabriel merged 5 commits into
audacity:masterfrom
embarc-gabriel:10648-persist-audiocom-multiple-windows
Apr 14, 2026
Merged

embarc-gabriel merged 5 commits into
audacity:masterfrom
embarc-gabriel:10648-persist-audiocom-multiple-windows

Conversation

@embarc-gabriel

Copy link
Copy Markdown
Contributor

Resolves: #10648

The account should be the same for all opened windows.

  • I signed CLA
  • The title of the pull request describes an issue it addresses
  • If changes are extensive, then there is a sequence of easily reviewable commits
  • Each commit's message describes its purpose and effects
  • There are no behavior changes unnecessary for the stated purpose of the PR

Recommended:

  • Each commit compiles and runs on my machine without known undesirable changes of behavior

QA:

  • Autobot test cases have been run

@coderabbitai

coderabbitai Bot commented Apr 9, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Overlapping cloud syncs now return a distinct blocked status and no longer interfere with shared sync state.
  • Refactor

    • Sign-in/authorization flows converted to action-based dispatch (no direct dialog calls).
    • Cloud project operations simplified by removing extra async indirection.
    • Upload handling made more robust for concurrent uploads and late status events.
    • Authorization and usage services moved to a global scope and lifecycle adjusted.

Walkthrough

The PR moves au3cloud service creation/exports from context to module/global scope, replaces many muse::ContextInject members with muse::GlobalInject, and switches IAuthorization/IUsageInfo from MODULE_EXPORT_INTERFACE to MODULE_GLOBAL_INTERFACE. IAuthorization::ensureAuthorization() and openSignInDialog() were removed; call sites now dispatch an audacity://cloud/open-signin-dialog action (via an ActionsDispatcher) instead of invoking those methods. OAuth reply handler and Au3CloudService were decoupled from IoC/contextable, several thread-dispatch indirections were removed, and upload subscription handling was made concurrent-safe.

Sequence Diagram(s)

sequenceDiagram
    participant UI as UI / Model
    participant Dispatcher as ActionsDispatcher
    participant Controller as CloudActionsController / Module
    participant Auth as IAuthorization (global)
    participant Interactive as Interactive

    UI->>Dispatcher: dispatch(audacity://cloud/open-signin-dialog, {sync:, showTourPage:false})
    Dispatcher->>Controller: route action
    Controller->>Auth: isAuthorized()
    alt authorized
        Controller-->>UI: signed-in state (no-op)
    else not authorized
        Controller->>Interactive: open / openSync SIGNIN_URI (based on sync param)
        Interactive-->>Auth: perform OAuth flow
        Auth-->>Controller: auth state updated
        Controller-->>UI: update signed-in state
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • kryksyh
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title references issue #10648 but is vague about the actual changes; 'persist audiocom multiple windows' doesn't clearly convey the technical approach of switching to global dependency injection.
Description check ✅ Passed The PR description follows the template and includes issue reference, accomplishes CLA and title checks, and explains the objective (same account across windows).
Linked Issues check ✅ Passed The PR addresses issue #10648 by switching dependency injection scopes from context to global, ensuring account state persists across multiple windows.
Out of Scope Changes check ✅ Passed Minor side effects like removing ensureAuthorization/openSignInDialog methods and changing reply handler constructors are directly necessary to support the global DI refactoring.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
au3/libraries/au3-cloud-audiocom/CloudSyncService.cpp (1)

383-391: 🧹 Nitpick | 🔵 Trivial

Inconsistent promise-reset pattern between OpenFromCloud and SyncProject.

OpenFromCloud now correctly resets mSyncPromise after checking mSyncInProcess, but SyncProject still resets it before the check (line 386). While SyncProject is protected by ASSERT_MAIN_THREAD(), consider aligning the patterns for consistency and clarity.

♻️ Suggested alignment with OpenFromCloud pattern
 CloudSyncService::SyncFuture CloudSyncService::SyncProject(
     AudacityProject& project, const std::string& path, bool forceSync,
     sync::ProgressCallback callback)
 {
     ASSERT_MAIN_THREAD();
 
-    // Reset promise
-    mSyncPromise = {};
-
     if (mSyncInProcess.exchange(true)) {
-        CompleteSync({ sync::ProjectSyncResult::StatusCode::Blocked });
-        return mSyncPromise.get_future();
+        auto blockedPromise = SyncPromise {};
+        blockedPromise.set_value({ sync::ProjectSyncResult::StatusCode::Blocked, {}, {} });
+        return blockedPromise.get_future();
     }
+
+    // Reset promise
+    mSyncPromise = {};
src/project/internal/projectactionscontroller.cpp (1)

805-825: ⚠️ Potential issue | 🟠 Major

Double authorization check with potential race condition.

The authorization is checked both at line 805 (before download) and at line 823 (before resuming sync). Both calls are subject to the race condition in ensureAuthorization(). Additionally, if the user is prompted to sign in twice (once at line 805 and once at line 823), it creates a poor user experience.

Consider caching the authorization result from the first check, or using the authState() reactive channel to properly await authorization completion.

src/au3cloud/internal/au3cloudservice.h (1)

51-51: 🧹 Nitpick | 🔵 Trivial

Consider documenting ownership of m_replyHandler.

m_replyHandler is a raw pointer that's parented to this during init(), which ensures proper Qt-based cleanup. A brief comment clarifying this ownership model would improve maintainability.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 74e360b2-b59d-4f4c-9928-d3e1912d6c13

📥 Commits

Reviewing files that changed from the base of the PR and between cc65295 and 27dcb305f0ca26a4ec438cb667592a7fec93fe65.

📒 Files selected for processing (25)
  • au3/libraries/au3-cloud-audiocom/CloudSyncService.cpp
  • src/appshell/qml/Audacity/AppShell/FirstLaunchSetup/appupdateusageinfopagemodel.h
  • src/appshell/qml/Audacity/AppShell/FirstLaunchSetup/signinaudiocompagemodel.h
  • src/au3cloud/au3cloudmodule.cpp
  • src/au3cloud/au3cloudmodule.h
  • src/au3cloud/dev/cloudtestsmodel.h
  • src/au3cloud/iauthorization.h
  • src/au3cloud/internal/au3audiocomservice.cpp
  • src/au3cloud/internal/au3cloudactionscontroller.cpp
  • src/au3cloud/internal/au3cloudactionscontroller.h
  • src/au3cloud/internal/au3cloudservice.cpp
  • src/au3cloud/internal/au3cloudservice.h
  • src/au3cloud/internal/oauthhttpserverreplyhandler.cpp
  • src/au3cloud/internal/oauthhttpserverreplyhandler.h
  • src/au3cloud/iusageinfo.h
  • src/au3cloud/view/accountinfomodel.cpp
  • src/au3cloud/view/accountinfomodel.h
  • src/project/internal/projectactionscontroller.cpp
  • src/project/internal/projectactionscontroller.h
  • src/project/view/cloudaudiofilesmodel.cpp
  • src/project/view/cloudaudiofilesmodel.h
  • src/project/view/cloudprojectsmodel.cpp
  • src/project/view/cloudprojectsmodel.h
  • src/stubs/au3cloud/authorizationstub.cpp
  • src/stubs/au3cloud/authorizationstub.h
💤 Files with no reviewable changes (2)
  • src/stubs/au3cloud/authorizationstub.cpp
  • src/stubs/au3cloud/authorizationstub.h

@embarc-gabriel
embarc-gabriel force-pushed the 10648-persist-audiocom-multiple-windows branch from 27dcb30 to 60176d9 Compare April 9, 2026 18:55

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/au3cloud/internal/au3audiocomservice.cpp (1)

460-477: ⚠️ Potential issue | 🔴 Critical

projectSaveCallback() is ignored, so uploads get marked aborted unconditionally.

Line 461 only schedules the save on the main thread, but Lines 468-477 call OnSyncCompleted(...Aborted...) immediately on the worker thread regardless of whether the save succeeds. That aborts successful uploads and races the actual save result.

🐛 Proposed fix
         if (projectSaveCallback) {
             muse::async::Async::call(this, [project, projectSaveCallback = std::move(projectSaveCallback)]() {
                 bool ret = projectSaveCallback();
                 if (ret) {
                     return;
                 }
-            }, muse::runtime::mainThreadId());
-
-            au::au3::Au3Project* au3Project = reinterpret_cast<au::au3::Au3Project*>(project->au3ProjectPtr());
-            if (!au3Project) {
-                return;
-            }
-
-            auto& projectCloudExtension = audacity::cloud::audiocom::sync::ProjectCloudExtension::Get(*au3Project);
-            projectCloudExtension.OnSyncCompleted(nullptr,
-                                                  audacity::cloud::audiocom::sync::CloudSyncError {
-                audacity::cloud::audiocom::sync::CloudSyncError::Aborted, muse::trc("project", "Could not save project locally") },
-                                                  AudiocomTrace::SaveProjectSaveToCloudMenu);
+                au::au3::Au3Project* au3Project =
+                    reinterpret_cast<au::au3::Au3Project*>(project->au3ProjectPtr());
+                if (!au3Project) {
+                    return;
+                }
+
+                auto& projectCloudExtension =
+                    audacity::cloud::audiocom::sync::ProjectCloudExtension::Get(*au3Project);
+                projectCloudExtension.OnSyncCompleted(
+                    nullptr,
+                    audacity::cloud::audiocom::sync::CloudSyncError {
+                        audacity::cloud::audiocom::sync::CloudSyncError::Aborted,
+                        muse::trc("project", "Could not save project locally")
+                    },
+                    AudiocomTrace::SaveProjectSaveToCloudMenu);
+            }, muse::runtime::mainThreadId());
         }
src/au3cloud/iauthorization.h (1)

13-29: ⚠️ Potential issue | 🔴 Critical

IAuthorization interface removal breaks active call sites.

The interface no longer exposes ensureAuthorization() or checkCloudIsAvailable(), but these methods are still called actively in src/project/internal/opensaveprojectscenario.cpp (lines 185, 191). These will not compile.

Additionally, the change from context-scoped to MODULE_GLOBAL_INTERFACE affects linked consumers in musescore/musescore which expect context-scoped cloud/auth APIs and ContextPtr-based constructors.

♻️ Duplicate comments (1)
src/au3cloud/internal/au3cloudactionscontroller.cpp (1)

32-34: ⚠️ Potential issue | 🟠 Major

showTourPage is bypassed for already-authorized users.

Line 32 returns before the showTourPage branch, so requests with showTourPage=true become no-op when auth is already present.

Proposed fix
 void Au3CloudActionsController::openSignInDialog(const muse::actions::ActionQuery& query)
 {
-    if (authorization()->isAuthorized()) {
-        return;
-    }
-
     const bool showTourPage = query.param("showTourPage").toBool();
     const bool sync = query.param("sync").toBool();
 
-    if (sync) {
-        muse::RetVal<muse::Val> rv = interactive()->openSync(SIGNIN_URI);
-        if (!rv.ret) {
-            return;
-        }
-    } else {
-        interactive()->open(SIGNIN_URI);
+    if (!authorization()->isAuthorized()) {
+        if (sync) {
+            muse::RetVal<muse::Val> rv = interactive()->openSync(SIGNIN_URI);
+            if (!rv.ret) {
+                return;
+            }
+        } else {
+            interactive()->open(SIGNIN_URI);
+        }
     }
 
     if (showTourPage) {
         platformInteractive()->openUrl(TOUR_PAGE_URL);
     }
 }

Also applies to: 48-50


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2cf08c22-3e7e-4de7-b191-66e336f26fc6

📥 Commits

Reviewing files that changed from the base of the PR and between 27dcb305f0ca26a4ec438cb667592a7fec93fe65 and 60176d9f466e2440c915de9efbc2997ce424df9d.

📒 Files selected for processing (25)
  • au3/libraries/au3-cloud-audiocom/CloudSyncService.cpp
  • src/appshell/qml/Audacity/AppShell/FirstLaunchSetup/appupdateusageinfopagemodel.h
  • src/appshell/qml/Audacity/AppShell/FirstLaunchSetup/signinaudiocompagemodel.h
  • src/au3cloud/au3cloudmodule.cpp
  • src/au3cloud/au3cloudmodule.h
  • src/au3cloud/dev/cloudtestsmodel.h
  • src/au3cloud/iauthorization.h
  • src/au3cloud/internal/au3audiocomservice.cpp
  • src/au3cloud/internal/au3cloudactionscontroller.cpp
  • src/au3cloud/internal/au3cloudactionscontroller.h
  • src/au3cloud/internal/au3cloudservice.cpp
  • src/au3cloud/internal/au3cloudservice.h
  • src/au3cloud/internal/oauthhttpserverreplyhandler.cpp
  • src/au3cloud/internal/oauthhttpserverreplyhandler.h
  • src/au3cloud/iusageinfo.h
  • src/au3cloud/view/accountinfomodel.cpp
  • src/au3cloud/view/accountinfomodel.h
  • src/project/internal/projectactionscontroller.cpp
  • src/project/internal/projectactionscontroller.h
  • src/project/view/cloudaudiofilesmodel.cpp
  • src/project/view/cloudaudiofilesmodel.h
  • src/project/view/cloudprojectsmodel.cpp
  • src/project/view/cloudprojectsmodel.h
  • src/stubs/au3cloud/authorizationstub.cpp
  • src/stubs/au3cloud/authorizationstub.h
💤 Files with no reviewable changes (2)
  • src/stubs/au3cloud/authorizationstub.h
  • src/stubs/au3cloud/authorizationstub.cpp

@embarc-gabriel
embarc-gabriel force-pushed the 10648-persist-audiocom-multiple-windows branch from 60176d9 to 05a545f Compare April 10, 2026 12:45
@embarc-gabriel
embarc-gabriel force-pushed the 10648-persist-audiocom-multiple-windows branch from 05a545f to 30e3c02 Compare April 10, 2026 12:47

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/au3cloud/internal/au3audiocomservice.cpp (1)

460-477: ⚠️ Potential issue | 🔴 Critical

Don't mark the upload aborted before projectSaveCallback() finishes.

The save callback is now only queued onto the main thread, but OnSyncCompleted(...Aborted...) runs immediately afterward regardless of the callback result. That aborts successful uploads and races the save itself.

🛠️ Suggested fix
         if (projectSaveCallback) {
             muse::async::Async::call(this, [project, projectSaveCallback = std::move(projectSaveCallback)]() {
                 bool ret = projectSaveCallback();
                 if (ret) {
                     return;
                 }
-            }, muse::runtime::mainThreadId());
-
-            au::au3::Au3Project* au3Project = reinterpret_cast<au::au3::Au3Project*>(project->au3ProjectPtr());
-            if (!au3Project) {
-                return;
-            }
-
-            auto& projectCloudExtension = audacity::cloud::audiocom::sync::ProjectCloudExtension::Get(*au3Project);
-            projectCloudExtension.OnSyncCompleted(nullptr,
-                                                  audacity::cloud::audiocom::sync::CloudSyncError {
-                audacity::cloud::audiocom::sync::CloudSyncError::Aborted, muse::trc("project", "Could not save project locally") },
-                                                  AudiocomTrace::SaveProjectSaveToCloudMenu);
+                auto* au3Project = reinterpret_cast<au::au3::Au3Project*>(project->au3ProjectPtr());
+                if (!au3Project) {
+                    return;
+                }
+
+                auto& projectCloudExtension = audacity::cloud::audiocom::sync::ProjectCloudExtension::Get(*au3Project);
+                projectCloudExtension.OnSyncCompleted(
+                    nullptr,
+                    audacity::cloud::audiocom::sync::CloudSyncError {
+                        audacity::cloud::audiocom::sync::CloudSyncError::Aborted,
+                        muse::trc("project", "Could not save project locally") },
+                    AudiocomTrace::SaveProjectSaveToCloudMenu);
+            }, muse::runtime::mainThreadId());
         }
♻️ Duplicate comments (2)
src/au3cloud/internal/au3audiocomservice.cpp (1)

564-582: ⚠️ Potential issue | 🟠 Major

Handle Blocked explicitly and clean up NotFound by the requested path.

OpenFromCloud() can return StatusCode::Blocked with no ResponseResult, and failed opens do not populate ProjectPath. The current else branch therefore misclassifies blocked opens, and Line 578 will not remove the stale DB row on NotFound.

🛠️ Suggested fix
-        if (result.Status == sync::ProjectSyncResult::StatusCode::Succeeded) {
-            progress->finish(muse::make_ok());
-        } else {
-            const auto err = syncResultCodeToErr(result.Result.Code);
-            if (err == Err::SyncResultNotFound) {
-                removeProjectFromDatabase(result.ProjectPath);
-            }
-
-            progress->finish(make_ret(err));
-        }
+        switch (result.Status) {
+        case sync::ProjectSyncResult::StatusCode::Succeeded:
+            progress->finish(muse::make_ok());
+            break;
+        case sync::ProjectSyncResult::StatusCode::Blocked:
+            progress->finish(muse::make_ret(
+                muse::Ret::Code::UnknownError,
+                muse::trc("cloud", "Another cloud sync is already in progress")));
+            break;
+        case sync::ProjectSyncResult::StatusCode::Failed: {
+            const auto err = syncResultCodeToErr(result.Result.Code);
+            if (err == Err::SyncResultNotFound) {
+                removeProjectFromDatabase(muse::io::path_t(path));
+            }
+
+            progress->finish(make_ret(err));
+            break;
+        }
+        }
src/au3cloud/internal/au3cloudactionscontroller.cpp (1)

32-49: ⚠️ Potential issue | 🟠 Major

Don't return before processing showTourPage.

Line 32 makes showTourPage unreachable for already-authorized users. With persisted auth, that becomes the common path, so callers that deliberately pass showTourPage=true now no-op.

Proposed fix
 void Au3CloudActionsController::openSignInDialog(const muse::actions::ActionQuery& query)
 {
-    if (authorization()->isAuthorized()) {
-        return;
-    }
-
     const bool showTourPage = query.param("showTourPage").toBool();
     const bool sync = query.param("sync").toBool();
 
-    if (sync) {
-        muse::RetVal<muse::Val> rv = interactive()->openSync(SIGNIN_URI);
-        if (!rv.ret) {
-            return;
+    if (!authorization()->isAuthorized()) {
+        if (sync) {
+            muse::RetVal<muse::Val> rv = interactive()->openSync(SIGNIN_URI);
+            if (!rv.ret) {
+                return;
+            }
+        } else {
+            interactive()->open(SIGNIN_URI);
         }
-    } else {
-        interactive()->open(SIGNIN_URI);
     }
 
     if (showTourPage) {
         platformInteractive()->openUrl(TOUR_PAGE_URL);
     }
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: adec51ee-0eb9-4fb2-9af4-99637b69364e

📥 Commits

Reviewing files that changed from the base of the PR and between 60176d9f466e2440c915de9efbc2997ce424df9d and 30e3c02.

📒 Files selected for processing (25)
  • au3/libraries/au3-cloud-audiocom/CloudSyncService.cpp
  • src/appshell/qml/Audacity/AppShell/FirstLaunchSetup/appupdateusageinfopagemodel.h
  • src/appshell/qml/Audacity/AppShell/FirstLaunchSetup/signinaudiocompagemodel.h
  • src/au3cloud/au3cloudmodule.cpp
  • src/au3cloud/au3cloudmodule.h
  • src/au3cloud/dev/cloudtestsmodel.h
  • src/au3cloud/iauthorization.h
  • src/au3cloud/internal/au3audiocomservice.cpp
  • src/au3cloud/internal/au3cloudactionscontroller.cpp
  • src/au3cloud/internal/au3cloudactionscontroller.h
  • src/au3cloud/internal/au3cloudservice.cpp
  • src/au3cloud/internal/au3cloudservice.h
  • src/au3cloud/internal/oauthhttpserverreplyhandler.cpp
  • src/au3cloud/internal/oauthhttpserverreplyhandler.h
  • src/au3cloud/iusageinfo.h
  • src/au3cloud/view/accountinfomodel.cpp
  • src/au3cloud/view/accountinfomodel.h
  • src/project/internal/projectactionscontroller.cpp
  • src/project/internal/projectactionscontroller.h
  • src/project/view/cloudaudiofilesmodel.cpp
  • src/project/view/cloudaudiofilesmodel.h
  • src/project/view/cloudprojectsmodel.cpp
  • src/project/view/cloudprojectsmodel.h
  • src/stubs/au3cloud/authorizationstub.cpp
  • src/stubs/au3cloud/authorizationstub.h
💤 Files with no reviewable changes (2)
  • src/stubs/au3cloud/authorizationstub.cpp
  • src/stubs/au3cloud/authorizationstub.h

Q_OBJECT

muse::ContextInject<IAuthorization> authorization = { this };
muse::GlobalInject<IAuthorization> authorization;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Update the stub export to match this global injection.

authorization now resolves through GlobalInject, but src/stubs/au3cloud/au3cloudstubmodule.cpp still publishes IAuthorization via ioc()->registerExport(...). In stub/dev builds this model will dereference an unresolved dependency until the stub export is moved to globalIoc().

Comment thread src/au3cloud/iusageinfo.h

namespace au::au3cloud {
class IUsageInfo : MODULE_EXPORT_INTERFACE
class IUsageInfo : MODULE_GLOBAL_INTERFACE

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Keep the stub IUsageInfo export in global scope too.

This interface is now global, but src/stubs/au3cloud/au3cloudstubmodule.cpp still registers IUsageInfo on the context IoC. Any GlobalInject<IUsageInfo> consumer will fail under stub builds until that export is moved to globalIoc().

Comment on lines +819 to 821
if (!ensureAuthorization()) {
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider whether re-checking authorization is necessary here.

This ensureAuthorization() call occurs inside the progress->finished().onReceive() callback after successfully opening a cloud project. The user was already authenticated at line 801 before initiating the download.

If the auth check at line 801 passed and the download succeeded, under what scenario would the user become unauthorized by the time this callback fires? If token expiration mid-operation is a concern, this makes sense; otherwise, it may be redundant.

Comment on lines +1112 to +1125
muse::Ret ProjectActionsController::ensureAuthorization()
{
if (authorization()->isAuthorized()) {
return make_ret(Ret::Code::Ok);
}

muse::actions::ActionQuery query("audacity://cloud/open-signin-dialog");
query.addParam("sync", muse::Val(true));
query.addParam("showTourPage", muse::Val(false));

dispatcher()->dispatch(query);

return authorization()->isAuthorized() ? make_ret(Ret::Code::Ok) : make_ret(Ret::Code::Cancel);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if there's synchronization between dialog close and auth state update
echo "=== Searching for auth state synchronization mechanisms ==="
rg -n "authState\(\).*onReceive|authState.*ch\.|waitFor" src/au3cloud/ src/project/ --type cpp -B 2 -A 3

echo ""
echo "=== Check SigninAudiocomPageModel for when dialog closes ==="
rg -n "close\(\)|reject\(\)|accept\(\)" src/appshell/ --type cpp -B 2 -A 3 | head -40

echo ""
echo "=== Check if dispatcher->dispatch blocks on sync actions ==="
rg -n "dispatch.*sync\|synchronous" src/framework/actions/ --type cpp --type h -B 2 -A 3 | head -30

Repository: audacity/audacity

Length of output: 5578


🏁 Script executed:

#!/bin/bash
# Find Au3CloudActionsController::openSignInDialog implementation
echo "=== Looking for Au3CloudActionsController::openSignInDialog ==="
find . -name "*.cpp" -o -name "*.h" | xargs grep -l "Au3CloudActionsController\|openSignInDialog" | head -10

echo ""
echo "=== Search for Au3CloudActionsController and openSignInDialog ==="
rg -n "openSignInDialog|class Au3CloudActionsController" --type cpp --type h -A 10 | head -80

Repository: audacity/audacity

Length of output: 4023


🏁 Script executed:

#!/bin/bash
# Find where auth state is set in Au3CloudService
echo "=== Search for authState.set or m_authState in au3cloud ==="
rg -n "m_authState.*set|authState.*set|m_authState\s*=" src/au3cloud/ --type cpp -B 2 -A 2

echo ""
echo "=== Look for OAuth token callback mechanism ==="
rg -n "onAuthReceived|onTokenReceived|OAuth.*callback" src/au3cloud/ --type cpp -B 3 -A 3

Repository: audacity/audacity

Length of output: 7428


🏁 Script executed:

#!/bin/bash
# Check if there's any waiting or synchronization after openSync
echo "=== Search for interactive()->openSync usage ==="
rg -n "openSync\|interactive\(\)" src/au3cloud/ src/appshell/ --type cpp -B 5 -A 5 | head -100

Repository: audacity/audacity

Length of output: 109


🏁 Script executed:

#!/bin/bash
# Get the full openSignInDialog implementation
echo "=== Full openSignInDialog implementation ==="
sed -n '30,60p' src/au3cloud/internal/au3cloudactionscontroller.cpp

echo ""
echo "=== Check if there's anything after openSync call ==="
rg -n "openSync" src/au3cloud/internal/au3cloudactionscontroller.cpp -A 15

Repository: audacity/audacity

Length of output: 1041


🏁 Script executed:

#!/bin/bash
# Look for what interactive()->openSync does and returns
echo "=== Search for openSync definition ==="
rg -n "openSync\|IInteractive" src/ --type cpp --type h | grep -i "opensync\|class.*Interactive" | head -20

Repository: audacity/audacity

Length of output: 99


🏁 Script executed:

#!/bin/bash
# Search for any event loop processing or signal emission in openSync context
echo "=== Look for event processing in the codebase ==="
rg -n "exec\(\)|processEvents\|QEventLoop" src/au3cloud/ src/project/ --type cpp | head -30

echo ""
echo "=== Check if OAuthHttpServerReplyHandler emits signal immediately or deferred ==="
rg -n "callbackReceived\|emit.*callback" src/au3cloud/internal/oauthhttpserverreplyhandler.cpp -B 3 -A 3

Repository: audacity/audacity

Length of output: 255


🏁 Script executed:

#!/bin/bash
# Check what exactly happens in the callback - is it immediate or queued?
echo "=== Full callback connection and processing ==="
sed -n '20,100p' src/au3cloud/internal/au3cloudservice.cpp | grep -A 20 "callbackReceived"

Repository: audacity/audacity

Length of output: 1048


🏁 Script executed:

#!/bin/bash
# Search the entire codebase for where callbacks are emitted in OAuthHttpServerReplyHandler
echo "=== Find where callbackReceived signal is emitted ==="
rg -n "Q_EMIT callbackReceived\|emit callbackReceived" src/ --type cpp

Repository: audacity/audacity

Length of output: 114


🏁 Script executed:

#!/bin/bash
# Search for where callbackReceived is emitted (try variations)
echo "=== Search for callbackReceived emission with variations ==="
rg -n "callbackReceived" src/au3cloud/internal/oauthhttpserverreplyhandler.cpp

echo ""
echo "=== Get the full OAuthHttpServerReplyHandler class definition ==="
rg -n "class OAuthHttpServerReplyHandler\|callbackReceived\|signals:" src/au3cloud/internal/oauthhttpserverreplyhandler.h -A 5

echo ""
echo "=== Look for HTTP request handling that might emit the signal ==="
rg -n "handle\|request\|reply\|POST\|GET" src/au3cloud/internal/oauthhttpserverreplyhandler.cpp | head -30

Repository: audacity/audacity

Length of output: 312


🏁 Script executed:

#!/bin/bash
# Check timing: look at ensureAuthorization in projectactionscontroller
echo "=== Look at ensureAuthorization and when dispatch returns ==="
sed -n '1110,1130p' src/project/internal/projectactionscontroller.cpp

echo ""
echo "=== Check if there's event loop processing between dispatch and isAuthorized ==="
rg -n "dispatcher\(\)->dispatch" src/project/internal/projectactionscontroller.cpp -A 3 | head -20

Repository: audacity/audacity

Length of output: 1310


🏁 Script executed:

#!/bin/bash
# Critical: understand if dispatch() blocks or is async
echo "=== Search for dispatcher->dispatch behavior ==="
rg -n "dispatch\(.*ActionQuery\)" src/project/ --type cpp -B 2 -A 2 | head -50

echo ""
echo "=== Look for IActionsDispatcher interface definition ==="
rg -n "IActionsDispatcher\|dispatch.*virtual\|class.*Dispatcher" src/ --type h | grep -i "actions\|dispatch" | head -20

echo ""
echo "=== Check if dispatch is synchronous by looking at its implementation ==="
rg -n "void dispatch\|RetVal.*dispatch" src/ --type h -A 2 | head -30

Repository: audacity/audacity

Length of output: 242


🏁 Script executed:

#!/bin/bash
# Check when the HTTP callback is received - is it during openSync or after?
echo "=== Look for HTTP server implementation that handles the callback ==="
sed -n '140,160p' src/au3cloud/internal/oauthhttpserverreplyhandler.cpp

echo ""
echo "=== Get more context around the emit ==="
sed -n '140,165p' src/au3cloud/internal/oauthhttpserverreplyhandler.cpp

Repository: audacity/audacity

Length of output: 2096


🏁 Script executed:

#!/bin/bash
# Check what openSync returns and if there's any sync with auth state
echo "=== Look at how openSync is implemented ==="
rg -n "openSync.*IInteractive" src/ --type h -B 2 -A 8 | head -40

echo ""
echo "=== Check how AuthorizeCode works - is it sync or async? ==="
rg -n "AuthorizeCode" src/au3cloud/ --type cpp -B 3 -A 10 | head -60

echo ""
echo "=== Check if there's any blocking/waiting after dispatch ==="
rg -n "ensure.*Authorization\|openCloud.*Project" src/project/internal/projectactionscontroller.cpp -A 15 | head -80

Repository: audacity/audacity

Length of output: 1380


🏁 Script executed:

#!/bin/bash
# Look at the past commits mentioned in the review
echo "=== Check git history for the mentioned fix commits ==="
git log --oneline | grep -E "de79fa2|60176d9" | head -5

echo ""
echo "=== Get info about those commits ==="
git show de79fa2 --stat 2>/dev/null | head -30
git show 60176d9 --stat 2>/dev/null | head -30

Repository: audacity/audacity

Length of output: 501


🏁 Script executed:

#!/bin/bash
# Understand the signal connection type and callback timing
echo "=== Check the connect call for callbackReceived - is it async/queued? ==="
rg -n "connect.*callbackReceived\|callbackReceived.*connect" src/ --type cpp -B 2 -A 2

echo ""
echo "=== Check if AuthorizeCode is async (uses callbacks) ==="
rg -n "AuthorizeCode.*callback\|std::function.*token" src/ --type cpp -B 2 -A 3 | head -40

echo ""
echo "=== Verify the timing: when does the token callback execute? ==="
rg -n "AuthorizeCode" src/ --type h -A 8

Repository: audacity/audacity

Length of output: 258


🏁 Script executed:

#!/bin/bash
# Most critical: does openSync() pump the event loop?
echo "=== Search for what openSync actually does - is it a dialog exec()? ==="
rg -n "interactive\(\)->openSync\|openSync" src/ --type h | head -20

echo ""
echo "=== Check if muse framework is available in repo or external ==="
find . -name "*Interactive*" -o -name "*interactive*" | grep -E "\.(h|cpp)$" | head -10

Repository: audacity/audacity

Length of output: 198


🏁 Script executed:

#!/bin/bash
# Check the actual flow and timing
echo "=== Detailed: connection type check ==="
sed -n '25,35p' src/au3cloud/internal/au3cloudservice.cpp

echo ""
echo "=== Check AuthorizeCode parameters ==="
rg -n "AuthorizeCode.*code\|void.*AuthorizeCode" src/ --type h -A 5

Repository: audacity/audacity

Length of output: 776


🏁 Script executed:

#!/bin/bash
# The connect() uses default Qt connection type - need to check if it's queued or direct
echo "=== Read the full connect line to see if connection type is specified ==="
sed -n '28,35p' src/au3cloud/internal/au3cloudservice.cpp

echo ""
echo "=== Check if dispatch is in the same thread or queued ==="
rg -n "dispatch" src/project/internal/projectactionscontroller.cpp -B 5 -A 5 | grep -A 5 -B 5 "1122"

echo ""
echo "=== Look for the dispatcher implementation or interface ==="
find . -path ./build -prune -o -name "*.h" -print | xargs grep -l "class.*Dispatcher\|IActionsDispatcher" | head -5

Repository: audacity/audacity

Length of output: 1308


🏁 Script executed:

#!/bin/bash
# Check if dispatch blocks or returns immediately
echo "=== Search for dispatcher()->dispatch calling patterns ==="
rg -n "dispatcher\(\)->dispatch" src/ --type cpp | head -30

echo ""
echo "=== Check what type dispatcher() returns ==="
rg -n "dispatcher\(\)" src/au3cloud/internal/au3cloudactionscontroller.h -B 2 -A 2

Repository: audacity/audacity

Length of output: 3854


🏁 Script executed:

#!/bin/bash
# Find the dispatcher type and see if it's blocking
echo "=== Check Au3CloudActionsController header for dispatcher type ==="
cat src/au3cloud/internal/au3cloudactionscontroller.h

echo ""
echo "=== Check what ContextInject is ==="
rg -n "ContextInject.*dispatcher" src/ --type h -B 2 -A 2 | head -20

Repository: audacity/audacity

Length of output: 3063


🏁 Script executed:

#!/bin/bash
# Search for the muse::actions namespace to understand dispatch behavior
echo "=== Look for dispatch method signature ==="
rg -n "dispatch.*ActionQuery\|dispatch.*action" src/ --type h | grep -v "^Binary" | head -30

echo ""
echo "=== Check if there are any event loop pumps or sync waits in the code path ==="
rg -n "processEvents\|QEventLoop\|exec\(\)" src/au3cloud/ --type cpp | head -20

Repository: audacity/audacity

Length of output: 183


🏁 Script executed:

#!/bin/bash
# Check the actual flow and understand if openSync pumps the event loop
echo "=== Get context on what openSync does by looking for its usage ==="
rg -n "openSync" src/ --type cpp -B 3 -A 3 | head -80

echo ""
echo "=== Check if the callback is emitted synchronously or asynchronously ==="
sed -n '145,160p' src/au3cloud/internal/oauthhttpserverreplyhandler.cpp

Repository: audacity/audacity

Length of output: 7779


🏁 Script executed:

#!/bin/bash
# Critical: check if there's event loop pumping during openSync
echo "=== Check dialog implementation to see if it pumps event loop ==="
rg -n "class.*Dialog\|QDialog\|exec\|eventLoop" src/ --type h | grep -E "(Dialog|IInteractive)" | head -20

echo ""
echo "=== Search for specific test or timing fix related to authorization ==="
git log --oneline --all | grep -i "auth\|cloud\|sync\|race" | head -20

echo ""
echo "=== Check if there's any synchronization between openSync returning and auth check ==="
rg -n "openSync\|isAuthorized" src/au3cloud/internal/au3cloudactionscontroller.cpp -A 15

Repository: audacity/audacity

Length of output: 1426


🏁 Script executed:

#!/bin/bash
# Check the Qt signal connection type more carefully
echo "=== Look at the full connection to see if connection type is specified ==="
sed -n '25,65p' src/au3cloud/internal/au3cloudservice.cpp

Repository: audacity/audacity

Length of output: 2000


🏁 Script executed:

#!/bin/bash
# Check the commit that says "Return early if authorized"
echo "=== Check commit 30e3c023 ==="
git show 30e3c023 --stat

echo ""
echo "=== Check the actual changes in that commit ==="
git show 30e3c023

Repository: audacity/audacity

Length of output: 50376


🏁 Script executed:

#!/bin/bash
# See the flow: openSync pumps event loop, but AuthorizeCode is async
echo "=== Verify AuthorizeCode is indeed async ==="
rg -n "void AuthorizeCode\|AuthorizeCode.*callback" src/ --type h -A 3 | head -40

echo ""
echo "=== Check what happens in the token callback - when does m_authState actually get set? ==="
sed -n '40,55p' src/au3cloud/internal/au3cloudservice.cpp

Repository: audacity/audacity

Length of output: 882


🏁 Script executed:

#!/bin/bash
# Final verification: check if there's any synchronization we missed
echo "=== Check if AuthorizeCode is truly async or blocks somewhere ==="
rg -n "AuthorizeCode" src/ --type h -A 15 | head -50

echo ""
echo "=== Verify if there's any event loop pumping or waiting after dispatch ==="
sed -n '1112,1135p' src/project/internal/projectactionscontroller.cpp

echo ""
echo "=== Check if token callback sets m_authState synchronously ==="
sed -n '40,75p' src/au3cloud/internal/au3cloudservice.cpp

Repository: audacity/audacity

Length of output: 2588


The authorization state is not synchronized with the sign-in dialog close event.

After openSync() returns (dialog closed), the authorization state is checked immediately via isAuthorized(). However, the OAuth token callback is asynchronous—it fires in response to a network call (AuthorizeCode() takes a callback parameter, not a return value). The token response callback, which calls m_authState.set(Authorized()), may not have completed by the time the authorization check executes.

This timing gap causes a race condition: successful sign-in appears to fail because isAuthorized() returns false on line 1124, even though the user successfully authenticated. The returned Ret::Code::Cancel blocks subsequent cloud operations.

To fix, add a blocking wait for the token callback to complete before returning from ensureAuthorization(), or restructure to confirm auth state updates before the method returns.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/au3cloud/internal/au3audiocomservice.cpp (1)

476-494: ⚠️ Potential issue | 🔴 Critical

Race condition: OnSyncCompleted(Aborted) is called unconditionally after async dispatch.

The muse::async::Async::call dispatches projectSaveCallback to the main thread asynchronously but does not block. The worker thread immediately continues and calls OnSyncCompleted(...Aborted...) regardless of whether the callback succeeded or failed.

This means:

  1. If projectSaveCallback() returns true (success), the sync is still incorrectly marked as Aborted
  2. There's a race between the main-thread callback and the worker-thread OnSyncCompleted call
🐛 Proposed fix: synchronize with callback result
 if (projectSaveCallback) {
+    std::promise<bool> savePromise;
+    auto saveFuture = savePromise.get_future();
+
     muse::async::Async::call(this, [project, projectSaveCallback = std::move(projectSaveCallback)]() {
-        bool ret = projectSaveCallback();
-        if (ret) {
-            return;
-        }
+        return projectSaveCallback();
+    }, muse::runtime::mainThreadId()).onResolve(this, [&savePromise](bool result) {
+        savePromise.set_value(result);
     });
 
-    au::au3::Au3Project* au3Project = reinterpret_cast<au::au3::Au3Project*>(project->au3ProjectPtr());
-    if (!au3Project) {
-        return;
-    }
+    bool saveSucceeded = saveFuture.get();
+    if (saveSucceeded) {
+        return; // Save succeeded, sync completion handled by status subscription
+    }
 
-    auto& projectCloudExtension = audacity::cloud::audiocom::sync::ProjectCloudExtension::Get(*au3Project);
-    projectCloudExtension.OnSyncCompleted(nullptr,
-                                          audacity::cloud::audiocom::sync::CloudSyncError {
-        audacity::cloud::audiocom::sync::CloudSyncError::Aborted, muse::trc("project", "Could not save project locally") },
-                                          AudiocomTrace::SaveProjectSaveToCloudMenu);
+    // Save failed - mark sync as aborted
+    au::au3::Au3Project* au3Project = reinterpret_cast<au::au3::Au3Project*>(project->au3ProjectPtr());
+    if (au3Project) {
+        auto& projectCloudExtension = audacity::cloud::audiocom::sync::ProjectCloudExtension::Get(*au3Project);
+        projectCloudExtension.OnSyncCompleted(nullptr,
+                                              audacity::cloud::audiocom::sync::CloudSyncError {
+            audacity::cloud::audiocom::sync::CloudSyncError::Aborted, muse::trc("project", "Could not save project locally") },
+                                              AudiocomTrace::SaveProjectSaveToCloudMenu);
+    }
 }

Note: The exact fix depends on whether muse::async::Async::call returns a chainable promise. If not, consider using a std::promise/std::future pair set from within the callback lambda.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: ca856946-cb24-4e60-a3c4-697ed7edfab0

📥 Commits

Reviewing files that changed from the base of the PR and between 30e3c02 and c0266f6.

📒 Files selected for processing (2)
  • src/au3cloud/internal/au3audiocomservice.cpp
  • src/au3cloud/internal/au3audiocomservice.h

@embarc-gabriel
embarc-gabriel merged commit ef0dcc2 into audacity:master Apr 14, 2026
8 checks passed
This was referenced Apr 14, 2026
@embarc-gabriel
embarc-gabriel deleted the 10648-persist-audiocom-multiple-windows branch August 28, 2026 10:21
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.

Audio.com signin should persist across different windows

2 participants