Skip to content

Commit b6f8372

Browse files
committed
Handle Codex CLI warmup state
1 parent 952664d commit b6f8372

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Sources/CodexBar/CodexStatusProbe.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ struct CodexStatusProbe {
5252
static func parse(text: String) throws -> CodexStatusSnapshot {
5353
let clean = TextParsing.stripANSICodes(text)
5454
guard !clean.isEmpty else { throw CodexStatusProbeError.timedOut }
55+
if clean.localizedCaseInsensitiveContains("data not available yet") {
56+
throw CodexStatusProbeError.parseFailed("data not available yet")
57+
}
5558
if self.containsUpdatePrompt(clean) {
5659
throw CodexStatusProbeError.updateRequired(
5760
"Run `bun install -g @openai/codex` to continue (update prompt blocking /status).")

Sources/CodexBar/UsageStore.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,24 @@ final class UsageStore: ObservableObject {
293293
{
294294
await MainActor.run { self.probeLogs[.codex] = raw }
295295
}
296+
297+
// Special-case the CLI "data not available yet" warmup state: keep cached credits and show a soft hint.
298+
if let codexError = error as? CodexStatusProbeError,
299+
case let .parseFailed(message) = codexError,
300+
message.localizedCaseInsensitiveContains("data not available yet")
301+
{
302+
await MainActor.run {
303+
if let cached = self.lastCreditsSnapshot {
304+
self.credits = cached
305+
self.lastCreditsError = nil // keep quieter when we still have cached credits
306+
} else {
307+
self.credits = nil
308+
self.lastCreditsError = "Codex CLI is still loading credits; will retry shortly."
309+
}
310+
}
311+
return
312+
}
313+
296314
await MainActor.run {
297315
self.creditsFailureStreak += 1
298316
if let cached = self.lastCreditsSnapshot {

Tests/CodexBarTests/TTYIntegrationTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ final class TTYIntegrationTests: XCTestCase {
1717
// Acceptable: confirms we detected the update prompt and surfaced a clear message.
1818
XCTAssertFalse(message.isEmpty)
1919
} catch let CodexStatusProbeError.parseFailed(raw) {
20+
if raw.localizedCaseInsensitiveContains("data not available yet") {
21+
throw XCTSkip("Codex CLI is still warming up: \(raw)")
22+
}
2023
XCTFail("Codex PTY parse failed: \(raw.prefix(200))")
2124
} catch CodexStatusProbeError.timedOut {
2225
XCTFail("Codex PTY probe timed out.")

0 commit comments

Comments
 (0)