Skip to content

Commit 1935aa9

Browse files
committed
review (greptile): swallow metric-emission errors in except handler
If get_llm_metrics().requests.add() raises (misbehaving exporter, OTel SDK bug, network blip mid-export), the original LLM exception would be shadowed by the metric error. Callers — retry logic, circuit breakers, the OpenAI Agents Temporal plugin's retryable/non-retryable classifier — inspect the typed exception (RateLimitError, APITimeoutError, etc.) and would silently break with an unexpected OTel exception in its place. Wrap the .add() call in a bare try/except so the metric is best-effort and the typed LLM exception always propagates.
1 parent b08e48f commit 1935aa9

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/agentex/lib/core/temporal/plugins/openai_agents/models/temporal_streaming_model.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,16 @@ async def get_response(
10721072
logger.error(f"Error using Responses API: {e}")
10731073
# Emit a request-counter event so 429s, 5xxs, timeouts, etc. are
10741074
# observable on the SDK side. Status histograms / token counters
1075-
# only fire on successful completion above.
1076-
get_llm_metrics().requests.add(
1077-
1, {"model": self.model_name, "status": classify_status(e)}
1078-
)
1075+
# only fire on successful completion above. Wrapped in a bare
1076+
# try/except so a misbehaving exporter can't shadow the original
1077+
# LLM exception — callers (retry logic, circuit breakers) need
1078+
# to see the typed RateLimitError / APITimeoutError / etc.
1079+
try:
1080+
get_llm_metrics().requests.add(
1081+
1, {"model": self.model_name, "status": classify_status(e)}
1082+
)
1083+
except Exception:
1084+
pass
10791085
raise
10801086

10811087
# The _get_response_with_responses_api method has been merged into get_response above

0 commit comments

Comments
 (0)