Skip to content

Java SDK: Honor TaskFlow arg bindings sent by the supervisor - #71188

Draft
jason810496 wants to merge 8 commits into
apache:mainfrom
jason810496:feature/java-sdk-arg-bindings-runtime
Draft

Java SDK: Honor TaskFlow arg bindings sent by the supervisor#71188
jason810496 wants to merge 8 commits into
apache:mainfrom
jason810496:feature/java-sdk-arg-bindings-runtime

Conversation

@jason810496

@jason810496 jason810496 commented Aug 5, 2026

Copy link
Copy Markdown
Member

Merge order:

  1. Support TaskFlow call syntax on stub tasks for the Lang SDK #69757 — Support TaskFlow call syntax on stub tasks for the Lang SDK
  2. Java SDK: Register tasks as first-class TaskDef objects #71057 — Register tasks as first-class TaskDef objects
  3. Java SDK: Honor TaskFlow arg bindings sent by the supervisor #71188 — Honor TaskFlow arg bindings sent by the supervisor (current one)
  4. Java SDK: Author complete Dags in Java without a Python stub file #71189 — Author complete Dags in Java without a Python stub file
  5. Java SDK: Serialize native Dags to DagSerialization v3 #71190 — Serialize native Dags to DagSerialization v3

Every PR targets main because GitHub cannot base a pull request on a branch that exists only on a fork, so these diffs are cumulative — the compare link above shows only this layer.

Why

For a stub-backed Dag, the Python file's @task.stub call site is the graph the scheduler actually orders the run by — so it should also be what feeds each Java task its inputs. Until now the Java side re-declared that data flow itself, with @Builder.XCom(task = "extract") naming the upstream to pull. That is the same wiring written twice, in two languages, with nothing keeping the copies honest: rename or re-wire a task in the Dag file and the Java annotation keeps pulling the old upstream, silently. It also cannot express a literal written at the call site at all.

The 2026-10-30 supervisor schema delivers the call site's argument bindings with every task run, so the Java runtime can read the real wiring instead of restating a guess at it.

How

  • Binding is positional: a task method's data parameters — everything other than the injected Client and Context — resolve the binding at their index, in declaration order. This matches the Go SDK's flat-parameter contract, and it is deliberate: Java parameter names are not API, so an IDE rename must never rebind an input.
  • Keyword-style calls bind by name only through an explicit TaskInput bundle parameter, whose public fields declare their wire names (@ArgName("region_code"), or the verbatim field name). That is the one tagged place where the stub's snake_case argument names cross into camelCase Java fields, rather than an implicit convention applied everywhere.
  • A task declares flat data parameters or one bundle, never both, and never two bundles — otherwise field names and flat positions could shift each other. Both cases fail at compile time.
  • A primitive parameter cannot hold null, so it fails with MissingXComException when its binding resolves to nothing; boxed and reference types receive null. Declaring more data parameters than the call site bound fails the task rather than running it with missing inputs.
  • Interface-API tasks get the same information imperatively, through Client.hasArgs / hasArg / getArg, by position or by name.
  • @Builder.XCom is removed outright rather than deprecated — the SDK is pre-1.0, and leaving a second, diverging way to declare the same data flow is the problem this change fixes.
  • jsonSchema2Pojo cannot express the kind-discriminated binding union, so the generated TIRunContext carries the raw payload and a small hand-written decoder materializes the typed view.

What

  • Bump the pinned supervisor schema to 2026-10-30 and refresh the schema snapshot, which adds TIRunContext.arg_bindings.
  • Add ArgBinding + decodeArgBindings, TaskInput, @ArgName, internal.ArgValues, and Client.hasArgs / hasArg / getArg.
  • BuilderProcessor classifies each @Builder.Task parameter as Client, Context, a TaskInput bundle, or a flat data parameter, and emits the matching ArgValues resolution; @Builder.XCom and its codegen are gone.
  • Migrate the Java examples and their Python stub Dag to TaskFlow-style calls, including a TaskInput bundle bound from keyword arguments, and document argument binding in the Java SDK docs.

Was generative AI tooling used to co-author this PR?

