You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The component initializes Monaco models in OnInitializedAsync, but the @ref for the editor is typically not populated until after first render. This can cause the initial models/theme setup to be skipped (because _diffEditor is null) and never retried, leaving the editor without the expected content/models. Consider moving initialization to OnAfterRenderAsync (firstRender) and/or re-initializing when the reference becomes available.
protected override async Task OnInitializedAsync()
{
await Global.SetTheme(jsRuntime, "vs-dark");
await InitModels();
}
public async Task SetModels(string original, string modified)
{
await SetOriginalModel(original);
await SetModifiedModel(modified);
}
public async Task SetOriginalModel(string value)
{
if (_diffEditor is null)
return;
await _diffEditor.OriginalEditor.SetValue(value);
}
public async Task SetModifiedModel(string value)
{
if (_diffEditor is null)
return;
await _diffEditor.ModifiedEditor.SetValue(value);
}
private async Task InitModels()
{
if (_diffEditor is null)
return;
var originalModel = await Global.GetModel(jsRuntime, $"{Id}-original") ??
await Global.CreateModel(jsRuntime, InitOriginalContent, "markdown", $"{Id}-original");
var modifiedModel = await Global.GetModel(jsRuntime, $"{Id}-modified") ??
await Global.CreateModel(jsRuntime, InitModifiedContent, "markdown", $"{Id}-modified");
await _diffEditor.SetModel(new DiffEditorModel
{
Original = originalModel,
Modified = modifiedModel,
});
}
Loading the image via File.ReadAllBytes in a static field initializer relies on a relative path and executes at type-load time. This can fail depending on working directory and hosting model (and will throw early, potentially breaking page/component initialization). Consider embedding the asset, using an injected file provider, or resolving via AppContext.BaseDirectory/content root and handling missing file gracefully.
The retry loop uses ShouldRetry(finalContent, retryCount++) with MaxRetries = 2, which effectively allows an extra iteration compared to what the name suggests (and can also append duplicate chat history across retries). Consider making retry counting explicit (e.g., increment before check or use >=) and/or isolating chat history per attempt if you only want the final attempt’s messages.
string?finalContent=null;varretryCount=0;varchatHistory=newList<ChatItem>();do{varchat=PrepareAgentsChat(request);chat.AddChatMessage(offerMessage);if(request.OfferSummaryis not null){varsummaryMessage=newChatMessageContent(AuthorRole.User,$"offerSummary: {request.OfferSummary}");chat.AddChatMessage(summaryMessage);}varasyncResponse=chat.InvokeAsync(cancellationToken);awaitforeach(varresponseinasyncResponse){chatHistory.Add(ChatItem.From(response));finalContent=response.Content;}}while(ShouldRetry(finalContent,retryCount++));if(finalContentisnull||!finalContent.Contains(DoneSignal))returnnewResponse(false,"",chatHistory);varadjustedCv=finalContent.Replace(DoneSignal,"").Trim();returnnewResponse(true,adjustedCv,chatHistory);}privatestaticboolShouldRetry(string?lastContent,intretryCount){if(retryCount>MaxRetries)// accept content after max retriesreturnfalse;if(string.IsNullOrEmpty(lastContent))returntrue;if(lastContent.Contains(FailSignal,StringComparison.OrdinalIgnoreCase))returntrue;if(lastContent.Length<DoneSignal.Length+50)// CV should be significantly longer than just the signalreturntrue;returnfalse;}
Avoid reading files during type initialization, because a missing/relative path will throw and can crash the app on first access to TestData. Load the image lazily and resolve the path from AppContext.BaseDirectory, returning an empty array when the file is not found.
Why: File.ReadAllBytes(...) in a static readonly initializer can throw (missing file/relative path), causing failures as soon as TestData is accessed. Lazy-loading and resolving from AppContext.BaseDirectory meaningfully improves runtime robustness for this dev/test helper.
Medium
Avoid out-of-range and async issues
Guard the RemoveAt call to avoid an exception when chatHistory is empty (e.g., failed/short agent responses). Also await the editor update to ensure the UI is updated deterministically and avoid firing-and-forgetting a task.
-chatHistory.RemoveAt(chatHistory.Count - 1); // remove last item because it is CV content+if (chatHistory.Count > 0)+ chatHistory.RemoveAt(chatHistory.Count - 1); // remove last item because it is CV content+
ModifiedContent = result.AdjustedCvContent;
-_ =_diffEditor.SetModifiedModel(ModifiedContent);+if (_diffEditor is not null)+ await _diffEditor.SetModifiedModel(ModifiedContent);+
Suggestion importance[1-10]: 6
__
Why: chatHistory.RemoveAt(chatHistory.Count - 1) can throw if chatHistory is unexpectedly empty, and fire-and-forget _diffEditor.SetModifiedModel(...) can lead to nondeterministic UI updates. Guarding the removal and awaiting the editor update is a correct, low-risk stability improvement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.