crawlee icon indicating copy to clipboard operation
crawlee copied to clipboard

Statistics fail to resume after migration

Open nikitachapovskii-dev opened this issue 4 months ago • 1 comments

Statistics persist to SDK_CRAWLER_STATISTICS_<id>, where <id> is a process-global counter. The order isn't guaranteed to be the same after a restart (migration / OOM / resurrect), so a crawler's stats can be saved under a different key on the new container and fail to resume, so you end up with two separate statistics records and the final "Total N requests: X succeeded, Y failed" only reflects the last segment.

https://console.apify.com/view/runs/QHf8KefhZMis54gfP

Proposed fix: expose persistStateKey in StatisticsOptions, defaulting to the current SDK_CRAWLER_STATISTICS_<id>. Then callers with multiple crawlers can pass a fixed key so each crawler's stats resume reliably:

new PlaywrightCrawler({ statisticsOptions: { persistStateKey: 'MAIN_CRAWLER_STATS' } })

Happy to PR.

nikitachapovskii-dev avatar Jul 22 '26 07:07 nikitachapovskii-dev

Thank you for the report @nikitachapovskii-dev ! See that we're already doing this in v4 ⬇️

https://github.com/apify/crawlee/blob/c6f32564692e694dc7f10ffbd4c8d6d5c1d0f00f/packages/core/src/crawlers/statistics.ts#L478-L486

This was added in #3309 .

Perhaps you can reapply the Statistics-related hunks of that v4 commit on v3? Afaik it shouldn't be breaking, as it's purely additive.

Cheers!

barjin avatar Jul 22 '26 07:07 barjin