{"record":{"id":"ad36f827ec640944","repo":"chenhg5/cc-connect","slug":"codex-app-server-usage-unavailable","errorCode":null,"errorMessage":"codex app-server usage unavailable","messagePattern":"codex app-server usage unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agent/codex/appserver_session.go","lineNumber":929,"sourceCode":"}\n\nfunc (s *appServerSession) GetReasoningEffort() string {\n\ts.runtimeMu.RLock()\n\tdefer s.runtimeMu.RUnlock()\n\treturn strings.TrimSpace(s.effort)\n}\n\nfunc (s *appServerSession) GetUsage(ctx context.Context) (*core.UsageReport, error) {\n\tif err := s.refreshUsage(ctx); err != nil {\n\t\tif cached := s.cachedUsage(); cached != nil {\n\t\t\treturn cached, nil\n\t\t}\n\t\treturn nil, err\n\t}\n\tif cached := s.cachedUsage(); cached != nil {\n\t\treturn cached, nil\n\t}\n\treturn nil, fmt.Errorf(\"codex app-server usage unavailable\")\n}\n\nfunc (s *appServerSession) GetContextUsage() *core.ContextUsage {\n\treturn s.cachedContextUsage()\n}\n\nfunc (s *appServerSession) Alive() bool {\n\treturn s.alive.Load()\n}\n\nfunc (s *appServerSession) Close() error {\n\ts.alive.Store(false)\n\ts.cancel()\n\n\ts.procMu.Lock()\n\tif s.stdin != nil {\n\t\t_ = s.stdin.Close()\n\t\ts.stdin = nil","sourceCodeStart":911,"sourceCodeEnd":947,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/appserver_session.go#L911-L947","documentation":"GetUsage first refreshes usage from the app-server and falls back to the cached value; if both the fetch and the cache fail it returns this error. It means no token/usage accounting data is available at all for this session.","triggerScenarios":"Calling GetUsage when the usage fetch request fails (or returns empty) and s.cachedUsage() returns nil because no successful usage response has ever been received this session.","commonSituations":"Fresh session that has not completed a turn yet (no usage data recorded); codex binary that doesn't emit usage/account info; usage request timed out right after startup; auth issues preventing the account/usage lookup.","solutions":["Complete at least one turn so usage data is produced, then retry GetUsage","Verify the codex binary/account supports usage reporting and is properly authenticated","Retry GetUsage later once the cache is populated after a successful fetch","Handle nil usage gracefully in the caller instead of failing the command"],"exampleFix":"// before\nusage, err := sess.GetUsage(ctx)\nif err != nil { return err }\n// after\nusage, err := sess.GetUsage(ctx)\nif err != nil {\n    slog.Warn(\"usage not available yet\", \"err\", err)\n    return nil // render placeholder UI instead of failing\n}","handlingStrategy":"fallback","validationCode":"// no pre-call validation possible; gate on a completed turn\nif sess.TurnCount() == 0 {\n    // usage not yet available\n}","typeGuard":null,"tryCatchPattern":"usage, err := sess.GetUsage(ctx)\nif err != nil {\n    // show \"usage unavailable\" placeholder; retry after next turn\n    usage = nil\n}","preventionTips":["Only request usage after at least one completed turn","Retry with backoff — the cache fills after the first successful fetch","Verify the codex account/auth supports usage reporting","Return cached=nil gracefully in UI code instead of erroring the command"],"tags":["usage","codex","cache"],"backgroundTag":"empty-result-set","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}