Skip to content

Jetbrains Autocomplete Crash Prevention #5825

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

RomneyDa
Copy link
Collaborator

@RomneyDa RomneyDa commented May 24, 2025

This was a primarily AI-generated PR. Had Claude analyze #5819 and it came up with this analysis and solution:

AI analysis

After analyzing the code, I can identify several potential issues that could be causing crashes and conflicts with other JetBrains extensions:

Race Conditions in Lookup Management: The AutocompleteLookupListener uses an AtomicBoolean for tracking lookup state, but there's a potential race condition in the state management. The isLookupEmpty() function might return incorrect values if called between state changes.

Inlay Rendering Conflicts: The ContinueInlayRenderer doesn't check for existing inlays from other extensions before rendering, which could cause visual conflicts or crash when multiple extensions try to render inlays at the same position.

Interference with IDE's Native Completion: The AutocompleteService attempts to handle both native IDE completions and Continue's completions simultaneously, which can lead to conflicts. The shouldSkipRender check might not be sufficient to prevent all edge cases.

Resource Cleanup Issues: In AutocompleteService, the cleanup of inlays isn't always guaranteed in all code paths, especially during error conditions. This could lead to memory leaks or visual artifacts.

Thread Safety Concerns: The code mixes UI thread operations with background processing without proper synchronization in some places.

These changes address the main issues by:

Adding proper thread synchronization with a dedicated lock object
Improving state management for lookup tracking
Adding checks for conflicting inlays from other extensions
Ensuring cleanup happens in a thread-safe manner
Adding error handling and cleanup in failure cases
Using WriteAction.runAndWait instead of WriteAction.run to ensure proper sequencing
Additionally, you should consider adding these settings to give users more control:

Add a setting to control the delay before showing completions to avoid conflicts with IDE completions
Add a setting to control whether Continue completions should show while IDE completions are active
Add a setting to control the maximum number of concurrent inlays allowed
These changes should significantly reduce crashes and conflicts with other JetBrains extensions while maintaining the core functionality of the Continue autocomplete feature.

The main cause of the crashes appears to be race conditions and improper handling of concurrent modifications to the editor's inlay model when multiple extensions are active. The solution focuses on proper synchronization and conflict prevention rather than trying to force compatibility in all cases.


Summary by cubic

Improved JetBrains autocomplete stability by fixing race conditions, adding thread safety, and preventing conflicts with other extensions.

  • Bug Fixes
    • Added locks and better state tracking to avoid race conditions.
    • Prevented inlay rendering conflicts with other extensions.
    • Ensured proper cleanup and error handling to reduce crashes.

@RomneyDa RomneyDa requested a review from a team as a code owner May 24, 2025 00:46
@RomneyDa RomneyDa requested review from tomasz-stefaniak and removed request for a team May 24, 2025 00:46
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 24, 2025
Copy link

netlify bot commented May 24, 2025

Deploy Preview for continuedev canceled.

Name Link
🔨 Latest commit 4645d6e
🔍 Latest deploy log https://app.netlify.com/projects/continuedev/deploys/683116df19d2070008d67707

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

1 participant