← Back to Pull requests

fix(agent-runtime): stop DockerDeployer env from overriding governance settings #4409

Closed
unknown closed this pull request without merging on Oct 27, 2026 01:40 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 06:01 UTC
Author

Related Issue


None. This is a bug I found in agent_runtime.deploy.DockerDeployer; the sections below are filled in as the template asks.

Problem & Solution


Problem. DockerDeployer.deploy turns GovernanceConfig into AGT_* variables and then appends the caller's env entries after them:

"-e", f"AGT_KILL_SWITCH={str(config.kill_switch_enabled).lower()}",
...
if env:
    for k, v in env.items():
        cmd.extend(["-e", f"{k}={v}"])

docker run keeps the last -e for a name, so an env entry with a governance name replaces the configured value:

deployer.deploy("a1", "img", GovernanceConfig(kill_switch_enabled=True),
                env={"AGT_KILL_SWITCH": "false"})
# docker run ... -e AGT_KILL_SWITCH=true ... -e AGT_KILL_SWITCH=false img
# -> the container runs with AGT_KILL_SWITCH=false

The same applies to AGT_POLICY_PATH, AGT_TRUST_LEVEL, AGT_AUDIT_ENABLED, AGT_MAX_TOOL_CALLS, AGT_RATE_LIMIT_RPM and AGT_RETENTION_DAYS. The DeploymentResult says nothing about it, so the container quietly runs with different governance settings from the GovernanceConfig it was deployed with. A name containing = does the same thing: Docker splits -e AGT_KILL_SWITCH=false= at the first =.

Solution. deploy builds the governance variables as a dict and, before running Docker, raises ValueError if env names one of them or has an = in a name. The message points at GovernanceConfig as the place to set the value. Other variables, including other AGT_ names such as AGT_LOG_LEVEL, are passed exactly as before, and the docker run arguments for a valid call are unchanged.

Impact on Your Work


GovernanceConfig is what callers rely on to set the kill switch, audit flag, policy and limits of a deployed agent. With the bug, an env mapping assembled elsewhere (app settings, a copied .env) can turn those off with no sign in the result.

Timeline


None.

Alternatives Considered


  • Put env first so the governance values win. That keeps the configured values but silently drops what the caller asked for; raising tells them to set it on GovernanceConfig instead.

  • Reject every AGT_ name. Too broad: only the seven variables deploy sets from GovernanceConfig can collide, and other AGT_ variables may be legitimate agent settings.

  • Return a FAILED DeploymentResult. Invalid arguments already raise ValueError (_validate_agent_id) before Docker runs, so this follows the same pattern.
  • KubernetesDeployer.deploy takes no env argument, so it is not affected.

    Type of Change


  • Bug fix (non-breaking change that fixes an issue)
  • Package(s) Affected


  • agent-runtime
  • Testing


    Unit Testing


    In agent-runtime/tests/test_deploy.py:
  • test_deploy_rejects_env_overriding_governance_config (parametrized over the seven governance variables): deploy raises ValueError naming the variable and never calls Docker.

  • test_deploy_rejects_env_name_with_equals: env={"AGT_KILL_SWITCH=false": ""} raises ValueError.

  • test_deploy_keeps_other_agt_env: AGT_LOG_LEVEL is still passed and AGT_KILL_SWITCH=true comes from the config.
  • The first eight cases fail on main.

    Manual Testing


  • agent-runtime/tests: 127 passed.

  • ruff check --select E,F,W --ignore E501 (as in CI): clean on the changed files.

  • Spell check: ran cspell with .cspell.json on the changed files; no issues on added lines.
  • Checklist


  • I have linked a related issue above, or completed "Problem & Solution", "Impact on Your Work", and "Alternatives Considered"

  • My code follows the project style guidelines (ruff check)

  • I have added tests that prove my fix/feature works

  • All new and existing tests pass (pytest)

  • I have updated documentation as needed (CHANGELOG)

  • I have signed the Microsoft CLA
  • Attribution & Prior Art


  • This contribution does not contain code copied or derived from other projects without attribution

  • Any external projects that inspired this design are credited in code comments or documentation

  • If this PR implements functionality similar to an existing open-source project, I have listed it below
  • None.

    AI Assistance


  • I can explain every meaningful change in this PR: what it does, why, and what tradeoffs were considered

  • I have run tests and verification appropriate for this change

  • No part of this PR was autonomously submitted by an AI agent without my review

  • I have not used AI to generate review comments on others' PRs
  • I used Claude Code (Claude Opus) to help find the bug and draft the fix and tests. I reviewed the full diff and will handle review comments myself.

    IP, Patents, and Licensing


  • This contribution does not implement patent-pending or patent-encumbered techniques

  • This contribution does not require an NDA or licensing agreement to understand or use

  • Any AI tools used have terms compatible with the MIT License
  • 🤖 Generated with Claude Code

    Diff: 638 lines (+478 / -160) across 7 files Reviewer: prayagupa Review duration: 6938m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.74) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.74 · 638 lines diff across 7 files
    0.74
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.386
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.074
    Real PR Conversation Timeline
    1 comments
    "Review active on #4409"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 73.6% (HIGH) · Higher = larger blast radius
    73.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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 29.1% · Safe to merge
    29.1%