fix(skills): skip vendored dep trees in install verification script enumeration (#3943)

* fix(skills): skip vendored dep trees in install verification script enumeration

sortedScriptPaths fed every .py/.js/.sh in the bundle into one shell 'for
f in ...' command. A skill that vendors a scientific venv (pandas/scipy/
matplotlib etc.) carries thousands of .py files under .venv/, and the
generated command exceeds the exec single-argument limit (MAX_ARG_STRLEN,
128KiB): /bin/sh fails with 'argument list too long' (exit 255) before
any check runs, so no dependency-heavy skill can ever install.

Vendored trees are installed dependencies, not scripts the model can
name; their health is already covered by the dependency verification
passes. Skip .venv/ and node_modules/ prefixes in sortedScriptPaths,
which fixes the tree check, the per-language parse passes and the
runtime prerequisite pass at once.

Verified by installing a 4862-file / 105MB quant skill (pandas+numpy+
scipy+statsmodels+matplotlib venv, real interpreter binary instead of
symlinks since zips cannot carry them): install failed before the fix,
reaches ready after it.

* fix(skills): skip vendored trees at any depth, not only at the bundle root

Bundles are author-zipped, so tools/.venv/ or sub/package/node_modules/
are as legal as root-level trees and enumerated just the same. The
filter now matches vendored trees under any prefix; nested placements
are covered by a regression test.

---------

Co-authored-by: vicfei <vicfei@users.noreply.github.com>
main
Fei.Chen 2026-10-08 01:28:45 +08:00 committed by GitHub
parent 562127c654
commit b8d83eab1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 0 deletions

View File

@ -1401,6 +1401,20 @@ func TestSortedScriptPathsIsDeterministic(t *testing.T) {
"only files the runtime can execute are scripts")
}
func TestSortedScriptPathsSkipsVendoredTreesAtAnyDepth(t *testing.T) {
bundle := &SkillBundle{Files: map[string][]byte{
"scripts/main.py": []byte("x"),
".venv/lib/pkg/a.py": []byte("x"),
"node_modules/leftpad/index.js": []byte("x"),
"tools/.venv/lib/otherpkg/b.py": []byte("x"),
"sub/package/node_modules/pkg/c.mjs": []byte("x"),
}}
require.Equal(t, []string{"scripts/main.py"},
sortedScriptPaths(bundle, allScriptExtensions...),
"vendored trees are skipped at the bundle root and nested under subprojects")
}
type stubWorkspaceSandboxPolicy struct {
disabled bool
}

View File

@ -426,12 +426,24 @@ var allScriptExtensions = []string{".py", ".js", ".mjs", ".cjs", ".sh"}
// sortedScriptPaths returns the bundle's files with any of the given suffixes,
// in a stable order so the emitted command is deterministic.
//
// Vendored dependency trees (.venv/, node_modules/) are skipped at any depth:
// they are installed dependencies, not scripts the model can name. A scientific
// stack vendors thousands of .py files, and enumerating them overflows the exec
// single-argument limit ("argument list too long") in every pass that builds
// one command from this list; the trees' health is covered by the dependency
// verification passes instead. Bundles are author-zipped, so a vendored tree
// can sit inside a subproject directory (tools/.venv/…) as easily as at the
// root — both placements are filtered.
func sortedScriptPaths(bundle *SkillBundle, suffixes ...string) []string {
if bundle == nil {
return nil
}
var matches []string
for rel := range bundle.Files {
if underVendoredTree(rel) {
continue
}
for _, suffix := range suffixes {
if strings.HasSuffix(rel, suffix) {
matches = append(matches, rel)
@ -443,6 +455,17 @@ func sortedScriptPaths(bundle *SkillBundle, suffixes ...string) []string {
return matches
}
// underVendoredTree reports whether a bundle-relative path sits inside a
// .venv or node_modules tree, at the bundle root or nested under any prefix.
func underVendoredTree(rel string) bool {
for _, tree := range []string{".venv/", "node_modules/"} {
if strings.HasPrefix(rel, tree) || strings.Contains(rel, "/"+tree) {
return true
}
}
return false
}
// nodeDependencyNames lists the runtime dependencies package.json declares.
// devDependencies are excluded: they are a build-time concern and the image
// is not asked to carry them.