Deliver the per-run log ID template to workers via TIRunContext#69688
Open
jason810496 wants to merge 5 commits into
Open
Deliver the per-run log ID template to workers via TIRunContext#69688jason810496 wants to merge 5 commits into
jason810496 wants to merge 5 commits into
Conversation
The LogTemplate model pins the log_id template to each Dag run so task logs written before a config change stay readable, but the Airflow 3 paths of the Elasticsearch and OpenSearch handlers rendered log_id from the current conf value on both the write (worker) and read (API server) sides, so changing [elasticsearch/opensearch] log_id_template orphaned all previously written logs. Workers cannot query the metadata DB, so the pinned template is delivered to the supervisor through a new optional TIRunContext field populated by the ti_run Execution API endpoint (with a version migration for older clients); the API-server read paths restore the per-run lookup directly. Handlers that do not opt into the new ti_context keyword keep their existing upload signature and behavior.
…r-side TIs Worker-side RuntimeTIs have no get_dagrun and cannot reach the metadata DB; the pinned template reaches them through TIRunContext instead. Opening a session just to fail also trips the DB-access guard (AirflowInternalRuntimeError is a BaseException, so the fallback except clause cannot catch it) in non-DB test runs.
…n supervisor tests The remote-logging supervisor tests drop airflow.sdk.log (and the logging-config modules) from sys.modules to force a fresh import, but the re-import rebinds the attribute on the parent package and monkeypatch only restores the sys.modules entry. On Python < 3.12 mock.patch resolves dotted targets through getattr on the parent package, so later tests on the same worker patched the stale module object while the code under test imported the restored one, failing test_upload_logs_forwards_ti_context and TestUploadToRemoteTIContext::test_no_ti_context_keeps_handler_default in CI.
Keep this branch scoped to the core plumbing (Execution API and Task SDK) that delivers the per-run log ID template to workers. The Elasticsearch and OpenSearch handler changes re-land in per-provider PRs stacked on this branch, so each provider change can be reviewed and released on its own cadence.
This was referenced Jul 15, 2026
…mplate Exercises the pinning behavior across several LogTemplate rows in a loop, rather than a single row, to guard against the value being cached or resolved against a stale row.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The
LogTemplatemodel pins the log ID template to each Dag run so task logs written before alog_id_templateconfig change stay readable, but on the Airflow 3 write path workers render the log ID from the current conf value — they cannot query the metadata DB to fetch the pinned row. This PR adds the core plumbing that hands the pinned template to workers; the Elasticsearch and OpenSearch handler changes that consume it follow in per-provider PRs stacked on this one.How
LogTemplate.elasticsearch_idis delivered to the supervisor via a new optionalTIRunContext.log_id_templatefield, populated by theti_runExecution API endpoint.upload_to_remoteforwards the run context only to handlers whoseuploadopts into ati_contextkeyword, so S3/GCS/third-partyRemoteLogIOimplementations and old-provider × new-sdk combinations are untouched.What
airflow-core: addTIRunContext.log_id_template; populate it in theti_runroute fromdr.get_log_template(); add Execution API version2026-09-30with a Cadwyn migration.task-sdk: retain theTIRunContextonActivitySubprocessand pass it toupload_to_remote; regenerate the client datamodels; add the first in-progress supervisor-schema version file plus the regeneratedschema.jsonsnapshot.Was generative AI tooling used to co-author this PR?