fix(quota): say when Cline's saved login expired and how to renew it (#1736)

* fix(clinepass): say when the Cline login expired and how to renew it

An expired saved Cline login only said "Run cline to refresh it". It now
reads "Cline login expired 3h ago" (age from the saved expiry, when known)
and asks to send a message in Cline or run `cline auth cline`, then press
Retry. Still a retryable state, so the last quota is kept. CLI and menubar.

* fix(menubar): title an expired Cline login instead of "Retrying"

A provider failure can now carry a short status title. The expired Cline
login sets "Cline login expired", which the settings pane and the dock
caption show in place of the generic retrying text. It stays a retryable
state and keeps the last quota; the title clears with the error.

* fix(clinepass): match the expired-login hint to the visible control

"Then press Retry" only fits where a Retry button shows: the settings pane
with no last quota. Everywhere else, including the CLI, the hint now ends
with "CodeBurn picks up the new login on its next refresh."
This commit is contained in:
Resham Joshi 2026-10-10 21:40:52 +02:00 • committed by GitHub
parent ff7c40e9ab
commit 6ddd8b6735
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 129 additions and 24 deletions

View file

@ -218,6 +218,7 @@ final class AppStore {
/// `ProviderConnectionCatalog`.
var capacityDockProviderSummaries: [String: QuotaSummary] = [:]
var capacityDockProviderErrors: [String: String] = [:]
var capacityDockProviderStatusTitles: [String: String] = [:]
var capacityDockProvidersLoading: Set<String> = []
var capacityDockProviderTransientFailures: Set<String> = []
private var capacityDockProviderRefreshGenerations: [String: UInt64] = [:]
@ -2457,6 +2458,7 @@ final class AppStore {
capacityDockProviderRefreshGenerations[provider.id, default: 0] &+= 1
capacityDockProviderSummaries[provider.id] = nil
capacityDockProviderErrors[provider.id] = nil
capacityDockProviderStatusTitles[provider.id] = nil
capacityDockProvidersLoading.remove(provider.id)
capacityDockProviderTransientFailures.remove(provider.id)
}
@ -2488,6 +2490,7 @@ final class AppStore {
}
capacityDockProviderSummaries[provider.id] = nil
capacityDockProviderErrors[provider.id] = nil
capacityDockProviderStatusTitles[provider.id] = nil
capacityDockProvidersLoading.remove(provider.id)
capacityDockProviderTransientFailures.remove(provider.id)
// Drop the provider from the persisted dock selection too. A
@ -2537,13 +2540,20 @@ final class AppStore {
}
capacityDockProviderSummaries[provider.id] = summary
capacityDockProviderErrors[provider.id] = nil
capacityDockProviderStatusTitles[provider.id] = nil
capacityDockProviderTransientFailures.remove(provider.id)
} catch {
guard capacityDockProviderRefreshGenerations[provider.id, default: 0] == generation,
!(quiet && (error as? CapacityDockProviderFetchFailure)?.notSignedIn == true) else {
return
}
capacityDockProviderErrors[provider.id] = sanitizeForUI(error.localizedDescription)
let failure = error as? CapacityDockProviderFetchFailure
// Without a last quota the pane offers Retry; with one it shows Disconnect.
let retryShown = capacityDockProviderSummaries[provider.id] == nil
capacityDockProviderErrors[provider.id] = sanitizeForUI(
(retryShown ? failure?.retryMessage : nil) ?? error.localizedDescription
)
capacityDockProviderStatusTitles[provider.id] = failure?.statusTitle
if let failure = error as? CapacityDockProviderFetchFailure,
failure.disposition == .transient {
capacityDockProviderTransientFailures.insert(provider.id)

View file

@ -154,6 +154,10 @@ enum CapacityDockProviderFetchFailureDisposition: Equatable, Sendable {
struct CapacityDockProviderFetchFailure: LocalizedError, Equatable, Sendable {
let message: String
let disposition: CapacityDockProviderFetchFailureDisposition
/// A short status shown instead of the generic one for this failure.
var statusTitle: String?
/// The message variant for when a Retry button is on screen.
var retryMessage: String?
init(message: String, disposition: CapacityDockProviderFetchFailureDisposition) {
self.message = message
@ -177,6 +181,8 @@ struct CapacityDockProviderFetchFailure: LocalizedError, Equatable, Sendable {
}
message = error.localizedDescription
disposition = Self.disposition(for: error)
statusTitle = (error as? ClinePassSubscriptionService.FetchError)?.statusTitle
retryMessage = (error as? ClinePassSubscriptionService.FetchError)?.retryMessage
}
var errorDescription: String? { message }

View file

@ -12,7 +12,8 @@ enum ClinePassSubscriptionService {
enum FetchError: Error, Equatable, LocalizedError, Sendable {
case noCredentials
case authenticationRejected
case signInExpired
/// `age` is how long ago the saved login expired, when the file says.
case signInExpired(age: String?)
case rateLimited
case providerUnavailable
case parseFailure
@ -39,14 +40,30 @@ enum ClinePassSubscriptionService {
var isTerminal: Bool { classification == .terminalAuth }
/// Replaces the generic "Retrying" status where a retry alone cannot help.
var statusTitle: String? {
if case .signInExpired = self { return L("Cline login expired") }
return nil
}
/// The same guidance for where a Retry button is on screen.
var retryMessage: String? {
guard case let .signInExpired(age) = self else { return nil }
return "\(expiredPrefix(age)) Send a message in Cline or run `cline auth cline`, then press Retry."
}
private func expiredPrefix(_ age: String?) -> String {
"Cline login expired\(age.map { " \($0)" } ?? "")."
}
var errorDescription: String? {
switch self {
case .noCredentials:
return "Sign in with Cline, or enter a ClinePass API key, then click Retry."
case .authenticationRejected:
return "ClinePass rejected this API key."
case .signInExpired:
return "Cline sign-in expired. Run cline to refresh it."
case let .signInExpired(age):
return "\(expiredPrefix(age)) Send a message in Cline or run `cline auth cline`; CodeBurn picks up the new login on its next refresh."
case .rateLimited:
return "ClinePass rate-limited the quota request."
case .providerUnavailable:
@ -150,8 +167,12 @@ enum ClinePassSubscriptionService {
}
credential = ambient
}
if credential.isOAuth, let expiresAt = credential.expiresAt, expiresAt <= deps.now() {
throw FetchError.signInExpired
let now = deps.now()
let expiredAge = credential.expiresAt.flatMap {
$0 <= now ? CodexBankedResetPresentation.compactAge(of: $0, now: now) : nil
}
if credential.isOAuth, let expiredAge {
throw FetchError.signInExpired(age: expiredAge)
}
var request = URLRequest(url: usageURL)
@ -174,7 +195,7 @@ enum ClinePassSubscriptionService {
case 200:
break
case 401, 403:
throw credential.isOAuth ? FetchError.signInExpired : FetchError.authenticationRejected
throw credential.isOAuth ? FetchError.signInExpired(age: expiredAge) : FetchError.authenticationRejected
case 429:
throw FetchError.rateLimited
case 500...599:

View file

@ -615,6 +615,7 @@
"This credential predates a live CodeBurn quota adapter and is not treated as a connection." = "This credential predates a live CodeBurn quota adapter and is not treated as a connection.";
"Quota adapter not available" = "Quota adapter not available";
"Retrying" = "Retrying";
"Cline login expired" = "Cline login expired";
"%@ is catalogued, but CodeBurn cannot fetch its live quota yet." = "%@ is catalogued, but CodeBurn cannot fetch its live quota yet.";
"Live quota is available to Capacity Dock." = "Live quota is available to Capacity Dock.";
"Waiting for quota data." = "Waiting for quota data.";

View file

@ -608,6 +608,7 @@
"This credential predates a live CodeBurn quota adapter and is not treated as a connection." = "Cet identifiant précède un adaptateur de quota CodeBurn en direct et n'est pas considéré comme une connexion.";
"Quota adapter not available" = "Adaptateur de quota indisponible";
"Retrying" = "Nouvel essai";
"Cline login expired" = "Connexion Cline expirée";
"%@ is catalogued, but CodeBurn cannot fetch its live quota yet." = "%@ est répertorié, mais CodeBurn ne peut pas encore récupérer son quota en direct.";
"Live quota is available to Capacity Dock." = "Le quota en direct est disponible pour le Capacity Dock.";
"Waiting for quota data." = "En attente des données de quota.";

View file

@ -608,6 +608,7 @@
"This credential predates a live CodeBurn quota adapter and is not treated as a connection." = "この認証情報はCodeBurnのリアルタイムクォータアダプターより前のものであり、接続としては扱われません。";
"Quota adapter not available" = "クォータアダプター未対応";
"Retrying" = "再試行中";
"Cline login expired" = "Clineのログインの有効期限切れ";
"%@ is catalogued, but CodeBurn cannot fetch its live quota yet." = "%@は登録されていますが、CodeBurnはまだそのリアルタイムクォータを取得できません。";
"Live quota is available to Capacity Dock." = "リアルタイムのクォータを容量ドックで利用できます。";
"Waiting for quota data." = "クォータデータを待機中です。";

View file

@ -608,6 +608,7 @@
"This credential predates a live CodeBurn quota adapter and is not treated as a connection." = "이 자격 증명은 실시간 CodeBurn 할당량 어댑터보다 이전의 것이라 연결로 처리되지 않습니다.";
"Quota adapter not available" = "할당량 어댑터 사용 불가";
"Retrying" = "재시도 중";
"Cline login expired" = "Cline 로그인 만료됨";
"%@ is catalogued, but CodeBurn cannot fetch its live quota yet." = "%@은(는) 등록되어 있지만 CodeBurn이 아직 실시간 할당량을 가져올 수 없습니다.";
"Live quota is available to Capacity Dock." = "캐퍼시티 독에서 실시간 할당량을 사용할 수 있습니다.";
"Waiting for quota data." = "할당량 데이터를 기다리는 중입니다.";

View file

@ -607,6 +607,7 @@
"This credential predates a live CodeBurn quota adapter and is not treated as a connection." = "此凭证早于 CodeBurn 的实时配额适配器,不会被视为一个连接。";
"Quota adapter not available" = "配额适配器不可用";
"Retrying" = "正在重试";
"Cline login expired" = "Cline 登录已过期";
"%@ is catalogued, but CodeBurn cannot fetch its live quota yet." = "%@ 已收录,但 CodeBurn 还无法获取其实时配额。";
"Live quota is available to Capacity Dock." = "实时配额已可供容量 Dock 使用。";
"Waiting for quota data." = "正在等待配额数据。";

View file

@ -605,6 +605,7 @@
"This credential predates a live CodeBurn quota adapter and is not treated as a connection." = "此憑證早於 CodeBurn 的實時配額介面卡,不會被視為一個連線。";
"Quota adapter not available" = "配額介面卡不可用";
"Retrying" = "正在重試";
"Cline login expired" = "Cline 登入已過期";
"%@ is catalogued, but CodeBurn cannot fetch its live quota yet." = "%@ 已收錄,但 CodeBurn 還無法獲取其實時配額。";
"Live quota is available to Capacity Dock." = "實時配額已可供容量 Dock 使用。";
"Waiting for quota data." = "正在等待配額資料。";

View file

@ -1411,13 +1411,14 @@ struct CapacityDockDetailView: View {
.font(.system(size: 10))
.foregroundStyle(Color.capacityDockText.opacity(0.52))
case .stale:
Text(store.quotaRefreshIsInFlight(for: provider)
? L("Last known usage · refreshing")
: L("Last known usage"))
Text(store.capacityDockProviderStatusTitles[provider.id].map { "\(L("Last known usage")) · \($0)" }
?? (store.quotaRefreshIsInFlight(for: provider)
? L("Last known usage · refreshing")
: L("Last known usage")))
.font(.system(size: 10))
.foregroundStyle(.yellow.opacity(0.82))
case .transientFailure:
Text(L("Last known usage · retrying"))
Text(store.capacityDockProviderStatusTitles[provider.id] ?? L("Last known usage · retrying"))
.font(.system(size: 10))
.foregroundStyle(.orange.opacity(0.86))
case .disconnected:

View file

@ -2108,8 +2108,10 @@ private struct GenericProviderConnectionSections: View {
switch summary.connection {
case .connected: return L("Connected")
case .loading: return L("Connecting…")
case .stale: return store.quotaRefreshIsInFlight(for: provider) ? L("Refreshing…") : L("Connected")
case .transientFailure: return L("Retrying")
case .stale:
if let title = store.capacityDockProviderStatusTitles[provider.id] { return title }
return store.quotaRefreshIsInFlight(for: provider) ? L("Refreshing…") : L("Connected")
case .transientFailure: return store.capacityDockProviderStatusTitles[provider.id] ?? L("Retrying")
case .terminalFailure: return L("Reconnect required")
case .disconnected: return L("Not connected")
}

View file

@ -271,7 +271,7 @@ struct CapacityDockProviderQuotaServiceTests {
func clinePassExpiredSignInIsTransient() async throws {
let provider = try #require(CapacityDockProvider(rawValue: "clinepass"))
let cases: [(ClinePassSubscriptionService.FetchError, CapacityDockProviderFetchFailureDisposition)] = [
(.signInExpired, .transient),
(.signInExpired(age: "3h ago"), .transient),
(.authenticationRejected, .terminal),
(.noCredentials, .terminal),
]
@ -495,6 +495,51 @@ struct CapacityDockProviderQuotaServiceTests {
}
}
@Test("an expired Cline login sets a status title, keeps the last quota, and a success clears it")
func clineExpiredStatusTitle() async throws {
let provider = try #require(CapacityDockProvider(rawValue: "clinepass"))
let expired = ExpiryToggle()
let store = AppStore()
store.capacityDockCredentialLoader = { _ in CapacityDockProviderCredential() }
store.capacityDockProviderQuotaService = CapacityDockProviderQuotaService(dependencies: .init(
refreshClinePass: { _ in
if expired.isOn { throw ClinePassSubscriptionService.FetchError.signInExpired(age: "3h ago") }
return Self.summary(percent: 0.3)
},
refreshCommandCode: Self.unusedCommandCode,
refreshCursor: Self.unusedCursor,
refreshDevin: Self.unusedDevin,
refreshGrok: Self.unusedGrok,
refreshGrokBot: Self.unusedGrokBot,
refreshZai: Self.unusedZai,
refreshZcode: Self.unusedZcode
))
expired.isOn = true
await store.refreshCapacityDockProvider(provider)
#expect(store.capacityDockProviderStatusTitles[provider.id] == "Cline login expired")
#expect(store.capacityDockQuotaSummary(for: provider)?.connection == .transientFailure)
#expect(store.capacityDockProviderErrors[provider.id]
== "Cline login expired 3h ago. Send a message in Cline or run `cline auth cline`, then press Retry.")
expired.isOn = false
await store.refreshCapacityDockProvider(provider)
#expect(store.capacityDockProviderStatusTitles[provider.id] == nil)
expired.isOn = true
await store.refreshCapacityDockProvider(provider)
#expect(store.capacityDockProviderStatusTitles[provider.id] == "Cline login expired")
let kept = store.capacityDockQuotaSummary(for: provider)
#expect(kept?.connection == .stale)
#expect(kept?.primary?.percent == 0.3)
#expect(store.capacityDockProviderErrors[provider.id]
== "Cline login expired 3h ago. Send a message in Cline or run `cline auth cline`; CodeBurn picks up the new login on its next refresh.")
}
private final class ExpiryToggle: @unchecked Sendable {
var isOn = false
}
@Test("disconnect invalidates an in-flight provider refresh")
func disconnectWinsOverInFlightRefresh() async throws {
let provider = try #require(CapacityDockProvider(rawValue: "clinepass"))

View file

@ -102,7 +102,7 @@ final class ClinePassQuotaTests: XCTestCase {
let recorder = RequestRecorder()
let deps = Self.makeDeps(
recorder: recorder,
ambient: .init(token: "workos:old", isOAuth: true, expiresAt: Date(timeIntervalSince1970: 1_799_999_999))
ambient: .init(token: "workos:old", isOAuth: true, expiresAt: Date(timeIntervalSince1970: 1_800_000_000 - 3 * 3600))
) { request in
(Self.successBody.data(using: .utf8)!, Self.httpResponse(request, status: 200))
}
@ -110,8 +110,10 @@ final class ClinePassQuotaTests: XCTestCase {
_ = try await ClinePassSubscriptionService.refresh(apiKey: nil, deps: deps)
XCTFail("Expected an expired sign-in")
} catch {
XCTAssertEqual(error as? ClinePassSubscriptionService.FetchError, .signInExpired)
XCTAssertEqual(error.localizedDescription, "Cline sign-in expired. Run cline to refresh it.")
XCTAssertEqual(error as? ClinePassSubscriptionService.FetchError, .signInExpired(age: "3h ago"))
XCTAssertEqual(
error.localizedDescription,
"Cline login expired 3h ago. Send a message in Cline or run `cline auth cline`; CodeBurn picks up the new login on its next refresh.")
XCTAssertEqual((error as? ClinePassSubscriptionService.FetchError)?.classification, .transient)
}
XCTAssertTrue(recorder.requests.isEmpty)
@ -129,7 +131,10 @@ final class ClinePassQuotaTests: XCTestCase {
_ = try await ClinePassSubscriptionService.refresh(apiKey: nil, deps: rejected)
XCTFail("Expected an expired sign-in")
} catch {
XCTAssertEqual(error as? ClinePassSubscriptionService.FetchError, .signInExpired)
XCTAssertEqual(error as? ClinePassSubscriptionService.FetchError, .signInExpired(age: nil))
XCTAssertEqual(
error.localizedDescription,
"Cline login expired. Send a message in Cline or run `cline auth cline`; CodeBurn picks up the new login on its next refresh.")
}
let none = Self.makeDeps(recorder: recorder) { request in
(Data("{}".utf8), Self.httpResponse(request, status: 200))

View file

@ -11,13 +11,13 @@
import os from 'node:os'
import path from 'node:path'
import { compactAge } from './codex.js'
import { quotaRequestSignal, readSecureFile, sanitizeError } from './security.js'
import type { QuotaProvider, QuotaWindow } from './types.js'
const USAGE_ENDPOINT = 'https://api.cline.bot/api/v1/users/me/plan/usage-limits'
const API_KEY_VARS = ['CLINEPASS_API_KEY', 'CLINE_API_KEY'] as const
const REJECTED_FOOTER = ['ClinePass rejected this API key.']
const EXPIRED_FOOTER = ['Cline sign-in expired. Run cline to refresh it.']
const RATE_LIMITED_FOOTER = ['ClinePass rate-limited the quota request.']
const UNAVAILABLE_FOOTER = ['ClinePass is temporarily unavailable.']
const PARSE_FOOTER = ['ClinePass quota response was malformed.']
@ -36,6 +36,11 @@ function defaultDeps(): ClinePassDeps {
return { fetch: globalThis.fetch, env: process.env, readFile: readSecureFile, homeDir: os.homedir(), now: Date.now }
}
function clineExpiredFooter(expiresAt: number | null, now: number): string[] {
const age = expiresAt !== null && expiresAt <= now ? ` ${compactAge(expiresAt, now)}` : ''
return [`Cline login expired${age}. Send a message in Cline or run \`cline auth cline\`; CodeBurn picks up the new login on its next refresh.`]
}
function empty(connection: QuotaProvider['connection'], footerLines: string[] = []): QuotaProvider {
return { provider: 'clinepass', connection, primary: null, details: [], planLabel: null, footerLines }
}
@ -147,14 +152,18 @@ export async function fetchClinePassQuota(options: Partial<ClinePassDeps> & { si
// Not terminal: running cline refreshes the session file this only reads,
// so the next scheduled read recovers on its own.
if (credential.oauth && credential.expiresAt !== null && credential.expiresAt <= deps.now()) {
return { quota: empty('transientFailure', EXPIRED_FOOTER) }
return { quota: empty('transientFailure', clineExpiredFooter(credential.expiresAt, deps.now())) }
}
const response = await deps.fetch(USAGE_ENDPOINT, {
method: 'GET', signal: quotaRequestSignal(options.signal),
headers: { Accept: 'application/json', Authorization: `Bearer ${credential.token}`, 'User-Agent': 'CodeBurn' },
})
if (response.status === 401 || response.status === 403) {
return { quota: credential.oauth ? empty('transientFailure', EXPIRED_FOOTER) : empty('terminalFailure', REJECTED_FOOTER) }
return {
quota: credential.oauth
? empty('transientFailure', clineExpiredFooter(credential.expiresAt, deps.now()))
: empty('terminalFailure', REJECTED_FOOTER),
}
}
if (response.status === 429) {
const raw = response.headers.get('Retry-After')

View file

@ -77,10 +77,10 @@ describe('ClinePass credential discovery', () => {
})
it('stops at an expired Cline session without fetching, as a retryable failure', async () => {
const file = providersFile({ auth: { accessToken: 'workos:old', expiresAt: NOW - 1 } })
const file = providersFile({ auth: { accessToken: 'workos:old', expiresAt: NOW - 3 * 3_600_000 } })
const result = await fetchClinePassQuota({ env: {}, fetch: neverFetch, readFile: async () => file, now: () => NOW })
expect(result.quota.connection).toBe('transientFailure')
expect(result.quota.footerLines).toEqual(['Cline sign-in expired. Run cline to refresh it.'])
expect(result.quota.footerLines).toEqual(['Cline login expired 3h ago. Send a message in Cline or run `cline auth cline`; CodeBurn picks up the new login on its next refresh.'])
})
it('reads a rejected session token as an expired sign-in', async () => {
@ -90,7 +90,7 @@ describe('ClinePass credential discovery', () => {
fetch: (async () => jsonResponse({}, 401)) as unknown as typeof fetch,
})
expect(result.quota.connection).toBe('transientFailure')
expect(result.quota.footerLines).toEqual(['Cline sign-in expired. Run cline to refresh it.'])
expect(result.quota.footerLines).toEqual(['Cline login expired. Send a message in Cline or run `cline auth cline`; CodeBurn picks up the new login on its next refresh.'])
})
})