Skip to content

feat: add a concurrency limit for child runs - #1154

Draft
vdusek wants to merge 36 commits into
masterfrom
feat/child-run-concurrency-limit
Draft

vdusek wants to merge 36 commits into
masterfrom
feat/child-run-concurrency-limit

Conversation

@vdusek

@vdusek vdusek commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Adds the max_concurrent_child_runs Actor option. While that many child runs are READY, RUNNING, ABORTING or TIMING-OUT, Actor.start, Actor.call, Actor.start_task or Actor.call_task waits to start or resurrect a run until one of them finishes. Reattaching to a recorded run never waits. Runs with and without a run_name both count.

The count comes from the child run registry, so children started before a migration count too. A child's status is fetched again before counting once it's more than 10 seconds old, so a finished run nobody waited on stops counting. Actor.call and Actor.call_task stop counting their run as soon as it finishes. A start counts toward the limit until its run is recorded, which keeps concurrent starts within the limit.

Once the parent receives ABORTING, a start still waiting under the limit raises a RuntimeError without starting a run. Waiting further would block the abort of the other children.

Runs started without a run_name are now recorded too, under their run ID in a separate __ACTOR_UNNAMED_CHILD_RUNS key. So they show up in Actor.child_runs (keyed by run ID) and support abort_with_parent. No later call reattaches to them, so surviving a migration still needs a run_name. An unnamed Actor.call / Actor.call_task now starts the run and waits for it in the SDK, so the run can be recorded.

The named record keeps its key and JSON shape. Both records are persisted through crawlee's RecoverableState and saved on every change.

Closes: #1138

✍️ Drafted by Claude Code

@vdusek vdusek added the t-tooling Issues with this label are in the ownership of the tooling team. label Sep 30, 2026
@vdusek vdusek self-assigned this Sep 30, 2026
@vdusek
vdusek added this pull request to stack #1152 September 30, 2026 09:49
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.04306% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.10%. Comparing base (3638c75) to head (0c64da0).

Files with missing lines Patch % Lines
src/apify/_child_runs.py 98.95% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1154      +/-   ##
==========================================
+ Coverage   93.93%   94.10%   +0.16%     
==========================================
  Files          54       54              
  Lines        3828     3970     +142     
==========================================
+ Hits         3596     3736     +140     
- Misses        232      234       +2     
Flag Coverage Δ
e2e 31.51% <32.53%> (+0.26%) ⬆️
integration 50.55% <34.44%> (-0.47%) ⬇️
unit 91.41% <99.04%> (+0.26%) ⬆️

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.

@vdusek
vdusek force-pushed the feat/child-run-concurrency-limit branch from 5bbadc2 to 033624c Compare October 6, 2026 13:20
@vdusek
vdusek force-pushed the feat/child-run-concurrency-limit branch from 7322d8e to 7c3d462 Compare October 9, 2026 15:11
@vdusek
vdusek force-pushed the feat/child-run-concurrency-limit branch from 7c3d462 to 6f9300e Compare October 15, 2026 12:35
Base automatically changed from feat/abort-child-runs-with-parent to master October 29, 2026 13:19
@vdusek
vdusek force-pushed the feat/child-run-concurrency-limit branch from 6f9300e to c2f5a87 Compare October 29, 2026 13:38
@vdusek
vdusek marked this pull request as ready for review October 29, 2026 14:26
@apify-service-account apify-service-account added the tested Temporary label used only programatically for some analytics. label Oct 29, 2026
@vdusek
vdusek requested a review from barjin October 29, 2026 14:28

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

Thanks. It reads way better with new names. Just two more nits, otherwise good.

Comment thread src/apify/_child_runs.py Resolved
Comment thread src/apify/_child_runs.py Resolved
@Pijukatel

Pijukatel commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Btw. not using RecoverableState for persitence?

@vdusek

vdusek commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Btw. not using RecoverableState for persitence?

Refactored to use it.

@barjin barjin left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @vdusek , I left a few ideas below ⬇️ , but mostly lgtm

Comment thread src/apify/_actor.py Resolved
Comment thread src/apify/_actor.py Resolved
Comment thread src/apify/_child_runs.py Resolved
@vdusek vdusek changed the title feat: add a concurrency limit for named child runs feat: add a concurrency limit for child runs Nov 11, 2026
@vdusek

vdusek commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

I'll scope this PR back to the concurrency limit for child runs (both named and unnamed) and merge it in that form.

Support for child runs without a run_name will move to seprate "fix:" PRs (they should be probably merged at first):

  • List child runs started without a run_name in Actor.child_runs. This PR already records them, but only for the concurrency limit.
  • Support abort_with_parent for child runs started without a run_name.

And later we can try to implement Pepa's idea: #1154 (comment) .

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.

Limit the number of concurrent child runs

4 participants