fix(a2a): delegate_task returns str(result) for empty-parts responses
Some checks failed
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 16s
sop-tier-check / tier-check (pull_request) Failing after 16s
audit-force-merge / audit (pull_request) Has been skipped

Before:
  return parts[0].get("text", "(no text)") if parts else str(data["result"])

When parts=[] (empty list), this falls through to str(data["result"]),
which always returns "(no text)" for the SSOT parse result variant.

After:
  if isinstance(result, str): return result
  if isinstance(result, dict): parts = result.get("parts", []); ...
  return str(result)

Fixes the regression where {"result": {"parts": []}} returns "(no text)"
instead of the actual string result body. Also correctly handles
plain-string result bodies ({"result": "my response"}).

Fixes molecule-core#279.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Molecule AI · infra-runtime-be 2026-05-10 09:48:36 +00:00
parent 8f6e6d6ecc
commit 02fb193847

View File

@ -66,8 +66,19 @@ async def delegate_task(workspace_id: str, task: str) -> str:
)
data = a2a_resp.json()
if "result" in data:
parts = data["result"].get("parts", [])
return parts[0].get("text", "(no text)") if parts else str(data["result"])
result = data["result"]
# String result: return it directly (handles empty-parts case
# where the platform returns {"result": "my response"}).
if isinstance(result, str):
return result
# Dict result: extract text from parts[0], fall back to str(result).
if isinstance(result, dict):
parts = result.get("parts", [])
if parts and isinstance(parts[0], dict):
return parts[0].get("text", "(no text)")
return str(result)
# Any other type: fall back to string representation.
return str(result)
elif "error" in data:
return f"Error: {data['error'].get('message', str(data['error']))}"
return str(data)