DeepTutor icon indicating copy to clipboard operation
DeepTutor copied to clipboard

[Bug]: Chat reports generic "Couldn't reach the server" when a learner account has no LLM model granted

Open zhuoran opened this issue 3 weeks ago • 4 comments

Description

When a learner account has no LLM model granted (models.llm = [] in its grant), sending a chat message fails with a generic connection error:

Couldn't reach the server. Please check your connection and retry.

with a "Resend" affordance. This points the user (and anyone triaging) at the network, when the actual cause is that no language model is available to the account. The same UI string is used for real transport failures, so the two cases are indistinguishable from the outside.

Steps to reproduce

  1. Deploy 1.7.1 via Docker, enable multi-user auth, configure an LLM provider as admin.
  2. Create a learner account; in PUT /api/multi-user/users/{id}/grants leave models.llm empty (default learning policy).
  3. Log in as the learner, open Chat, send any message.
  4. The message drops to a "Not sent" draft with the connection-error message above; retrying repeats the same failure.

Expected Behavior

A distinct, actionable error, e.g. "no language model is available for this account — ask an administrator to grant one", shown once without a resend loop. The role gating itself is fine; the issue is error classification/surfacing.

Related Module

Frontend/Web

Configuration Used

Multi-user auth; learner preset; empty models.llm grant; one OpenAI-compatible LLM profile configured as admin.

Logs and screenshots

Access log during the failed send shows the WebSocket accepted ("WebSocket /ws" [accepted]) — nothing distinguishes this failure from a healthy session server-side, which makes support triage harder. Screenshot of the chat error state available (can attach).

Additional Information

  • DeepTutor Version: 1.7.1 (Docker, ghcr.io/hkuds/deeptutor)
  • Operating System: Linux (Docker host)
  • Browser: Chromium

zhuoran avatar Nov 12 '26 05:11 zhuoran

B2_learner-no-model-chat-error

zhuoran avatar Nov 12 '26 05:11 zhuoran

Confirmed against current dev — the misclassification is real, and here is the exact funnel. The backend already classifies this failure; the client then discards the classification.

1. Server side sends a distinct, terminal rejection. deeptutor/services/session/turns/request_preparer.py:550-553 — for a non-admin with no usable LLM grant:

if not has_capability_access("llm"):
    raise RuntimeError(
        "No LLM model is assigned to your account. Please contact an administrator."
    )

deeptutor/api/routers/unified_ws.py:229-236 catches that RuntimeError at admission and emits it as a terminal error with error_code="start_turn_rejected", carrying the actionable text as the event content.

2. The client toasts the real message — for 10 seconds — then throws it away. web/features/chat/ChatStateAdapter.tsx:2411-2426 recognizes start_turn_rejected as a submission rejection: it toasts the server's text (line 2425), but the persistent STREAM_END dispatch (lines 2459-2465) sets submissionFailed: true without errorMessage.

3. The banner the user actually reads only knows transport failures. web/features/chat/components/ChatWorkspace.tsx:2859-2888 renders the submission-failure banner from local flags alone and defaults to the hardcoded transport copy — "Couldn't reach the server. Please check your connection and retry." (line 2875) — with the Resend affordance.

So the actionable message is demoted to a 10-second toast while the persistent UI element — the one users read and screenshot — claims a network problem. This also explains your server-side observation ("WebSocket accepted, nothing distinguishes this failure"): an admission rejection is not a transport event, so nothing transport-shaped shows up in the logs.

Fix shape (minimal, keeps #1594 semantics intact): carry the server's rejection text through the funnel — dispatch STREAM_END with errorMessage: event.content when submissionRejected, and in the banner render state.submissionErrorMessage ?? t("Couldn't reach the server. Please check your connection and retry."). Optionally drop the now-duplicate toast. Note this is general, not just for the no-model case: any future start_turn_rejected reason (workspace changed, protocol errors) currently gets the same network-failure masquerade. The unsent row + Resend behavior from #1594 is unaffected.

Happy to open a PR against dev with the two-line state change plus a regression test (no-model grant → banner shows the server's text, not the connection copy) if this direction is acceptable.

00xcyd avatar Nov 13 '26 04:11 00xcyd

Implemented as proposed: PR #2664 — the server's rejection text now rides STREAM_END onto the flagged unsent row and renders in the banner, with the transport copy kept as the fallback for genuine connection failures (both covered by regression tests). The #1594 unsent-row + Resend semantics are unchanged, and the same fix de-masks the mastery-side rejection captured in #2638.

00xcyd avatar Nov 13 '26 11:11 00xcyd

Verified fixed on the current local dev branch (a3dde93ffa50), with regression checks.

will be fixed in the next releases!

pancacake avatar Nov 14 '26 16:11 pancacake