Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(usage): tell a Grok 401 that starting a Grok session refreshes credentials (#1234)

eneskirca900bdb87ea28
diff --git a/src/renderer/components/UsageIndicator.grok.test.tsx b/src/renderer/components/UsageIndicator.grok.test.tsx
index 2ac2b95b9..68cce216f 100644
--- a/src/renderer/components/UsageIndicator.grok.test.tsx
+++ b/src/renderer/components/UsageIndicator.grok.test.tsx
@@ -64,6 +64,11 @@ describe('Grok billing diagnostics in the usage popover', () => {
expect(text).not.toContain('expired')
expect(text).not.toContain('No usage data.')
})
+ it('wires the provider id through, so the Grok 401 hint shows (issue #983)', async () => {
+ await open(snapshot('unavailable'), [{ provider: 'grok', account: null,
+ status: 'error', limits: [], updatedAt: 0, diagnostics: [{ view: 'credits', reason: 'http', httpStatus: 401 }] }])
+ expect(host.querySelector('.usage-account')?.textContent).toContain('Starting a Grok session refreshes the saved credentials')
+ })
it.each(['unavailable', 'error'] as const)('keeps Claude %s distinct from a Grok failure', async (status) => {
await open(snapshot(status), [{ provider: 'grok', account: null,
status: 'error', limits: [], updatedAt: 0, diagnostics: [{ view: 'credits', reason: 'network' }] }])
diff --git a/src/renderer/components/UsageIndicator.tsx b/src/renderer/components/UsageIndicator.tsx
index ef019c41b..bea7f03a8 100644
--- a/src/renderer/components/UsageIndicator.tsx
+++ b/src/renderer/components/UsageIndicator.tsx
@@ -329,7 +329,7 @@ function ProviderBlock({ u, mode, hostKey }: { u: ProviderUsage; mode: 'used' |
<HeldNote u={u} />
{/* One line per distinct reason (issue #912): two views failing the same way are one
failure of this provider, not two paragraphs of the same sentence. */}
- {usageDiagnosticLines(label, u.diagnostics).map((line) => (
+ {usageDiagnosticLines(label, u.diagnostics, u.provider).map((line) => (
<div className="usage-popover__empty" key={line}>
{line}
</div>
diff --git a/src/renderer/lib/usageDiagnostic.test.ts b/src/renderer/lib/usageDiagnostic.test.ts
index 0977d2e1f..d0a0388c0 100644
--- a/src/renderer/lib/usageDiagnostic.test.ts
+++ b/src/renderer/lib/usageDiagnostic.test.ts
@@ -38,3 +38,22 @@ describe('usageDiagnosticLines (issue #912)', () => {
expect(usageDiagnosticLines('Grok', [])).toEqual([])
})
})
+
+describe('Grok 401 hint (issue #983)', () => {
+ const d401 = { view: 'credits', reason: 'http', httpStatus: 401 } as const
+
+ it('says that starting a Grok session refreshes the saved credentials', () => {
+ const [line] = usageDiagnosticLines('Grok', [d401], 'grok')
+ expect(line).toMatch(/Grok authentication failed \(HTTP 401\)/)
+ expect(line).toMatch(/Starting a Grok session refreshes the saved credentials/)
+ expect(line).not.toMatch(/expired/)
+ expect(usageDiagnosticText('Grok', d401, 'grok')).toMatch(/Starting a Grok session/)
+ })
+
+ it('keeps the generic text for a 403, for other providers, and without a provider id', () => {
+ const generic = /Check the CLI authentication on the machine running this project\.$/
+ expect(usageDiagnosticLines('Grok', [{ ...d401, httpStatus: 403 }], 'grok')[0]).toMatch(generic)
+ expect(usageDiagnosticLines('Codex', [d401], 'codex')[0]).toMatch(generic)
+ expect(usageDiagnosticLines('Grok', [d401])[0]).toMatch(generic)
+ })
+})
diff --git a/src/renderer/lib/usageDiagnostic.ts b/src/renderer/lib/usageDiagnostic.ts
index 26d56e275..9951fab31 100644
--- a/src/renderer/lib/usageDiagnostic.ts
+++ b/src/renderer/lib/usageDiagnostic.ts
@@ -4,14 +4,25 @@ function viewLabel(view: UsageDiagnostic['view']): string {
return view === 'credits' ? 'Credits view' : 'Default view'
}
-/** The reason sentence alone, without the view it was read from. */
-function usageDiagnosticMessage(provider: string, diagnostic: UsageDiagnostic): string {
+/**
+ * Grok's usage reader only ever READS the key the CLI saved in `$GROK_HOME/auth.json` and never
+ * refreshes it (core/usage/grok-usage.ts). Reported in issue #983: the 401 showed while no Grok
+ * session had run for a while, and starting one (which lets the CLI replace the key) fixed it. The
+ * expiry is a hypothesis, not a measurement, so the copy names the remedy and claims no cause
+ * (UsageIndicator.grok.test.tsx pins that no diagnostic says "expired").
+ */
+const GROK_401 = 'Grok authentication failed (HTTP 401). Starting a Grok session refreshes the saved credentials; then refresh usage. If that does not help, sign in to the Grok CLI again on the machine running this project.'
+
+/** The reason sentence alone, without the view it was read from. `providerId` (the provider's
+ * stable id, not its label) selects a provider-specific variant where one exists. */
+function usageDiagnosticMessage(provider: string, diagnostic: UsageDiagnostic, providerId?: string): string {
switch (diagnostic.reason) {
case 'timeout': return 'Usage request timed out. Try again later.'
case 'network': return `Could not reach ${provider}. Check the connection and try again.`
case 'invalid-response': return 'Usage response could not be read. Try again later.'
case 'http': {
const status = diagnostic.httpStatus
+ if (status === 401 && providerId === 'grok') return GROK_401
return status === 401 || status === 403
? `${provider} authentication failed (HTTP ${status}). Check the CLI authentication on the machine running this project.`
: status === 429
@@ -24,8 +35,8 @@ function usageDiagnosticMessage(provider: string, diagnostic: UsageDiagnostic):
}
/** Static copy only: diagnostics never carry provider response text or credential details. */
-export function usageDiagnosticText(provider: string, diagnostic: UsageDiagnostic): string {
- return `${viewLabel(diagnostic.view)}: ${usageDiagnosticMessage(provider, diagnostic)}`
+export function usageDiagnosticText(provider: string, diagnostic: UsageDiagnostic, providerId?: string): string {
+ return `${viewLabel(diagnostic.view)}: ${usageDiagnosticMessage(provider, diagnostic, providerId)}`
}
/**
@@ -35,11 +46,12 @@ export function usageDiagnosticText(provider: string, diagnostic: UsageDiagnosti
*/
export function usageDiagnosticLines(
provider: string,
- diagnostics: readonly UsageDiagnostic[] | undefined
+ diagnostics: readonly UsageDiagnostic[] | undefined,
+ providerId?: string
): string[] {
const groups = new Map<string, string[]>()
for (const d of diagnostics ?? []) {
- const message = usageDiagnosticMessage(provider, d)
+ const message = usageDiagnosticMessage(provider, d, providerId)
const views = groups.get(message) ?? []
const label = viewLabel(d.view)
groups.set(message, views.includes(label) ? views : [...views, label])