惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
Y
Y Combinator Blog
IT之家
IT之家
博客园 - 聂微东
L
LangChain Blog
爱范儿
爱范儿
H
Help Net Security
GbyAI
GbyAI
F
Fortinet All Blogs
B
Blog
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
D
DataBreaches.Net
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: refresh stale codex auth profile routing · openclaw/...
BunsDev · 2026-05-04 · via Recent Commits to openclaw:main

@@ -18,10 +18,12 @@ import {

1818

} from "./state.js";

1919

import type {

2020

AuthProfileCredential,

21+

AuthProfileFailureReason,

2122

AuthProfileSecretsStore,

2223

AuthProfileStore,

2324

OAuthCredential,

2425

OAuthCredentials,

26+

ProfileUsageStats,

2527

} from "./types.js";

26282729

export type LegacyAuthStore = Record<string, AuthProfileCredential>;

@@ -213,6 +215,107 @@ function isNewerUsableOAuthCredential(

213215

);

214216

}

215217218+

const AUTH_INVALIDATION_REASONS = new Set<AuthProfileFailureReason>([

219+

"auth",

220+

"auth_permanent",

221+

"session_expired",

222+

]);

223+224+

function hasAuthInvalidationSignal(stats: ProfileUsageStats | undefined): boolean {

225+

if (!stats) {

226+

return false;

227+

}

228+

if (

229+

(stats.cooldownReason && AUTH_INVALIDATION_REASONS.has(stats.cooldownReason)) ||

230+

(stats.disabledReason && AUTH_INVALIDATION_REASONS.has(stats.disabledReason))

231+

) {

232+

return true;

233+

}

234+

return Object.entries(stats.failureCounts ?? {}).some(

235+

([reason, count]) =>

236+

AUTH_INVALIDATION_REASONS.has(reason as AuthProfileFailureReason) &&

237+

typeof count === "number" &&

238+

count > 0,

239+

);

240+

}

241+242+

function isProfileReferencedByAuthState(store: AuthProfileStore, profileId: string): boolean {

243+

if (Object.values(store.order ?? {}).some((profileIds) => profileIds.includes(profileId))) {

244+

return true;

245+

}

246+

return Object.values(store.lastGood ?? {}).some((value) => value === profileId);

247+

}

248+249+

function resolveProviderAuthStateValue<T>(

250+

values: Record<string, T> | undefined,

251+

providerKey: string,

252+

): T | undefined {

253+

if (!values) {

254+

return undefined;

255+

}

256+

for (const [key, value] of Object.entries(values)) {

257+

if (normalizeProviderId(key) === providerKey) {

258+

return value;

259+

}

260+

}

261+

return undefined;

262+

}

263+264+

function findMainStoreOAuthReplacementForInvalidatedProfile(params: {

265+

base: AuthProfileStore;

266+

override: AuthProfileStore;

267+

profileId: string;

268+

credential: OAuthCredential;

269+

}): string | undefined {

270+

const providerKey = normalizeProviderId(params.credential.provider);

271+

if (

272+

providerKey !== "openai-codex" ||

273+

!isProfileReferencedByAuthState(params.override, params.profileId) ||

274+

!hasAuthInvalidationSignal(params.override.usageStats?.[params.profileId])

275+

) {

276+

return undefined;

277+

}

278+279+

const candidates = Object.entries(params.base.profiles)

280+

.flatMap(([profileId, credential]): Array<[string, OAuthCredential]> => {

281+

if (

282+

profileId === params.profileId ||

283+

credential.type !== "oauth" ||

284+

normalizeProviderId(credential.provider) !== providerKey ||

285+

!hasUsableOAuthCredential(credential)

286+

) {

287+

return [];

288+

}

289+

return [[profileId, credential]];

290+

})

291+

.toSorted(([leftId, leftCredential], [rightId, rightCredential]) => {

292+

const leftExpires = Number.isFinite(leftCredential.expires) ? leftCredential.expires : 0;

293+

const rightExpires = Number.isFinite(rightCredential.expires) ? rightCredential.expires : 0;

294+

if (rightExpires !== leftExpires) {

295+

return rightExpires - leftExpires;

296+

}

297+

return leftId.localeCompare(rightId);

298+

});

299+

if (candidates.length === 0) {

300+

return undefined;

301+

}

302+303+

const candidateIds = new Set(candidates.map(([profileId]) => profileId));

304+

const orderedProfileId = resolveProviderAuthStateValue(params.base.order, providerKey)?.find(

305+

(profileId) => candidateIds.has(profileId),

306+

);

307+

if (orderedProfileId) {

308+

return orderedProfileId;

309+

}

310+311+

const lastGoodProfileId = resolveProviderAuthStateValue(params.base.lastGood, providerKey);

312+

if (lastGoodProfileId && candidateIds.has(lastGoodProfileId)) {

313+

return lastGoodProfileId;

314+

}

315+316+

return candidates.length === 1 ? candidates[0]?.[0] : undefined;

317+

}

318+216319

function findMainStoreOAuthReplacement(params: {

217320

base: AuthProfileStore;

218321

legacyProfileId: string;

@@ -343,14 +446,21 @@ function reconcileMainStoreOAuthProfileDrift(params: {

343446

}): AuthProfileStore {

344447

const replacements = new Map<string, string>();

345448

for (const [profileId, credential] of Object.entries(params.override.profiles)) {

346-

if (credential.type !== "oauth" || !isLegacyDefaultOAuthProfile(profileId, credential)) {

449+

if (credential.type !== "oauth") {

347450

continue;

348451

}

349-

const replacementProfileId = findMainStoreOAuthReplacement({

350-

base: params.base,

351-

legacyProfileId: profileId,

352-

legacyCredential: credential,

353-

});

452+

const replacementProfileId = isLegacyDefaultOAuthProfile(profileId, credential)

453+

? findMainStoreOAuthReplacement({

454+

base: params.base,

455+

legacyProfileId: profileId,

456+

legacyCredential: credential,

457+

})

458+

: findMainStoreOAuthReplacementForInvalidatedProfile({

459+

base: params.base,

460+

override: params.override,

461+

profileId,

462+

credential,

463+

});

354464

if (replacementProfileId) {

355465

replacements.set(profileId, replacementProfileId);

356466

}