Skip to content

fix: handle stale locks and missing ui_messages.json on startup #6027

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Jul 21, 2025

Summary

This PR fixes the gray screen issue that occurs when ui_messages.json is missing but lock files remain in the task directory.

Problem

When VS Code crashes or the Remote Extension Host is killed mid-task:

  • Lock files remain in the task directory
  • ui_messages.json may be missing
  • On reload, Roo Code tries to acquire locks but fails repeatedly with "Lock file is already being held"
  • The UI becomes unresponsive (gray screen)

Solution

  1. Startup Scan: Added stale lock detection on extension activation that scans task directories for orphaned locks
  2. Automatic Recovery:
    • Removes lock files older than 10 minutes when ui_messages.json is missing
    • Creates an empty ui_messages.json to restore functionality
  3. Preventive Guard: Updated safeWriteJson to create the target file before lock acquisition

Changes

  • Added staleLockRecovery.ts utility module with detection and recovery logic
  • Integrated stale lock recovery into extension activation
  • Modified safeWriteJson to handle missing files gracefully
  • Added comprehensive tests for all new functionality

Testing

  • ✅ All existing tests pass
  • ✅ Added new tests for stale lock detection and recovery
  • ✅ Added tests for safeWriteJson file creation behavior
  • ✅ Linting and type checking pass

Fixes #6022


Important

Fixes gray screen issue by detecting and recovering from stale lock files and missing ui_messages.json on startup.

  • Behavior:
    • On startup, detects and recovers from stale lock files in task directories if ui_messages.json is missing.
    • Removes lock files older than 10 minutes and creates an empty ui_messages.json to restore functionality.
    • Integrated recovery process into extension activation in extension.ts.
  • Utilities:
    • Added staleLockRecovery.ts for stale lock detection and recovery logic.
    • Modified safeWriteJson to create target file before lock acquisition.
  • Testing:
    • Added tests for stale lock detection and recovery in staleLockRecovery.test.ts.
    • Added tests for safeWriteJson behavior in safeWriteJson.staleLock.test.ts.

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

- Add stale lock detection on extension activation
- Automatically recover by removing stale locks and creating empty ui_messages.json
- Update safeWriteJson to create file before lock acquisition
- Add comprehensive tests for stale lock recovery

Fixes #6022
@roomote roomote bot requested review from mrubens, cte and jr as code owners July 21, 2025 17:05
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Jul 21, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 21, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Draft / In Progress] in Roo Code Roadmap Jul 22, 2025
@hannesrudolph hannesrudolph added PR - Draft / In Progress and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 22, 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 PR - Draft / In Progress size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
Status: PR [Draft / In Progress]
Development

Successfully merging this pull request may close these issues.

Gray Screen & Repeated Lock Errors When ui_messages.json Is Missing
2 participants