OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: `ov` CLI collapses multiple distinct backend errors into misleading "无法连接 OpenViking" message

Open livechenjt-prog opened this issue 4 months ago • 1 comments

[Bug]: ov CLI collapses multiple distinct backend errors into misleading "无法连接 OpenViking / Cannot connect to OpenViking"

Bug Description

The ov CLI (v0.4.8.dev0) displays a single generic error message for at least three distinct backend failure modes, making it very hard to diagnose which one actually occurred:

╭─ 连接错误 ────────────────────────────────────────────────╮
│ 无法连接 OpenViking。服务器可能未启动,或当前配置指向了错误的 URL。 │
╰───────────────────────────────────────────────────────────╯

下一步:
  ov config validate  检查当前配置
  ov health           快速检查服务器健康状态
  ov config switch    切换到其他配置

The "next step" hints all point at connection/config problems, but the real error is usually none of those — it's a server-side timeout, path-lock contention, or queue backpressure. The user (or an agent) wastes minutes running ov config switch, restarting, or re-authenticating, none of which help.

Reproduce

Reproducer 1 — path_lock contention (most common):

# Same target URI, rm followed immediately by add-resource
ov rm viking://resources/myproj/ --recursive --wait --timeout 60
sleep 5
ov add-resource /tmp/newfile.md \
  --to viking://resources/myproj/newfile.md \
  --wait --timeout 300
# → "无法连接 OpenViking"

Reproducer 2 — queue backpressure during heavy Semantic-Nodes work:

# Large file (500KB+ markdown) already in-flight, semantic indexing queue with pending > 500
# Immediately try a second add-resource to the same parent
ov add-resource /tmp/another.md --to viking://resources/myproj/another.md --wait --timeout 30
# → "无法连接 OpenViking"
# But server is healthy, and API returned DEADLINE_EXCEEDED

Reproducer 3 — Resource busy on fresh short op right after a large delete:

ov add-resource /tmp/small.md --to viking://resources/myproj/small.md --wait --timeout 30
# → CONFLICT: Resource is busy (visible sometimes)
# → 无法连接 OpenViking (other times, same underlying condition)

Expected Behavior

Each backend condition should map to a distinct CLI error message with a matching next-step hint:

Real backend error Preferred CLI message Next-step hint
DEADLINE_EXCEEDED: Queue processing timed out after Ns 处理超时 (队列繁忙) / Processing timed out (queue busy) ov observer queue
path_lock timeout on /local/.../subtree 目录锁冲突 / Path lock contention ov status --verbose | grep -A5 lock
CONFLICT: Resource is busy: <uri> 资源忙 (并发操作冲突) / Resource busy (concurrent op in flight) Wait/retry with backoff
Transport error (ConnectError / ECONNREFUSED / 5xx) Current 无法连接 OpenViking Current ov config validate / ov health

Only the last one should point at config/URL/service-down. The first three should point at server-side observation tools, not config.

Actual Behavior

All four map to the same generic "Cannot connect" message with config-related next steps.

Evidence — real session, 2026-07-15 15:26-15:45

  • CLI reports: 无法连接 OpenViking on ov add-resource and ov rm
  • ov health passes (已连接(健康), server 0.4.7, API key auth OK)
  • ov config validate passes (有效, 可连接, 健康)
  • ov observer queue shows:
    |     Queue      | Pending | In Progress | Errors |
    |   Embedding    |    0    |      0      |   0    |
    |    Semantic    |    2    |      4      |   0    |
    | Semantic-Nodes |   688   |      4      |   0    |
    
  • ov status --verbose shows 3 stale locks in /local/default/user/hermes/memories, Duration > 449s, Idle > 100s
  • Server journalctl -u openviking shows repeated:
    [TREE] Timeout waiting for lock on: /local/default/user/hermes/memories/tools
    [TREE] Timeout waiting for lock on: /local/default/user/hermes/memories/events
    
    at 2026-07-15 15:26:15 through 15:33:26.
  • Direct HTTP probe returns DEADLINE_EXCEEDED: Queue processing timed out after 30.0s for the same request that CLI shows as "无法连接".

