Skip to content

Try merge upstream main - #2527

Closed
CassiopeiaCode wants to merge 30 commits into
QuantumNous:mainfrom
CassiopeiaCode:try-merge-upstream-main
Closed

Try merge upstream main#2527
CassiopeiaCode wants to merge 30 commits into
QuantumNous:mainfrom
CassiopeiaCode:try-merge-upstream-main

Conversation

@CassiopeiaCode

@CassiopeiaCode CassiopeiaCode commented Dec 25, 2025

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features
    • Added hourly model health analytics dashboard with success rate tracking
    • Added user hourly call ranking interface
    • Added recent API calls debug viewer
    • Added random quota redemption code generation
    • Added admin user rate limit exemption capability
    • Added per-channel model role mapping configuration
    • Added multi-site OAuth redirect support
  • Improvements
    • Enhanced client IP logging and capture
    • Added hourly usage statistics tracking

✏️ Tip: You can customize this high-level summary in your review settings.

CassiopeiaCode and others added 30 commits December 25, 2025 01:38
Document differences between the current implementation and Newapi, detailing features such as model health monitoring, rate limiting, API call caching, user call statistics, random code generation, and role conversion.
DashboardListModels now returns a flattened model list in data and keeps grouped data separately. Add regression test.
- ModelHealthHourly: 模型选择下拉框改用独立 Select 组件
- RecentCalls: limit 下拉框改用独立 Select 组件
- UserHourlyCallsRank: limit 下拉框改用独立 Select 组件

Semi Design 的 Form.Select 在受控模式(value属性)下与动态 optionList 配合时存在显示问题
@coderabbitai

coderabbitai Bot commented Dec 25, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces a comprehensive monitoring and observability system with health tracking, recent calls caching, user hourly call rankings, per-channel model role mappings, and enhanced rate-limit exemptions. It includes new database models, async event processing, API endpoints, frontend pages, and an updated CI workflow for GHCR publishing. The VERSION is bumped to v0.1.29.

Changes

