Skip to content

fix(cli): ag init --force replaces existing admin key instead of crashing (#3351)#3384

Merged
aegis-gh-agent[bot] merged 3 commits into
developfrom
fix/3351-init-force-duplicate-key
May 14, 2026
Merged

fix(cli): ag init --force replaces existing admin key instead of crashing (#3351)#3384
aegis-gh-agent[bot] merged 3 commits into
developfrom
fix/3351-init-force-duplicate-key

Conversation

@OneStepAt4time

Copy link
Copy Markdown
Owner

Fix for #3351

Problem

ag init --force crashes with DUPLICATE_KEY_NAME when an admin key from a previous init already exists.

Root Cause

Two issues:

  1. createKey("ag-init-admin", ...) always uses the same name — no cleanup of the old key
  2. --yes --force still prompts "Overwrite config?" because the prompter block ran even when force=true
  3. createAdminToken was false when existing token found, even with --force

Fix

  1. When --force, delete existing ag-init-admin key before creating new one
  2. Skip interactive overwrite prompt when --yes --force
  3. Set createAdminToken = !existingToken || force

Verification

  • tsc --noEmit: ✅ Zero errors
  • npm run build: ✅ Success
  • vitest run src/__tests__/cli-init.test.ts: ✅ 9/9 passed (including new regression test)

Also Fixes

#3355 (same root cause — DUPLICATE_KEY_NAME with --force)

…hing (#3351)

- Delete existing 'ag-init-admin' key before creating new one when --force
- Auto-overwrite config file when --yes --force (skip interactive prompt)
- Set createAdminToken=true when force=true even if existing token found
- Regression test: verifies new token differs from old after --force

@aegis-gh-agent aegis-gh-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved.

Three-part fix for ag init --force crash:

  1. createAdminToken = !existingToken || force — force always recreates token.
  2. if (!yes || !force) guard — skips overwrite prompt when both flags set.
  3. Revoke existing ag-init-admin key before creating new one when --force.

Test verifies: first init creates token, second init with --force creates a different token (no crash, no DUPLICATE_KEY_NAME).

CI green. All merge gates pass. Merging.

Minor style note (non-blocking): The closing brace for the new if (!yes || !force) block uses 2-space indent instead of the surrounding 4-space. Functionally correct but inconsistent with file style. Consider a cleanup pass.

@aegis-gh-agent aegis-gh-agent Bot merged commit 048560d into develop May 14, 2026
17 checks passed
@aegis-gh-agent aegis-gh-agent Bot deleted the fix/3351-init-force-duplicate-key branch May 14, 2026 09:32
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