All jobs

Fix grpc.WithInsecure Is Deprecated (SA1019) in a Go gRPC Service

Yes. An agent runs staticcheck, replaces WithInsecure with WithTransportCredentials(insecure.NewCredentials()), moves Dial to NewClient and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and reads the Go module first. In a small Raft-over-gRPC service like Jille/raft-grpc-example, go.mod declares go 1.18 with google.golang.org/grpc v1.57.0, github.com/hashicorp/raft v1.7.0 and github.com/Jille/raft-grpc-transport v1.6.0. Two files dial: main.go builds the node-to-node transport with transport.New(raft.ServerAddress(myAddress), []grpc.DialOption{grpc.WithInsecure()}), and cmd/hammer/hammer.go opens its client with grpc.Dial("multi:///localhost:50051,localhost:50052,localhost:50053", grpc.WithDefaultServiceConfig(serviceConfig), grpc.WithInsecure(), ...), with a multi resolver registered by a blank import and a retry interceptor. The README's cluster commands build three nodes by hand, there is no .github directory and no _test.go file.

Then it shows why nobody noticed. go build ./... and go vet ./... are both clean, because vet does not report deprecations. staticcheck ./... reports exactly two lines, cmd/hammer/hammer.go:28:49 and main.go:88:71, each with the full message: google.golang.org/grpc.WithInsecure is deprecated: use WithTransportCredentials and insecure.NewCredentials() instead. Will be supported throughout 1.x. (SA1019). After go get google.golang.org/grpc@latest, which raises the go directive and pulls a newer google.golang.org/protobuf, the build still passes and staticcheck grows: grpc.Dial is deprecated: use NewClient instead on the hammer, io/ioutil has been deprecated since Go 1.19 in application.go line 7, and four protoimpl.MessageInfo.Exporter lines in the generated proto/service.pb.go.

The fix is two files. The agent imports google.golang.org/grpc/credentials/insecure in both, replaces each grpc.WithInsecure() with grpc.WithTransportCredentials(insecure.NewCredentials()), and changes the hammer's grpc.Dial to grpc.NewClient, keeping the multi:/// target, the service config and the interceptor as they are. NewClient does not connect until the first RPC, which is also how Dial behaved here, since the file never passed WithBlock; the hammer already sends every call with grpc.WaitForReady(true), so a cluster that is still electing a leader is waited for as before. The transport stays plain text between Raft nodes, exactly as the old option meant it.

It checks the change the same way it found the problem: gofmt -l . prints nothing, go build ./... and go vet ./... pass, and staticcheck ./... no longer names WithInsecure or Dial. The ioutil import and the generated protobuf file are left alone and listed in the pull request, since the first is a one-line swap the owner may want in the same series and the second is regenerated through proto/Makefile, whose --go_out=plugins=grpc flag belongs to the old protoc plugin and is a separate change.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "staticcheck reports SA1019 in this Go service: google.golang.org/grpc.WithInsecure is deprecated. Read go.mod and every file that imports google.golang.org/grpc first, run go build ./..., go vet ./... and staticcheck ./... (install it with go install honnef.co/go/tools/cmd/staticcheck@latest), and quote each deprecation line. Replace every grpc.WithInsecure() with grpc.WithTransportCredentials(insecure.NewCredentials()) from google.golang.org/grpc/credentials/insecure, and change grpc.Dial to grpc.NewClient where the target string and options allow it; keep every other dial option. Then run go get google.golang.org/grpc@latest in a second commit, rebuild, and report any new deprecation staticcheck shows without fixing unrelated ones. Run gofmt, go build, go vet and staticcheck again, run any tests, and open a pull request that quotes the staticcheck output before and after.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request with two commits. The first touches main.go and cmd/hammer/hammer.go only: one new import each, two credential options, one NewClient. The second bumps go.mod and go.sum to the current gRPC release, which in this repository also moves the go directive, and the description says so plainly so the owner can drop that commit if the team's toolchain is older. The description quotes the two SA1019 lines from before, the clean staticcheck run after, and the extra deprecations the upgrade surfaced (ioutil, the generated Exporter fields), each with the file and line.

A reviewer checks three things: that no WithTransportCredentials call was given real TLS credentials by accident, since this service is meant to speak plain text between its own nodes; that the hammer's target string, service config and retry interceptor are unchanged; and that go build ./... is green on the bumped module. The run's record holds every command and its output, so the staticcheck lines in the description can be opened as the terminal sessions that produced them.

Run it on every Monday morning

Add an automation to the Project with this prompt and a schedule trigger, cron set to 0 9 * * 1 in your timezone. Each Monday one run bumps google.golang.org/grpc, runs staticcheck and opens one pull request on its own branch; a week where the build or staticcheck cannot be made to pass ends needs_review with the output attached rather than a half-fixed branch, and a week with nothing to change opens nothing.

The same body works from your own code on any schedule you already run: POST /o/{org}/sessions with an API key starts the run, and the key's webhook_url receives run.completed or run.failed with the session URL and the pull request when it ends.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

A Go deprecation is invisible to the commands most teams run. go build and go vet stay green while WithInsecure and Dial wait for the release that removes them, so the warning is only ever seen by whoever installs staticcheck and runs it against the newest gRPC. On Rush the run does that in a sandbox of its own, with the module's declared version and then with the latest, and both staticcheck outputs stay in the run's record, so the pull request argues from what the tool printed rather than from a changelog someone remembers.

It also scales to every Go service at once. Each repository gets its own run and its own pull request with the same prompt, the branch is attributable to the automation that opened it, and nothing merges by itself: the result is a reviewed change with the proof attached, not a dependency bot's version bump with no idea what it broke.

Frequently asked questions

Why does go vet not report this?

Deprecation is a comment convention, // Deprecated: on the symbol, and vet does not check it. staticcheck's SA1019 does, which is why the agent installs it and runs it in the sandbox rather than trusting the build. The same check is what CI should run afterwards, and the pull request says where to add it.

Does NewClient change how the hammer connects?

Not in this repository. grpc.Dial without WithBlock already returned before any connection was made, and NewClient does the same; the target, the multi resolver, the round-robin service config and the retry interceptor are passed through unchanged. The calls themselves use grpc.WaitForReady(true), so they still wait for a healthy node instead of failing fast.

Is the connection still insecure afterwards?

Yes, on purpose. insecure.NewCredentials() is the explicit spelling of what WithInsecure() meant, plain text with no TLS, which is what this example uses between Raft nodes on localhost. Adding real TLS is a different change, and the pull request does not make it.

Will it also replace ioutil and regenerate the proto file?

Only if you ask. The prompt scopes the work to the gRPC deprecations; the ioutil import and the generated service.pb.go are reported with their lines so you can decide. Regenerating needs the protoc plugin named in proto/Makefile, and that command itself uses the old plugins=grpc form.

More jobs like this: Upgrade dependencies weekly

Keep reading