Skip to content

Commit f998e54

Browse files
Ambient Code Botclaude
andcommitted
fix(runner): fix credential retry error message and observability end_turn import
- auth.py: don't retry with fresh CP token when caller-token BOT_TOKEN fallback fails; preserve that path's original error message - observability.py: guard claude_agent_sdk import in end_turn with try/except so Langfuse generation.update() is still called when the SDK is not installed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8af45d4 commit f998e54

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

components/runners/ambient-runner/ambient_runner/observability.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,19 @@ def end_turn(
515515
return
516516

517517
try:
518-
from claude_agent_sdk import TextBlock
518+
# Extract text content — TextBlock is optional (claude_agent_sdk may not be installed)
519+
try:
520+
from claude_agent_sdk import TextBlock as _TextBlock
521+
except ImportError:
522+
_TextBlock = None
519523

520-
# Extract text content
521524
text_content = []
522525
message_content = getattr(message, "content", []) or []
523526
for blk in message_content:
524-
if isinstance(blk, TextBlock):
527+
if _TextBlock is not None and isinstance(blk, _TextBlock):
525528
text_content.append(getattr(blk, "text", ""))
529+
elif hasattr(blk, "text") and isinstance(getattr(blk, "text", None), str):
530+
text_content.append(blk.text)
526531

527532
output_text = (
528533
"\n".join(text_content) if text_content else "(no text output)"

components/runners/ambient-runner/ambient_runner/platform/auth.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,6 @@ def _do_req():
174174
try:
175175
with _urllib_request.urlopen(fallback_req, timeout=10) as resp:
176176
return resp.read().decode("utf-8", errors="replace")
177-
except _urllib_request.HTTPError as fallback_err:
178-
if fallback_err.code in (401, 403):
179-
return _retry_with_fresh_bot_token(fallback_err.code)
180-
logger.warning(
181-
f"{credential_type} BOT_TOKEN fallback also failed: {fallback_err}"
182-
)
183-
raise PermissionError(
184-
f"{credential_type} authentication failed: caller token expired "
185-
f"and BOT_TOKEN fallback also failed"
186-
) from fallback_err
187177
except Exception as fallback_err:
188178
logger.warning(
189179
f"{credential_type} BOT_TOKEN fallback also failed: {fallback_err}"

0 commit comments

Comments
 (0)