fix(agents): keep Python bytecode in bundled code deploys #11008
All Vouch review confidence checks passed
Residual risk 0.35 = Change Risk (0.66) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.66 · 351 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.351
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.066
Real PR Conversation Timeline
1 comments
"Review active on #11008"
general
weight: 0.35
1AbdullahButt
Summary
dependency_resolution: bundled,azd deploystripped every__pycache__/directory and.pycfile from the code package, because the default.agentignore(both the fileazd ai agent initwrites and the fallback defaults) excludes them. The hosted runtime can't write bytecode into the read-only package, so each cold start recompiled every imported module. The issue measured about 2 s of extra import time per cold start.__pycache__/directories and.pycfiles. This is option 1 from the issue. Every other.agentignorerule still applies (.venv/,.env,.pyo, the azd files, and so on), andremote_buildpackaging is unchanged.azd ai agent initnow shows the command from the issue:python -m compileall -q --invalidation-mode checked-hash .. Timestamp-based.pycfiles go stale after the zip is extracted, so the hint uses checked-hash.The override applies even when a user's own
.agentignorelists__pycache__/or.pyc, because the generated file contains those lines and most bundled projects have it. In bundled mode, the person deploying has built the tree on purpose, so shipping their bytecode seemed the right default. If you'd rather keep explicit user rules in charge, I can change it, for example by only overriding when the lines match the generated defaults.Fixes #10985.
Validation
GOTOOLCHAIN=auto):go test ./internal/project/passes, andgo vet ./internal/project/ ./internal/cmd/is clean. The changed files are gofmt-clean.bundled_bytecode_test.gorunpackageCodeDeployon apip install --targetstyle tree with the generated.agentignore:-
TestPackageCodeDeploy_PythonBundledKeepsBytecode: the zip has__pycache__/main.cpython-313.pycandrequests/__pycache__/__init__.cpython-313.pyc, and not.venv/.-
TestPackageCodeDeploy_RemoteBuildStillDropsBytecode: with nodependencyResolutionset, or withremote_build, the bytecode is still left out.-
TestAgentIgnore_KeepPythonBytecode: matcher-level check that other rules still apply.PythonBundledKeepsBytecodeandKeepPythonBytecodeboth fail (the zip has no.pycfiles), and the remote-build test still passes.go test ./internal/cmd/has two failures,TestFoundryResourceOwnershipMetadataandTestFoundryReleaseMetadata. They fail the same way on main in my checkout, so they're not caused by this change.I didn't deploy to a hosted agent or re-measure cold starts. The timings are the ones in the issue.
AI disclosure: I made this change with help from Claude Code, and I reviewed the diff and the test results myself.
🤖 Generated with Claude Code