Skip to content

fix: harden auto-format workflow and auto-regenerate OpenAPI snapshots#2026

Merged
nick-inkeep merged 2 commits intomainfrom
fix/ci-flakiness-auto-format-openapi
Feb 16, 2026
Merged

fix: harden auto-format workflow and auto-regenerate OpenAPI snapshots#2026
nick-inkeep merged 2 commits intomainfrom
fix/ci-flakiness-auto-format-openapi

Conversation

@nick-inkeep
Copy link
Collaborator

Summary

  • Fix auto-format workflow race condition that fails when PRs are merged while the workflow is running
  • Add lint-staged hook to auto-regenerate OpenAPI snapshots when route files change

Problem

Two recurring CI/CD flakiness issues identified across recent PRs:

1. Auto-format race condition (PRs #2005, #2012)

When a PR is merged within seconds of the auto-format workflow triggering, GitHub deletes the PR branch. The workflow's git fetch / git push then fails because the branch no longer exists on the remote.

2. OpenAPI snapshot drift (PRs #2009, #2010, #2011)

Developers change API route summaries/tags/paths but forget to run pnpm openapi:update-snapshot. The snapshot test catches this in CI, but the manual step is easy to forget.

Changes

Auto-format workflow (.github/workflows/auto-format.yml)

3-layer defense against branch deletion during workflow execution:

  1. PR state check — queries gh pr view before doing any work; skips if PR is already merged/closed
  2. Checkout fallbackcontinue-on-error: true on checkout with graceful exit if it fails
  3. Push guardgit ls-remote --exit-code before push and before each retry to verify branch still exists

OpenAPI snapshot auto-update (package.json)

  • Added lint-staged rule scoped to route files + openapi.ts + createApp.ts
  • When these files are committed, automatically runs openapi:update-snapshot and stages the result
  • Narrow glob avoids triggering on unrelated agents-api file changes (tests, utils, etc.)
  • CI remains the safety net for bypassed hooks or edge cases

Test plan

  • Format check passes
  • lint-staged runs and correctly skips new rule when no route files are staged
  • Commit succeeds with pre-commit hooks

🤖 Generated with Claude Code

Auto-format race condition: Add 3-layer defense against branch deletion
during workflow execution. When a PR is merged while auto-format is running,
the branch gets deleted and git fetch/push fails. Now: (1) check PR state
before starting, (2) continue-on-error on checkout with graceful exit,
(3) git ls-remote guard before push/retry.

OpenAPI snapshot drift: Add lint-staged hook to auto-regenerate the OpenAPI
snapshot when route files or openapi.ts change. Developers no longer need
to manually run `pnpm openapi:update-snapshot` — it happens automatically
on commit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Feb 16, 2026

⚠️ No Changeset found

Latest commit: 1dec593

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Feb 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Feb 16, 2026 1:08am
agents-docs Ready Ready Preview, Comment Feb 16, 2026 1:08am
agents-manage-ui Ready Ready Preview, Comment Feb 16, 2026 1:08am

Request Review

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

(0) Total Issues | Risk: Low

This PR implements a well-designed solution to two orthogonal CI/CD reliability problems. The 3-layer defense against the auto-format race condition (PR state check → checkout fallback → push guard) is robust, and the lint-staged hook for OpenAPI snapshot auto-regeneration is a sensible DX improvement with appropriately scoped file matching.

🔴❗ Critical (0) ❗🔴

None

🟠⚠️ Major (0) 🟠⚠️

None

🟡 Minor (0) 🟡

None

💭 Consider (1) 💭

💭 1) .github/workflows/auto-format.yml:52-56 Misleading step name

Issue: The step "Exit if checkout failed" doesn't actually exit the workflow — it only emits a GitHub notice annotation.

Why: The name implies termination, but execution continues (relying on conditional guards in subsequent steps). This works correctly but could confuse future maintainers.

Fix: Rename to "Log checkout failure" for accuracy, or add exit 0 if early termination semantics are preferred.

Refs: auto-format.yml:52-56


✅ APPROVE

Summary: Clean implementation with thoughtful defensive patterns. The 3-layer defense (PR state check, checkout fallback, branch existence verification) handles the race condition gracefully, and the lint-staged automation reduces manual steps without adding excessive overhead. Ship it! 🚀

Discarded (7)
Location Issue Reason Discarded
auto-format.yml:44 Actions pinned to mutable tags Pre-existing pattern across all repo workflows, not introduced by this PR
auto-format.yml:26-39 Good PR state check pattern Positive feedback, not an actionable issue
auto-format.yml:119-135 Good branch existence verification Positive feedback, not an actionable issue
package.json:104-106 Glob pattern syntax verification Author confirmed testing in PR description; low confidence concern
package.json:105 Bash wrapper for lint-staged Standard pattern, not an issue
package.json:104-106 Good DX improvement Positive feedback, not an actionable issue
auto-format.yml:22-23 Permissions appropriately scoped Positive feedback, not an actionable issue
Reviewers (2)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
pr-review-devops 8 0 1 0 0 0 7
pr-review-standards 0 0 0 0 0 0 0
Total 8 0 1 0 0 0 7

@github-actions github-actions bot deleted a comment from claude bot Feb 16, 2026
Rename "Exit if checkout failed" to "Log checkout failure" since the step
only emits a notice annotation — it doesn't terminate the workflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

(0) Total Issues | Risk: Low

Delta Review

This is a re-review scoped to changes since the last automated review. The delta consists of a single commit (1dec593f) that renames a workflow step from "Exit if checkout failed" to "Log checkout failure".

Prior feedback status: ✅ Addressed — the rename directly resolves the only "Consider" item from the previous review, which noted the misleading step name.

🔴❗ Critical (0) ❗🔴

None

🟠⚠️ Major (0) 🟠⚠️

None

🟡 Minor (0) 🟡

None

💭 Consider (0) 💭

None — the prior Consider item has been addressed by this commit.


✅ APPROVE

Summary: The delta addresses the only feedback from the prior review. The step name now accurately reflects its behavior (logging, not exiting). No new issues identified. Ship it! 🚀

Reviewers (0)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
orchestrator (self-review) 1 0 0 0 0 0 0
Total 1 0 0 0 0 0 0

Note: Subagent reviewers were not dispatched for this delta review because the change is trivial (1-line rename addressing prior feedback) with no functional impact.

@github-actions github-actions bot deleted a comment from claude bot Feb 16, 2026
@nick-inkeep nick-inkeep merged commit 130b7ba into main Feb 16, 2026
11 checks passed
@nick-inkeep nick-inkeep deleted the fix/ci-flakiness-auto-format-openapi branch February 16, 2026 01:20
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