-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: improve command registration for slow environments like PROOT-distro/Termux #8817
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
base: main
Are you sure you want to change the base?
Conversation
…stro/Termux - Add early command registration before potentially blocking operations - Add timeout handling for MDM and ContextProxy initialization - Improve error handling in registerCommands to continue with partial functionality - Register placeholder handlers for critical commands as fallback - Re-register commands with proper handlers after provider initialization This ensures commands are available even on slow environments that may timeout during initialization. Fixes #8816
Review SummaryI've reviewed this PR and identified 3 issues that need to be addressed:
While the approach of early command registration is sound for addressing the PROOT-distro/Termux issue, the implementation has some critical flaws that will prevent it from working as intended. |
| context.subscriptions.push(vscode.commands.registerCommand(command, callback)) | ||
| try { | ||
| // Check if command already exists (might have been registered as placeholder) | ||
| const existingIndex = context.subscriptions.findIndex((sub) => (sub as any).command === command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command re-registration logic is broken because VSCode's Disposable objects don't have a command property. This findIndex will never find existing commands, meaning the disposal code on lines 77-80 will never execute. As a result, when commands are re-registered at line 303 in extension.ts, you'll get duplicate command registrations rather than replacements. VSCode command disposables are opaque objects - there's no way to introspect which command they represent. Consider maintaining a separate Map<string, Disposable> to track command registrations if you need to replace them.
| } catch (error) { | ||
| outputChannel.appendLine( | ||
| `[ContextProxy] Failed to initialize, using fallback: ${error instanceof Error ? error.message : String(error)}`, | ||
| ) | ||
| // Force creation even if slow | ||
| contextProxy = await ContextProxy.getInstance(context) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ContextProxy fallback after timeout could still hang indefinitely. If ContextProxy.getInstance() times out on line 124, the catch block on line 132 forces creation without any timeout protection. In slow environments like PROOT-distro/Termux (the issue this PR addresses), this could cause the same hang that the timeout was trying to prevent. Consider either accepting undefined for contextProxy when timeout occurs, or implementing a retry with exponential backoff rather than forcing immediate re-creation.
| for (const cmdId of criticalCommands) { | ||
| try { | ||
| const command = `${Package.name}.${cmdId}` | ||
| if (!context.subscriptions.find((sub) => (sub as any).command === command)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback command detection has the same issue as the main registration - checking (sub as any).command === command won't work because Disposables don't expose which command they registered. This means the if condition on line 181 will always be false, and you'll register duplicate placeholder commands every time this fallback executes. This could lead to multiple warning messages appearing when a user clicks a button. The safer approach would be to maintain a Set of registered command IDs to prevent duplicates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review complete. Found 3 issues that need to be addressed before this PR can be merged.
Summary
This PR addresses Issue #8816 by improving command registration to ensure commands are available even in slow or resource-constrained environments like PROOT-distro/Termux on mobile devices.
Problem
Users on PROOT-distro/Termux were experiencing a "command 'roo-cline.settingsButtonClicked' not found" error when clicking the settings button (and potentially other buttons) in the Roo Code extension. This issue began appearing in version 3.11.10.
Solution
The fix implements a multi-layered approach to ensure robust command registration:
1. Early Command Registration
2. Improved Error Handling
3. Timeout Protection
4. Command Re-registration
Changes
Testing
Impact
This change is backward compatible and non-breaking. It ensures the extension works reliably on:
Fixes #8816
Important
Improves command registration in slow environments by implementing early registration, error handling, and timeouts in
extension.tsandregisterCommands.ts.activate()inextension.tsto ensure availability in slow environments.MdmServiceand 10-second timeout forContextProxyinitialization inextension.ts.registerCommands()inregisterCommands.tsto allow partial functionality if some commands fail.outputChannelfor diagnostics.extension.ts: Implements early registration, timeouts, and re-registration logic.registerCommands.ts: Handles command registration and error logging.This description was created by
for ad846c8. You can customize this summary. It will automatically update as commits are pushed.