[Bug]: ConfirmTopicRequest rejects modules with >7 knowledge points, blocking structured-curriculum imports (edit path was relaxed in #1784)
Description
POST /api/mastery-paths/topics (ConfirmTopicRequest) rejects any module with more than 7 knowledge points, which makes it unusable as an import path for externally-authored curricula:
422 {"detail": "Route region 1 may have at most 7 waypoints; it has 10"}
We use this endpoint to inject a textbook-aligned primary-school math curriculum (284 knowledge points across 12 semester modules, ~24 points per module). Real curricula routinely exceed 7 points per module, so the whole import is blocked.
Steps to reproduce
- Deploy 1.7.1 via Docker, enable multi-user auth, configure any LLM.
- Create a mastery path via
POST /api/mastery-paths/topicswith amodulesarray where one module has 10 knowledge points (strict default). - The request is rejected wholesale with the error above.
Expected Behavior
The per-module waypoint cap should not apply (or should be configurable) when the caller supplies a fully-authored module structure instead of asking the model to generate a route.
Why the cap fits generation but not import
_MAX_OBJECTIVES_PER_MODULE(deeptutor/learning/topic_generation.py:35) exists to keep generated routes navigable — a fair constraint for LLM output.- The strict path already contradicts it internally: when editing existing modules, the limit is raised to the existing count (
objective_limit = max(objective_limit, existing_objective_counts.get(module_id, 0))) — this looks like the fix for #1784, where saved maps with >7 objectives per module could not be edited. So a module may legitimately hold >7 points once it exists — it just can't be created that way, which is what an import caller needs.
Possible directions: raise the default, parameterize the cap for import callers, or bypass it when every module in the request is caller-authored. We run a one-line hotfix (7 → 60) in production and outline/board/sessions all behave correctly with 24+ points per module. Happy to send a PR for whichever variant you prefer.
Related Module
Guided Learning
Configuration Used
Multi-user auth enabled; one OpenAI-compatible LLM profile; modules supplied client-side in ConfirmTopicRequest.
Logs and screenshots
Error above is the full response body. Nothing relevant in server logs beyond the 422.
Additional Information
- DeepTutor Version: 1.7.1 (Docker, ghcr.io/hkuds/deeptutor); cap verified unchanged at v1.7.2 (60fb3bdf)
- Operating System: Linux (Docker host)
- Deployment: self-hosted single container
- Related Issues: #1784 (edit-path counterpart, fixed via the existing-count relaxation)
Verified against current dev (v1.7.2, 60fb3bd) — the cap is unchanged, and the analysis above maps cleanly onto the code:
_MAX_OBJECTIVES_PER_MODULE = 7(deeptutor/learning/topic_generation.py:35) is enforced on the strict path at lines 391–397.- The edit-path relaxation the issue mentions lives at lines ~388–390:
objective_limit = max(objective_limit, existing_objective_counts.get(module_id, 0))— that's the #1784 fix, and it is the strongest internal evidence that a module legitimately holds >7 waypoints once it exists.
Given that, the variant that seems most consistent with the codebase's own precedent is the caller-authored bypass: when ConfirmTopicRequest supplies the full modules structure (i.e. the caller authors the route instead of asking the model to generate one), the waypoint cap should not apply — the same trust boundary the edit path already established. Concretely, the strict limit would key off whether the module content is caller-supplied rather than model-generated, so generated routes keep their navigability ceiling and imports of externally-authored curricula (12 modules × ~24 KPs) pass validation untouched.
A flat raise of the default would also work but would loosen the guard for genuinely generated routes too, which is the case the constant exists to protect.
@zhuoran — you mentioned being happy to send a PR for whichever variant is preferred; I'm equally glad to implement the caller-authored variant with tests if that helps avoid duplicated effort. Whichever way the maintainers lean, happy to coordinate.
Agreed — the caller-authored bypass is the right shape: it keeps the generation guard intact and extends the trust boundary the edit path already established in #1784. One practical note: a confirm payload is caller-supplied by definition (generation happens earlier, at the draft step), so implementing this as "the strict cap no longer applies to the materialize path, generation unchanged" should cover it.
Division of labor works for us: you implement with tests, we validate against our real-world payload (284 KPs / 12 modules, ~24 per module) on a vanilla deployment and report back. If the maintainers prefer otherwise or you'd rather not, we'll send the PR ourselves — whichever avoids duplication.
The implementation is up: #2663, and it lands exactly on the shape you described — the strict cap no longer applies to the materialize path on the confirm route (objective_cap=None), while draft generation (strict=False) and map edits keep the cap unchanged. The #1784 edit budget and test_edit_legacy_topic_map_cannot_add_a_ninth_objective stay green as deliberate no-changes.
Local suite: deeptutor/learning/tests/ 714 passed, including two new repro shapes at your scale — a ~24-waypoint region admitted whole (your ~24-per-module figure) and the 10-waypoint strict repro. The first head failed CI on ruff format; ca992b8 fixes that, but fork-run workflows sit in action_required until a maintainer approves them once, so local green is the current proof.
@zhuoran — your 284 KPs / 12 modules payload is the validation still missing; a deployment of #2663 is ready for it. @pancacake — if this lands on the dev branch instead, say the word and I will close #2663 the same way the other three went.