All jobs

Fix "expected exactly 5 fields, found 6" After Upgrading robfig/cron to v3

Yes. The agent finds the six-field specs v3 rejects, keeps seconds with cron.WithSeconds or rewrites them, makes the ignored error fatal, and opens a pull request.

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

What the agent does

robfig/cron v1 parsed six fields, seconds first, by default. v3 parses the standard five, so a spec such as 0 0 */2 * * * is refused with expected exactly 5 fields, found 6. The refusal comes back as an error from AddFunc, and code that discards that error, as v1-era wrappers often do, compiles cleanly and simply never runs the job. The run starts with the report that a scheduled job stopped firing, or with the error from a log, and the agent clones the repository into its own cloud sandbox.

In a Go service like sunnyegg/go-so, go.mod requires github.com/robfig/cron v1.2.0. cron/cron.go wraps the library: NewCron calls cron.New(), and the method AddFunc(spec string, cmd func()) calls cron.cron.AddFunc(spec, cmd) and returns nothing. api/cron.go registers two jobs when the server is built in api/server.go: ValidateToken on @hourly and DeleteExpiredSession on "0 0 */2 * * *", a six-field spec. The Makefile's test target runs go test -v -cover ./..., and .github/workflows/ci.yml runs it on Go ^1.22.0 against a Postgres container.

The agent reproduces the change before touching the code. It switches the import to github.com/robfig/cron/v3 and runs go get github.com/robfig/cron/v3@v3.0.1; go build ./... and go vet both pass, because v3's AddFunc returns (EntryID, error) and the wrapper's bare call discards both values. A small test then shows the behaviour: AddFunc("0 0 */2 * * *", ...) on a plain cron.New() returns expected exactly 5 fields, found 6: [0 0 */2 * * *], @hourly returns no error, and the same six-field spec on cron.New(cron.WithSeconds()) returns no error.

The fix has two parts. For the schedule, the agent either builds the scheduler with cron.WithSeconds(), which keeps every existing spec valid, or rewrites the one six-field spec as the five-field 0 */2 * * *; it picks the rewrite when no job needs second precision, and says so. For the silence, the wrapper's AddFunc now returns the error and registerCron fails server construction on a bad spec, so a wrong schedule stops the service at startup instead of waiting for someone to notice a job that never ran. A test in cron/ registers each production spec and asserts no error.

Start it with one API call

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

{
  "agent": "claude",
  "input": "After upgrading github.com/robfig/cron from v1 to v3 a scheduled job silently stopped. Find every schedule spec and the wrapper that registers it, show which specs v3 refuses with 'expected exactly 5 fields', fix them either with cron.WithSeconds or by rewriting to five fields, make the wrapper return AddFunc's error and fail startup on a bad spec, add a test that registers each spec, run go vet and go test, and open a pull request that explains the parser change.",
  "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 that changes go.mod, go.sum, cron/cron.go, api/cron.go and adds a test under cron/. Its description quotes the v3 parser error for the six-field spec, states which option it chose for the schedule and why, and shows go vet and go test ./... passing on the branch.

A reviewer checks that the rewritten spec fires at the same times as before (every two hours, on the hour), that the @hourly job is unchanged, and that a bad spec now fails NewServer rather than being logged and ignored. The CI workflow runs the suite against its Postgres container as for any pull request.

If other services in the organisation wrap the same library the same way, the pull request names the pattern (AddFunc with its error dropped) so they can be checked, and the session keeps the probe test and its output as the record.

Run it on every pull request labelled dependencies

Create an automation in the Project with this prompt and a github trigger on pull_request.labeled with the label dependencies. A label Dependabot or Renovate sets itself comes from a bot and fires nothing, so a maintainer adds it to the bump they want checked. Each labelled pull request starts one run with the event after the prompt; the run checks out that branch, registers every production spec against the new library version, and reports a refused spec on the pull request before it merges.

The run opens a pull request only when there is a code change to make, such as the parser option or the error handling; a bump that registers every spec without error ends with a comment and no pull request.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

This break is invisible to the compiler and to a test suite that never registers the real schedules: the build is green and the job is gone. A Rush run upgrades the module in its own sandbox, writes the probe that makes the parser's refusal visible, and keeps that output in the session, so the pull request shows the failure it fixes.

A major version change in a scheduling library affects every spec in every service that uses it. Runs can go in parallel, one per repository, each with the same probe and its own pull request, and each ends with proof: go test ./... on the branch and the list of specs the new parser accepts.

Frequently asked questions

Should I use cron.WithSeconds() or rewrite the specs?

If any job needs second precision, WithSeconds keeps the old six-field grammar for every spec. If none does, five-field specs are what every other cron tool reads, so the agent rewrites them and leaves the default parser. It states its choice and the specs it changed.

Why did the build pass if the schedule was wrong?

v3's AddFunc returns an EntryID and an error. The wrapper called it as a statement and discarded both, which Go allows. The job was refused at registration and never scheduled. The pull request makes the wrapper return the error so this cannot happen silently again.

Does the @hourly job need any change?

No. Descriptors such as @hourly and @every 1h parse the same in v1 and v3. The probe test registers it alongside the six-field spec to show which one the new parser refuses.

Will the import path change break anything else?

v3 lives at github.com/robfig/cron/v3, so the agent updates the import in cron/cron.go and lets go mod tidy drop the v1 requirement. The types used here, *cron.Cron, New, AddFunc and Start, exist in both, which is why the build passed.

More jobs like this: Fix a bug from an alert

Keep reading