Cohort / File(s) Summary
CI/CD Workflows
.github/workflows/docker-image-alpha.yml, .github/workflows/docker-image-arm64.yml, .github/workflows/ghcr-publish.yml
Removes legacy multi-arch Docker image workflows (alpha and arm64 branches); introduces new GHCR-focused workflow on tag pushes with amd64-only build and optional arm64 via commented QEMU setup
Documentation
Difference.md, PROJECT_CONTEXT.md, plans/health_migration_design.md
Adds feature documentation, development guidelines, and health measurement migration design; no executable code
Version & Configuration
VERSION, common/constants.go, go.mod
Updates version to v0.1.29; adds HourlyCallRankCountFailedEnabled toggle; downgrades Go toolchain to 1.25.0
Health Monitoring Models & Queries
model/model_health_slice.go, model/model_health_writer.go, model/model_health_query.go, model/main.go
Introduces ModelHealthSlice5m schema with 5-minute aggregation, async event writing via worker pool, query functions for hourly health stats, and DB migration integration
Recent Calls Cache
service/recent_calls_cache.go
Implements thread-safe, circular-buffer in-memory cache for HTTP interactions with context integration, streaming support, sensitive-header masking, and body truncation handling
User Hourly Call Tracking
model/user_call_hourly.go, model/user_call_hourly_query.go, model/user_call_hourly_writer.go
Defines UserCallHourly model, async writer with hourly aggregation and success/failure tallying, and ranking query with per-hour or range-based filtering
Model Role Mappings
dto/channel_settings.go, service/model_role_mapping.go
Adds per-channel model role mappings with JSON marshalling, validation, hierarchical prefix matching, request snapshot/restore, and application to GeneralOpenAI and Responses request types
Rate Limit Exemptions
setting/rate_limit.go, setting/rate_limit_test.go, middleware/model-rate-limit.go, controller/option.go, model/option.go
Introduces ModelRequestRateLimitExemptUserIDs configuration with parsing, thread-safe lookup, middleware bypass, option validation, and test coverage
Controller: Recent Calls
controller/debug_recent_calls.go
Adds GetRecentCalls and GetRecentCallByID handlers for retrieving cached call records with pagination and ID-based lookup
Controller: Health & Ranking
controller/model_health.go, controller/user_rank.go, controller/hour_utils.go
Implements hourly model health stats API with Redis/memory caching, public 24h health endpoint, user hourly calls rank API, and hour-list parsing utilities
Controller: Helpers & Models
controller/model.go, controller/model_test.go
Flattens channel-scoped model lists in DashboardListModels response, maintains grouped metadata, adds test verifying response data is an array
Logging & Event Recording
model/log.go
Removes dynamic IP gating, forces IP logging; adds async health and hourly user-call event emission from RecordErrorLog and RecordConsumeLog
Redemption Enhancement
dto/redemption.go, controller/redemption.go
Adds CreateRedemptionRequest DTO with random quota mode support; implements per-code generation with prefix + UUID, cryptographically-secure quota randomization, and unique constraint error detection
Request/Response Handling
controller/relay.go, service/http.go, middleware/logger.go
Captures request role snapshots for per-channel re-application; initializes recent calls cache on channel attempts; records errors to cache; extracts and normalizes client IP for logging
Relay Channel Handlers
relay/channel/baidu/relay-baidu.go, relay/channel/claude/relay-claude.go, relay/channel/dify/relay-dify.go, relay/channel/gemini/relay-gemini*.go, relay/channel/openai/relay-openai.go, relay/channel/openai/audio.go, relay/channel/openai/relay_responses.go, relay/channel/xai/text.go
Integrate recent calls streaming cache hooks (EnsureStreamByContext, AppendStreamChunkByContext, FinalizeStreamAggregatedTextByContext) and upstream response caching (UpsertUpstreamResponseByContext) across multiple channel implementations
Relay Utilities
relay/helper/stream_scanner.go
Adds fallback for non-positive streaming timeout to 60 seconds
Router Configuration
router/api-router.go
Registers debug endpoints for recent calls, admin endpoints for user hourly ranking and model health, and public endpoint for 24h model health
Frontend: Pages
web/src/pages/ModelHealthHourly/index.jsx, web/src/pages/ModelHealthPublic/index.jsx, web/src/pages/RecentCalls/index.jsx, web/src/pages/UserHourlyCallsRank/index.jsx
Introduces four new React pages with data fetching, visualization, filtering, error handling, and responsive layouts for health monitoring, recent call inspection, and user rankings
Frontend: Services & Utilities
web/src/services/recentCalls.js, web/src/helpers/render.jsx, web/src/helpers/api.js
Adds recent calls API helpers; extends icon mapping for model_health and recent_calls; embeds origin host into OAuth state for multi-site redirect support
Frontend: Routing & Navigation
web/src/App.jsx, web/src/components/layout/SiderBar.jsx, web/src/hooks/common/useNavigation.js, web/src/hooks/common/useSidebar.js
Registers lazy-loaded routes for new pages; adds navigation items and sidebar toggles for model health, user rankings, and recent calls; merges defaults for backward compatibility
Frontend: Settings & Configuration
web/src/pages/Setting/Operation/SettingsHeaderNavModules.jsx, web/src/pages/Setting/Operation/SettingsSidebarModulesAdmin.jsx, web/src/components/settings/RateLimitSetting.jsx, web/src/components/settings/ModelSetting.jsx, web/src/components/table/channels/modals/EditChannelModal.jsx, web/src/components/table/redemptions/modals/EditRedemptionModal.jsx
Adds toggles for new admin modules, exemption user IDs textarea, Gemini model settings card, per-channel JSON model role mapping editor, and random quota UI for redemption creation
Static Assets
web/public/oauth-redirect.html, web/package.json
Introduces multi-site OAuth redirect HTML page with domain extraction and fallback logic; adds Ant Design (antd ^5.29.3) dependency

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant R as Relay Handler
    participant RC as RecentCallsCache
    participant E as Event Queue
    participant H as HealthWriter
    participant DB as Database

    C->>R: POST /v1/chat/completions
    R->>RC: BeginFromContext(c)
    RC->>RC: Create RecentCallRecord
    R->>R: Apply role mappings
    R->>R: Process request
    alt Streaming Response
        R->>RC: EnsureStreamByContext
        loop Each chunk
            R->>RC: AppendStreamChunkByContext(chunk)
        end
        R->>RC: FinalizeStreamAggregatedTextByContext
    else Error Path
        R->>RC: UpsertErrorByContext(error)
    else Success Path
        R->>RC: UpsertUpstreamResponseByContext(response)
    end
    
    R->>E: RecordModelHealthEventAsync(event)
    E->>H: Worker processes event
    H->>DB: UpsertModelHealthSlice5m
    
    R->>E: RecordUserCallHourlyEventAsync(event)
    par Async Processing
        E->>DB: UpsertUserCallHourly
    end
    
    C->>RC: GET /api/debug/recent_calls
    RC-->>C: Return cached records
