Skip to content

fix(log): redirect the run log when the first log stream comes back empty - #1084

Open
vdusek wants to merge 7 commits into
masterfrom
fix/streamed-log-empty-start
Open

vdusek wants to merge 7 commits into
masterfrom
fix/streamed-log-empty-start

Conversation

@vdusek

@vdusek vdusek commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Python twin of apify/apify-client-js#1105.

call(logger=...) and get_streamed_log() could redirect no log lines at all. When a run hasn't written its first line yet, the API answers GET /logs/:id?stream=1 with an empty 200 and closes it right away. StreamedLog and StreamedLogAsync opened the stream once, so they took that empty response as the whole log.

Both now reopen a stream that ended without any bytes, after a 0.5 s pause. If stop() comes before anything has arrived, the log is read once with get_as_bytes():

  • In StreamedLog the streaming thread does that read. stop() cuts the pause short, and a stream that opens while stop() is running is dropped in favor of the read, since it would end after its first chunk.
  • In StreamedLogAsync, stop() does the read after cancelling the task, so the task still ends cancelled.

A run that finishes quickly gets its whole log redirected.

Tests cover the same five cases as #1105, for both StreamedLog and StreamedLogAsync and on both HTTP clients:

  • the first stream is empty, so the log has to come through the reopened one
  • every stream stays empty until stop(), which reads the whole log
  • stop() lands while the reopened stream is connecting
  • a missing log is neither reopened nor read
  • a failing one-shot read is logged and stop() still returns

The first three fail without the fix.

✍️ Drafted by Claude Code

@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Oct 2, 2026
@vdusek vdusek self-assigned this Oct 2, 2026
@vdusek
vdusek requested a review from Pijukatel October 2, 2026 09:58
@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.41270% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.38%. Comparing base (ac60559) to head (88b51da).

Files with missing lines Patch % Lines
src/apify_client/_streamed_log.py 98.41% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1084      +/-   ##
==========================================
+ Coverage   95.30%   95.38%   +0.07%     
==========================================
  Files          60       60              
  Lines        5755     5788      +33     
==========================================
+ Hits         5485     5521      +36     
+ Misses        270      267       -3     
Flag Coverage Δ
integration 91.27% <57.14%> (-0.22%) ⬇️
unit 87.97% <98.41%> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek
vdusek marked this pull request as ready for review October 2, 2026 10:01
@apify-service-account apify-service-account added the tested Temporary label used only programatically for some analytics. label Oct 2, 2026

This branch has not been deployed

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

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants