Skip to content

fix(crawlers): persist session pool and predictor after migration or abort pause - #2577

Closed
cobanfurkanx wants to merge 1 commit into
apify:v2from
cobanfurkanx:fix/persist-session-pool-predictor-on-pause
Closed

cobanfurkanx wants to merge 1 commit into
apify:v2from
cobanfurkanx:fix/persist-session-pool-predictor-on-pause

Conversation

@cobanfurkanx

Copy link
Copy Markdown

Description

  • Add persist_state() to SessionPool, RenderingTypePredictor (no-op default so custom subclasses stay compatible), and DefaultRenderingTypePredictor, delegating to self._state.persist_state() the same way Statistics.persist_state() does.
  • Extract BasicCrawler._persist_state() called at the end of _pause_by_event() to persist both self._statistics and self._session_pool after in-flight requests drain on MIGRATING and ABORTING.
  • Override AdaptivePlaywrightCrawler._persist_state() to also persist self._rendering_type_predictor after in-flight requests finish.

Issues

Testing

  • Added unit tests for SessionPool.persist_state() and DefaultRenderingTypePredictor.persist_state() (with persistence enabled and disabled).
  • Added parametrized migration/abort pause regression tests in test_basic_crawler.py and test_adaptive_playwright_crawler.py verifying that session mutations (cookies + retired status) and predictor model updates learned while draining in-flight requests are written to the crawler's key-value store after the pause.
  • Verified locally with:
    • uv run --no-sync pytest tests/unit/sessions/test_session_pool.py tests/unit/crawlers/_adaptive_playwright/test_predictor.py tests/unit/crawlers/_adaptive_playwright/test_adaptive_playwright_crawler.py -k "not import_error" (99 passed)
    • uv run --no-sync pytest tests/unit/crawlers/_basic/test_basic_crawler.py -k "migration or abort or pause" (22 passed)
    • uv run --no-sync ruff format --check & uv run --no-sync ruff check (all checks passed)
    • uv run --no-sync ty check (all checks passed)

Checklist

  • CI passed

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Dec 3, 2026
@Mantisus

Mantisus commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Thank you for your PR!

However, this is an internal task, and we'll address it later in v2, once we resolve a few other bottlenecks. So I'm closing this PR.

@Mantisus Mantisus closed this Dec 3, 2026
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.

2 participants