The @task.stub TaskFlow support in providers-standard imports
KNOWN_CONTEXT_KEYS, PlainXComArg, MappedOperator and the decorator base
classes through the compat layer so the provider keeps working down to
Airflow 2.11. Those symbols first ship in common-compat 1.19.0 (1.18.0
was released from main in the meantime without them), so the version is
cut here for the standard provider's pin to resolve.
Stub tasks silently ignored TaskFlow call arguments, so a Dag author
could not hand literals or upstream XCom results to a lang-SDK runtime.
The decorator now binds the call to the stub's signature at parse time
and captures an ordered arg spec (literal values and direct upstream
XCom references, with pydantic-derived JSON value schemas) that
serializes with the Dag, while rejecting what cannot cross the language
boundary: custom XCom keys, aggregated mapped outputs, non-JSON
literals, and stubs with arguments inside mapped task groups. Mapped
(.expand()) stubs capture no spec and keep the legacy behavior until a
follow-up delivers per-map-index bindings.
TIRunContext gains an arg_bindings field so a lang-SDK runtime receives
the stub task's TaskFlow arg spec at startup. ti_run derives it from the
serialized Dag only for stub operators, so regular tasks never pay for
the lookup, and only for clients on the new API version -- gated on the
Cadwyn VersionChangeWithSideEffects.is_applied check rather than a date
comparison -- so stub Dags that predate arg bindings keep running
against older clients, for which the version migration strips the field.
StartupDetails in the supervisor wire schema carries the new
arg_bindings so foreign runtimes receive the spec at task startup, with
a version migration that strips it for runtimes pinned to the previous
schema. The Go and TS SDKs regenerate against the new schema version;
the Go arg-binding runtime itself lands in a stacked follow-up PR.
An XComArg buried in a list or dict literal fell through to the JSON
check, whose "pass it in its JSON form instead" advice is impossible to
follow for a task output. Detect nested references up front and point
the author at the working alternative: pass the upstream output as its
own argument.
When a PR cuts a new provider version while the previous version is
still being voted on, only the rcN tags exist on the apache remote -
the final tag is pushed after the vote passes. The changes-table walk
in _get_all_changes_for_package assumed every past version has a final
tag and crashed with git exit 128 in that window, breaking CI for any
PR that bumps a provider version during a release wave.
`dag.addTask("extract", Extract.class)` stored tasks as a plain
`Map<String, Class<out Task>>`, which leaves nowhere to hang anything
else a task needs: dependency edges, task-level configuration, and
argument wiring all have to attach to a per-task object, and a map of
classes cannot carry them. Introducing that object now keeps those
follow-ups additive instead of forcing another break of the registration
API later.

The annotation surface keeps `Builder.Dag` / `Builder.Task`, and the
interface users implement keeps the `Task` name, so the definition
objects are `DagDef` and `TaskDef` -- a pairing that stays unambiguous
next to `Task` at a use site. The SDK is pre-1.0, so the old
string-keyed overload is removed outright rather than deprecated.
For a stub-backed Dag the Python file's `@task.stub` call site is the graph
the scheduler actually orders the run by, so it must also be what feeds the
Java task its inputs. The Java side previously re-declared that data flow
with `@Builder.XCom(task = "...")`, duplicating the Dag file's wiring in a
second place that nothing keeps honest: rename or re-wire a task in Python
and the Java annotation silently keeps pulling the old upstream. The
2026-10-30 supervisor schema delivers the call site's bindings with every
task run, so the runtime can read them instead of guessing.

Binding is positional, matching the Go SDK's flat-parameter contract: Java
parameter names are not API, so an IDE rename must never rebind an input.
Keyword-style calls bind by name only through an explicit `TaskInput` bundle
whose public fields declare their wire names -- the deliberate, tagged
boundary for snake_case-to-camelCase crossings. A task declares flat data
parameters or one bundle, never both, so field names and positions cannot
shift each other.

jsonSchema2Pojo cannot express the kind-discriminated binding union, so the
generated `TIRunContext` carries the raw payload and a small hand-written
decoder materializes the typed view.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant