Commit ff22ca6
Two #3185 LLMInterface-retirement misses shipped silently in the same
helper, causing chat() to silently return a canned "I'm currently
unable to generate a response" string for every user request:
Bug 1 — broken module path (api/chat.py:106):
from llm_service import LLMService # module never existed
Canonical path is services.llm_service. The import was inside
``get_llm_service()`` so it deferred to first call rather than
boot — silent until a chat request arrives, then ModuleNotFoundError.
Bug 2 — feature-degradation guard around a stale method (api/chat.py:543):
if hasattr(llm_service, "generate_response"):
return await llm_service.generate_response(...)
else:
return {"content": "I'm currently unable to generate a response..."}
LLMService doesn't expose generate_response (that was an LLMInterface
method). The hasattr guard always took the else branch, so every
request received the canned fallback regardless of whether LLMService
was healthy. Major user-facing functional regression.
Fix
---
1. Update lazy import to ``services.llm_service.LLMService``.
2. Replace the hasattr/else dance with a real ``llm_service.chat(...)``
call. Map LLMService's contract:
- messages ← llm_context (already OpenAI-format)
- conversation_id ← session_id (per-conversation overrides)
- request_id ← request_id (passes through **kwargs for tracing)
Read response.error / response.content per LLMResponse's Pydantic
model (verified shapes against services/llm_service.py:99-112).
3. User-facing fallback strings are unchanged on error — internal
error reasons are logged via ``logger.warning`` but never leaked
to the response.
Verification
------------
Added ``api/chat_generate_ai_response_test.py`` — 5 tests pinning the
contract:
- happy path: response.content surfaces as result["content"]
- chat() args: messages/conversation_id/request_id passed through
- LLM returns error: fallback string, error reason NOT leaked to user
- chat() raises: fallback string, exception detail NOT leaked
- **regression pin** for the original bug: hasattr(llm_service,
"generate_response") path can never silently swallow output again
— test fails if a future change reintroduces it
- **regression pin** for the import path: assert source contains
``from services.llm_service import LLMService``
$ python3 -m pytest autobot-backend/api/chat_generate_ai_response_test.py -xvs
============================== 5 passed in 2.80s ===============================
Per the feedback memory I just saved (verify_return_shape_in_method_migration):
- LLMResponse.content: str ✓ verified
- LLMResponse.error: Optional[str] ✓ verified
- chat() return type: LLMResponse (inspected via inspect.signature)
Closes #7047 (items 1 + 2). The remaining sites flagged in the issue
body (async_chat_workflow.py, modern_ai_integration.py,
nl_database_service.py) are tracked for separate per-site verification —
their contexts differ enough that batching them risks the same return-
shape miss this PR caught with tests.
Co-authored-by: t <t@t>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9d2348c commit ff22ca6
2 files changed
Lines changed: 160 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
548 | 553 | | |
549 | | - | |
| 554 | + | |
550 | 555 | | |
551 | 556 | | |
| 557 | + | |
552 | 558 | | |
553 | 559 | | |
554 | 560 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
0 commit comments