Skip to content

[Feature] Add workspace doctor command for health diagnostics and autofix#164

Merged
JonnyTran merged 15 commits intodevelopfrom
copilot/add-doctor-command-for-workspaces
Nov 23, 2025
Merged

[Feature] Add workspace doctor command for health diagnostics and autofix#164
JonnyTran merged 15 commits intodevelopfrom
copilot/add-doctor-command-for-workspaces

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Description

Adds extralit workspaces doctor CLI command to diagnose and autofix workspace infrastructure issues, particularly S3 bucket configurations that can break after environment changes or manual deletions.

Related Tickets & Documents

Closes #

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Implementation

Server API

  • Endpoint: POST /api/v1/workspaces/{workspace_id}/doctor?autofix=true
  • Health Checks:
    • S3 bucket existence (autofix: creates bucket with versioning)
    • Bucket versioning policy (informational)
    • RQ worker pool connectivity (informational)
    • Elasticsearch dataset indexes (informational)

Client & CLI

  • WorkspacesAPI.doctor(workspace_id, autofix=True) method
  • CLI command with rich table output showing check results, status emojis, and fix indicators

Usage

# Auto-fix mode (default)
extralit workspaces --name my-workspace doctor

# Diagnostic only
extralit workspaces --name my-workspace doctor --no-autofix
result = client.workspaces.doctor(workspace.id, autofix=True)
for check in result.checks:
    print(f"{check.check_name}: {check.status} - {check.message}")

Steps to QA

  1. Create a workspace, manually delete its S3 bucket
  2. Run extralit workspaces --name test doctor
  3. Verify bucket is recreated and all checks display properly
  4. Run --no-autofix variant, confirm no autofix occurs

Added/updated tests?

  • Yes
  • Unit tests: 5 test cases covering healthy/unhealthy scenarios, auth, autofix behavior
  • Integration tests: CLI command execution with both flags

Added/updated documentations?

  • Yes
  • CLI guide: usage examples and check descriptions
  • Workspace guide: programmatic API usage

Checklist

Original prompt

This section details on the original issue you should resolve

<issue_title>Create a extralit workspaces doctor command to autofix missing bucket issues</issue_title>
<issue_description>When a workspace is created, extralit-server automatically creates a S3 bucket (or equivalent with LocalFileClient), but the bucket may be deleted or has other environments env vars broken. Creating a extralit workspaces --name {ws_name} doctor CLI command can help users check that the S3 bucket exists for the workspace, and if it doesn't exist, then autofix it by creating one (provided the user's role has permission).

It may also display other useful status information, though these checks doesn't need autofix yet:

  • The s3 bucket has appropriate proper file versioning policy
  • Show that the connection to RQ worker pool from extralit_server.jobs.queues import DEFAULT_QUEUE works
  • The workspace's datasets has elasticsearch indexes (only do this task if straightforward)

You'll need to modify files at extralit/src/extralit/cli (see existing patterns using Typer CLI) to call APIs defined in extralit-server/src/extralit_server/api/handlers/v1/files.py and extralit-server/src/extralit_server/api/handlers/v1/workspaces.py</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: Python Backend and SDK Developer
Implements high-quality, maintainable code following clean architecture principles with pragmatic documentation


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 6 commits November 18, 2025 07:58
Co-authored-by: JonnyTran <4750391+JonnyTran@users.noreply.github.com>
Co-authored-by: JonnyTran <4750391+JonnyTran@users.noreply.github.com>
Co-authored-by: JonnyTran <4750391+JonnyTran@users.noreply.github.com>
Co-authored-by: JonnyTran <4750391+JonnyTran@users.noreply.github.com>
Co-authored-by: JonnyTran <4750391+JonnyTran@users.noreply.github.com>
Co-authored-by: JonnyTran <4750391+JonnyTran@users.noreply.github.com>
Copilot AI changed the title [WIP] Add extralit workspaces doctor command for bucket autofix [Feature] Add workspace doctor command for health diagnostics and autofix Nov 18, 2025
Copilot AI requested a review from JonnyTran November 18, 2025 08:15
Copy link
Contributor

@Sparshr04 Sparshr04 left a comment

Choose a reason for hiding this comment

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

Thanks @JonnyTran for kicking off this feature!

I tested the extralit workspaces doctor command locally and found one integration issue on the client side.

Originally in the the CLI was calling client.workspaces.doctor(...) but, client.workspaces (fromextralit/src/extralit/client/resources.py) is the high-level resource manager and does not expose doctor(). The actual low-level API wrapper (which does include .doctor() and .get_by_name()) is located at client.api.workspaces (at extralit/src/extralit/_api/_workspaces.py)

So I switched the CLI to use the low-level WorkspacesAPI, which does include .get_by_name() and .doctor() updating the extralit/src/extralit/cli/workspaces/__main__.py file.

Essentially I replaced high-level resource manager with low-level WorkspacesAPI

api = client.api.workspaces
workspace_obj = api.get_by_name(workspace.name)
doctor_response = api.doctor(workspace_obj.id, autofix=autofix)

@Sparshr04
Copy link
Contributor

Hey @JonnyTran, thanks for your patience on this one! The debugging took way longer than expected.

Fixed failing integration tests for the workspaces doctor command by switching from subprocess-based testing to Typer's CliRunner.

I mainly had to tweak the extralit/tests/integration/conftest.py file and the extralit/tests/integration/test_cli_commands.py file.

  1. Used CliRunner instead of run_cli_command() to keep tests in-process where httpx_mock works
  2. Added proper mock responses for /api/v1/me/workspaces endpoint with required fields (inserted_at, updated_at)
  3. Added workspace_id to doctor endpoint mock responses to match Pydantic validation requirements

Both test variants --autofix and --no-autofix now pass 🚀

@JonnyTran JonnyTran marked this pull request as ready for review November 23, 2025 18:21
@JonnyTran JonnyTran requested review from a team as code owners November 23, 2025 18:21
- Updated user guide to clarify CLI usage for workspace diagnostics.
- Removed redundant code and comments in workspace model and API handler.
- Enhanced test CLI commands for better readability and consistency.
- Streamlined the doctor method in WorkspacesAPI for better readability.
- Enhanced test fixtures for workspace creation and cleanup in integration tests.
- Removed unnecessary comments and consolidated code for clarity.
…formatting

- Changed default value of the autofix option to False for the workspace doctor command.
- Removed unnecessary status emoji from the output for clearer diagnostics.
- Cleaned up whitespace for improved code readability.
- Updated the command line interface documentation to include the new --autofix option for the workspace doctor command.
- Cleaned up test method formatting for improved readability in the workspace doctor tests.
- Ensured proper formatting in package-lock.json by adding a newline at the end of the file.
@JonnyTran JonnyTran merged commit b84aa8b into develop Nov 23, 2025
9 checks passed
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.

Create a extralit workspaces doctor command to autofix missing bucket issues

3 participants

Comments