fix!: do not count downtime towards crawler_runtime after migration or resurrection by Pijukatel · Pull Request #2204 · apify/crawlee-python · GitHub
Skip to content

fix!: do not count downtime towards crawler_runtime after migration or resurrection - #2204

Open
Pijukatel wants to merge 2 commits into
v2from
claude/actor-resurrection-time-tracking-bixxkl
Open

Pijukatel wants to merge 2 commits into
v2from
claude/actor-resurrection-time-tracking-bixxkl

Conversation

@Pijukatel

@Pijukatel Pijukatel commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator
  • After an Actor migration or resurrection, the first periodic statistics log reported crawler_runtime including the downtime between the runs (e.g. 38.01s for a ~0.5 s run); later logs corrected themselves. Now the first log reports exactly the runtime accumulated so far (0 for a fresh run).
  • Also covers two rarer edge cases: a state persisted mid-run and never finished cleanly baked the downtime into the runtime permanently, and repeated resurrections kept only the last run's segment of the accumulated runtime.
  • StatisticsState.accumulated_runtime now stores the runtime of the previous runs; the read-only crawler_runtime property adds the run in progress, and every persist checkpoints the live total.
  • Breaking (v2): crawler_runtime_for_serialization is removed, and crawlerRuntimeMillis is persisted as a number of milliseconds instead of an ISO 8601 duration string. Documented in docs/upgrading/upgrading_to_v2.md.
  • Runtime tracking matches Crawlee JS (accumulation across resumes, checkpoint on every persist, downtime excluded).
  • Related to Remove deprecated StatisticsState.crawler_runtime setter #1567.

@github-actions github-actions Bot added this to the 148th sprint - Tooling team milestone Aug 31, 2026
@github-actions github-actions Bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Aug 31, 2026
@codecov

codecov Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

@Pijukatel

Copy link
Copy Markdown
Collaborator Author

Waiting for V2 as this might be breaking change and will inlcude removal of deprecated fields

@Pijukatel Pijukatel changed the title fix: do not count downtime towards crawler_runtime after migration or resurrection fix!: do not count downtime towards crawler_runtime after migration or resurrection Sep 3, 2026
@Pijukatel
Pijukatel force-pushed the claude/actor-resurrection-time-tracking-bixxkl branch from 4b9f3e5 to 8af9ee3 Compare October 20, 2026 07:47
@Pijukatel
Pijukatel changed the base branch from master to v2 October 20, 2026 07:48
@Pijukatel
Pijukatel force-pushed the claude/actor-resurrection-time-tracking-bixxkl branch 6 times, most recently from de270b1 to 7ca479e Compare October 21, 2026 06:50
…r resurrection

The `crawler_runtime` statistic no longer counts the downtime between
the runs of a resumed crawler, and it accumulates correctly across any
number of persist/resume cycles:

- The first periodic statistics log reports exactly the runtime
  accumulated so far: zero for a fresh start, the previously persisted
  total for a resumed run.
- The accumulated runtime is stored in the new `accumulated_runtime`
  field, persisted under `crawlerRuntimeMillis`. Every persist writes
  the live total, so a state persisted mid-run (migration, abort)
  carries the runtime up to that moment and a resumed run continues
  from the last checkpoint.
- The timestamps of the previous run are cleared before the new run
  starts being measured, so they cannot leak the downtime into the
  runtime, and a backwards clock jump during a run cannot push the
  runtime below the accumulated total.

BREAKING CHANGE: `StatisticsState.crawler_runtime_for_serialization`
is removed; the `crawler_runtime` property is backed by the new
`accumulated_runtime` field. `crawlerRuntimeMillis` is serialized as
a number of milliseconds instead of an ISO 8601 duration string.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VMHwDx87jV4rnu5LkbpNxy
@Pijukatel
Pijukatel force-pushed the claude/actor-resurrection-time-tracking-bixxkl branch from 7ca479e to fbab2a8 Compare October 21, 2026 06:59
@Pijukatel
Pijukatel requested a review from vdusek October 21, 2026 07:04
@Pijukatel
Pijukatel marked this pull request as ready for review October 21, 2026 07:04

@apify-factory apify-factory left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good, just one note.

Outside the diff:

  • src/crawlee/statistics/_models.py: Note: crawlerRuntimeMillis is serialized as the total (including the last run's segment) but validated back into accumulated_runtime alongside the unchanged crawlerLastStartTimestamp/crawlerFinishedAt, so StatisticsState.model_validate(state.model_dump(by_alias=True)).crawler_runtime counts the last run twice. Only Statistics.__aenter__ clears the timestamps, so any consumer that parses a persisted statistics record with StatisticsState gets an inflated runtime.

🏭 Factory review — ℹ️ not auto-approved

This change was reviewed but cannot be auto-approved: a gate failed, so the review cannot end in an approval.

check result
Static gates ❌ 13/16 — base-branch, max-lines, pr-title
Review findings ❌ not clean
Reviewer escalation ❌ Changes the persisted statistics format (crawlerRuntimeMillis type and meaning) and removes a public model field, a breaking public contract that downstream consumers like the Apify SDK may read.
Juror 1 — claude-sonnet-5-5, adversarial ⏭️ skipped — a gate failed
Why it was not auto-approved

Failed gates:

  • base-branch: base is v2, required master
  • max-lines: 217 changed lines (+194/-23), limit 200
  • pr-title: breaking changes are never auto-approved

The comments above are the review itself; this section only explains the approval decision. Push a change and request @apify-factory again to re-run it, or ask a human to review.

Reviewed fc873682f · workflow run

@Pijukatel
Pijukatel marked this pull request as draft October 21, 2026 07:38
@Pijukatel

Pijukatel commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

@Pijukatel
Pijukatel marked this pull request as ready for review October 21, 2026 07:57

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. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove deprecated StatisticsState.crawler_runtime setter

4 participants