3.6 KiB
Summary task routing review — 2026-10-27
Cause and bounded production fix
The released 总结当前病情 shortcut sends the unchanged question 请根据当前病历总结患者病情、证候与风险。. It previously relied on free-text inference, where 证候 matched tcm_pattern before 总结 could match summary. This selected a full TCM report contract for a summary request.
app/src/doctor_workstation/ui/dialogs/ai_consult.py: the shortcut now captures an explicit stabletask="summary". Other shortcuts retain their existing task inference and local actions. The question bytes are unchanged.app/src/doctor_workstation/ui/dialogs/prescription_ai.py: summary intent now wins over incidental TCM evidence terms. Explicittcm_patternwording and complete TCM report requests retaintcm_pattern. Existing specific glucose, medication, complication, exam, prescription, guideline, lifestyle and case-analysis priorities remain in place.app/tests/test_ai_quick_tools_synthetic_contract.py: changed only the frozen expected task for this exact shortcut fromtcm_patterntosummary.
No PHP, Dify configuration, model selection, runtime logs, credentials, or live patient data were changed or accessed by this subtask. Existing unrelated working-tree changes were preserved. Repository AGENTS.md was read; .trellis/ is absent.
Verification
app/tests/test_ai_summary_task_routing.py adds 17 mixed-intent classifier cases and six actual workstation widget dispatch cases:
- Actual
总结当前病情button mouse click, while the classifier is deliberately forced to returntcm_pattern, still sendstask=summarythrough the real worker,RemoteDoctorRepository, API request builder and SSE parser. - Free-text send button uses the same unchanged question and sends
summary. - Explicit
_ask(..., task="tcm_pattern")remains authoritative. - All three entry paths cover streaming and missing-route legacy fallback. Exact prompt, diagnosis ID, task, response preservation, completed state, summary label and re-enabled send control are asserted. No model override is sent.
- Every HTTP request ends in a synchronous wrapper around
httpx.MockTransportat reserved hostexample.test, with synthetic text only.
Command from D:/web/zyt/app:
$env:PYTHONPATH = 'D:\web\zyt\app\.venv\Lib\site-packages;D:\web\zyt\app\src'
& ./.python/cpython-3.12.13-windows-x86_64-none/python.exe -m pytest tests/test_ai_summary_task_routing.py tests/test_prescription_ai_ui.py -q
Result: 39 passed (23 new routing checks and 16 existing prescription AI checks). New-test Ruff check and scoped git diff --check also passed.
The initial asynchronous MockTransport attempt could not complete in this sandbox. A bounded faulthandler probe located the block in Windows asyncio event-loop initialization at socket._fallback_socketpair() / accept(), before transport dispatch. Those attempts were stopped. The final fixture uses the synchronous mock transport and runs the real worker deterministically after the real button signal; it makes no production transport changes. The earlier broad offscreen run was interrupted and is not claimed as passed.
Independent read-only review confirmed the task binding and specific-task priority. Its missing-中医 marker finding was repaired and covered by the complete-Chinese-TCM-report case.
Practical limit
This proves desktop dispatch and repository routing using synthetic responses. It does not prove a live model answer, live backend validation, or the currently running workstation process has reloaded the source. Those checks remain with the parent runtime verification task.