Skip to content

修复:凭证刷新「没写回」被一律判成失败(AutoClaw 未临期时原样回同一份凭证) - #498

Open
a137460387 wants to merge 1 commit into
aimod-cc:betafrom
a137460387:fix/credential-refresh-no-change
Open

a137460387 wants to merge 1 commit into
aimod-cc:betafrom
a137460387:fix/credential-refresh-no-change

Conversation

@a137460387

Copy link
Copy Markdown

问题

3.4.1 为 #407 加的结果核验(refresh_checked)在刷新前后各取一次 (expiresAt, updatedAt),指纹没推进就判失败。但有一类正常情形会落进这条判据:上游在 access token 仍在有效期内时原样回同一份凭证 —— AutoClaw 的 /userapi/v1/refresh 就是这样(它给的是「一份能用的」,不是「换一份新的」),插件按设计「没变化就不落盘」,账号记录一个字节不动。

结果:用户点「刷新 token」得到 502 账号 … 的凭证刷新未产生变化(适配器报成功但凭据未更新),请重新登录该账号,每小时自动维护也刷一条 ❌ —— 而其实什么都不用做。

复现(v3.4.1 + 插件 3.4.1):未临期账号点刷新稳定 502;日志里插件那行是 token 已刷新(仅内存生效),紧跟一行网关的 未产生变化。

改动

没写回时再问一次适配器:credentials_expiring_async(store, id) 为 false(已不在临期窗口)就视为「无需刷新」正常返回,只留一条 verbose 日志;只有「确实临期/已过期、却还是没换发」才是真故障,继续报错并提示重新登录。

复查放在 refresh_access_token 之后取,判据是刷新结果落盘后的现状,不是调用前的快照。手动刷新(POST /api/accounts/refresh)与自动维护共用本函数,两处口径同时生效。

实测

  • 未临期账号刷新:502 → 200,日志出现「刷新未换发新凭证,但当前仍在有效期内 —— 视为无需刷新」
  • 批量 refresh-expiring:失败 0
  • 同一批里凭证已过期、上游确实不换发的账号仍然照旧报错

只改 1 个文件、21 行(server/src/server/core/credential_maintenance.rs),cargo check / cargo build --release 均通过。

🤖 本条回复由 AI Agent 生成
Generated by an AI agent.

…At, updatedAt)`,指纹没推进就报「适配器报成功但凭据未更新,请重新登录该账号」。但有一类**正常**情形会落进这条判据:上游在 access token 仍在有效期内时原样回同一份凭证(AutoClaw 的 `/userapi/v1/refresh` 就是这样 —— 它给的是「一份能用的」,不是「换一份新的」),插件按设计「没变化就不落盘」,记录一个字节不动。用户点「刷新 token」得到的是一句把人往重新登录带的话,而其实什么都不用做。实测(v3.4.1 + 插件 3.4.1):未临期账号点刷新稳定 502。

2. 优化:没写回时先复查一次适配器的临期判定 —— `credentials_expiring_async(store, id)` 为 false(已不在临期窗口)就视为「无需刷新」正常返回,只留一条 verbose 日志;仍临期 / 已过期却没换发才是真故障,继续报错并提示重新登录。复查放在 `refresh_access_token` 之后取,判据是刷新结果落盘后的现状,不是调用前的快照。
3. 说明:手动刷新(`POST /api/accounts/refresh`)与自动维护共用本函数,两处口径同时生效。实测:未临期账号刷新由 502 变为 200,日志出现「刷新未换发新凭证,但当前仍在有效期内 —— 视为无需刷新」;同一批里凭证已过期、上游又确实不换发的账号仍然照旧报错。
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 97d645d7-151b-4c9b-8e84-4824668268bf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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