Loading
sequenceDiagram
    participant Admin as Admin UI
    participant API as Controller
    participant Service as Service Layer
    participant Cache as Redis/Memory
    participant DB as Database

    Admin->>API: GET /api/model_health/hourly
    API->>Service: GetModelHealthCache
    alt Cache Miss
        Service->>DB: GetModelHealthHourlyStats
        DB-->>Service: Hourly stats
        Service->>Cache: Store with 5min TTL
    else Cache Hit
        Cache-->>Service: Return cached data
    end
    Service-->>API: Response
    API-->>Admin: Hourly health data + chart
    
    Public->>API: GET /api/public/model_health/hourly_last24h
    API->>Cache: Check 24h cache
    alt Cache Miss
        API->>DB: GetAllModelsHealthHourlyStats
        API->>Cache: Store last 24h
    end
    Cache-->>API: Cached data
    API-->>Public: JSON response
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion
  • creamlike1024

Poem

🐰 Hop skip and a bound, new features abound!
Health metrics dance in five-minute rounds,
Recent calls cached, roles remapped with grace,
User rankings and dashboards light up the place!

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97b0268 and ed3fd6d.

📒 Files selected for processing (68)
  • .github/workflows/docker-image-alpha.yml
  • .github/workflows/docker-image-arm64.yml
  • .github/workflows/ghcr-publish.yml
  • Difference.md
  • PROJECT_CONTEXT.md
  • VERSION
  • common/constants.go
  • controller/debug_recent_calls.go
  • controller/hour_utils.go
  • controller/model.go
  • controller/model_health.go
  • controller/model_test.go
  • controller/option.go
  • controller/redemption.go
  • controller/relay.go
  • controller/user_rank.go
  • dto/channel_settings.go
  • dto/redemption.go
  • go.mod
  • middleware/logger.go
  • middleware/model-rate-limit.go
  • model/log.go
  • model/main.go
  • model/model_health_query.go
  • model/model_health_slice.go
  • model/model_health_writer.go
  • model/option.go
  • model/user_call_hourly.go
  • model/user_call_hourly_query.go
  • model/user_call_hourly_writer.go
  • plans/health_migration_design.md
  • relay/channel/baidu/relay-baidu.go
  • relay/channel/claude/relay-claude.go
  • relay/channel/dify/relay-dify.go
  • relay/channel/gemini/relay-gemini-native.go
  • relay/channel/gemini/relay-gemini.go
  • relay/channel/gemini/relay_gemini_stream_recent_calls_test.go
  • relay/channel/openai/audio.go
  • relay/channel/openai/relay-openai.go
  • relay/channel/openai/relay_responses.go
  • relay/channel/xai/text.go
  • relay/helper/stream_scanner.go
  • router/api-router.go
  • service/http.go
  • service/model_role_mapping.go
  • service/recent_calls_cache.go
  • setting/rate_limit.go
  • setting/rate_limit_test.go
  • web/package.json
  • web/public/oauth-redirect.html
  • web/src/App.jsx
  • web/src/components/layout/SiderBar.jsx
  • web/src/components/settings/ModelSetting.jsx
  • web/src/components/settings/RateLimitSetting.jsx
  • web/src/components/table/channels/modals/EditChannelModal.jsx
  • web/src/components/table/redemptions/modals/EditRedemptionModal.jsx
  • web/src/helpers/api.js
  • web/src/helpers/render.jsx
  • web/src/hooks/common/useNavigation.js
  • web/src/hooks/common/useSidebar.js
  • web/src/pages/ModelHealthHourly/index.jsx
  • web/src/pages/ModelHealthPublic/index.jsx
  • web/src/pages/RecentCalls/index.jsx
  • web/src/pages/Setting/Operation/SettingsHeaderNavModules.jsx
  • web/src/pages/Setting/Operation/SettingsSidebarModulesAdmin.jsx
  • web/src/pages/Setting/RateLimit/SettingsRequestRateLimit.jsx
  • web/src/pages/UserHourlyCallsRank/index.jsx
  • web/src/services/recentCalls.js

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@CassiopeiaCode
CassiopeiaCode deleted the try-merge-upstream-main branch December 25, 2025 12:56
@CassiopeiaCode

Copy link
Copy Markdown
Author

Apologies for the noise. I accidentally opened this PR due to a local git configuration error (mis-pushed my downstream branch to the upstream repo). I have closed the PR and deleted the branch. Sorry for the inconvenience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant