Skip to content

fix(deploy): hand the process CODEFLY_GRPC_PORT in the deployment - #124

Merged
antoinetoussaint-byte merged 1 commit into
mainfrom
fix/project-grpc-port-in-deployment
Oct 29, 2026
Merged

antoinetoussaint-byte merged 1 commit into
mainfrom
fix/project-grpc-port-in-deployment

Conversation

@antoinetoussaint-byte

@antoinetoussaint-byte antoinetoussaint-byte commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A deployed FastAPI service that declares a gRPC endpoint (grpc-server.enabled) gets the gRPC containerPort and Service port from this agent's kustomize template, but its container env carries no CODEFLY_GRPC_PORT: the template projected only CODEFLY_CONNECT_PORT. Locally the runtime hands the process CODEFLY_GRPC_PORT (runtime.go), so a service that reads the variable strictly works locally and crashloops in the cluster with KeyError (measured live on a cell). The scaffold hid this by guessing 9090 when the variable is unset; a deployed service should not have to guess a port the agent already rendered into the Service.

Fix

templates/deployment/kustomize/base/deployment.yaml.tmpl now projects CODEFLY_GRPC_PORT from .Deployment.Parameters.GRPCPort whenever GRPCEnabled is set, mirroring the Connect block. The env value and the Service/containerPort come from the same parameter (core's standards.Port(standards.GRPC)). No port is hardcoded and no service code changes.

Docs: the Parameters doc comment in builder.go no longer says the app defaults when the variable is unset, and the scaffold's main.py.tmpl comment says codefly hands the port locally and in the deployment. docs/ and the repo have no other description of the deployment env (there is no README).

Classification: fix, at the owning place (this agent's deployment recipe). Reuses the existing GRPCEnabled/GRPCPort parameters and the existing Connect env pattern; adds no mechanism.

Tests

  • TestDeploymentRendersGRPCPort (extended) asserts the rendered deployment carries - name: CODEFLY_GRPC_PORT / value: "9090" for a gRPC-enabled render and no CODEFLY_GRPC_PORT when gRPC is off. It fails against the previous template (checked by restoring it).
  • Local (macOS arm64, cgo on, Docker/OrbStack, uv, syft, nix present): go build ./..., go vet ./..., go mod tidy -diff, gofmt -l clean. Full go test -count=1 -timeout 40m -v ./...: ok in 391 s, 180 top-level tests passed, 0 failed, 1 skipped (TestNativeAgentOwnershipLifecycle, which needs FASTAPI_NATIVE_AGENT_HOME/FASTAPI_QUALIFICATION_CLI). The lifecycle matrix ran native, nix and docker; TestCreateToRunDocker passed. go test -race was left to the CI race job (runtime.go is untouched).

Not verified: a redeploy on a cluster with the released agent.

🤖 Generated with Claude Code

A deployed FastAPI service with grpc-server on got the gRPC containerPort
and Service port from the kustomize template, but its container env carried
only CODEFLY_CONNECT_PORT. Locally the runtime hands the process
CODEFLY_GRPC_PORT; in the cluster the app had to guess the port the agent
had already rendered into the Service. The scaffold guessed 9090, and a
service that reads the variable strictly crashlooped with KeyError.

The deployment template now projects CODEFLY_GRPC_PORT from
Parameters.GRPCPort whenever GRPCEnabled is set, mirroring the Connect
block, so the variable and the Service port come from the same value. The
Parameters doc comment and the scaffold's main.py comment say so.

TestDeploymentRendersGRPCPort asserts the variable and its value on a
gRPC-enabled render and its absence when gRPC is off; it fails against the
previous template.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@antoinetoussaint-byte
antoinetoussaint-byte merged commit a3fe434 into main Oct 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant