Skip to content

fix: auto-retry deployment when personal account org ID causes scope error#298

Merged
amondnet merged 3 commits intomasterfrom
amondnet/comet-mantis
Mar 26, 2026
Merged

fix: auto-retry deployment when personal account org ID causes scope error#298
amondnet merged 3 commits intomasterfrom
amondnet/comet-mantis

Conversation

@amondnet
Copy link
Copy Markdown
Owner

@amondnet amondnet commented Mar 25, 2026

  • Investigate CI failures
  • Root cause: setEnv() exported VERCEL_PROJECT_ID unconditionally, causing Vercel CLI v41 scope error even without VERCEL_ORG_ID
  • Fix: Revert setEnv() to only export VERCEL_PROJECT_ID when vercelOrgId is set
  • Fix: In retry path, also delete process.env.VERCEL_PROJECT_ID
  • Rebuild dist/index.js
  • Lint and tests pass
  • Code review: no issues
  • CodeQL: no alerts

⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

…error

Vercel CLI v41+ rejects VERCEL_ORG_ID for personal accounts with
"You cannot set your Personal Account as the scope" error.

- Catch the scope error and retry without VERCEL_ORG_ID using --project flag
- Remove vercel-org-id from personal account CI workflows
- Rebuild dist/
Copilot AI review requested due to automatic review settings March 25, 2026 22:37
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a breaking change introduced in Vercel CLI v41 that prevented deployments from personal accounts when VERCEL_ORG_ID was specified. The core change introduces a robust retry mechanism that detects this specific error and automatically re-attempts the deployment without the problematic organization ID, ensuring continued functionality for personal account users. Additionally, it refactors the deployment argument construction for better code organization and updates example workflows to reflect best practices for personal accounts.

