← Back to Pull requests

fix(agents): keep Python bytecode in bundled code deploys #11008

Open
unknown opened this pull request with 351 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 19, 2026 18:17 UTC
Author

Summary

  • With dependency_resolution: bundled, azd deploy stripped every __pycache__/ directory and .pyc file from the code package, because the default .agentignore (both the file azd ai agent init writes 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.

  • Python bundled packaging now keeps __pycache__/ directories and .pyc files. This is option 1 from the issue. Every other .agentignore rule still applies (.venv/, .env, .pyo, the azd files, and so on), and remote_build packaging is unchanged.

  • The bundled-mode hint printed during azd ai agent init now shows the command from the issue: python -m compileall -q --invalidation-mode checked-hash .. Timestamp-based .pyc files go stale after the zip is extracted, so the hint uses checked-hash.
  • The override applies even when a user's own .agentignore lists __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

  • Go 1.26 (GOTOOLCHAIN=auto): go test ./internal/project/ passes, and go vet ./internal/project/ ./internal/cmd/ is clean. The changed files are gofmt-clean.

  • New tests in bundled_bytecode_test.go run packageCodeDeploy on a pip install --target style tree with the generated .agentignore:

  • - TestPackageCodeDeploy_PythonBundledKeepsBytecode: the zip has __pycache__/main.cpython-313.pyc and requests/__pycache__/__init__.cpython-313.pyc, and not .venv/.
    - TestPackageCodeDeploy_RemoteBuildStillDropsBytecode: with no dependencyResolution set, or with remote_build, the bytecode is still left out.
    - TestAgentIgnore_KeepPythonBytecode: matcher-level check that other rules still apply.
  • With the fix turned off, PythonBundledKeepsBytecode and KeepPythonBytecode both fail (the zip has no .pyc files), and the remote-build test still passes.

  • go test ./internal/cmd/ has two failures, TestFoundryResourceOwnershipMetadata and TestFoundryReleaseMetadata. 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

    Diff: 351 lines (+263 / -88) across 4 files Reviewer: 1AbdullahButt Review duration: 12289m
    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
    0.66
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 65.6% (HIGH) · Higher = larger blast radius
    65.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 35.0% · Safe to merge
    35.0%