Hi Alisha, Thanks for driving this. I agree on the mechanics. The break picks the buffering point, and only the checkpoint wait makes the input stable.
I prefer the default break in the shared fuser, with (b)/(c) as the opt-out. A silent correctness hole is worse than one extra stage, and on portable runners the cost looks bounded: one more SDK harness round trip, no extra checkpoint wait. A warning only helps people who read it, and PairWithRandomKeyFn is exactly the case nobody would think to mark. For the design doc, I would like to see the measurement you offered on the GBK -> Values -> sink pattern, so the cost is a number rather than an assumption. I also agree the marker belongs in ParDoPayload next to requires_stable_input. Thanks, Hongye On Tue, 1 Dec 2026 18:03:08 +0530, Alisha <[email protected]> wrote: > Thanks Jan, agreed - and the external side effects are exactly why the > stage boundary has to sit directly in front of the stable DoFn. > > Kenn, does that answer your question? If we agree on the mechanics, I'd > like to get a sense of which direction people prefer - (c) plus a > runner-side warning, or a default break in the shared fuser with (b) as > the opt-out - so I can start a design doc. > > On Tue, Dec 1, 2026 at 4:38 PM Jan Lukavský <[email protected]> wrote: > > > Yes, only checkpoint ensures stability. Only a whole Operator can be > > checkpointed, though - and this operator consists of fused PTransforms > > (executable stage). Therefore only a complete stage can consume > > checkpointed data (this is how @RequiresStableInput is implemented), but if > > the stage then starts with non-deterministic ParDo, then the inputs to the > > @RequiresStableInput DoFn are *not* stable. It is true that the old outputs > > of the stable DoFn will be discarded on failure (all operators will be > > restored to last checkpoint), but if the DoFn has some external > > side-effects, these will not be stable. > > > > Jan > > On 11/30/26 17:39, Kenneth Knowles via dev wrote: > > > > But for Flink isn't it true that a fusion break does not convert > > nondeterministic output to stable input anyhow? Only waiting for a > > checkpoint does that? > > > > Kenn > > > > On Mon, Nov 30, 2026 at 7:22 AM Jan Lukavský <[email protected]> wrote: > > > >> Hi Alisha, > >> > >> I think this boils down to several options we have to tackle this: > >> a) break fusion just before every @RequiresStableInput ParDo (this is > >> known to come with performance penalty even for pipelines that don't need > >> it), or > >> > >> b) add @Deterministic annotation that will allow to fuse annotated > >> ParDos into the stage that should be stable, or > >> > >> c) add @NonDeterministic annotation that will explicitly _forbid_ fusing > >> into stable stage (before the stable ParDo) > >> > >> d) add a brand new "fusion break" marker to the pipeline directly from > >> SDK > >> > >> The rest would be non-reliable guesses and therefore would need b), c) or > >> d) nevertheless. > >> > >> Now, currently the default in Beam model is that _any_ DoFn _can_ be > >> non-deterministic. This would suggest a correct approach would be b), but > >> that implies a lot of boiler plate code, as majority of real-life DoFns are > >> likely deterministic (at least those without external data sources). Option > >> d) is too low level, applies only to portable pipelines and works with > >> internal concept (fusion) that is not otherwise visible to the SDK. > >> > >> I'm therefore leaning towards option c) - this actually adds an option > >> for pipeline authors to resolve the fusion instability bug that can > >> currently be solved only via artifical Repartition/Reshuffle. > >> > >> To make this more clear to users we might not introduce it as an > >> annotation, but maybe something like ParDo.ofNonDeterministic() (Java SDK), > >> which might be more comprehensible. > >> > >> The question (probably for Beam 3.0) would be if we should change our > >> assumption that DoFns can be non-deterministic by default and rather > >> motivate users to use deterministic logic and mark the > >> non-determinstic/non-stable (e.g. fetches from external db) explicitly. > >> > >> I'd also like to head what others think about this. > >> > >> Jan > >> On 11/25/26 08:20, Alisha wrote: > >> > >> Hi all, > >> > >> I'd like to restart the discussion on > >> https://github.com/apache/beam/issues/24655 (originally raised by Jan in > >> the Dec 2022 thread "@RequiresStableInput and Pipeline fusion"). I've been > >> working on @RequiresStableInput in the Flink runner (#41448, #41514, > >> #41519) and would like to help move this one forward. > >> > >> == The problem == > >> > >> A runner can only guarantee stable input at the boundary of an executable > >> stage. If GreedyPipelineFuser fuses NonDeterministicDoFn -> StableDoFn into > >> one stage, the runner makes the input to the *stage* stable, but on retry > >> the leading DoFn re-runs and the StableDoFn sees different input. > >> RequiresStableInputIT reproduces this with MapElements(PairWithRandomKeyFn) > >> followed by a stable DoFn. Today the only workaround is an explicit > >> Reshuffle (or other fusion break) right before the stable DoFn. > >> > >> The counter-concern (Kenn, on the issue): always breaking fusion is > >> expensive. Dataflow saw major regressions when it did this, because many > >> SDK transforms put a cheap projection between a checkpoint and the stable > >> DoFn (e.g. GBK -> drop keys -> write files). For context, the original > >> Dataflow implementation (PR 5787 in the design doc, > >> s.apache.org/requires-stable-input) was exactly this: every stable ParDo > >> T was replaced by Reshuffle + T, so that's the behaviour the regression > >> numbers refer to. > >> > >> == Options == > >> > >> 1. Unconditional fusion break in the fuser > >> GreedyPipelineFuser (and the Python fn_api fuser) ends the stage > >> before any ParDo with requires_stable_input = true, unless its input is > >> already a stage boundary. This also covers the "ParDo immediately after a > >> GBK" corner case left open in the design doc's future work. > >> + Simple, correct by default, no new user-facing API. > >> - Extra materialization for the GBK -> projection -> sink pattern. As > >> far as I understand, this only affects runners using the shared fuser > >> (portable Flink/Spark/Samza, etc.), not Dataflow. > >> > >> 2. Opt-in determinism marker (the direction from the issue) > >> Add a determinism property (e.g. @Deterministic in Java, plus a field > >> next to requires_stable_input in the proto so it works cross-language). A > >> PCollection is stable if it comes from a stage boundary/checkpoint, or from > >> a deterministic transform applied to stable input. The fuser keeps fusing > >> only through stable chains. The default is non-deterministic, i.e. break > >> fusion. (This isn't covered in the original design doc.) > >> + Correct by default, and recovers the performance of option 1 > >> wherever transforms are marked. > >> - New API surface. Determinism belongs to the user fn, not the > >> transform (MapElements can't be blanket-marked). Mis-annotation silently > >> brings the bug back, and it is hard to test. > >> - Realistically most adoption comes from SDK-internal transforms > >> (Values, Keys, file-write internals), IO authors, and auto-insertion by > >> SQL/YAML, where the logic is easier to analyze. > >> > >> 3. Heuristics > >> Infer non-determinism from signals like @StartBundle/@FinishBundle, > >> state/timers, or side inputs. > >> - As Jan noted, these aren't sufficient. At best they work as a > >> negative signal ("never treat as deterministic"), not as a way to prove > >> determinism. > >> > >> 4. Keep fusion as is: validate and document > >> Runners check the pipeline requirements and reject (or warn on) a > >> stable ParDo fused behind non-boundary transforms, as Luke suggested in the > >> original thread. Document Reshuffle as the required pattern. Also tie this > >> to the Redistribute work: either Redistribute is defined as an > >> unconditional fusion break, or we add an explicit "must break fusion" hint, > >> so deprecating Reshuffle doesn't remove the workaround. > >> + Cheapest, no behaviour change. > >> - Leaves a silent correctness hole for anyone who doesn't read the > >> docs. > >> > >> Note: a fusion break is necessary but not sufficient. It only puts the > >> stable DoFn at the start of a stage; each runner still has to make that > >> stage's input stable (e.g. buffering until checkpoint on Flink). As Luke > >> suggested in the original thread, runners can check requires_stable_input > >> on the ExecutableStage to decide this. > >> > >> == Strawman == > >> > >> - Phase 1: option 1 in the shared fusers (correctness first), possibly > >> behind an opt-out option for users who knowingly rely on the old behaviour. > >> Add a portable ValidatesRunner test based on RequiresStableInputIT without > >> the Reshuffle. > >> - Phase 2: option 2 with a proto-level determinism field. Mark the > >> obvious SDK-internal transforms first, then explore auto-marking for > >> SQL/YAML. > >> - In parallel: settle the fusion-break semantics of Redistribute, or add > >> an explicit hint. > >> > >> == Questions for the list == > >> > >> - Is a default fusion break in GreedyPipelineFuser acceptable for the > >> portable runners, given that the regression data we have comes from > >> Dataflow? > >> - Should determinism be a DoFn-level or a transform-level property, and > >> should it live in ParDoPayload or in a transform annotation? > >> - Which SDK transforms sit between a checkpoint and a stable DoFn today, > >> so they could be marked first? (Pointers welcome.) > >> - Any objection to tying this to the Redistribute/fusion-hint discussion? > >> > >> I'm happy to write this up as a design doc once there's rough agreement > >> on the direction. > >> > >> Thanks, > >> Alisha > >> > >>
