Skip to content

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

Open
vdusek wants to merge 4 commits into
fix/wait-for-child-run-startsfrom
feat/child-run-concurrency-limit
Open

vdusek wants to merge 4 commits into
fix/wait-for-child-run-startsfrom
feat/child-run-concurrency-limit

Conversation

@vdusek

@vdusek vdusek commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Part 5 of 6 of the final specification of Actor composability: "Tracking child runs", section 5. Stacked on #1272.

  • New option Actor(max_concurrent_child_runs=...). None, the default, means no limit, and any other value must be a positive integer. It needs child run tracking.
  • While the recorded runs with an active status plus the starts in flight are at the limit, a call that would start a new run waits. Waiting calls start in the order in which they were made. A call that returns a recorded run never waits.
  • A recorded active status that this process did not get from the API in the last 10 seconds is fetched again before it counts. This covers every status loaded from an earlier process. A run that the API does not return does not count.
  • After the abort starts, a call that waits for the limit, or would have to, raises a RuntimeError.
  • timeout='inherit' is resolved when the start request goes out, so the child does not get the time that the call spent waiting.
  • The limit is held in memory, so the parent sets it in every process.

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 94.89796% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.01%. Comparing base (a93f627) to head (79c304e).

Files with missing lines Patch % Lines
src/apify/_child_runs.py 94.62% 5 Missing ⚠️
Additional details and impacted files
@@                        Coverage Diff                        @@
##           fix/wait-for-child-run-starts    #1154      +/-   ##
=================================================================
- Coverage                          94.05%   94.01%   -0.04%     
=================================================================
  Files                                 54       54              
  Lines                               4105     4196      +91     
=================================================================
+ Hits                                3861     3945      +84     
- Misses                               244      251       +7     
Flag Coverage Δ
e2e 31.05% <24.48%> (-0.16%) ⬇️
integration 49.78% <24.48%> (-0.57%) ⬇️
unit 91.46% <94.89%> (+0.01%) ⬆️

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 review from Pijukatel and 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.

I am struggling a lot with the variable naming in this PR. Reading this with fresh eyes the variable names gave me a lot of false leads instead of building a helpful mental model.

The usage of word slot here had a very confusing effect on me. One time it was for an asyncio.Condition and the second time for a very custom context manager that uses the first one inside...
On top of it, slot has its own established meaning in Python, but here it is not related in any manner.

Comment thread src/apify/_child_runs.py Resolved
Comment thread src/apify/_actor.py Resolved
Comment thread src/apify/_child_runs.py Resolved
Comment thread src/apify/_child_runs.py Resolved
Comment thread src/apify/_child_runs.py Resolved
@vdusek
vdusek requested a review from Pijukatel October 30, 2026 08:47

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

@vdusek
vdusek marked this pull request as draft November 12, 2026 11:51
@vdusek
vdusek removed this pull request from stack #1152 November 20, 2026 16:33
@vdusek
vdusek force-pushed the feat/child-run-concurrency-limit branch from 0c64da0 to 50604d5 Compare November 20, 2026 16:35
@vdusek
vdusek changed the base branch from master to fix/wait-for-child-run-starts November 20, 2026 16:35
@vdusek
vdusek added this pull request to stack #1274 November 20, 2026 16:35
@vdusek
vdusek force-pushed the feat/child-run-concurrency-limit branch from 50604d5 to 663af55 Compare November 20, 2026 17:52
@vdusek
vdusek marked this pull request as ready for review November 20, 2026 17:58
@vdusek
vdusek requested review from Pijukatel and barjin November 20, 2026 17:58
@vdusek
vdusek force-pushed the feat/child-run-concurrency-limit branch from 663af55 to 1fa9bba Compare November 20, 2026 18:39
@vdusek
vdusek force-pushed the feat/child-run-concurrency-limit branch from 730b008 to 881d56b Compare November 27, 2026 14:12
@vdusek
vdusek removed this pull request from stack #1274 November 27, 2026 14:16
@vdusek
vdusek added this pull request to stack #1286 November 27, 2026 14:16

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