Skip to content

Conversation

@jimweller
Copy link

@jimweller jimweller commented Aug 18, 2025

Related GitHub Issue

Closes: # 7173

Roo Code Task Context (Optional)

N/A

Description

When using vscode setting roo-cline.customStoragePath there is a race condition in getStorageBasePath().

Update getStorageBasePath() to append a random suffix to .write_test file to prevent a race condition where concurrent operations want to read or remove the file.

add a test to verify functionality.

Test Procedure

cd src && npx vitest run utils/__tests__/storage.test.ts --reporter=verbose

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

n/a

Documentation Updates

Does this PR necessitate updates to user-facing documentation?

  • No documentation updates are required.
  • Yes, documentation updates are required. (Please describe what needs to be updated or link to a PR in the docs repository).

Additional Notes

n/a

Get in Touch

jim.weller


Important

Fix race condition in getStorageBasePath by appending unique suffix to test file, ensuring concurrent operations do not conflict.

  • Behavior:
    • Fix race condition in getStorageBasePath in storage.ts by appending unique suffix to .write_test file.
    • Ensures concurrent operations do not conflict when validating custom storage paths.
  • Testing:
    • Adds test in storage.test.ts to verify concurrent storage validations handle race conditions correctly.
    • Mocks VSCode and i18n modules to simulate environment.

This description was created by Ellipsis for 6f3f6eb. You can customize this summary. It will automatically update as commits are pushed.

@jimweller jimweller requested review from cte, jr and mrubens as code owners August 18, 2025 07:58
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 18, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! This PR effectively addresses the race condition issue in getStorageBasePath(). The fix is clean, minimal, and well-tested. I've left a few minor suggestions for potential improvements, but the current implementation looks solid and ready to merge.


// Test if path is writable
const testFile = path.join(customStoragePath, ".write_test")
// Test if path is writable (use unique filename to avoid race conditions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Great fix! Consider making the comment slightly more detailed to explain why we need the unique suffix, e.g.:

// Test if path is writable
const testFile = path.join(customStoragePath, ".write_test")
// Test if path is writable (use unique filename to avoid race conditions)
const uniqueSuffix = `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`
Copy link
Contributor

Choose a reason for hiding this comment

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

The unique suffix generation pattern works well. As a minor enhancement for future consideration, this could be extracted to a small utility function if similar unique ID generation is needed elsewhere in the codebase. But for a single use case, the current implementation is perfectly fine.

vi.restoreAllMocks()
})

it("should handle concurrent storage validations without race conditions", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent test coverage for the race condition scenario! For future enhancements, consider adding test cases for:

  • Custom path becoming inaccessible during runtime
  • Invalid/non-writable custom path handling
  • Fallback to default path when custom path fails

These would provide even more comprehensive coverage of edge cases.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 18, 2025
@jimweller
Copy link
Author

I actually like PR # 7164 better. It's more elegant and less intrusive.

#3788
#7173

@daniel-lxs
Copy link
Member

Closing in favor of #7164

@daniel-lxs daniel-lxs closed this Aug 19, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 19, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants