Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: concurrency issue between catalog and inference manager #1216

Merged
merged 1 commit into from
Jun 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type { TaskRegistry } from '../../registries/TaskRegistry';
import { Messages } from '@shared/Messages';
import type { InferenceProviderRegistry } from '../../registries/InferenceProviderRegistry';
import type { InferenceProvider } from '../../workers/provider/InferenceProvider';
import type { CatalogManager } from '../catalogManager';

vi.mock('@podman-desktop/api', async () => {
return {
Expand Down Expand Up @@ -86,7 +87,15 @@ const inferenceProviderRegistryMock = {
get: vi.fn(),
} as unknown as InferenceProviderRegistry;

const catalogManager = {
onCatalogUpdate: vi.fn(),
} as unknown as CatalogManager;

const getInitializedInferenceManager = async (): Promise<InferenceManager> => {
vi.mocked(catalogManager.onCatalogUpdate).mockImplementation(fn => {
fn();
return { dispose: vi.fn() };
});
const manager = new InferenceManager(
webviewMock,
containerRegistryMock,
Expand All @@ -95,6 +104,7 @@ const getInitializedInferenceManager = async (): Promise<InferenceManager> => {
telemetryMock,
taskRegistryMock,
inferenceProviderRegistryMock,
catalogManager,
);
manager.init();
await vi.waitUntil(manager.isInitialize.bind(manager), {
Expand Down
7 changes: 5 additions & 2 deletions packages/backend/src/managers/inference/inferenceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { basename, dirname } from 'node:path';
import type { InferenceProviderRegistry } from '../../registries/InferenceProviderRegistry';
import type { InferenceProvider } from '../../workers/provider/InferenceProvider';
import type { ModelInfo } from '@shared/src/models/IModelInfo';
import type { CatalogManager } from '../catalogManager';

export class InferenceManager extends Publisher<InferenceServer[]> implements Disposable {
// Inference server map (containerId -> InferenceServer)
Expand All @@ -48,6 +49,7 @@ export class InferenceManager extends Publisher<InferenceServer[]> implements Di
private telemetry: TelemetryLogger,
private taskRegistry: TaskRegistry,
private inferenceProviderRegistry: InferenceProviderRegistry,
private catalogManager: CatalogManager,
) {
super(webview, Messages.MSG_INFERENCE_SERVERS_UPDATE, () => this.getServers());
this.#servers = new Map<string, InferenceServer>();
Expand All @@ -59,8 +61,9 @@ export class InferenceManager extends Publisher<InferenceServer[]> implements Di
this.podmanConnection.onMachineStart(this.watchMachineEvent.bind(this, 'start'));
this.podmanConnection.onMachineStop(this.watchMachineEvent.bind(this, 'stop'));
this.containerRegistry.onStartContainerEvent(this.watchContainerStart.bind(this));

this.retryableRefresh(3);
this.catalogManager.onCatalogUpdate(() => {
this.retryableRefresh(3);
});
}

public isInitialize(): boolean {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export class Studio {
this.#telemetry,
this.#taskRegistry,
this.#inferenceProviderRegistry,
this.#catalogManager,
);
this.#inferenceManager.init();
this.#extensionContext.subscriptions.push(this.#inferenceManager);
Expand Down