Skip to content

fix(sessions)!: make session retirement permanent - #2348

Open
gauravch-code wants to merge 1 commit into
apify:v2from
gauravch-code:fix/2312-terminal-session-retirement
Open

gauravch-code wants to merge 1 commit into
apify:v2from
gauravch-code:fix/2312-terminal-session-retirement

Conversation

@gauravch-code

Copy link
Copy Markdown

Description

Keep retired sessions from becoming usable again when mark_good() lowers their error score. A session explicitly retired after a blocked request should not be handed out again by the pool, including after saving and restoring the pool.

  • Track retirement independently of the error score and persist it in SessionModel.
  • Default the new flag to False when loading older saved state.
  • Make repeated retire() calls leave the error score unchanged.
  • Document the behavior change in the v2 migration guide.

Issues

Closes #2312

Testing

  • Reproduced the original behavior on unchanged v2: a fresh session becomes usable after retire() followed by mark_good() (error score 3.0 -> 2.5). Two regression tests failed before the fix.
  • Added six tests covering terminal retirement, JSON round trips, older saved state, repeated retirement, pool lookups, and pool persistence/reopening.
  • uv run pytest tests/unit/sessions tests/unit/crawlers/_basic -q --timeout=90: 193 passed, 1 existing skip on Windows / Python 3.12.13.
  • Repository-wide Ruff lint and formatting checks passed.
  • Type checks passed for the changed modules and tests. The full repository check passed with --python-platform linux.
  • Both pre-commit hooks passed using a temporary, untracked ty configuration matching the repository settings with the Linux target. That configuration was removed and is not part of this PR.

The default Windows repository-wide type check reports three errors in the unchanged tests/unit/_utils/test_system.py involving ForkContext, ForkServerContext, and BaseContext.Process. Full unit and platform end-to-end suites were not run.

Checklist

  • CI passed

Persist retirement independently of error scores and cover session and pool restoration.

BREAKING CHANGE: Retired sessions cannot become usable again after mark_good().
@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Oct 21, 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

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