uranusjr commented on code in PR #70671:
URL: https://github.com/apache/airflow/pull/70671#discussion_r4397653672


##########
airflow-core/src/airflow/utils/log/file_task_handler.py:
##########
@@ -647,21 +645,22 @@ def _read(
             TaskInstanceState.DEFERRED,
         )
 
-        with LogStreamAccumulator(out_stream, HEAP_DUMP_SIZE) as 
stream_accumulator:
-            log_pos = stream_accumulator.total_lines
-            out_stream = stream_accumulator.stream
-
-            # skip log stream until the last position
-            if metadata and "log_pos" in metadata:
-                out_stream = islice(out_stream, metadata["log_pos"], None)
-            else:
-                # first time reading log, add messages before interleaved log 
stream
-                out_stream = chain(header, out_stream)
+        out_metadata: LogMetadata = {"end_of_log": end_of_log}
+        if not end_of_log:
+            # Only an unfinished read needs log_pos for the continuation 
token, and counting
+            # lines drains the stream eagerly, so finished reads stream 
straight through.
+            with LogStreamAccumulator(out_stream, HEAP_DUMP_SIZE) as 
stream_accumulator:
+                out_metadata["log_pos"] = stream_accumulator.total_lines
+                out_stream = stream_accumulator.stream

Review Comment:
   This now ties a base-class handler to the API's continuation-token behavior, 
using `end_of_log` as a stand-in for "the caller needs `log_pos`". Make sure 
#75211 makes this an explicit caller-side request (a parameter, or a flag in 
metadata) instead of adding more inference here.



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