Skip to content

fix: Fix 'Restart Workspace from Local Devfile' for empty workspace use case#746

Open
RomanNikitenko wants to merge 3 commits into
che-incubator:mainfrom
RomanNikitenko:fix-restart-for-empty-ws
Open

fix: Fix 'Restart Workspace from Local Devfile' for empty workspace use case#746
RomanNikitenko wants to merge 3 commits into
che-incubator:mainfrom
RomanNikitenko:fix-restart-for-empty-ws

Conversation

@RomanNikitenko

@RomanNikitenko RomanNikitenko commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

  • Problem: I found that Restart Workspace from Local Devfile command hangs when used in workspaces without a pre-cloned git repo. The restartWorkspace() method calls stopWorkspace via the extension host, but the extension host dies when the workspace stops, leaving the await hanging forever — the browser never redirects.
  • Fix: Stop the workspace via the Dashboard REST API directly from the browser side, instead of going through the extension host. Poll the Dashboard API for workspace STOPPED status, then redirect.

What issues does this PR fix?

https://redhat.atlassian.net/browse/CRW-9559

How to test this PR?

Restart Workspace from Local Devfile use case

  1. Go to the Dashboard
  2. Set quay.io/che-incubator-pull-requests/che-code:pr-746-amd64 in the Editor Image field
  3. Click Empty Workspace
  4. Click Clone Repository in the Explorer when the workspace starts
  5. Set https://github.com/RomanNikitenko/web-nodejs-sample.git => Clone from URL => Select as Repository Destination: /projects => Add to Workspace
  6. F1 => Restart Workspace from Local Devfile

Expected result:

  • the workspace should be restarted successfully
  • Cannot reconnect. Please reload the window. dialog is not displayed.

Stop Workspace command use case

Stop Workspace command is also affected by the current PR changes

  1. Go to the Dashboard
  2. Set quay.io/che-incubator-pull-requests/che-code:pr-746-amd64 in the Editor Image field
  3. Create any workspace
  4. F1 => Stop Workspace when the workspace is ready to use

Expected result:

  • the workspace should be stopped successfully
  • user should be redirected to the dashboard

Does this PR contain changes that override default upstream Code-OSS behavior?

  • the PR contains changes in the code folder (you can skip it if your changes are placed in a che extension )
  • the corresponding items were added to the CHANGELOG.md file
  • rules for automatic git rebase were added to the .rebase folder

Summary by CodeRabbit

  • New Features

    • Workspace stop and restart actions now use the dashboard’s browser-side API for smoother control and more reliable state handling.
    • A stopping indicator is now tracked so the app can better avoid duplicate disconnect handling during shutdown.
  • Bug Fixes

    • Improved workspace shutdown flow to wait for the stopped state or time out gracefully before redirecting.
    • Reduced reliance on client-side polling and command execution for stop/restart behavior.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Click here to review and test in web IDE: Contribute

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@tolusha

tolusha commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Hi! I'm che-ai-assistant — I help with your pull requests.

Available commands:

  • /che-ai-assistant generate-che-doc — Generate a documentation PR based on this PR's changes
  • /che-ai-assistant ok-pr-review — Run a comprehensive PR review (summary, code review, deep review, impact analysis)
  • /che-ai-assistant check-pr-test-failures — Analyze failing CI checks, identify root causes, and suggest fixes
  • /che-ai-assistant help — Show this help message

Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
Assisted-by: Cursor AI
@RomanNikitenko RomanNikitenko force-pushed the fix-restart-for-empty-ws branch from 1f574dd to da5028b Compare July 6, 2026 10:28
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

…r restarts a workspace

Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
Assisted-by: Cursor AI
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@RomanNikitenko RomanNikitenko marked this pull request as ready for review July 7, 2026 11:56
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@RomanNikitenko, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6d72e0f5-9369-4648-b3eb-d9339a32b269

📥 Commits

Reviewing files that changed from the base of the PR and between f1b5ee3 and c50f5ae.

📒 Files selected for processing (1)
  • code/src/vs/workbench/contrib/remote/browser/che/devWorkspaceAssistant.ts
📝 Walkthrough

Walkthrough

DevWorkspaceAssistant is updated to stop and restart the dev workspace using the Che Dashboard browser-side PATCH API instead of a remote command with client-side polling. New polling constants and an _isStopping state with public getter are added, along with stopWorkspaceViaDashboardApi() and waitForStopped() methods. The constructor no longer requires ICommandService. In remote.ts, the DevWorkspaceAssistant instantiation is updated accordingly, and CheDisconnectionHandler.handle() now skips processing when isStopping is true.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CheDisconnectionHandler
  participant DevWorkspaceAssistant
  participant DashboardApi

  CheDisconnectionHandler->>DevWorkspaceAssistant: stopWorkspaceAndRedirectToDashboard()
  DevWorkspaceAssistant->>DevWorkspaceAssistant: set _isStopping = true
  DevWorkspaceAssistant->>DashboardApi: PATCH /spec/started=false
  DevWorkspaceAssistant->>DevWorkspaceAssistant: redirect to dashboard

  Note over CheDisconnectionHandler: subsequent handle() calls
  CheDisconnectionHandler->>DevWorkspaceAssistant: check isStopping
  DevWorkspaceAssistant-->>CheDisconnectionHandler: true (skip further handling)
Loading

Alterations to the declarations of exported or public entities

  • DevWorkspaceAssistant constructor in code/src/vs/workbench/contrib/remote/browser/che/devWorkspaceAssistant.ts
    • Before: constructor(commandService: ICommandService, requestService: IRequestService, environmentVariableService: IEnvironmentVariableService, progressService: IProgressService)
    • After: constructor(requestService: IRequestService, environmentVariableService: IEnvironmentVariableService, progressService: IProgressService)
  • New public getter isStopping added to DevWorkspaceAssistant.

Suggested labels: che, remote, bug

Suggested reviewers: che-incubator maintainers familiar with remote workbench and dev workspace lifecycle

Poem:
A workspace once stopped with a command and a wait,
Now PATCHes the Dashboard to seal its own fate.
No more setInterval ticking away,
Just polling for STOPPED, then off to redirect and away!
🐰 stops, restarts, and hops to the dashboard's embrace.


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Title check ❌ Error The title is relevant but exceeds the 72-character limit and is more verbose than required. Shorten it to an imperative summary under 72 characters, e.g. "Fix restart workspace for empty local devfile".
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Rebase Rules For Upstream Changes ✅ Passed Only Che-only code/.../browser/che/* files changed; no upstream counterpart or new .rebase routing is needed, and the upstream wrapper already has existing rebase handling.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@code/src/vs/workbench/contrib/remote/browser/che/devWorkspaceAssistant.ts`:
- Around line 150-155: The timeout handling in waitForStopped() currently
resolves after STOP_TIMEOUT_MS for every caller, which allows the flow around
the start/navigation path to continue while the workspace is still stopping.
Update the stop-wait logic in DevWorkspaceAssistant.waitForStopped and the
caller near the navigation/start sequence so that a timeout does not trigger a
restart or proceed to start; instead, only continue once the stopped state is
actually observed, or fail/abort the flow when the stop timeout is reached.
- Around line 196-205: The restart/stop flow leaves _isStopping stuck true when
stopWorkspaceViaDashboardApi or waitForStopped rejects, which keeps
CheDisconnectionHandler.handle() from recovering. Update doRestart and
stopWorkspaceAndRedirectToDashboard to reset _isStopping on failure, preferably
by wrapping the stop/poll sequence in try/finally or equivalent error handling
so the flag is cleared whenever the operation does not complete successfully.
- Around line 136-143: The stop request in devWorkspaceAssistant should fail
fast when the PATCH does not succeed, because requestService.request may resolve
with a non-2xx response context and the flow can continue incorrectly. Update
the request handling in the stop path around requestService.request in
devWorkspaceAssistant to inspect context.res.statusCode after the PATCH, and
throw an error before any redirect or restart logic continues when the status
indicates failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 90df71f6-afa8-459a-8103-fc849729b915

📥 Commits

Reviewing files that changed from the base of the PR and between 828719e and f1b5ee3.

📒 Files selected for processing (2)
  • code/src/vs/workbench/contrib/remote/browser/che/devWorkspaceAssistant.ts
  • code/src/vs/workbench/contrib/remote/browser/che/remote.ts

Comment thread code/src/vs/workbench/contrib/remote/browser/che/devWorkspaceAssistant.ts Outdated
Comment thread code/src/vs/workbench/contrib/remote/browser/che/devWorkspaceAssistant.ts Outdated
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
Assisted-by: Cursor AI
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants