DeepTutor icon indicating copy to clipboard operation
DeepTutor copied to clipboard

[Bug]: Half-open Mastery Path for learner accounts — sessions composer stuck on 403s from admin-gated init calls; grant vocabulary lacks the learning surface

Open zhuoran opened this issue 3 weeks ago • 7 comments

Description

On a vanilla deployment, learner accounts end up in a half-open state around the /learning (mastery path / practice) pages:

  • Learners can open /learning pages, and the mastery APIs themselves return 200 for them (GET /api/mastery-paths/topics, GET /api/mastery-paths/progress/{path_id}/board, POST /topics/draft + /topics).
  • But an admin cannot grant access to that area: the grantable surface vocabulary does not include it — LEARNING_SURFACES = {"books", "chat", "reading"} in deeptutor/multi_user/grants.py, the same trio hardcoded in the device-credential surface check (auth.py), and mirrored by the frontend types (allowed_surfaces: Array<"chat" | "reading">).
  • And the mastery sessions page breaks for learners: during page initialization the frontend calls a set of endpoints that return 403 for learner accounts while returning 200 for standard (non-admin) accounts:
403 /api/settings
403 /api/settings/workspace/registrations
403 /api/settings/workspace/resources
403 /api/settings/chat-attachments
403 /api/tools
403 /api/capabilities/registered
403 /api/partners
403 /api/partner-groups
403 /api/space/mcp/servers
403 /api/subagents/settings
403 /api/subagents/connections

The page does not tolerate these failures: the outline renders, but the composer stays stuck in a "Not sent" draft — the message can never be sent, and refresh / discard draft / retype does not recover it.

Decisive control, same learner account, clean session: /chat sends fine; /learning/mastery/{pathId}/sessions gets stuck. The same sessions page works fully for an admin account.

Steps to reproduce

  1. Deploy 1.7.1 via Docker, enable multi-user auth, configure any LLM.
  2. Admin creates a learner and grants it one LLM model via PUT /api/multi-user/users/{id}/grants (default learning policy; surfaces ["chat","reading"] — all valid today).
  3. As the learner, create a mastery path via POST /api/mastery-paths/topics/draft + /topics (both 200).
  4. Open /learning/mastery/{pathId}/sessions as the learner and send a message: stuck "Not sent". Repeat as admin: works.

Expected Behavior