Highlights

  • Automatic Deployment Retry: Implemented an automatic retry mechanism for Vercel deployments that fail specifically due to the 'You cannot set your Personal Account as the scope' error from Vercel CLI v41+.
  • Personal Account Scope Handling: When a scope error occurs, the action now retries the deployment without the VERCEL_ORG_ID and instead uses the --project flag, effectively bypassing the personal account scope restriction.
  • Code Refactoring: Extracted argument building logic into two new helper functions, buildDeployArgs() and appendProjectArgs(), to improve code clarity and maintainability within the vercelDeploy function.
  • Workflow Updates: Removed the vercel-org-id input from several GitHub Actions workflow files (deploy.yml, example-angular.yml, example-nextjs.yml, example-static.yml) that are intended for personal account deployments.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: .github/workflows/** (4)
    • .github/workflows/deploy.yml
    • .github/workflows/example-angular.yml
    • .github/workflows/example-nextjs.yml
    • .github/workflows/example-static.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

Deploy preview for express-basic-auth ready!

✅ Preview
https://express-basic-auth-dv50nfdlf-minsu-lees-projects-b1e388b7.vercel.app

Built with commit 8773840.
This pull request is being automatically deployed with vercel-action

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Vercel deployment logic by extracting argument building into dedicated functions and introduces a retry mechanism. Specifically, if a Vercel deployment fails because a personal account is used as a scope, the action will now retry the deployment by clearing the VERCEL_ORG_ID and explicitly using the --project flag. Feedback indicates a potential issue where the scope argument might be incorrectly re-added during the retry, which could lead to repeated failures. It is also suggested to refactor the argument building logic for the retry into a helper function to avoid duplication and improve maintainability.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Vercel GitHub Action to handle a Vercel CLI v41+ failure mode where personal accounts reject VERCEL_ORG_ID/scope, by retrying the deploy without the org scope and using --project instead. It also removes vercel-org-id usage from the repository’s personal-account example workflows.

Changes:

  • Detects the “You cannot set your Personal Account as the scope” deploy failure and retries without VERCEL_ORG_ID, adding --project as a fallback.
  • Refactors deploy argument construction into buildDeployArgs() and appendProjectArgs() helpers.
  • Removes vercel-org-id from personal-account example workflows and rebuilds dist/index.js.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
index.js Adds scope-error detection and retry logic; refactors deploy arg building.
dist/index.js Compiled output updated to include the new retry behavior.
.github/workflows/deploy.yml Removes vercel-org-id from the deploy workflow configuration.
.github/workflows/example-angular.yml Removes vercel-org-id from the Angular example workflow.
.github/workflows/example-nextjs.yml Removes vercel-org-id from the Next.js example workflow.
.github/workflows/example-static.yml Removes vercel-org-id from the static example workflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 6 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="index.js">

<violation number="1" location="index.js:225">
P2: Setting `VERCEL_ORG_ID` to empty string does not remove it from the process environment. The spawned child process will still see `VERCEL_ORG_ID=''`. Add `delete process.env.VERCEL_ORG_ID` to fully remove it so the retry's `npx vercel` invocation cannot detect the variable at all.</violation>

<violation number="2" location="index.js:231">
P1: The retry path still appends `--scope` when `vercelScope` is set. If the scope input itself triggered the personal-account error (rather than `VERCEL_ORG_ID`), the retry will fail with the same error. Skip `--scope` on the retry attempt to ensure the fallback actually works.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- Restore independent VERCEL_PROJECT_ID export (was incorrectly nested)
- Clear process.env.VERCEL_ORG_ID for in-process retry subprocess
- Guard retry with vercelProjectId check for actionable error message
@amondnet amondnet self-assigned this Mar 26, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="index.js">

<violation number="1" location="index.js:232">
P2: The `delete` is immediately undone by `core.exportVariable` on the next line, leaving `VERCEL_ORG_ID=''` in the environment for the retry subprocess. Swap the order so that `exportVariable` writes to `GITHUB_ENV` for future steps first, then `delete` removes it from `process.env` for the current retry.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- Remove --scope from retry path to prevent personal-account error
  from recurring on the fallback attempt
- Swap order of exportVariable/delete so process.env.VERCEL_ORG_ID
  is cleared after GITHUB_ENV is written, not before
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Requires human review: This PR refactors core deployment logic, introduces error-based retry handling, and extracts logic into helpers, which requires human validation of the execution flow and fallback behavior.

@amondnet amondnet merged commit 1b0001f into master Mar 26, 2026
8 of 15 checks passed
@amondnet amondnet deleted the amondnet/comet-mantis branch March 26, 2026 01:28
amondnet added a commit that referenced this pull request Mar 26, 2026
- Add core.setSecret for vercel token to prevent log exposure
- Disable telemetry with VERCEL_TELEMETRY_DISABLED env var
- Require both org and project IDs together (v41+ compat)
- Auto-retry deployment on personal account scope error
- Sanitize commit message newlines and quotes in metadata
- Add ignoreReturnCode for proper exit code handling
- Update tests for new behavior (105 total)
amondnet added a commit that referenced this pull request Mar 26, 2026
- Add core.setSecret for vercel token to prevent log exposure
- Disable telemetry with VERCEL_TELEMETRY_DISABLED env var
- Require both org and project IDs together (v41+ compat)
- Auto-retry deployment on personal account scope error
- Sanitize commit message newlines and quotes in metadata
- Add ignoreReturnCode for proper exit code handling
- Update tests for new behavior (105 total)
amondnet added a commit that referenced this pull request Mar 26, 2026
- Add core.setSecret for vercel token to prevent log exposure
- Disable telemetry with VERCEL_TELEMETRY_DISABLED env var
- Require both org and project IDs together (v41+ compat)
- Auto-retry deployment on personal account scope error
- Sanitize commit message newlines and quotes in metadata
- Add ignoreReturnCode for proper exit code handling
- Update tests for new behavior (105 total)
amondnet added a commit that referenced this pull request Mar 26, 2026
* refactor: migrate to TypeScript with Vitest and modern tooling

BREAKING CHANGE: @actions/github upgraded from v2 to v6

- Convert index.js to src/index.ts with strict TypeScript mode
- Extract pure utility functions to src/utils.ts for testability
- Add tsconfig.json with strict compiler options

- Replace Jest with Vitest for faster, ESM-native testing
- Add comprehensive unit tests for utility functions (43 tests)
- Add integration tests for GitHub Action structure (12 tests)
- Target: 80%+ code coverage

- Migrate from deprecated `new github.GitHub(token)` to `github.getOctokit(token)`
- Update all API calls from `octokit.repos.*` to `octokit.rest.repos.*`
- Update all API calls from `octokit.issues.*` to `octokit.rest.issues.*`
- Update all API calls from `octokit.git.*` to `octokit.rest.git.*`

- Enable TypeScript support in @antfu/eslint-config
- Replace Jest globals with Vitest globals (vi instead of jest)
- Add lib/ to ignore patterns

- Update ncc build to compile TypeScript directly
- Add source maps and licenses to dist output
- Add typecheck script for standalone type checking
- Update all npm scripts for TypeScript workflow

- index.js (migrated to src/index.ts)
- index.test.js (migrated to src/__tests__/*.test.ts)
- jest.config.js (replaced by vitest.config.ts)
- now.js (unused legacy file)

Closes #291

* chore: apply AI code review suggestions

- Move PullRequestPayload and ReleasePayload interfaces to top of file
- Use PullRequestPayload type instead of inline type assertion
- Simplify parseArgs regex match logic (remove redundant fallback)

* refactor: split index.ts into smaller modules

- Extract types to src/types.ts
- Extract config and initialization to src/config.ts
- Extract Vercel functions to src/vercel.ts
- Extract GitHub comment functions to src/github-comments.ts
- Refactor run() into smaller focused functions (< 50 LOC each)
- Add try-catch around execSync for git log with descriptive error
- Add error handling for GitHub API calls
- Make alias failures explicit with warning messages
- Extract magic numbers to named constants (RETRY_DELAY_MS, ALIAS_RETRY_COUNT)
- Use buildCommentPrefix() consistently in both comment functions

All files now under 300 LOC limit, all functions under 50 LOC limit.

* build: rebuild dist after refactoring

* build: update vercel to v50

* fix: improve error handling in vercel deploy and comment functions

- Extract and validate deployment URL from vercel CLI stdout
- Wrap vercelInspect exec in try-catch to prevent action failure
- Expand try-catch scope in comment functions to cover API lookups
- Route stderr to core.warning for better error visibility

* test: add tests for vercel, config, and github-comments modules

- Add vercel.test.ts: URL extraction, inspect regex, alias retry
- Add config.test.ts: alias domain substitution, env export
- Add github-comments.test.ts: comment create/update, error handling
- Total tests: 55 → 100

* fix: port personal account scope error handling from PR #297/#298

- Add core.setSecret for vercel token to prevent log exposure
- Disable telemetry with VERCEL_TELEMETRY_DISABLED env var
- Require both org and project IDs together (v41+ compat)
- Auto-retry deployment on personal account scope error
- Sanitize commit message newlines and quotes in metadata
- Add ignoreReturnCode for proper exit code handling
- Update tests for new behavior (105 total)

* refactor: use DeploymentContext object in vercelDeploy signature

Reduce parameter count from 6 to 2 by passing DeploymentContext
object instead of individual ref, commit, sha, commitOrg, commitRepo
arguments. Aligns with AGENTS.md parameter limit of 5.

* fix: port alias retry without --scope for personal accounts (#310)

Capture stderr in alias exec and retry without --scope when Vercel CLI
rejects personal account scope, matching the deploy retry pattern.
Add tests for alias scope retry, retry failure, and non-scope failures.

* fix: remove declaration maps to fix check-dist CI failure

Source map files (.d.ts.map) contain absolute local paths that differ
between local builds and CI runners, causing check-dist to fail.
Disable declarationMap in tsconfig.json since these files are not
needed for GitHub Action runtime execution.

* chore: apply AI code review suggestions

- Implement exponential backoff in retry function (was constant delay)
- Fix debug log for head_commit to use JSON.stringify
- Change vercelInspect stderr logging from warning to info level
- Fix retry after PERSONAL_ACCOUNT_SCOPE_ERROR to omit --scope
- Bump @types/node from ^20.0.0 to ^24.0.0 to match Node 24 runtime
- Add setSecret to @actions/core mock in index.test.ts
- Fix mock path in config.test.ts from ../package.json to ../../package.json
- Update test expectation to match mocked vercel version (30.0.0)
- Remove pull_request_target from PullRequestPayload (always undefined)
- Add per_page: 100 to comment listing API calls to reduce duplicate risk
- Fix Node version in session-summary.md (20 → 24)

* fix: make vercelScope optional to clean up retry cast in vercelDeploy

Co-authored-by: amondnet <1964421+amondnet@users.noreply.github.com>
Agent-Logs-Url: https://github.com/amondnet/vercel-action/sessions/16d171b4-3be8-43f8-a736-b5f3ff13deba

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: amondnet <1964421+amondnet@users.noreply.github.com>
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.

3 participants