fix: TransferEncodingError on task extraction failure

- brain.py: unwrap JSON array responses from Claude (occasional array
  instead of object caused AttributeError → broken chunked stream)
- main.py: wrap extract_task_fields() in try/except so any extraction
  failure gracefully falls back to regex — generator always completes
- tools.py: _resolve_project() uses alphanumeric-stripped matching so
  "Generaladm" resolves to General/Admin via identifier prefix match.
  Word-overlap fallback added. Default changed from Agent Ecosystem to
  General/Admin (correct catch-all bucket)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-02 06:09:45 +00:00
parent 6cb29d94e6
commit 4a09def6dc
3 changed files with 33 additions and 5 deletions
+6 -2
View File
@@ -686,8 +686,12 @@ async def chat_completions(req: ChatRequest):
elif intent == "task":
# LLM extraction — handles any natural language phrasing
fields, usage = await extract_task_fields(user_message)
log_usage("task_extract", usage["prompt_tokens"], usage["completion_tokens"])
try:
fields, usage = await extract_task_fields(user_message)
log_usage("task_extract", usage["prompt_tokens"], usage["completion_tokens"])
except Exception as e:
logger.warning(f"extraction failed, falling back to regex: {e}")
fields = {}
title = fields.get("title") or extract_task_title(user_message)
project_hint = fields.get("project") or extract_project_name(user_message)