Quellcode durchsuchen

docs: clarify task hint session cache

jimmylee vor 2 Wochen
Ursprung
Commit
9fdf577ca0

+ 21 - 7
docs/superpowers/specs/2026-04-25-english-speaking-task-hint-modal-design.md

@@ -65,12 +65,15 @@ else:
   Backend reads session grade/topic/vocabulary/sentences
-  Single LLM request asks for JSON text
-    ↓
-  Backend parses + validates + normalizes
-    ↓
-  if valid: return normalized TaskHint
-  if invalid: return deterministic fallback TaskHint
+  if cached TaskHint exists for this session:
+    return cached TaskHint without calling the LLM
+  else:
+    Single LLM request asks for JSON text
+      ↓
+    Backend parses + validates + normalizes
+      ↓
+    if valid: persist and return normalized TaskHint
+    if invalid: persist and return deterministic fallback TaskHint
 ```
 
 ## Frontend Design
@@ -254,6 +257,14 @@ Response:
 
 The endpoint reads course variables from the existing session record. The frontend should not resend grade, topic, vocabulary, or sentences for this endpoint.
 
+The endpoint is idempotent per dialogue session:
+
+- If a task hint has already been generated or fallback-created for the session, return the stored `TaskHint` directly.
+- Do not call the LLM again for the same session after the first successful endpoint completion.
+- This backend cache is required in addition to the frontend's mounted-component cache, so refreshing the page or remounting the chat view still reuses the existing hint.
+
+Storage can be implemented with a JSON column on the dialogue session, a separate one-row-per-session table, or an existing session metadata store. For MVP, prefer the smallest storage change that fits the current backend schema.
+
 ## LLM Generation Strategy
 
 MVP decision:
@@ -265,6 +276,7 @@ Do not require provider-specific structured output.
 If the provider supports JSON mode, the backend may enable it.
 Regardless of provider support, always parse and validate server-side.
 On parse or validation failure, return deterministic fallback content.
+Persist whichever valid `TaskHint` is returned, including fallback.
 ```
 
 This keeps the MVP provider-agnostic while still benefiting from JSON mode when available in providers such as Qwen, DeepSeek, Kimi, or GLM.
@@ -335,6 +347,7 @@ The fallback does not need to be as polished as LLM output. It only needs to kee
 Backend:
 
 - Missing session: return 404.
+- Existing cached task hint: return it with 200 and skip LLM generation.
 - LLM provider/network failure: return fallback `TaskHint` with 200 unless the service cannot read the session.
 - LLM parse/schema failure: return fallback `TaskHint` with 200.
 - Unexpected server error before fallback construction: return 500.
@@ -356,6 +369,7 @@ Frontend:
 
 Backend:
 
+- Endpoint returns cached task hint without calling the LLM when one already exists for the session.
 - Endpoint returns generated valid task hint for valid LLM JSON.
 - Endpoint returns fallback when LLM returns malformed JSON.
 - Endpoint returns fallback when LLM returns valid JSON with missing fields.
@@ -368,6 +382,6 @@ Backend:
 2. Add real and mock API implementations.
 3. Extract `TaskHintModal.vue` from the inline modal markup/styles.
 4. Wire `DialogueChatView.vue` lazy-load state and button behavior.
-5. Add backend endpoint and service function.
+5. Add backend endpoint, service function, and per-session task-hint storage/cache.
 6. Add backend prompt, parse/validate/normalize/fallback logic.
 7. Add focused frontend and backend tests.