Skip to content

feat: Add since to streamed logs and reopen closed streams - #1253

Open
Pijukatel wants to merge 17 commits into
masterfrom
claude/affectionate-fermi-74vvu9
Open

Pijukatel wants to merge 17 commits into
masterfrom
claude/affectionate-fermi-74vvu9

Conversation

@Pijukatel

@Pijukatel Pijukatel commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor
  • get_streamed_log() and StreamedLog take since: datetime | None. from_start is deprecated; its removal in v4 is tracked in Delete deprecated from_start and update upgrading guide #1259.
  • New StreamedLog.last_redirected_at: pass it plus 1 ms as since to continue the redirection after a reboot.
  • A stream the platform cuts off on a quiet but still running run (apify/apify-core#26653) fails with a transport error. It is reopened, and lines up to last_redirected_at are skipped. The reopen re-downloads the whole log, because the API can't start from a given point.

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.20000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.54%. Comparing base (739f097) to head (2729297).

Files with missing lines Patch % Lines
src/apify_client/_streamed_log.py 99.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1253      +/-   ##
==========================================
+ Coverage   91.39%   91.54%   +0.14%     
==========================================
  Files          65       65              
  Lines        6798     6892      +94     
==========================================
+ Hits         6213     6309      +96     
+ Misses        585      583       -2     
Flag Coverage Δ
unit 91.54% <99.20%> (+0.14%) ⬆️

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.

@Pijukatel
Pijukatel force-pushed the claude/affectionate-fermi-74vvu9 branch from 56f958a to 44f93a7 Compare November 25, 2026 08:26
@Pijukatel
Pijukatel changed the base branch from master to claude/intelligent-cerf-xz42y2 November 25, 2026 08:26
@Pijukatel
Pijukatel requested a review from vdusek November 25, 2026 12:21
@Pijukatel
Pijukatel marked this pull request as ready for review November 25, 2026 12:57
@Pijukatel
Pijukatel requested a review from szaganek as a code owner November 25, 2026 12:57
@vdusek
vdusek added this pull request to stack #1257 November 26, 2026 08:44
Comment thread src/apify_client/_streamed_log.py Resolved
Comment thread src/apify_client/_streamed_log.py Resolved
Comment thread src/apify_client/_streamed_log.py Resolved
Comment thread src/apify_client/_streamed_log.py Resolved
Comment thread src/apify_client/_streamed_log.py Resolved
Comment thread src/apify_client/_streamed_log.py Resolved
Comment thread docs/04_upgrading/upgrading_to_v4.mdx Resolved
@vdusek vdusek changed the title feat: redirect run logs from a given time and resume after the platform closes the stream feat: Redirect run logs from a given time and reopen closed log streams Nov 27, 2026
@vdusek vdusek changed the title feat: Redirect run logs from a given time and reopen closed log streams feat: Add since to streamed logs and reopen closed streams Nov 27, 2026
@Pijukatel
Pijukatel force-pushed the claude/affectionate-fermi-74vvu9 branch from 43356e5 to fbd56b4 Compare November 27, 2026 10:39

@vdusek vdusek 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.

LGTM

Base automatically changed from claude/intelligent-cerf-xz42y2 to master November 27, 2026 14:08
claude and others added 14 commits November 27, 2026 15:08
…rm closes the stream

`RunClient.get_streamed_log()`, `StreamedLog`, and their async counterparts take
a `since` datetime and redirect only the log lines logged at that time or later.
The `from_start` argument is deprecated in favour of it: `from_start=True` maps to
`since=None` and `from_start=False` to `since=datetime.now(tz=UTC)`. It emits a
`DeprecationWarning` and will be removed in v4, which the new v4 upgrading guide
describes.

The platform closes a log stream that has carried no data for several minutes,
even when the run is still going (apify/apify-core#26653). A streamed log created
by `get_streamed_log()` now checks the run status when its stream ends, reopens
the stream if the run has not finished, and skips the replayed lines up to the
last redirected one. A stream that broke off with an error gets one more reopen
after the run finishes, so the last lines are not lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
…warning

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
…eams from it

`StreamedLog` and `StreamedLogAsync` get a read-only `last_redirected_at`
property with the timestamp of the last redirected line, so a redirection can
be continued in another process, for example after the redirecting Actor
reboots, by passing it plus one millisecond as `since`.

A stream reopened after the platform closes it uses the same rule: it redirects
only lines logged after `last_redirected_at`, which replaces the tracking of
how many lines share the last timestamp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
…r reboots

The test builds two Actors: one that logs numbered lines, and one that runs a
wheel of the client from this checkout. The second one redirects the first
one's log, saves `last_redirected_at` to its key-value store, reboots, and
resumes with `since`. The test checks that every line was redirected exactly
once, with some lines before the reboot and some after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
…x minutes

The Actor under test logs a counter for 30 seconds, counts silently until
390 seconds, which is longer than the platform keeps an idle log stream open,
and then logs the counter again. The test checks that `ActorClient.call`
redirects every logged line exactly once and that the log stream was reopened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
A redirector Actor running a wheel of the client from this checkout calls the
silent counting Actor with the default logger, so the redirected lines land in
the redirector's own log. The test checks that log for every counter line,
exactly once, and for the number of times the log stream was opened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
… backoff

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
…atch-up reopen

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
Measured on the platform: a log stream cut off for being idle always fails
with a transport error (impit: `RemoteProtocolError`, after 330 s on the
in-platform API URL and up to 360 s on the public one), while a stream that
ends without an error has always delivered the whole log of a finished run.
The run status read right after such a clean end was not terminal yet in 11
of 26 runs, so reopening on a non-terminal status downloaded the whole log a
second time.

The redirection now reopens a stream only when reading it failed after it
had delivered data, and stops at a clean end. It no longer reads the run
status, so `StreamedLog` no longer takes a `run_client`. Messages replayed
by the reopened stream are skipped up to the last redirected timestamp
without changing `since`. A stream timeout ends the redirection as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAJFbkcdJ8X36dT46m4
Only a failed read of the stream means it broke off. A failure to process
a received line, such as an undecodable byte, repeats on every replay, so
treating it as a broken stream re-downloaded the whole log once a second
until `stop`. It now ends the redirection with a logged error again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAJFbkcdJ8X36dT46m4
A stream read that fails is reopened only when the HTTP client classifies
the error as a retryable transport error that is not a timeout, instead of
after any exception. The error both built-in transports raise when the
platform cuts off an idle stream (`RemoteProtocolError`) is classified so.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAJFbkcdJ8X36dT46m4
…ing a replay that makes no progress

- A reopened stream skips the replayed messages by timestamp and by how many
  messages at the last timestamp were already redirected, so a stream that
  breaks off inside a group of same-millisecond lines loses none of them.
- A reopened stream that breaks off again before it replays the last
  redirected line ends the redirection with a warning, instead of reopening
  and downloading the log again at the same point indefinitely.
- The `from_start` deprecation warning uses `stacklevel=3`.
- `_is_broken_read` moves to `StreamedLogBase`, the async `last_redirected_at`
  docstring names `RunClientAsync.get_streamed_log`, and a comment about `stop`
  no longer assumes that no earlier stream delivered data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
The removal of `from_start` is tracked in #1259.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ocuAHA5qh4VqF6Ps7XR5p
@Pijukatel
Pijukatel force-pushed the claude/affectionate-fermi-74vvu9 branch from c5d9b74 to 2729297 Compare November 27, 2026 14:08

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

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants