Skip to content

chore: clear the fmt and gen pre-commit debt on main - #409

Merged
ibetitsmike merged 1 commit into
mainfrom
mike/issue-407-precommit-debt
Nov 21, 2026
Merged

ibetitsmike merged 1 commit into
mainfrom
mike/issue-407-precommit-debt

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Refs #407.

What and why

A clean checkout of main at 5c8c0e2 fails make pre-commit in the fork-dev workspace: make fmt rewrites 24 files, make gen leaves generated files modified, and make lint reports 114 golangci-lint issues. This PR clears the fmt and gen debt with no logic changes. It does not fix the lint findings and does not add a lint job to fork-ci: that is PR #140, and this branch keeps clear of it.

The fork-ci fmt-drift job is split out of this PR into a patch posted on #407. Pushing a commit that touches .github/workflows/fork-ci.yaml is rejected because the token Mike uses lacks the workflow scope, and GitHub checks every pushed commit, so a revert on top does not help. The branch here contains no commit touching any workflow file. Applying the patch on #407 in a follow-up PR adds the fmt job to fork-ci.

Changes

  1. chore: pre-commit debt on main, fmt sweep and gen output (single commit, mechanical):
    • Go import grouping in fork files and one re-indented case in coderd/agentapi/context.go: what make fmt (gofumpt plus gci via scripts/format_go_file.sh) rewrites on a clean main checkout. 13 Go files.
    • Biome formatting (indentation, import order) in site/src/pages/AgentsPage and site/src/pages/AISettingsPage: 5 TS files.
    • Markdown table padding in docs/coder-agents/index.md: 1 file.
    • Generated output of make gen on the same checkout: coderd/apidoc/docs.go, coderd/apidoc/swagger.json, docs/reference/api/general.md, docs/reference/api/schemas.md.

Root causes found

make gen nondeterminism

In the repo, not a tool mismatch. The mise shim versions match the versions upstream pins (mise.toml, mise.lock): swag CLI v1.16.2, and the swag library that scripts/apidocgen/swaginit/main.go calls through go run is v1.16.6 from go.mod (the newest release). Both were confirmed with golangci-lint version, swag --version and go mod download.

The cause is in swag itself: PackagesDefinitions.ParseTypes in packages.go iterates pkgDefs.files, a Go map keyed by *ast.File, in random order, and collectConstVariables appends each package's constants to pkg.OrderedConst in that order. Any enum type whose constants span two files of one package gets a random enum order per run. This fork has exactly those, all created by fork files:

  • codersdk.Experiment (codersdk/deployment.go + codersdk/fork_experiments.go)
  • codersdk.ChatContextResourceKind (codersdk/chats.go + codersdk/fork_agent_definitions.go)
  • codersdk.ChatWatchEventKind (codersdk/chats.go + codersdk/fork_chat_watch.go)
  • codersdk.ChatTodoStatus shows the same class of issue

Evidence: two back-to-back go run ./scripts/apidocgen/swaginit runs produced different swagger.json (sha256 c9dd124b7baf then 5b11cb8dd544). A .github/fork/check-apidoc.sh jq filter already sorts three of these enums, added in commit d8a722f, which is why fork-ci did not catch it. The real fix belongs in swag (sort OrderedConst or iterate files deterministically), which is upstream code; this PR only commits one canonical generated output. That committed enum order is one sample from swag's random map order, so a later make gen may reorder it again; fork-ci's check-apidoc.sh sorts those enums, so CI stays stable. Making the generator output itself deterministic is #410.

make lint: 114 issues, not version drift

golangci-lint version reports v2.0.2, built with go1.26.10. mise.toml and mise.lock pin the same v2.0.2, and upstream CI installs the identical pin via mise install --locked with the same config. So the 114 issues are not version drift. They are pre-existing findings in fork files (about 110 of the 114 mention fork_), concentrated in coderd/x/chatd/fork_secret_answers.go (29, mostly revive unhandled-error on strings.Builder), fork_workflow_phases_internal_test.go (12), plus revive get-return, flag-parameter, gosec G115 and gocritic ruleguard findings across other fork files. Upstream's own .golangci.new-code.yaml gate passes with 0 issues (make lint/go/new-code on this branch: "0 issues."), so these never block new work. Fixing them is PR #140's scope, and this PR leaves every file #140 touches byte-identical to main.

Verification on the PR head (84ea060)

All Go, gen and make commands ran as flock ~/.fork-go.lock <command> in the fork-dev workspace.

  • make fmt, run twice: idempotent, second run rewrites nothing.
  • make gen, run twice on the committed output: no changes either time.
  • make lint/go/new-code: 0 issues.
  • make lint/docs-gen-filter: passes.
  • make lint/actions/actionlint: passes.
  • gofumpt -l over all non-generated Go files (Makefile FIND_EXCLUSIONS): empty.
  • go run github.com/daixiang0/gci diff --skip-generated -s standard -s default -s "Prefix(github.com/coder,cdr.dev/)" over the same file set: empty.
  • cd site && pnpm run format:check: "Checked 2537 files. No fixes applied."
  • pnpm run check-docs: markdownlint 0 errors, no table formatting applied.
  • cd site && pnpm run lint:types: passes.
  • cd site && pnpm test:ci src/pages/AgentsPage: 185 files, 3164 passed, 2 skipped.
  • The git hook opt-out git config --worktree coder.pre-commit false was set in this worktree only, per the interim rule in chore: clean main fails make pre-commit (fmt, gen and lint debt not gated by fork-ci) #407, and unset again.

Not verified

Overlap with PR #140

Checked with gh pr diff 140 -R ibetitsmike/coder --name-only. One file appears in both diffs, .github/workflows/fork-ci.yaml, and it reaches this PR only through the split-out patch on #407, not through this branch: the patch adds an fmt job, #140 adds a lint job after build, in separate hunks. The Go files in both diffs are disjoint except for coderd/x/chatd/fork_ancestors.go, where this PR changes one import blank line from the fmt sweep and #140 adds a //nolint:revive doc comment at line 20; separate hunks a normal merge resolves.

Scope guardrails

  • git diff --stat origin/main...HEAD -- coderd/database/migrations/chatdmig/nodes is empty.
  • Upstream-owned non-fork files changed only by what make fmt does to them on clean main: coderd/agentapi/context.go (one case re-indent), site/src/pages/AgentsPage/* (Biome), docs/coder-agents/index.md (table padding).
  • No em dashes in prose; every generated file matches make gen output.

One mechanical fmt sweep of what make fmt rewrites on a clean main
checkout (24 files: Go import grouping in fork files, Biome on site TS,
markdown table padding in docs) plus the make gen output of the same
checkout, because swag collects the enum constants of types declared
across two files in Go map order and the generated enum order shifts
from run to run (codersdk.Experiment, codersdk.ChatContextResourceKind,
codersdk.ChatWatchEventKind).

No logic changes. Nothing under
coderd/database/migrations/chatdmig/nodes is touched. Fork Go lint
findings and the fork-ci lint job are left to PR 140.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T11:36:09.677352Z 84ea060 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ibetitsmike
ibetitsmike merged commit 58f9009 into main Nov 21, 2026
11 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-407-precommit-debt branch November 21, 2026 11:45
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged at head 84ea060cb044a982793927cc1218903ad8925b65 as 58f9009, on main 5c8c0e2c7a0d4ace1fec54e4ebe5b1c5f33744c4, with the server running that main.

Gates on this exact head:

  1. The head matched the SHA I verified (--match-head-commit).
  2. Every check run passed. fork-ci run 44899254847 passed on this head.
  3. Codex receipt for this head: chore: clear the fmt and gen pre-commit debt on main #409 (comment). Code review completed with no findings, plus a +1 reaction.
  4. No unresolved review thread.
  5. 0 commits behind main.
  6. I checked this exact head myself:
    • git diff -w --ignore-blank-lines origin/main...84ea060cb0, excluding generated files: every changed line is an import moved between groups or a call or literal rewrapped. There are no logic changes.
    • swagger.json on main and on this head: byte-identical after sorting every string array with jq. Only enum order differs.
    • git diff --stat origin/main...84ea060cb0 -- coderd/database/migrations/chatdmig/nodes .github: empty.
    • The workstream ran make fmt and make gen twice each with no changes, gofumpt and gci with empty output, pnpm run format:check, lint:types, and pnpm test:ci src/pages/AgentsPage (3164 passed). I did not rerun those.

Not exercised: a running server. The change is formatting plus regenerated docs, and fork-ci build and chat-tests passed on this head.

This PR does not close #407. Two parts are still open: the fork-ci fmt-drift job, which waits on the token workflow scope or on Mike applying the patch on #407, and the golangci findings, which are draft #140's scope. Enum order determinism is #410.

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