conditionally log CancelledError as debug for speculative steps (#4252)

This commit is contained in:
pedrohsdb
2025-12-11 12:13:17 -08:00
committed by GitHub
parent 1df2e8a870
commit f1c9271085

View File

@@ -933,15 +933,27 @@ class LLMAPIHandlerFactory:
) )
raise SkyvernContextWindowExceededError() from e raise SkyvernContextWindowExceededError() from e
except CancelledError: except CancelledError:
# Speculative steps are intentionally cancelled when goal verification completes first,
# so we log at debug level. Non-speculative cancellations are unexpected errors.
t_llm_cancelled = time.perf_counter() t_llm_cancelled = time.perf_counter()
LOG.error( if is_speculative_step:
"LLM request got cancelled", LOG.debug(
llm_key=llm_key, "LLM request cancelled (speculative step)",
model=model_name, llm_key=llm_key,
prompt_name=prompt_name, model=model_name,
duration=t_llm_cancelled - t_llm_request, prompt_name=prompt_name,
) duration=t_llm_cancelled - t_llm_request,
raise LLMProviderError(llm_key) )
raise
else:
LOG.error(
"LLM request got cancelled",
llm_key=llm_key,
model=model_name,
prompt_name=prompt_name,
duration=t_llm_cancelled - t_llm_request,
)
raise LLMProviderError(llm_key) from None
except Exception as e: except Exception as e:
duration_seconds = time.time() - start_time duration_seconds = time.time() - start_time
LOG.exception( LOG.exception(
@@ -1301,14 +1313,25 @@ class LLMCaller:
) )
raise SkyvernContextWindowExceededError() from e raise SkyvernContextWindowExceededError() from e
except CancelledError: except CancelledError:
# Speculative steps are intentionally cancelled when goal verification returns completed,
# so we log at debug level. Non-speculative cancellations are unexpected errors.
t_llm_cancelled = time.perf_counter() t_llm_cancelled = time.perf_counter()
LOG.error( if is_speculative_step:
"LLM request got cancelled", LOG.debug(
llm_key=self.llm_key, "LLM request cancelled (speculative step)",
model=self.llm_config.model_name, llm_key=self.llm_key,
duration=t_llm_cancelled - t_llm_request, model=self.llm_config.model_name,
) duration=t_llm_cancelled - t_llm_request,
raise LLMProviderError(self.llm_key) )
raise
else:
LOG.error(
"LLM request got cancelled",
llm_key=self.llm_key,
model=self.llm_config.model_name,
duration=t_llm_cancelled - t_llm_request,
)
raise LLMProviderError(self.llm_key) from None
except Exception as e: except Exception as e:
LOG.exception("LLM request failed unexpectedly", llm_key=self.llm_key) LOG.exception("LLM request failed unexpectedly", llm_key=self.llm_key)
raise LLMProviderError(self.llm_key) from e raise LLMProviderError(self.llm_key) from e