rmfrall opened a new pull request, #77769:
URL: https://github.com/apache/airflow/pull/77769

   ## What problem does this PR solve?
   
   The `IdentifyArchivedTaskStateUpdates` version gate (v2026-10-30) already 
makes the
   execution API reject requests from an archived attempt (retry/clear) with 
**410** —
   heartbeat, RTIF overwrites, task state updates, rendered map index and XCom 
reads all
   distinguish "your attempt was archived" from "the resource does not exist". 
The four
   task state store endpoints (`GET/PUT/DELETE /store/ti/{...}`, `DELETE 
/store/ti/{id}`)
   were left out: their scope lookup folded *every* miss — cleared attempt 
included — into
   a plain `404 not_found`.
   
   That 404 is then translated to `TASK_STORE_NOT_FOUND` by the Task SDK 
client, and
   `TaskStateStoreAccessor.get()` treats it as "key has no value" and 
**silently returns
   the caller's default**. So in the window between a task being cleared and 
the kill
   signal arriving, task code that reads its own state store sees `None`:
   
   - `ResumableJobMixin.resume_decision()` reads 
`task_state_store.get(external_id_key)`
     and, on `None`, decides `"submit"` — re-submitting a fresh external job 
even though
     the durable record exists but the attempt is archived (exactly the 
double-submit the
     durable-execution path is supposed to prevent).
   - Writes through the same endpoints raise (`set()` has no 404 
special-casing), so the
     same task observes an asymmetric contract: reads lie quietly, writes 
explode loudly.
   
   ## What was done
   
   - `_get_task_scope_for_ti` now distinguishes three states: unknown TI id → 
404 (kept
     message); archived attempt → `_raise_ti_not_in_live_table(..., 
archived_in_history=
     IdentifyArchivedTaskStateUpdates.is_applied)` — i.e. **410 for clients on 
the version
     gate, 404 for older ones**, matching heartbeat/RTIF/state/map-index 
byte-for-byte in
     the `detail` payload.
   - New `ErrorType.TASK_INSTANCE_ARCHIVED` in the Task SDK; 
`TaskStateStoreOperations.get()`
     maps the 410 to it, and `TaskStateStoreAccessor.get()`/`aget()` therefore 
raise
     `AirflowRuntimeError` instead of falling back to the default (no code 
change needed
     in the accessor: any non-`TASK_STORE_NOT_FOUND` error already raises).
   - The new enum value is registered in the supervisor schema the way 
`XCOM_BACKEND_ERROR`
     was (`AddXComBackendErrorType`): `AddTaskInstanceArchivedErrorType` in the 
in-progress
     `2027-02-28` version file with a 
`convert_response_to_previous_version_for` fallback to
     `GENERIC_ERROR`, wired into the `VersionBundle`; `schema.json` snapshot 
regenerated via
     `dump_supervisor_schemas.py` and the ts/go/java vendored copies plus 
generated models
     synced (one enum member each).
   
   Backward compatibility: older clients send their pinned 
`Airflow-API-Version` header, the
   gate answers with the old 404, and their behavior is unchanged. Older 
language-SDK runtimes
   receive `GENERIC_ERROR` through the migrator converter.
   
   ## Verification (container, python:3.12 + task-sdk deps, main@d900cf21 base)
   
   - `airflow-core` head API tests: `versions/head/test_task_state_store.py` 
**39 passed**
     (new `test_archived_attempt_returns_410` × get/put/delete/clear; the 
legacy `404`
     parametrization for a pinned `2026-06-30` client still passes)
   - `versions/v2026_10_30/test_task_state_store.py`: **2 passed** 
(older-version contract)
   - Task SDK: `tests/task_sdk/api/test_client.py` — **192 passed**, full file
     (`TestVariableOperations::test_variable_not_found` errors identically on a 
pristine
     `main` checkout in this container — pre-existing environment issue, 
verified by A/B)
   - `tests/task_sdk/execution_time/test_context.py` accessor suite: **103 
passed**;
     the 8 size-limit errors in `TestAssetStateStoreAccessor` are 
byte-identical to a
     baseline run (A/B diff of the error sets: identical)
   - `tests/task_sdk/execution_time/schema/test_migrator.py`: **67 passed**, 
including the
     new `TestRealBundleTaskInstanceArchivedError` downgrade matrix (head keeps 
the type,
     2026-10-30 / 2026-06-16 get `GENERIC_ERROR`)
   - `dump_supervisor_schemas.py` regeneration diff vs the committed snapshot: 
exactly one
     line (`"TASK_INSTANCE_ARCHIVED",`)
   - `ruff check` + `ruff format --check`: clean on all 15 touched files
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — TeleAgent
   
   Generated-by: TeleAgent following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


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