Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixes creating .csv file in OpenAIUsageDebuggingPlugin. Closes #1460#1463

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
waldekmastykarz wants to merge1 commit intodotnet:main
base:main
Choose a base branch
Loading
fromwaldekmastykarz:fix-openusagedebug-file

Conversation

@waldekmastykarz
Copy link
Collaborator

Fixes creating .csv file in OpenAIUsageDebuggingPlugin.Closes#1460

@waldekmastykarzwaldekmastykarz requested a review froma team as acode ownerNovember 28, 2025 14:47
CopilotAI review requested due to automatic review settingsNovember 28, 2025 14:47
Copilot finished reviewing on behalf ofwaldekmastykarzNovember 28, 2025 14:50
Copy link
Contributor

CopilotAI 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

This PR addresses issue#1460 by moving CSV file creation logic fromInitializeAsync toAfterResponseAsync in the OpenAIUsageDebuggingPlugin. The change ensures the output file is created on-demand when the first OpenAI request is processed, rather than during plugin initialization.

Key changes:

  • Removed theInitializeAsync override that created the CSV file with headers during plugin initialization
  • Added file existence check and header creation logic directly inAfterResponseAsync before appending usage data

You can also share your feedback on Copilot code review for a chance to win a $100 gift card.Take the survey.

awaitFile.AppendAllLinesAsync(outputFileName,[UsageRecord.GetHeader()],cancellationToken);
}

awaitFile.AppendAllLinesAsync(outputFileName,[usage.ToString()],cancellationToken);

Choose a reason for hiding this comment

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

Potential file corruption: The file append operation is not protected by any synchronization mechanism. If multiple requests are processed concurrently, their writes to the CSV file could interleave, corrupting the file format. Consider protecting both the header initialization and data appending with the same lock mechanism.

Copilot uses AI. Check for mistakes.
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based onthis feedback

Comment on lines +110 to +114
if(!File.Exists(outputFileName))
{
Logger.LogDebug("Creating output file {FileName} with header",outputFileName);
awaitFile.AppendAllLinesAsync(outputFileName,[UsageRecord.GetHeader()],cancellationToken);
}

Choose a reason for hiding this comment

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

Race condition: Multiple concurrent requests could pass theFile.Exists check simultaneously before the header is written, potentially causing the header to be written multiple times or file corruption. Consider using a lock or a flag to ensure thread-safe file initialization.

Example solution:

privatereadonlyobject_fileLock=new();privatebool_fileInitialized=false;// In AfterResponseAsync:if(!_fileInitialized){lock(_fileLock){if(!_fileInitialized){Logger.LogDebug("Creating output file {FileName} with header",outputFileName);awaitFile.AppendAllLinesAsync(outputFileName,[UsageRecord.GetHeader()],cancellationToken);_fileInitialized=true;}}}

Copilot uses AI. Check for mistakes.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG]: Dev Proxy creates .csv files without intercepting results

1 participant

@waldekmastykarz

[8]ページ先頭

©2009-2025 Movatter.jp