Skip to content

[Bug]: Python file-based sinks emit their output file paths at MAX_TIMESTAMP, past the end of the global window #41245

In review

Description

@jonathansudhakar1

What happened?

In batch, iobase.Write (which backs WriteToText, WriteToAvro, WriteToParquet and WriteToTFRecord) returns a PCollection of the final file paths. Each path is emitted in the GlobalWindow with timestamp MAX_TIMESTAMP (iobase.py#L1476). That's past the end of the global window, since GlobalWindow().max_timestamp() is MAX_TIMESTAMP minus one day, so downstream aggregations treat the paths as data beyond their window's end:

  • Prism (the default local runner): a GroupByKey on the paths fails the job with panic in ElementManager.Bundles watermark evaluation goroutine: generating bundle for stage stage-009 at watermark +inf panicked.
    assert_that(paths, equal_to([...])) sees an empty PCollection and the job fails with nothing in progress and no refreshes with non zero pending elements: 3.
  • BundleBasedDirectRunner: beam.combiners.Count.Globally() on the paths returns 0 instead of 3.
  • FnApiRunner: works.

Repro on master (1cabbd7), Python 3.13:

import tempfile

import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions

tmp = tempfile.mkdtemp()
with beam.Pipeline(options=PipelineOptions(['--runner=PrismRunner'])) as p:
  paths = p | beam.Create(['a', 'b', 'c']) | beam.io.WriteToText(
      tmp + '/out', num_shards=3)
  _ = paths | beam.Map(lambda x: (0, x)) | beam.GroupByKey() | beam.Map(print)

The default num_shards=0 fails the same way. With --runner=BundleBasedDirectRunner, paths | beam.combiners.Count.Globally() | beam.Map(print) prints 0.

Cause. BEAM-5250 (7581caa, 2018) changed _WriteBundleDoFn to emit at GlobalWindow().max_timestamp() (L1346). Two places still use timestamp.MAX_TIMESTAMP:

  • _finalize_write (L1476), which produces the transform's output.
  • _WriteKeyedBundleDoFn (L1449), whose results are only read as a side input.

Possible fix. Emit at window.GlobalWindow().max_timestamp() in _finalize_write, and in _WriteKeyedBundleDoFn for consistency. I tried the _finalize_write change locally: the repro then works on all three runners (GroupByKey succeeds on Prism, and Count.Globally() returns 3 on Prism and on BundleBasedDirectRunner).

Streaming writes go through _finalize_windowed_write instead and aren't covered by this report. Separately, Prism panicking on these elements, rather than handling them as late data, may be worth a look by its maintainers.

I found this while working on #25769, which documents this output. A test that asserts on the output can't pass on Prism without this fix, so I plan to include the fix in that PR.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Infrastructure
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Prism Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner

Activity

  1. jonathansudhakar1 commented on Nov 12, 2026

    @jonathansudhakar1
    ContributorAuthor

    .add-labels bug,'awaiting triage'

  2. added 3 commits that reference this issue on Nov 17, 2026
    ba6853d
    e33a639
    1dd4539
  3. jonathansudhakar1 commented on Nov 28, 2026

    @jonathansudhakar1
    ContributorAuthor

    .take-issue

    The fix is now in its own PR, #41738 (split out of #41318, which keeps the docs for #25769).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions