From 8afc6dafaa57506f25a7a2e4dbd0520c0570a416 Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Tue, 3 Nov 2026 19:59:42 +1000 Subject: [PATCH] AGENTS.md: correct buf breaking and upstream PR pin entries, add .venv rule --- AGENTS.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 582530d..407f0ef 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,6 +5,7 @@ Project-intrinsic agent knowledge: build, test, release, architecture and sharp- ## Generated code - `proto/` is the only hand-edited code; everything under `packages/typescript/src` and `packages/python/tesla_protocol/*/` is generated (`pnpm install && pnpm generate`). CI fails on any diff, so never edit generated files directly. +- Run every repo Python script and test with `.venv/bin/python`, never system `python3` (it has no protobuf). `.venv` does not exist until `pnpm install && pnpm generate` has run in the checkout. Run buf as `pnpm exec buf`. - Each `proto//` compiles as an isolated `--proto_path` root (`GROUPS_LIST` in `scripts/generate.sh`); there is no cross-group `import`. Structurally identical types therefore exist independently in several groups on purpose - e.g. `energy_device/signed_message.proto`'s signing envelope for the Powerwall local v1r endpoint mirrors `command`'s `UniversalMessage`/`Signatures`, and `SignatureType` is defined in both `vcsec.proto` and `signatures.proto`. Do not "de-duplicate" across groups. - Adding a new proto directory means registering it in three places: the `buf.yaml` module list, `GROUPS_LIST`, and the README layout table. Package exports are wildcarded, so no per-group registration there. - Python output is compiled from a staged copy (`scripts/namespace_protos.py`) that registers every file as `tesla_protocol//.proto` and every package as `tesla_protocol.`, so the modules never collide in Python's process-wide descriptor pool with another library's copy of Tesla's protos. `proto/` and the TypeScript output keep upstream's names; the Python descriptor full names (e.g. `tesla_protocol.CarServer.Action`) intentionally differ from the `.proto` sources. @@ -15,20 +16,20 @@ The codegen toolchain is fully pinned (`scripts/requirements.txt`, ts-proto in r - The gencode stamp is a *minimum runtime requirement*, so RAISING it breaks every consumer below it. The stamp and the `protobuf>=…` floor in `pyproject.toml` move together, in one major-bump changeset, or not at all. One wheel serves every runtime; do NOT split the package by protoc version. - Verified grpcio-tools -> gencode mapping (recheck by compiling a throwaway proto): 1.74.0-1.80.0 emit 6.31.1, 1.81.0-1.81.1 emit 6.33.5, 1.82.0+ emit 7.35.x; no release emits 6.32.x. The pin sits at 1.81.1/6.33.5 because protobuf supports only the newest minor of a major (https://protobuf.dev/support/version-support), making 6.33 the lowest supported 6.x. Moving to 1.82.0+ raises `VersionError` at import for every 6.x runtime - a deliberate drop of 6.x support, not a routine bump. -- Bumping the pin rewrites the stamp in all 38 `_pb2.py` files and the `protoc vX` header of every `.ts` file while leaving serialized descriptors byte-identical. A stamp-only diff is expected and wire-neutral; anything else in that diff deserves scrutiny. +- Bumping the pin rewrites the stamp in every `_pb2.py` file and the `protoc vX` header of every `.ts` file while leaving serialized descriptors byte-identical. A stamp-only diff is expected and wire-neutral; anything else in that diff deserves scrutiny. ## Upstream sync - `upstream.json` pins the commit and per-file sha256 that `proto/command/` and `proto/telemetry/` are reconciled against. Run `scripts/upstream_coverage.py --mode pinned` before pushing proto changes; its module docstring documents the modes, the delta outcome classes and the upstream-wins/`Void {}` rule. - Local additions inside upstream-tracked files must carry a `TESLEMETRY-EXT` marker (trailing comment or `BEGIN`/`END` fence). The fence parser is flat and non-nesting: a `BEGIN` inside an open fence overwrites the open start, so only the innermost pair ends up marked. Adding a message inside an existing fenced block needs no new fence - it inherits the block's coverage. - `upstream-drift.yml` decides whether to reconcile from the delta's `reconcile_needed` field, NOT the exit code (which reflects schema coverage only): upstream re-publishing an already-local symbol changes pinned bytes without changing coverage. -- To pull in a not-yet-merged upstream change (an open PR against a branch owned by the upstream org, not a fork), pin `upstream.json` to that PR's head commit and file sha256 so `--mode pinned` passes - these are upstream fields, not `TESLEMETRY-EXT` extensions. When upstream merges with identical bytes, reconciliation is a no-op. +- To pull in a not-yet-merged upstream change, pin `upstream.json` to that PR's head commit and file sha256 so `--mode pinned` passes - these are upstream fields, not `TESLEMETRY-EXT` extensions. This works for a PR from a fork too: the upstream repo's raw URL serves the fork's head commit. When upstream merges with identical bytes, reconciliation is a no-op. While the pin sits on a PR head, the weekly `upstream-drift.yml` PR moves it back to upstream main and drops that PR's symbols; never push a fix to its `upstream-reconcile` branch, which every run force-pushes. ## Proto content rules - `CarServer.Response.response_msg` (`proto/command/car_server.proto`): every field must be either modelled in the oneof or `reserved` with a reason comment; `scripts/check_reply_coverage.py` enforces this against `KNOWN_REPLY_FIELDS`. Before modelling a new reply field, check whether its payload type pulls in an app-only namespace - either model it or add it as a reserved entry. - Un-reserving a field to model it trips buf's `RESERVED_MESSAGE_NO_DELETE` even though it is a wire-compatible addition; `buf.yaml` excepts that rule repo-wide. -- Tag renumbering is a hard `buf breaking` gate, not a guideline: it fires even with hard evidence a published tag is wrong, and reserving the number alone is not enough - `FIELD_NO_DELETE` also requires reserving the name, which then collides with reusing it at the corrected number. Never attempt an in-place renumber; it always needs a maintainer decision. The sanctioned fix, once approved, is to reserve the old number and name and add a differently-named field at the correct number - a breaking rename needing a major changeset. Live example: `NavigationSuperchargerRequest` keeps `"order"` reserved by name, with `id` at tag 1 and `remote_nav_trip_order` at tag 2. +- `buf breaking` (`WIRE_JSON`) fails every rename, renumber, retype and oneof move, even a wire-correct fix with hard evidence that a published tag or type is wrong. Never make one without a maintainer decision. Once one is approved, the release that carries it adds a temporary `breaking.ignore_only` block to `buf.yaml` that names only the rules that fired and only the files they fired on (buf scopes an ignore by file, not by field), merged with any block already there. Delete that block in the first PR after the release is published. For a single field, the other option is to reserve the old number and name and add a differently-named field at the correct number: `NavigationSuperchargerRequest` keeps `"order"` reserved by name, with `id` at tag 1 and `remote_nav_trip_order` at tag 2. - A symbol not yet seen on a live vehicle carries `UNCONFIRMED: not yet confirmed on a live vehicle`, plus `name not recovered` when its name is a placeholder (e.g. `field_3`); drop the marker once wire-confirmed. Published text (protos, changesets, PR bodies, docs) never narrates where a schema came from. - `CarServer.VehicleState` is upstream's name for the legacy vehicle-state surface (`VehicleData` 6); the current surface at `VehicleData` 18 is `CurrentVehicleState`. Never rename `VehicleState` (upstream owns the name; the coverage gate would fail permanently). The two share many field names at different tags, so add a field only to the message whose tag layout it belongs to. - Several `energy_device` fields and `MessageEnvelope` payload tags reference types from sibling proto packages this repo does not publish; they stay unmodelled behind a short inline comment rather than being guessed at or vendored in. @@ -44,7 +45,7 @@ The codegen toolchain is fully pinned (`scripts/requirements.txt`, ts-proto in r - Changesets tracks the npm package only; `scripts/sync-python-version.mjs` copies the version into `pyproject.toml` during `pnpm run version`. Bump rules: `.changeset/README.md`. Never use changesets prerelease mode - `-next.N` is not valid PEP 440. - Versions follow pragmatic versioning (BIGRELEASE.ANNOUNCE.INCREMENT, https://raw.githubusercontent.com/seveibar/pragmaticversioning/refs/heads/main/README.md), not strict semver: INCREMENT is the default for any ordinary contribution - don't deliberate over whether an addition "counts" as a feature. ANNOUNCE is for a substantial incompatible change or a user-visible feature set; BIGRELEASE for a marketed milestone. -- `publish.yml` calls `ci.yml` as a reusable workflow so the full suite runs against the exact SHA it publishes; both publish jobs depend on that gate - keep them wired to it if you touch the release path. Publish flow and interrupted-publish recovery (always re-run the failed job, never fix the registry by hand) are in README "Releases". +- The publish flow, its `ci.yml` gate and interrupted-publish recovery (always re-run the failed job, never fix the registry by hand) are in README "Releases". - The `production` GitHub environment's required reviewer and main-only branch policy are configured on the environment, not in-repo; inspect via `gh api repos/Teslemetry/tesla-protocol/environments/production`. ## Maintaining this file