Skip to content

Conversation

@punkouter26
Copy link
Owner

This PR addresses build issues by updating the global.json to match the installed .NET SDK version. It also optimizes the application by changing several core services from Scoped to Singleton lifetime. This allows LyricsService to cache lyrics data and AudioSynthesisService to cache Azure Speech tokens effectively, which was not working correctly with Scoped lifetime. It also prevents unnecessary instantiation of AzureOpenAIClient on every request.


PR created automatically by Jules for task 6263618300052399737 started by @punkouter26

- Update `global.json` to use installed .NET SDK 10.0.100.
- Change `TranslationService`, `LyricsService`, `AudioSynthesisService`, and `DiagnosticService` lifetimes from Scoped to Singleton to enable proper caching and resource reuse.
- Ensure validators are also Singleton to match the service lifetime.

Co-authored-by: punkouter26 <[email protected]>
Copilot AI review requested due to automatic review settings January 28, 2026 15:11
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@@ -116,20 +116,20 @@
builder.Services.Configure<ApiSettings>(builder.Configuration.GetSection("ApiSettings"));

Choose a reason for hiding this comment

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

⚠️ Potential runtime failure due to missing or malformed configuration

The line builder.Services.Configure<ApiSettings>(builder.Configuration.GetSection("ApiSettings")); binds configuration to the ApiSettings class. If the ApiSettings section is missing or contains invalid values, this may result in runtime errors or misconfigured services. It is recommended to validate the configuration at startup and fail fast if required settings are missing or malformed. Consider adding explicit validation logic or using IOptions<ApiSettings> with validation:

builder.Services.AddOptions<ApiSettings>()
    .Bind(builder.Configuration.GetSection("ApiSettings"))
    .ValidateDataAnnotations()
    .ValidateOnStart();

This ensures configuration issues are detected early.

Comment on lines +119 to 135
builder.Services.AddSingleton<ITranslationService, TranslationService>();
builder.Services.AddSingleton<ILyricsService, LyricsService>();

// Register validation services
builder.Services.AddSingleton<ISpeechConfigValidator, SpeechConfigValidator>();
builder.Services.AddScoped<IAudioSynthesisService, AudioSynthesisService>();
builder.Services.AddSingleton<IAudioSynthesisService, AudioSynthesisService>();
builder.Services.AddSingleton<IInputValidator, InputValidator>();

// Register diagnostic validators
builder.Services.AddScoped<IDiagnosticValidator, AzureOpenAIDiagnosticValidator>();
builder.Services.AddScoped<IDiagnosticValidator, AzureSpeechDiagnosticValidator>();
builder.Services.AddScoped<IDiagnosticValidator, InternetConnectivityDiagnosticValidator>();
builder.Services.AddScoped<IConfigurationValidator, ConfigurationValidator>();
builder.Services.AddScoped<IDiagnosticService, DiagnosticService>();
builder.Services.AddSingleton<IDiagnosticValidator, AzureOpenAIDiagnosticValidator>();
builder.Services.AddSingleton<IDiagnosticValidator, AzureSpeechDiagnosticValidator>();
builder.Services.AddSingleton<IDiagnosticValidator, InternetConnectivityDiagnosticValidator>();
builder.Services.AddSingleton<IConfigurationValidator, ConfigurationValidator>();
builder.Services.AddSingleton<IDiagnosticService, DiagnosticService>();

// Register utility services
builder.Services.AddSingleton<ILyricsUtilityService, LyricsUtilityService>();

Choose a reason for hiding this comment

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

⚠️ Singleton lifetime may cause issues if services are not stateless or depend on scoped services

All core, validation, diagnostic, and utility services are registered as singletons. If any of these services maintain state or depend on scoped services (such as HttpContext or per-request data), this can lead to data races or incorrect behavior. Review the implementation of these services to ensure singleton lifetime is appropriate. If any service requires per-request data, consider using AddScoped instead.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the repository’s pinned .NET SDK version and adjusts DI registrations so core services can be reused/cached across requests instead of being re-instantiated per-scope.

Changes:

  • Pin global.json to .NET SDK 10.0.100.
  • Change several server-side services (translation/lyrics/speech + diagnostics) from Scoped to Singleton lifetimes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/PoVicTranslate.Web/Program.cs Switches multiple service registrations to Singleton to enable cross-request caching/reuse.
global.json Updates the pinned .NET SDK version used for builds.

// Register validation services
builder.Services.AddSingleton<ISpeechConfigValidator, SpeechConfigValidator>();
builder.Services.AddScoped<IAudioSynthesisService, AudioSynthesisService>();
builder.Services.AddSingleton<IAudioSynthesisService, AudioSynthesisService>();
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

IAudioSynthesisService is now registered as a singleton, but AudioSynthesisService maintains mutable shared state (_accessToken / _tokenExpiry) without any synchronization. Under concurrent requests this can lead to races and redundant token fetches, and (in the worst case) using a stale token for a request. Consider adding an async lock/semaphore around token refresh (or using IMemoryCache with a single-flight pattern) so token acquisition is thread-safe when used as a singleton.

Suggested change
builder.Services.AddSingleton<IAudioSynthesisService, AudioSynthesisService>();
builder.Services.AddScoped<IAudioSynthesisService, AudioSynthesisService>();

Copilot uses AI. Check for mistakes.
builder.Services.AddScoped<ITranslationService, TranslationService>();
builder.Services.AddScoped<ILyricsService, LyricsService>();
builder.Services.AddSingleton<ITranslationService, TranslationService>();
builder.Services.AddSingleton<ILyricsService, LyricsService>();
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

With ILyricsService switched to singleton, LyricsService's SemaphoreSlim will live for the entire app lifetime. Since SemaphoreSlim is disposable and LyricsService doesn't implement IDisposable/IAsyncDisposable, consider disposing it (or refactoring to an alternative async-lock approach) to avoid holding undisposed resources for the process lifetime.

Suggested change
builder.Services.AddSingleton<ILyricsService, LyricsService>();
builder.Services.AddScoped<ILyricsService, LyricsService>();

Copilot uses AI. Check for mistakes.
Comment on lines 2 to 5
"sdk": {
"version": "10.0.102",
"version": "10.0.100",
"rollForward": "latestPatch",
"allowPrerelease": false
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

global.json pins the SDK to 10.0.100 with rollForward: latestPatch. This setting will NOT roll forward to a different feature band (e.g., 10.0.102), so environments that only have newer 10.0.10x SDKs installed will fail with “SDK not found”. To keep builds resilient across dev/CI machines, consider using rollForward: latestFeature (or updating CI to install 10.0.100 specifically).

Copilot uses AI. Check for mistakes.
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.

2 participants