-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Parallelize environment skill loading #29990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee1a3e5
Parallelize environment skill loading
anp-oai 04a59fc
codex: address PR review feedback (#29990)
anp-oai d1121cf
codex: address PR review feedback (#29990)
anp-oai 3db9e28
codex: address PR review feedback (#29990)
anp-oai be61f71
codex: address PR review feedback (#29990)
anp-oai 56e9e3f
codex: address PR review feedback (#29990)
anp-oai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ use codex_utils_path_uri::PathUri; | |
| use codex_utils_plugins::DISCOVERABLE_PLUGIN_MANIFEST_PATHS; | ||
| use codex_utils_plugins::plugin_namespace_for_root_uri; | ||
| use codex_utils_plugins::plugin_namespace_for_skill_uri; | ||
| use futures::StreamExt; | ||
| use futures::future::join_all; | ||
|
|
||
| use crate::model::SkillDependencies; | ||
|
|
@@ -31,6 +32,7 @@ use super::sanitize_single_line; | |
| use super::validate_len; | ||
|
|
||
| const MAX_SKILLS_ENTRIES_PER_ROOT: usize = 20_000; | ||
| const MAX_CONCURRENT_SKILL_LOADS: usize = 64; | ||
|
|
||
| /// URI-native metadata for one skill owned by an execution environment. | ||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
|
|
@@ -220,24 +222,32 @@ pub async fn load_environment_skills_from_root( | |
| .filter_map(|(plugin_root, namespace)| namespace.map(|namespace| (plugin_root, namespace))) | ||
| .collect::<HashMap<_, _>>(); | ||
|
|
||
| for path in discovery.skill_files { | ||
| let mut ancestor = path.parent(); | ||
| let plugin_namespace = loop { | ||
| let Some(current) = ancestor else { | ||
| break None; | ||
| // Remote executors can multiplex these independent per-skill reads, so polling a bounded | ||
| // number together allows the I/O for each skill and its metadata to happen concurrently. | ||
| let skill_results = futures::stream::iter(discovery.skill_files) | ||
| .map(|path| { | ||
| let mut ancestor = path.parent(); | ||
| let plugin_namespace = loop { | ||
| let Some(current) = ancestor else { | ||
| break None; | ||
| }; | ||
| if let Some(namespace) = plugin_namespaces.get(¤t) { | ||
| break Some(namespace.as_str()); | ||
| } | ||
| ancestor = current.parent(); | ||
| }; | ||
| if let Some(namespace) = plugin_namespaces.get(¤t) { | ||
| break Some(namespace.as_str()); | ||
| async move { | ||
| let result = | ||
| EnvironmentSkillMetadata::parse(file_system, &path, plugin_namespace).await; | ||
| (path, result) | ||
| } | ||
| ancestor = current.parent(); | ||
| }; | ||
| match EnvironmentSkillMetadata::parse( | ||
| file_system, | ||
| &path, | ||
| /*plugin_namespace*/ plugin_namespace, | ||
| ) | ||
| .await | ||
| { | ||
| }) | ||
| .buffered(MAX_CONCURRENT_SKILL_LOADS) | ||
|
anp-oai marked this conversation as resolved.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In term of defensive, this will be interesting because it means the executor can make the memory usage of the orchestrator explode through this. To me this is a potential attack surface |
||
| .collect::<Vec<_>>() | ||
| .await; | ||
|
|
||
| for (path, result) in skill_results { | ||
| match result { | ||
| Ok(skill) if skill.matches_product_restriction(restriction_product) => { | ||
| outcome.skills.push(skill); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.