0BVer opened a new pull request, #77758:
URL: https://github.com/apache/airflow/pull/77758

   `ClassifierRetryPolicy` and `LLMRetryPolicy` classify a failure from the 
exception alone: its class and message (or traceback), the attempt count and 
the category descriptions. For some failures that is not enough to tell a 
retryable failure from a permanent one. `KubernetesPodOperator` raises `Pod 
<name> returned a failure.` whatever happened inside the pod, and an exception 
raised late in a long run reads the same as one raised in its first step. The 
policy runs in the worker and receives the task's `context`, but until now 
`context` reached only the rules and `fallback_policy`, never the model.
   
   This adds two opt-in keyword arguments to both policies:
   
   * `extra_context`: a callable that takes the task's `context` and returns 
extra text for the prompt, or `None`. It is the way to give the model the tail 
of the task's output, the outcome of earlier attempts, or a lookup in the 
system the task launched.
   * `max_extra_context_length` (default 4096): the limit on that text.
   
   The text is redacted with the policy's `redactor` first and then cut to its 
tail, the same order as `include_traceback`. It is added to the prompt inside a 
block delimited by a random tag, with a note that it is data and not 
instructions. A callable that raises, or returns nothing, leaves the prompt as 
it was, so it cannot stop a retry decision. Nothing changes unless 
`extra_context` is set.
   
   The callable runs in the worker before the model call, so the policy's 
`timeout` does not cover it. The docs say so.
   
   The policies do not read task logs themselves. The log path is rendered by 
the scheduler or executor and handed to the supervisor only, and on main it 
depends on the loop and map position of the task instance, so a worker cannot 
rebuild it reliably from configuration. Where the text comes from is left to 
the callable. A built-in way to get at the task's own log needs the task-sdk to 
expose it, and that is tracked in #77757. The docs also warn that task output 
holds secrets and personal data more often than an exception message does, that 
the default `redactor` masks only registered secrets, and that text the model 
reads can steer it, which matters because FAIL ends a task with attempts left.
   
   The private `_prompt`, `_run` and `_classify` methods now take `context`. 
Nothing else in the repository calls them.
   
   Verification run locally:
   
   * `pytest providers/common/ai/tests/unit/common/ai/policies/` through `uv 
run --project providers/common/ai` and through `breeze testing 
providers-tests`: 187 passed.
   * `prek run --stage pre-commit` on the changed files: passed.
   * `breeze run mypy` on `retry.py` and on `test_retry.py`: no issues found.
   * `breeze build-docs common.ai` (build and spelling check): successful.
   
   related: #77757
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (Claude Code, Sonnet 5.5)
   
   Generated-by: Claude Code (Sonnet 5.5) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to