8000 [Bug]: Go CLI single-command mode panics without a command, appends the connection flags to the command, and cannot dispatch `ws`/`ws delete` · Issue #22651 · infiniflow/ragflow · GitHub
[go: up one dir, main page]

Skip to content

[Bug]: Go CLI single-command mode panics without a command, appends the connection flags to the command, and cannot dispatch ws/ws delete #22651

Open

Description

@ccclucky

Environment

RAGFlow main at d6fd68a88 (the refactor cli: single command change #22633), macOS arm64, CGO_ENABLED=0 go build -o ragflow-cli cmd/ragflow-cli.go.

What happens

CommandMode became the default mode in #22633 and the single-command wiring does not survive its own documented usage.

1. A bare ragflow-cli panics instead of opening the REPL. PrintUsage says "If no command is provided, CLI runs in interactive mode", and ParseArgs leaves Command nil in that case, but main dispatches on CLIMode == CommandMode:

$ ragflow-cli
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=...]
goroutine 1 [running]:
ragflow/internal/cli.(*CLI).RunSingleCommand(0x18?, 0x...)
        internal/cli/cli.go:928
main.main()
        cmd/ragflow-cli.go:74

Flag-only invocations panic the same way (ragflow-cli -v, ragflow-cli -o json). Even with the dispatch guarded, Run() has no CommandMode branch and replies unexpected CLI mode: command.

2. The connection flags are glued onto the command text. ParseArgs copies every argv entry into commandArgs for CommandMode, and unlike APIMode it never parses -h/-t/-u/-p/-f/-k, so the documented ragflow-cli -f rf.yml ls datasets form fails:

$ ragflow-cli -h 127.0.0.1:9380 ws ls
Command execution failed: expected command, got -

3. ws and ws delete <name> cannot be dispatched. ExecuteSingleCommand switches on "single_show_workspace" while the parser emits "single_show_current_workspace", and it has no case for "single_delete_workspace" at all, although SingleDeleteWorkspaceCommand exists:

$ ragflow-cli ws
Command execution failed: single command mode: single_show_current_workspace
$ ragflow-cli ws delete docs
Command execution failed: single command mode: single_delete_workspace

The other commands (ws ls, ws cat, ws search, ws find, ws use, ws new, ws save) reach their handlers.

Expected

  • No command → interactive REPL, as documented.
  • Connection flags configure the API client and never appear in the command text.
  • Every command type the single-mode parser emits has a handler.

Fix

All three are small wiring mistakes; a fix PR is linked below and covers them with tests (go test ./internal/cli/), including a red run against d6fd68a88.

Activity

  1. JinHai-CN commented on Nov 23, 2026

    @JinHai-CN
    Member

    SingleCommand mode is intended to prepare ragflow-cli for agent use, and the implementation in this PR does not align with that goal.

    ragflow-cli -o json ws ls
    ragflow-cli -f rf.yml ls datasets
    

    In SingleCommand mode, the server configuration is read from the default YAML file. The command-line argument is only the command itself.

  2. ccclucky commented on Nov 23, 2026

    @ccclucky
    ContributorAuthor

    @JinHai-CN Understood on the design: single-command mode reads the default rf.yml, and argv is the command itself.

    Current PR #22650 goes the other way in two places, and I will drop both: it parses -h/-t/-u/-p/-f/-k (letting -f point at another config file and logging in interactively when -u/-p are given); upstream main instead reads the fixed rf.yml and copies every argv entry into the command text.

    What I would keep from #22650, since it does not change where config comes from:

    • no command → interactive REPL instead of the RunSingleCommand nil dereference;
    • every command type the single-mode parser emits reaches its handler (ws, ws delete currently fail with single command mode: …);
    • reserved words (find, ws, new, …) still parse where a free-form word is expected.

    One point needs your call: should single-command mode accept the output switches (-o, --verbose) at all? Today ParseArgs parses them but leaves them in the command text, so ragflow-cli -o json ws ls fails with expected command, got -.

    1. Reject every leading switch with a clear message ("single-command mode reads rf.yml; pass only the command"), including -h/-t/-u/-p/-f/-k.
    2. Keep -o/--verbose as the only global switches and strip them from the command text, so an agent can ask for JSON.

    I will align #22650 with whichever you prefer; if it is (1) I will also make the connection flags fail with that message instead of being parsed.

  3. ccclucky commented on Nov 25, 2026

    @ccclucky
    ContributorAuthor

    Implemented in #22650 at 7194b50be, following your direction:

    • Single-command mode reads its settings from the default rf.yml only. -h/-t/-u/-p/-f/-k are rejected with single-command mode reads its settings from rf.yml; <flag> is not accepted, so -f can no longer point at another file and -u/-p no longer trigger an interactive login.
    • The command text is the argv words only. -o/--output, -v/--verbose, --help and --version remain global switches and are stripped, since your example shows ragflow-cli -o json ws ls as the agent-facing form; say the word if you would rather reject those too and I will drop them.
    • A rejected parse now prints the error instead of exiting silently, so the message is actually visible.
    • The rest of the PR is unchanged: no-command opens the REPL, ws / ws delete reach their handlers, and reserved words parse as names and one-word questions.

    Verification (local, CGO_ENABLED=0): go test -count=1 ./internal/cli/ → ok; go vet ./internal/cli/ → clean. Binary checks: ragflow-cli -f rf.yml ls datasets → the rf.yml rejection, exit 1; ragflow-cli -o json ws ls → command runs; bare ragflow-cli → RAGFlow(user)> REPL.

    The help text and PR description now document the single-command rule instead of the old -f rf.yml ... examples.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0