← Back to Pull requests

Add async Python client (ate-env-client) under clients/python #47

Closed
unknown closed this pull request without merging on Aug 28, 2026 20:44 UTC
View on GitHub
unknown unknown commented on Aug 26, 2026 19:52 UTC
Author

Summary

Adds an async Python client for the ate-env-api gRPC services under clients/python/ — distribution ate-env-client, import package ate_env — mirroring the Go client (env/) with the full API surface, grpc.aio throughout.

async with Client("localhost:7777") as client:
    env = await client.create("dev1")
    result = await env.shell("echo hello")
    await env.write_file("/workspace/notes.txt", b"hi\n")
    async for chunk in env.stream_outputs(pid, follow=True): ...

  • Client — lifecycle over EnvironmentService (create/get/suspend/delete) plus a no-RPC env() handle factory; async context manager; endpoint normalization matching the Go client.

  • Env — process API (start_process, get_process, kill_process, wait, stream_outputs as an async iterator with follow support, shell with captured output/exit code) and file API (read_file server-streaming, read_file_bytes, write_file client-streaming accepting bytes or sync/async chunk iterables). Guest calls automatically carry the x-env-id/x-env-atespace routing metadata.

  • Errors — gRPC status codes map to an EnvError hierarchy (NotFoundError, InvalidArgumentError, PermissionDeniedError, RpcError).

  • Types — frozen dataclasses/IntEnums; generated protobuf types stay out of the public API.

  • README documents the architecture (which client call hits which service over which hop, with diagram) and a how-to manual.
  • Codegen

    Generated stubs are committed under src/ate_env/_gen/ (matching the committed Go pb files). Regenerate with clients/python/scripts/gen-protos.sh (or make python-protos) — grpc_tools.protoc with a relative-import rewrite. Note buf.gen.yaml only covers Go (and hardcodes local plugin paths), so the script is the Python codegen path.

    Testing

    Three layers:

    1. 56 unit tests — pytest + pytest-asyncio against in-process grpc.aio fakes that replicate the API server's semantics, including the metadata contract (INVALID_ARGUMENT "x-env-id header is required"), streaming in both directions, 64 KiB chunking boundaries, shell's poll loop, cancellation, and error mapping.
    2. 17 integration tests against a real examples/guest-daemon (gated on ATE_ENV_GUEST_TARGET, zero cluster dependencies): real subprocesses, cwd/env passthrough, binary/empty/large file roundtrips, output offset replay, kill terminating a follow stream, sandbox-escape → PermissionDeniedError.
    3. Full-stack suite against a live ate-env-api (gated on ATE_ENV_API_TARGET): verified on a GKE substrate cluster — the environment lifecycle path (create, wake-on-route, status, suspend-then-delete, NotFound mapping) works end-to-end.

    56 passed, 19 skipped (gated e2e)
    

    Known dependency

    Guest operations (process/file) through a cluster additionally require substrate to carry gRPC trailers on the actor path — i.e. agent-substrate/substrate#1183. Without it they fail with server closed the stream without sending trailers (the router's actor_original_dst upstream is pinned to HTTP/1.1). Environment lifecycle is unaffected; the client README carries a callout.

    Follow-ups (not in this PR)

  • CI workflow (install dev extra, gen-script drift check, pytest) — the repo has no Python test CI today.

  • PyPI publication (ate-env-client name availability unverified; nothing is published here).
  • Diff: 433 lines (+324 / -109) across 5 files Reviewer: SHRUTI6991 Review duration: 2931m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 433 lines diff across 5 files
    0.45
    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.363
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #47"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    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: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    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: 17.8% · Safe to merge
    17.8%