One of two consistent states:

  • Learners are meant to use mastery paths: the surface vocabulary includes it (backend enum, device check, frontend types), and the learner page skips or gracefully degrades the admin-gated init calls above (none of them are needed to compose a session message).
  • Or mastery paths are not for learners yet: the learner navigation hides /learning/* and the learner-facing mastery routes are rejected, so the half-open state is unreachable.

We run the first variant as a hotfix in production (add the surface to the enum + grant it) and learners use mastery paths fine for everything except the stuck composer, which is what the second half of this report is about.

Related Module

Guided Learning

Configuration Used

Multi-user auth; learner preset with one granted OpenAI-compatible LLM; mastery path created by the learner account itself.

Logs and screenshots

The 403 block above is taken from server access logs during page init (learner session). Screenshot of the stuck composer state available (can attach).

Additional Information

  • DeepTutor Version: 1.7.1 (Docker, ghcr.io/hkuds/deeptutor); both the surface enum and the settings/tools/partners/mcp/subagents role gates verified unchanged at v1.7.2 (60fb3bdf)
  • Operating System: Linux (Docker host)
  • Browser: Chromium

zhuoran avatar Nov 12 '26 05:11 zhuoran

B4_learner-mastery-sessions-stuck

zhuoran avatar Nov 12 '26 05:11 zhuoran

Confirmed the code references against current dev, with two additions — one narrowing part (a), one that explains why the composer looks "stuck" instead of telling the learner why.

Part (a) — the surface vocabulary, confirmed plus one gap you didn't mention:

  • deeptutor/multi_user/grants.py:25 — LEARNING_SURFACES = {"books", "chat", "reading"} ✓
  • Grants are validated against it twice: input validation (grants.py:363-367, api/routers/multi_user.py:118-122) ✓
  • The runtime gate is deeptutor/multi_user/learning_access.py:68: if surface not in set(policy.get("allowed_surfaces") or ["chat", "reading"]) ✓
  • Additional inconsistency: the frontend type is narrower than the backend, not just mirrored — web/features/multi-user/types.ts:25 declares allowed_surfaces: Array<"chat" | "reading">, which doesn't even admit "books", and the GrantEditor default (GrantEditor.tsx:46) follows it. So a grant that uses the "books" surface the backend accepts is unrepresentable in the frontend types today.

Whichever variant you pick, the vocabulary needs to be decided in one place and mirrored: backend enum + device-credential check + runtime gate + frontend type.

Part (b) — why the composer renders as a stuck "Not sent" draft instead of an error:

The mastery composer is not a separate pipeline — MasteryComposer.tsx:90-129 sends through useChatStateAdapter().sendMessage, the same admission path as /chat. So the learner-vs-admin divergence must be in server-side turn admission (or in init state that gates the send), not in a different composer.

What makes it look stuck rather than failed:

  1. sendMessage persists the submission to localStorage before attempting the send (ChatStateAdapter.tsx:3441-3451), and a rejected admission flags the row via STREAM_END { submissionFailed: true } (ChatStateAdapter.tsx:2416-2465). On reload the durable record re-flags the row — which is exactly why "refresh does not recover it": the record isn't the bug, the recurring admission rejection is.
  2. The rejection's real reason is only ever a 10-second toast (ChatStateAdapter.tsx:2425); the persistent banner hardcodes the transport copy (ChatWorkspace.tsx:2859-2888). This is the same funnel as #2637 — the server's start_turn_rejected content is delivered but then discarded from the persistent UI. Whatever admission check is rejecting the learner's mastery turn is currently invisible, which is why this reads as a frozen composer rather than a refusal with a message.
  3. One more silent mask: MasteryStudy.tsx:430-438 returns false from submit without any feedback when sessionError is set — if any of the 403'd init calls flip that flag, sends are dropped before admission with no toast at all.

Concrete next step to pin the server side: the rejection text is being delivered — catch it in the 10-second toast, or watch the unified WS frames in devtools (terminal error event, error_code=start_turn_rejected); that string names the failing admission check. Candidates in request_preparer.start_turn: workspace-binding mismatches (lines 248-258), validate_chat_binding (269-276), and the LLM grant gate (550-553). Given that your hotfix added the surface and the composer still sticks, I'd suspect a check consulting workspace/resource state a learner can't reach — consistent with your 403'd /api/settings/workspace/* family — but the rejection text will say definitively.

Note the fix overlap: making the banner carry the server's rejection text (the #2637 fix) would make this failure self-explanatory too — the learner would see the actual reason next to the composer instead of a connection claim.

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

Your mechanism analysis matches our browser observations exactly — refresh / discard draft / retype never recovers, and the durable localStorage record re-flagging explains why.

One more narrowing data point: the same learner account sends fine on /chat (admission passes there) and sticks only on the mastery sessions page — so the failing check differs by page init state, consistent with your workspace-resource suspicion over the LLM grant gate.

We have a vanilla repro instance and will capture the start_turn_rejected terminal event to pin the exact admission check. Will report the string here.

zhuoran avatar Nov 13 '26 04:11 zhuoran

Captured it. The rejection string is:

This learning account cannot use this mode. Please choose an allowed learning mode.

Root cause is a second closed vocabulary next to the surface set: LEARNING_CAPABILITIES = {"chat", "immersive_reading"} (grants.py:22). The mastery composer submits with capability: "mastery_path", which apply_learning_policy (learning_access.py:41-44) rejects for any learner policy — and grant writes validate allowed_capabilities against the same set (grants.py:352), so mastery_path can neither be granted nor admitted. That is why the composer still sticks after the surface enum is extended.

Verified end-to-end on a derived instance: extending LEARNING_CAPABILITIES with "mastery_path" and adding it to the learner's allowed_capabilities lets the same learner account send on the mastery sessions page — the turn is admitted, tutor tools run, the reply streams. (The same account worked on /chat throughout, which matches your page-init-state narrowing.)

So the learner-facing mastery gap decomposes into three independent layers:

  1. LEARNING_SURFACES missing "learning" — grant vocabulary for the surface;
  2. LEARNING_CAPABILITIES missing "mastery_path" — turn admission; the actual stuck-composer trigger;
  3. the rejection-surfacing funnel you described (10-second toast + hardcoded transport banner) — turns a clear refusal into an invisible stuck draft; same fix as #2637.

(1) and (2) are one-line vocabulary extensions each; we run them in our deployment branch and can send them as a PR (together with the frontend type sync you flagged, including the missing "books") if that direction is confirmed.

zhuoran avatar Nov 13 '26 05:11 zhuoran

That capture settles it — and my workspace-resource suspicion was wrong: it's a second closed vocabulary, not a resource reach. Your three-layer decomposition is exactly the shape to act on:

  1. LEARNING_SURFACES — grant vocabulary (your PR).
  2. LEARNING_CAPABILITIES — the actual stuck-composer trigger (your PR) — apply_learning_policy at learning_access.py:41-44 rejecting capability: "mastery_path" is the admission check the rejection string names.
  3. The rejection-surfacing funnel — the 10-second toast + hardcoded transport banner that turned a clear refusal into an invisible stuck draft.

To keep the work independent: I'll take (3) as the #2637 PR — carrying the server's rejection text through STREAM_END into the submission banner (with the fallback only when there is no server text). With (3) landed, even before (1)+(2) ship, a learner hitting this sees "This learning account cannot use this mode. Please choose an allowed learning mode." next to the composer instead of a connection claim — and once (1)+(2) land, the same surface will be silent because admission succeeds.

One coordination note: (3) is pure frontend (state carry-through in ChatStateAdapter.tsx + the banner in ChatWorkspace.tsx), so it won't conflict with the vocabulary change on the backend — both can go in parallel.

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

Layer (3) is up: PR #2664 — admission rejections now carry the server's text into the submission banner, with the connection copy as fallback only. Frontend-only, so it can land in parallel with your (1)+(2) vocabulary PR without touching the backend.

With it in place, the failure you captured renders as "This learning account cannot use this mode. Please choose an allowed learning mode." next to the composer instead of a connection claim — and after your vocabulary change lands, admission succeeds and the banner never appears.

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

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

will be fixed in the next releases!

pancacake avatar Nov 14 '26 16:11 pancacake