Skip to content

fix(kernels): stream kernels output files through download_file - #1206

Merged
stevemessick merged 1 commit into
Kaggle:mainfrom
nefayran:fix/kernels-output-stream
Oct 1, 2026
Merged

stevemessick merged 1 commit into
Kaggle:mainfrom
nefayran:fix/kernels-output-stream

Conversation

@nefayran

@nefayran nefayran commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Summary

kaggle kernels output now saves each file through download_file, the path dataset and competition downloads already take. Files are written in chunks instead of held in memory, checked against Content-Length, and resumed after a dropped connection.

Problem

kernels_output fetches each file with requests.get(url, stream=True) and writes response.content, which reads the whole body into memory. The request has no read timeout, nothing retries it, and nothing compares the written size with Content-Length. The target file is opened before the body is read, so when the connection drops, the command fails and leaves an empty file under the final name.

Measured with an in-process HTTP server (macOS arm64, Python 3.14, requests 2.34.2):

case main this branch
512 MiB output: growth of the client's peak RSS 1,175 MB 7 MB
3 MiB output, connection cut after 1.5 MiB ChunkedEncodingError, 0-byte file left on disk resumed from the first 1 MiB chunk, all 3,145,728 bytes written

Solution

Call download_file for kernel output files and pass timeout=300 to the first request, the same read timeout download_file uses for its retries. Resume is on unless --force is given, as in datasets download.

download_file does not use its http_client argument, and the client opened for the output listing is closed by the time the files are fetched, so the call passes None.

Tests

  • New tests/unit/test_kernels_output_download.py runs kernels_output against a local HTTP server that supports Range requests. One test checks that the file goes through download_file and arrives intact. The other cuts the first connection halfway through the second 1 MiB chunk and checks that the retry asks for bytes=1048576- and that no .kaggle-partial marker is left. Both fail on main.
  • test_kernels_output_paths.py and two pagination tests in test_kernels_logs.py faked the old .content read. They now stub download_file, and the requests.get assertion includes the timeout.

pytest tests/unit: 1397 passed. black --check and mypy report no issues.

@google-cla

google-cla Bot commented Oct 1, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

kernels_output fetched each output file with requests.get(stream=True)
and then wrote response.content, which reads the whole body into memory.
It had no read timeout, no retry and no size check, and it opened the
target file before reading the body, so a dropped connection failed the
command and left an empty file under the final name.

Dataset and competition downloads already go through download_file:
chunked writes, a Content-Length check, retries that resume with a
Range request, and a 300 s read timeout. kernels_output now uses it
too. Measured with an in-process HTTP server: a 512 MiB output raised
the client's peak RSS by about 1,175 MB before and 7 MB after, and a
connection cut at 1.5 MiB of a 3 MiB file now resumes from the first
1 MiB chunk instead of failing.
@nefayran
nefayran force-pushed the fix/kernels-output-stream branch from 47e5661 to 67f6856 Compare October 1, 2026 00:41
@stevemessick

Copy link
Copy Markdown
Contributor

/gcbrun

@stevemessick
stevemessick self-requested a review October 1, 2026 21:31

@stevemessick stevemessick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!. Thanks.

@stevemessick
stevemessick merged commit b139309 into Kaggle:main Oct 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants