Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 8, 2026

Related GitHub Issue

Closes: #10436

Roo Code Task Context (Optional)

This PR was created by Roomote to address the reported issue.

Description

This PR attempts to address Issue #10436 where the extension hangs during activation on OSS Code (Arch Linux) with a btrfs filesystem.

Root Cause Analysis:
The safeWriteJson function uses proper-lockfile for advisory locking during JSON file operations. On btrfs (and potentially other copy-on-write filesystems), the stale lock detection mechanism may not work correctly because:

  1. btrfs has different mtime update characteristics due to Copy-on-Write semantics
  2. Lock files from previous crashes or updates may persist and not be detected as stale

Solution:
Added a cleanupStaleLocks() function that:

  • Scans the global storage directory for .lock files/directories created by proper-lockfile
  • Removes any locks older than the stale timeout (31 seconds, matching the lockfile config)
  • Is called early in extension activation, before any safeWriteJson operations
  • Handles both directory and file locks
  • Supports recursive scanning of subdirectories
  • Fails gracefully to not block activation if cleanup encounters errors

Key implementation details:

  • The cleanup runs synchronously at startup to ensure a clean state before file operations
  • Uses the same stale timeout as proper-lockfile (31 seconds) for consistency
  • Logs removed locks to help diagnose issues
  • Does not remove recent locks (within the stale window) to avoid interfering with legitimate concurrent operations

Test Procedure

  1. Unit tests added covering:

    • Empty/non-existent directories
    • Stale vs recent lock detection
    • Directory and file lock removal
    • Recursive scanning behavior
    • Custom stale duration
    • Error handling
  2. To manually test the fix:

    • On a btrfs filesystem, install the extension
    • Force-kill VS Code during extension activation
    • Restart VS Code - the extension should activate without hanging

Run the tests:

cd src && npx vitest run utils/__tests__/safeWriteJson.test.ts

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 - No UI changes.

Documentation Updates

  • No documentation updates are required.

Additional Notes

This is an attempt to address the issue based on the user's feedback that:

  • The hang occurs during extension activation after installation
  • It's specific to Roo Code (not other extensions)
  • The user is on a btrfs filesystem

Feedback and guidance are welcome!

Get in Touch

Roomote Bot


Important

Introduces cleanupStaleLocks() to remove stale lock files during extension activation, preventing hangs on btrfs filesystems.

  • Behavior:
    • Adds cleanupStaleLocks() in safeWriteJson.ts to remove stale lock files older than 31 seconds.
    • Invoked in activate() in extension.ts to prevent hangs on btrfs during extension activation.
    • Logs the number of removed locks and handles errors without blocking activation.
  • Tests:
    • Adds unit tests in safeWriteJson.test.ts for cleanupStaleLocks() covering scenarios like empty directories, stale lock detection, recursive cleaning, and error handling.
  • Misc:
    • Exports LOCK_STALE_MS constant in safeWriteJson.ts.

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

… hangs on btrfs

On btrfs and other copy-on-write filesystems, the proper-lockfile library's
stale lock detection may not work correctly. This can cause the extension
to hang indefinitely during activation after updates or crashes.

This fix adds a cleanupStaleLocks() function that:
- Scans for .lock directories/files created by proper-lockfile
- Removes locks older than the stale timeout (31 seconds)
- Handles both directory and file locks
- Supports recursive scanning

The cleanup is called early in extension activation, before any
safeWriteJson operations, to ensure a clean state.

Fixes #10436
@roomote
Copy link
Contributor Author

roomote bot commented Jan 8, 2026

Rooviewer Clock   See task on Roo Cloud

Reviewed the stale lock cleanup implementation. The approach is sound and addresses the reported btrfs hang issue. Found one minor code quality suggestion.

  • Consider using LOCK_STALE_MS constant in safeWriteJson function instead of hardcoded 31000 value to keep both usages synchronized

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

* The stale timeout for locks in milliseconds (must match the value in safeWriteJson).
* Locks older than this are considered abandoned and can be safely removed.
*/
const LOCK_STALE_MS = 31000
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The safeWriteJson function still uses a hardcoded 31000 value for the stale option (line 49). Consider updating it to use LOCK_STALE_MS to keep both values synchronized and avoid potential inconsistencies if one is changed without the other.

Suggested change
const LOCK_STALE_MS = 31000
const LOCK_STALE_MS = 31_000

Fix it with Roo Code or mention @roomote and request a fix.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Updating on OSS Code, Arch Linux requires OSS code to be forecfully terminated. Update seems to hang.

3 participants