Skip to content

Codex/model refresh health#50

Merged
cita-777 merged 6 commits intomainfrom
codex/model-refresh-health
Mar 10, 2026
Merged

Codex/model refresh health#50
cita-777 merged 6 commits intomainfrom
codex/model-refresh-health

Conversation

@cita-777
Copy link
Owner

@cita-777 cita-777 commented Mar 10, 2026

Summary by CodeRabbit

  • New Features

    • Model discovery now provides detailed status feedback with specific error codes and improved error messages.
    • Model previews are included in discovery results.
    • Enhanced error handling for timeouts, unauthorized access, disabled sites, and missing accounts.
  • Tests

    • Added comprehensive test coverage for model discovery scenarios and success/failure paths.
    • Introduced toast notification tests for model verification feedback.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This pull request refactors the model discovery and refresh functionality to return structured error information alongside a richer status payload. The service now classifies discovery failures into typed error codes and provides detailed messages, model previews, and health tracking to both the backend and frontend layers.

Changes

Cohort / File(s) Summary
Error Classification & Service Logic
src/server/services/modelService.ts
Introduced ModelRefreshErrorCode union type and helpers (classifyModelDiscoveryError, buildModelFailureMessage) for mapping discovery failures to structured codes. Expanded refreshModelsForAccount return shape to include status, errorCode, errorMessage, modelsPreview, token scanning flags, and credential discovery metadata. Reworked early-exit paths (missing account, disabled site, inactive account) to return comprehensive failure/skipped objects with detailed error codes instead of simple reason strings. Enhanced model discovery with failure aggregation, latency tracking per model, and account health updates on success.
Service Test Coverage
src/server/services/modelService.discovery.test.ts
Extended test suite for refreshModelsForAccount credential discovery with new test cases covering success path with enriched result fields, runtime health unhealthy on API token failure, and structured results for missing account, disabled site, and inactive account scenarios. Each test asserts status, errorCode, errorMessage, modelsPreview, and health tracking fields.
UI Handlers & Error Formatting
src/web/pages/Accounts.tsx
Added three helper functions (formatModelSuccess, formatModelFailure, handleCheckModels) to orchestrate model refresh flow, format success/failure responses into user-facing toast messages, and handle error codes (timeout, unauthorized, empty models) with fallbacks. Integrated robust error handling into per-account model check actions.
UI Test Setup & Toast Integration
src/web/pages/accounts.edit-panel.test.tsx
Introduced toast mocking scaffolding (toastMock, mocked Toast.js module with ToastProvider and useToast). Added test case validating successful model refresh toast notifications with model count and status messages.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant UI as Accounts.tsx
    participant API as API Handler
    participant Service as refreshModelsForAccount
    participant DB as Account & Model Store
    participant Discovery as Model Discovery<br/>(per credential)

    User->>UI: Click "Check Models"
    activate UI
    UI->>API: POST /checkModels
    activate API
    API->>Service: refreshModelsForAccount(accountId)
    activate Service
    
    Service->>DB: Load account details
    activate DB
    DB-->>Service: account data
    deactivate DB
    
    alt Account Not Found
        Service-->>API: {status: 'failed', errorCode: 'account_not_found'}
    else Site Disabled
        Service-->>API: {status: 'skipped', errorCode: 'site_disabled'}
    else Account Inactive
        Service-->>API: {status: 'skipped', errorCode: '...'}
    else Valid Account
        rect rgba(100, 150, 200, 0.5)
            Note over Service,Discovery: Attempt discovery across<br/>account.apiToken, discoveredApiToken,<br/>account.accessToken + enabled tokens
            loop Each Credential
                Service->>Discovery: Discover models (with timeout)
                activate Discovery
                Discovery-->>Service: models[] OR error
                deactivate Discovery
                Service->>Service: Classify error if needed<br/>Aggregate failures
            end
        end
        
        alt Discovery Success
            Service->>DB: Update account health to healthy<br/>Persist model availability
            activate DB
            DB-->>Service: persisted
            deactivate DB
            Service-->>API: {status: 'success', errorCode: null,<br/>modelsPreview, modelCount, ...}
        else All Discovery Failed
            Service->>DB: Update health tracking with failure reason
            activate DB
            DB-->>Service: updated
            deactivate DB
            Service-->>API: {status: 'failed', errorCode: classified,<br/>errorMessage, modelsPreview: [], ...}
        end
    end
    
    deactivate Service
    API-->>UI: response
    deactivate API
    
    UI->>UI: formatModelSuccess() OR<br/>formatModelFailure()
    UI->>UI: Show toast notification
    UI->>UI: Update loading state & reload
    UI-->>User: Display result
    deactivate UI
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰✨ Our models now speak with the clearest of voice,
With status and codes—oh, what wonderful choice!
Success or it's failed, every error's defined,
The discovery dance is more structured, refined.
From token to token, we search without haste,
And users see toasts—no more messages misplaced! 🌟

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Codex/model refresh health' is vague and does not clearly convey the main changes. It uses a namespace prefix and generic term 'health' without specifics about what is being improved. Consider a more descriptive title such as 'Add structured error reporting and health tracking to model refresh' or 'Enhance model discovery with comprehensive error codes and status tracking'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/model-refresh-health

Comment @coderabbitai help to get the list of available commands and usage tips.

@cita-777 cita-777 merged commit a60adf4 into main Mar 10, 2026
3 of 4 checks passed
@github-actions github-actions bot added area: server Server-side API and backend changes area: web Web UI changes size: XXL 2000 or more lines changed size: M 200 to 499 lines changed and removed size: XXL 2000 or more lines changed labels Mar 15, 2026
@cita-777 cita-777 deleted the codex/model-refresh-health branch March 15, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: server Server-side API and backend changes area: web Web UI changes size: M 200 to 499 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant