Skip to content

feat: stop command#31

Open
feloy wants to merge 1 commit intokortex-hub:mainfrom
feloy:stop
Open

feat: stop command#31
feloy wants to merge 1 commit intokortex-hub:mainfrom
feloy:stop

Conversation

@feloy
Copy link
Contributor

@feloy feloy commented Mar 9, 2026

Adds a workspace stop command and a stop alias, which removes the workspace from the list of workspaces

close #17

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

Warning

Rate limit exceeded

@feloy has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fbf70f25-0f40-41f8-bcf1-35fb9530cd72

📥 Commits

Reviewing files that changed from the base of the PR and between dcf71bd and 30a7ccf.

📒 Files selected for processing (6)
  • pkg/cmd/root.go
  • pkg/cmd/stop.go
  • pkg/cmd/stop_test.go
  • pkg/cmd/workspace.go
  • pkg/cmd/workspace_stop.go
  • pkg/cmd/workspace_stop_test.go
📝 Walkthrough

Walkthrough

Adds a new top-level stop command (alias) and a workspace stop subcommand that reads --storage, instantiates an instances.Manager, and deletes a workspace by ID, returning the ID on success or a user-friendly error when not found.

Changes

Cohort / File(s) Summary
Root Command Setup
pkg/cmd/root.go
Registers NewStopCmd() with the root command to expose a top-level stop alias.
Stop Command Alias
pkg/cmd/stop.go, pkg/cmd/stop_test.go
Adds NewStopCmd() that delegates to NewWorkspaceStopCmd(), copying handlers and flags; includes unit test verifying command wiring and parity.
Workspace Stop Implementation & Tests
pkg/cmd/workspace.go, pkg/cmd/workspace_stop.go, pkg/cmd/workspace_stop_test.go
Registers workspace stop subcommand; implements manager construction from --storage, instance deletion with ErrInstanceNotFound handling and concise output; extensive tests for argument validation, successful deletion, error paths, multi-instance scenarios, and alias behavior.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as Stop Command
    participant Manager as instances.Manager
    participant Storage as Storage (file system)

    User->>CLI: stop <workspace-id>
    CLI->>CLI: PreRunE: read --storage
    CLI->>Storage: NewManager(storageDir)
    Storage-->>Manager: manager instance
    CLI->>Manager: Delete(instanceID)
    alt Workspace Found
        Manager->>Storage: remove instance record
        Manager-->>CLI: success
        CLI-->>User: print workspace ID
    else Workspace Not Found
        Manager-->>CLI: ErrInstanceNotFound
        CLI-->>User: error + suggest "workspace list"
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: stop command' directly and clearly summarizes the main change—adding a new stop command feature to the CLI.
Description check ✅ Passed The description is related to the changeset; it explains that the PR adds a workspace stop command and a stop alias, which matches the code changes.
Linked Issues check ✅ Passed The PR implements the core requirements from issue #17: the stop command unregisters a workspace by UID (with proper error handling), uses the storage directory for persistence, and validates command arguments appropriately.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the stop command and its alias as specified in issue #17; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
pkg/cmd/workspace_stop_test.go (1)

43-114: Exercise (*workspaceStopCmd).preRun directly in the unit test.