So the CLI is receiving a specific structured error from the API and choosing to render it as a generic connection error.

Impact

  • Agents (Hermes / Claude Code / IDE integrations) that parse ov stderr can't distinguish transient backpressure from a real outage → they trigger the wrong recovery action (config switch, service restart, credential refresh) instead of the correct one (wait, retry with backoff, check queue).
  • Human operators waste minutes on false leads (ov config switch, re-issuing tokens) when the fix is simply to wait 30-60s for locks/queue to drain.
  • The "config-oriented" next-step hints actively mislead users away from ov observer queue and ov status --verbose, which are the two commands that would resolve the diagnosis in seconds.

Proposed Fix

In the CLI error rendering path (wherever the client SDK error is caught and formatted for display):

  1. Detect these API/SDK error classes distinctly:
    • DEADLINE_EXCEEDED (client timeout or server queue timeout)
    • RESOURCE_EXHAUSTED / CONFLICT: Resource is busy: ...
    • path_lock timeout (surfaced from the server as a structured error, if not already)
    • Transport-layer errors (ConnectionRefused, DNS, 5xx from a healthy /health)
  2. Render each with a specific message + specific next-step hint as sketched in the table above.
  3. Only fall through to the current generic "Cannot connect" message when the transport error is genuinely a connection failure (health check would also fail).

Falsification Signal

If main branch or an unreleased 0.4.9 has already refactored CLI error handling to separate these cases, this issue is redundant — please close and link the commit / PR.

Verification Signal

If accepted, the CLI running the reproducers above should return three different error messages instead of the current single generic one.

Environment

  • OpenViking server: v0.4.7 (self-hosted, local backend)
  • CLI: v0.4.8.dev0
  • OS: Linux
  • Deployment: single-node, systemd-managed, no S3
  • Concurrent clients during incident: 1 (single interactive session running ov rm + ov add-resource sequentially)

Related Issues (not duplicates)

  • #2699 (closed) — SemanticProcessor has no limit on concurrent DAG tasks causing lock contention — server-side root cause; this issue is complementary, focused on CLI-side error visibility rather than the concurrency limit itself.
  • #390 (closed) — Path locking and selective crash recovery for storage operations — server-side design; this issue asks that CLI surface those locks distinctly to the user.
  • #3122 (closed) — my earlier issue about restart-time queue avalanche and misleading FileExistsError — same theme (CLI error message quality), different trigger (steady-state contention vs restart).
  • #2383 (open) — repeated add_resource to same URI still reports Embedding queue work — closest to this issue but the observation is about queue accounting, not CLI error mapping.
  • #1705 (closed) — misleading NOT_FOUND for cross-account access — precedent of misleading error → user-visible fix.

Additional Context

Real agent transcript excerpt (paraphrased): after seeing "无法连接", the agent switched configs, revalidated credentials, and restarted the SSH shell — none of which changed anything, because the server was healthy the whole time. Only after running ov observer queue (not suggested in the CLI's next-step hint) did the root cause become obvious.

livechenjt-prog avatar Jul 15 '26 07:07 livechenjt-prog

Thanks for reporting this. The misleading connection-error classification is fixed by #3379.

Current CLI handling preserves structured server error codes and messages: queue wait failures remain DEADLINE_EXCEEDED, and resource/lock conflicts remain CONFLICT. Client request timeouts also have a separate timeout message instead of being reported as an inability to connect. The regression check confirming that structured API errors are not reclassified from their message text passes.

The additional queue/lock-specific titles and troubleshooting hints proposed here are not all implemented, but the original error-masking bug is resolved. Closing this issue on that basis.

qin-ctx avatar Sep 22 '26 07:09 qin-ctx