DeepSeek-Reasonix icon indicating copy to clipboard operation
DeepSeek-Reasonix copied to clipboard

[Bug]: API key 重启后失效:每次重设 key 后首次正常,重启 Reasonix 或新建对话即 401/404

Open BrunswickTabby opened this issue 5 months ago • 5 comments

环境 OS:Windows 11 配置文件:C:\Users<用户名>\AppData\Roaming\reasonix\config.toml 受影响的 API:DeepSeek、Gemini(均触发) 对比:Hermes 同机同 key 正常问题描述 Reasonix 的 API key 读取机制存在 Bug:

无论 DeepSeek 还是 Gemini key,reasonix setup 配置后第一次能用,重启应用/新建对话后立即 401 或 404 同一台电脑 Hermes 用同一批 key 正常,排除 key 本身问题 复现步骤 reasonix setup 配 key → 对话正常 关掉重启 → 对话报 401/404 重新 setup 换 key → 又正常 再重启 → 又挂。循环 根因 Reasonix 同时从 config.toml 和环境变量两处读 key,重启后读到的源跟写入时不一致,导致读到过期/错误的 key。

建议修复 统一 key 读取来源,写死只从 .env 文件读,不要同时从 config.toml 和环境变量两处读取造成冲突。参考 Hermes 的实现即可。

BrunswickTabby avatar Jun 22 '26 04:06 BrunswickTabby

建议修复方案 参考 Hermes 的做法(hermes config env-path → %LocalAppData%/hermes.env),将凭据持久化到确定路径:

  1. internal/config/config.go — 改 UserCredentialsPath()

将凭据路径改为写入 %LocalAppData%/reasonix/.env,而不是当前的多源查找。这样可以确保 setup 写入和运行时读取的是同一个文件。

  1. internal/config/dotenv.go — 统一文件读取来源

当前 loadDotEnvForRoot() 从 keyring、credentials、项目 .env、home .env 等多个源加载。建议统一为一个文件来源:只从 UserCredentialsPath() 返回的路径读取。

原理:setup 写入 %LocalAppData%/reasonix/.env → loadDotEnv() 也只从同一文件读 → 无多源冲突,重启不丢 key。

BrunswickTabby avatar Jun 22 '26 05:06 BrunswickTabby

用的是cli端?

SivanCola avatar Jun 22 '26 08:06 SivanCola

最新版桌面端的是直接固定路径读取,不会再读项目里的key

SivanCola avatar Jun 22 '26 08:06 SivanCola

我用的是windows端,额我还用codex给你写个pr···

Image Image

BrunswickTabby avatar Jun 22 '26 09:06 BrunswickTabby

@SivanCola 您说的新版是2.0 还是v1.11.0 我更新完了,貌似还是去我的来源:system credential store,而不是本地的一个env文件 Image

BrunswickTabby avatar Jun 23 '26 01:06 BrunswickTabby

Thanks @BrunswickTabby. I opened #5110 with the integrated fix for this issue and closed #5033 as superseded after carrying its contribution forward with co-author credit.

The fix in #5110 changes provider credential handling to a single source of truth:

  • Reasonix home .env is the only runtime source for provider keys saved by Reasonix.
  • Project .env, home .env, inherited process env, old credentials, and OS keyring values no longer act as provider-key runtime fallbacks.
  • CLI setup, desktop onboarding/settings, model refresh, and key deletion all use the same global .env path.
  • Old credentials files and keyring values are migrated non-destructively into the new global .env when a key is missing.
  • Docs now describe the global config.toml and .env structure and the migration behavior.

Verified on #5110 with:

  • go test ./...
  • (cd desktop && go test ./...)
  • (cd desktop && wails generate module)
  • (cd desktop/frontend && pnpm install --frozen-lockfile && pnpm run typecheck)
  • git diff --check

Closing this as completed because #5110 now tracks the maintainer integration fix and includes Closes #5015.

SivanCola avatar Jun 23 '26 03:06 SivanCola