Lines 43-114 still drive rootCmd.Execute(), so they only recheck Cobra wiring and never assert that preRun stores id and constructs manager on the command struct itself. A direct unit test here would isolate setup regressions from the E2E path. As per coding guidelines "Command tests should have two types of tests: unit tests that test the preRun method directly, and E2E tests that test full command execution via rootCmd.Execute()" and "In unit tests for commands, use t.Run() for subtests within a parent test function and verify struct fields are set correctly after preRun execution".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/cmd/workspace_stop_test.go` around lines 43 - 114, The tests currently
exercise the Cobra wiring via rootCmd.Execute() but do not unit-test
(*workspaceStopCmd).preRun directly; add a unit subtest that constructs the
workspace stop command struct (or obtains the *cobra.Command and its underlying
*workspaceStopCmd), sets Args to simulate one ID and sets the --storage flag to
a temp dir, then call workspaceStopCmd.preRun(cmd, args) directly and assert
that workspaceStopCmd.id equals the provided ID and workspaceStopCmd.manager is
non-nil (and can be used to find the instance); reference the preRun method and
the workspaceStopCmd.id and workspaceStopCmd.manager fields when locating code
to change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/cmd/workspace_stop.go`:
- Around line 46-50: The code constructs a new manager (instances.NewManager)
and immediately performs deletions without first reconciling stale/unreachable
workspace registrations; before calling the delete path (the code that invokes
manager.Delete in workspace_stop.go) invoke the manager's reconciliation routine
(e.g., Manager.Reconcile() or Manager.UnregisterInaccessible() — whichever is
implemented in pkg/instances/manager.go) right after w.manager = manager so that
inaccessible workspaces are unregistered and the subsequent calls to Delete
operate on up-to-date state.
- Around line 56-63: The stop command currently passes the raw argument to
Manager.Delete which only matches by GetID, so implement resolution of the
provided identifier to support both UID and workspace name: first try to find a
workspace whose GetID() equals the input, if not found iterate the manager's
listing (or call a GetByName helper if available) to match GetName() (or
equivalent) and use the found instance's ID when calling Manager.Delete; update
the workspaceStopCmd.run logic (and analogous branch at lines ~75-77) to perform
this lookup before Delete, and update the command Use/help text in the stop
command and corresponding tests to reflect that the command accepts either UID
or name.
- Around line 39-50: The --storage flag value (storageDir) must be normalized to
an absolute path in the command preRun before passing it to
instances.NewManager; import "path/filepath", call filepath.Abs(storageDir)
(handle and wrap any error) and use the absolute path when constructing the
manager (locations: the storageDir variable, preRun logic, and
instances.NewManager call).

---

Nitpick comments:
In `@pkg/cmd/workspace_stop_test.go`:
- Around line 43-114: The tests currently exercise the Cobra wiring via
rootCmd.Execute() but do not unit-test (*workspaceStopCmd).preRun directly; add
a unit subtest that constructs the workspace stop command struct (or obtains the
*cobra.Command and its underlying *workspaceStopCmd), sets Args to simulate one
ID and sets the --storage flag to a temp dir, then call
workspaceStopCmd.preRun(cmd, args) directly and assert that workspaceStopCmd.id
equals the provided ID and workspaceStopCmd.manager is non-nil (and can be used
to find the instance); reference the preRun method and the workspaceStopCmd.id
and workspaceStopCmd.manager fields when locating code to change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 17f8f19b-4f31-43fe-ba8c-f2ea4b20159d

📥 Commits

Reviewing files that changed from the base of the PR and between e6609e6 and 56cde4e.

📒 Files selected for processing (6)
  • pkg/cmd/root.go
  • pkg/cmd/stop.go
  • pkg/cmd/stop_test.go
  • pkg/cmd/workspace.go
  • pkg/cmd/workspace_stop.go
  • pkg/cmd/workspace_stop_test.go

@feloy feloy requested a review from benoitf March 9, 2026 14:33
Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

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

hello,

question: I would assume stop would stop the workspace but then I can resume the agent or restart it ? It's like going back to the 'init/stopped' state

I can then list all the agents, including the stopped one and decide or not to delete it. I could have an option delete on stop but I'm not sure it should be the default

if it's deleting the agent should it be a 'delete' or 'remove' option ?

@feloy
Copy link
Contributor Author

feloy commented Mar 9, 2026

hello,

question: I would assume stop would stop the workspace but then I can resume the agent or restart it ? It's like going back to the 'init/stopped' state

I can then list all the agents, including the stopped one and decide or not to delete it. I could have an option delete on stop but I'm not sure it should be the default

if it's deleting the agent should it be a 'delete' or 'remove' option ?

@slemeur WDYT? In https://redhat-internal.slack.com/archives/C09DNJCKZJQ/p1772793346412079?thread_ts=1772791436.021539&cid=C09DNJCKZJQ you are defining a STOP command, but no START or DELETE ones. Do we want to have an intermediary STOPPED level for a workspace? Or all existing workspaces will be running, and we delete them when we stop them?

Signed-off-by: Philippe Martin <phmartin@redhat.com>

Co-Authored-By: Claude Code (Claude Sonnet 4.5) <noreply@anthropic.com>
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.

instances management

2 participants