RehanAhmad25 commented on code in PR #76891:
URL: https://github.com/apache/airflow/pull/76891#discussion_r4540928241


##########
airflow-core/src/airflow/api_fastapi/execution_api/security.py:
##########
@@ -372,6 +374,31 @@ async def _require_live_attempt(token: ExecutionToken, *, 
allow_callback: bool)
     )
 
 
+async def is_execution_token_renewable(token: ExecutionToken) -> bool:
+    """
+    Tell whether the work an ``execution`` token was issued for is still 
unfinished.
+
+    The subject is a task attempt, a callback, or ``ASSET_WATCHER_ID``, which 
has no row and no
+    lifecycle. Any other subject is not renewable, including an attempt that 
is finished, archived
+    or deleted, so its token expires on its own. This is not an admission 
check: a finished attempt
+    still runs its success callbacks with the token it holds.
+    """
+    if token.id == ASSET_WATCHER_ID:
+        return True
+    async with create_session_async() as session:
+        attempt = (
+            await session.execute(
+                select(TaskInstance.state, TaskInstance.working_set)
+                .where(TaskInstance.id == token.id)
+                .execution_options(include_all_attempts=True)
+            )
+        ).one_or_none()
+        if attempt is not None:
+            return attempt.working_set is True and attempt.state not in 
State.finished

Review Comment:
   Should a worker’s `execution` token remain renewable while its task attempt 
is parked in `DEFERRED` or `UP_FOR_RESCHEDULE`?
   
   In both states, the existing attempt remains in the working set, so this 
check allows renewal during the wait. The Triggerer uses 
`InProcessExecutionAPI`, not the worker’s JWT, and a resumed worker receives a 
fresh token. That does not revoke the old token, but it means the Triggerer and 
resumed worker do not depend on renewing it during the wait.
   
   Is continued renewal intended for the full unfinished attempt lifecycle, or 
should renewal stop while the attempt is parked? A test covering the intended 
behavior would make this clear.



-- 
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