Skip to content

fix(#340): skip stale project catalog accounts instead of crashing on conflict#423

Merged
zts212653 merged 5 commits intomainfrom
fix/340-project-catalog-conflict-crash
Apr 10, 2026
Merged

fix(#340): skip stale project catalog accounts instead of crashing on conflict#423
zts212653 merged 5 commits intomainfrom
fix/340-project-catalog-conflict-crash

Conversation

@mindfn
Copy link
Copy Markdown
Collaborator

@mindfn mindfn commented Apr 10, 2026

Summary

  • migrateProjectAccountsToGlobal threw a fatal error on startup when global accounts.json diverged from a project's stale cat-catalog.json copy (e.g. different displayName or models)
  • Added skipConflicts option to mergeIntoGlobal — when enabled, conflicting accounts are logged and skipped (global wins) instead of throwing
  • Project catalog migration now uses skipConflicts: true and catches persistent errors to avoid retry loops

Root cause

After PR #420 merged, global accounts could be updated (new models, display name changes) while project cat-catalog.json retained the old snapshot. The strict equality check in mergeIntoGlobal treated this divergence as a fatal conflict, crashing the app on Windows at startup.

Test plan

  • Updated existing conflict test: asserts readCatalogAccounts succeeds and returns global version (not stale project version)
  • pnpm check passes (biome)
  • pnpm lint passes (tsc)
  • All catalog-accounts tests pass

🤖 Generated with Claude Code

@mindfn mindfn requested a review from zts212653 as a code owner April 10, 2026 09:42
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6a794c59f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

@codex review

Please review latest commit f1fb6f1 for P1/P2 only.

规则:任何 P1/P2 必须给"可执行复现":

  • 优先:新增/更新一个 failing test(最小复现)
  • 否则:给确定性复现步骤(命令 + 输入 + 预期/实际)
    没有证据的一律降级为 P3 建议,不算缺陷。

审查标准(详见 AGENTS.md "Review guidelines" section):

  • P0 数据丢失/安全漏洞 | P1 逻辑错误/测试缺失/架构违规
  • P2 性能/重复/命名 | P3 风格偏好
  • 禁止 any、文件 200 行警告/350 硬上限、新功能必须有测试

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7faa7feb6b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d2085cd0f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn mindfn force-pushed the fix/340-project-catalog-conflict-crash branch from 189b06d to d801ba3 Compare April 10, 2026 12:22
@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

@codex review

Please review latest commit d801ba3 for P1/P2 only.

规则:任何 P1/P2 必须给"可执行复现":

  • 优先:新增/更新一个 failing test(最小复现)
  • 否则:给确定性复现步骤(命令 + 输入 + 预期/实际)
    没有证据的一律降级为 P3 建议,不算缺陷。

审查标准(详见 AGENTS.md "Review guidelines" section):

  • P0 数据丢失/安全漏洞 | P1 逻辑错误/测试缺失/架构违规
  • P2 性能/重复/命名 | P3 风格偏好
  • 禁止 any、文件 200 行警告/350 硬上限、新功能必须有测试

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

mindfn and others added 5 commits April 10, 2026 20:35
… conflict

When global accounts.json diverges from a project's cat-catalog.json
(e.g. displayName or models updated), migrateProjectAccountsToGlobal
threw a fatal error crashing the app at startup. Since project catalog
accounts are documented as inert stale copies and global is authoritative,
conflicts should be silently skipped (global wins).

- Add skipConflicts option to mergeIntoGlobal
- Pass skipConflicts: true from migrateProjectAccountsToGlobal
- Catch block marks project as done to avoid retry loops on persistent errors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The DELETE endpoint test previously asserted that migration conflict
surfaced as a 400 error. Now that project catalog conflicts are silently
skipped (global wins), update the test to assert DELETE succeeds with
force:true (binding check is irrelevant to this migration test).

[宪宪/Opus-46🐾]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pre-F340 code (PR #290) wrote API keys directly to ~/.cat-cafe/credentials.json.
When globalRoot resolves to a different directory (projectRoot), those credentials
were not picked up — only provider-profiles.secrets.local.json was migrated.

Add migrateHomedirCredentials() that runs AFTER legacy secrets migration so
homedir credentials.json wins on overlap (newer source, user-updated keys).
Also handles the case where credentials.json exists at homedir without any
provider-profiles files.

[宪宪/Opus-46🐾]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Homedir credentials migration unconditionally overwrote target credentials,
which could replace user-updated keys with stale homedir copies. Fixed by:

1. Skip-existing semantics: only import refs not already at target
2. Reorder ensureMigrated: homedir credentials runs FIRST, before legacy
   secrets — legacy's `id in existing` check naturally defers to homedir

Priority chain: user-set target > homedir credentials.json > legacy secrets.

[宪宪/Opus-46🐾]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
JSON.parse succeeds on null/string/number but `in` operator throws
TypeError on non-objects. Normalize parsed value to {} when not a
plain object.

[宪宪/Opus-46🐾]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mindfn mindfn force-pushed the fix/340-project-catalog-conflict-crash branch from d801ba3 to 932eca2 Compare April 10, 2026 12:35
Copy link
Copy Markdown
Owner

@zts212653 zts212653 left a comment

Choose a reason for hiding this comment

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

Three independent reviewers (GPT-5.4, Codex, Opus) confirmed: bug is real, fix is correct, CI green. Approved for merge.

Reviewed files: catalog-accounts.ts, catalog-accounts.test.js, accounts-route.test.js
Decision: merge + absorbed intake

[宪宪/Opus-46🐾]

@zts212653 zts212653 merged commit 8917a37 into main Apr 10, 2026
5 checks passed
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.

2 participants