Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,13 @@ export class ClineProvider
}

// Initialize Roo Code Cloud profile sync.
this.initializeCloudProfileSync().catch((error) => {
this.log(`Failed to initialize cloud profile sync: ${error}`)
})
if (CloudService.hasInstance()) {
this.initializeCloudProfileSync().catch((error) => {
this.log(`Failed to initialize cloud profile sync: ${error}`)
})
} else {
this.log("CloudService not ready, deferring cloud profile sync")
}
}

/**
Expand Down Expand Up @@ -303,6 +307,25 @@ export class ClineProvider
}
}

/**
* Initialize cloud profile synchronization when CloudService is ready
* This method is called externally after CloudService has been initialized
*/
Copy link

Choose a reason for hiding this comment

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

Consider enhancing this comment to explain why this deferred initialization pattern is necessary. For example: 'Initialize cloud profile synchronization when CloudService is ready. This method is called externally after CloudService has been initialized to handle the race condition where ClineProvider may be created before CloudService.'

public async initializeCloudProfileSyncWhenReady(): Promise<void> {
try {
if (CloudService.hasInstance() && CloudService.instance.isAuthenticated()) {
await this.syncCloudProfiles()
}

if (CloudService.hasInstance()) {
CloudService.instance.off("settings-updated", this.handleCloudSettingsUpdate)
CloudService.instance.on("settings-updated", this.handleCloudSettingsUpdate)
Copy link

Choose a reason for hiding this comment

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

Is this intentional? The method removes and then immediately re-adds the "settings-updated" event listener (lines 321-322). This could lead to duplicate listeners if initializeCloudProfileSyncWhenReady() is called multiple times. Consider tracking whether a listener is already registered or using a flag to prevent duplicate registrations.

}
} catch (error) {
this.log(`Failed to initialize cloud profile sync when ready: ${error}`)
}
}

// Adds a new Task instance to clineStack, marking the start of a new task.
// The instance is pushed to the top of the stack (LIFO order).
// When the task is completed, the top instance is removed, reactivating the
Expand Down
9 changes: 9 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ export async function activate(context: vscode.ExtensionContext) {
// Add to subscriptions for proper cleanup on deactivate.
context.subscriptions.push(cloudService)

// Trigger initial cloud profile sync now that CloudService is ready
try {
await provider.initializeCloudProfileSyncWhenReady()
} catch (error) {
outputChannel.appendLine(
`[CloudService] Failed to initialize cloud profile sync: ${error instanceof Error ? error.message : String(error)}`,
Copy link

Choose a reason for hiding this comment

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

The error is caught and logged, but should the extension take any recovery action here? If cloud profile sync is critical for certain features, users might want to know if it fails during startup. Consider whether a user notification would be appropriate for this failure case.

)
}

// Finish initializing the provider.
TelemetryService.instance.setProvider(provider)

Expand Down
Loading