Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 90bb8ea3b1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e63aad5 to
62bf82e
Compare
Introduce end-to-end AI usage statistics for Halo admins. This adds runtime usage instrumentation across language, embedding, rerank, and image generation calls, persists logical calls and execution attempts in SQLite with retention and health tracking, exposes summary/trend/history/reset console APIs, regenerates the OpenAPI client, and adds a Chinese console view with filters, charts, call details, and reset flow.
62bf82e to
62e9002
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 62e9002a27
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc1e3a78d9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
# Conflicts: # app/src/main/java/run/halo/aifoundation/service/language/LanguageModelImpl.java
# Conflicts: # api-docs/openapi/v3_0/aiFoundationApis.json # app/build.gradle # app/src/main/java/run/halo/aifoundation/service/image/ImageGenerationModelImpl.java # app/src/main/java/run/halo/aifoundation/service/rerank/RerankingModelImpl.java # app/src/test/java/run/halo/aifoundation/service/embedding/EmbeddingModelImplTest.java # ui/src/api/generated/base.ts # ui/src/api/generated/models/model-parameter-definition-info.ts # ui/src/api/generated/models/provider-type-info.ts
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Direct SDK timeout exceptions are misclassified as failed calls, producing inaccurate status statistics.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds end-to-end AI usage tracking with provider normalization, resilient SQLite persistence, Console APIs, and a Vue administration interface.
Changes:
- Records logical calls, executions, retries, token usage, status, and health.
- Adds retention, rollups, recovery, filtering, trends, pagination, and reset.
- Adds generated API bindings, Console UI, and extensive regression tests.
| File | Description |
|---|---|
app/build.gradle |
Adds SQLite runtime support. |
app/.../endpoint/UsageStatisticsConsoleEndpoint.java |
Exposes statistics APIs. |
app/.../provider/** |
Normalizes provider usage metadata. |
app/.../service/audit/** |
Wraps SDK calls with usage recording. |
app/.../service/{embedding,image,language,rerank}/** |
Records physical model executions. |
app/.../service/observation/** |
Implements call and execution lifecycle accounting. |
app/.../service/usage/** |
Implements SQLite persistence, querying, recovery, and retention. |
app/src/test/** |
Covers providers, lifecycle, durability, APIs, and storage. |
api-docs/openapi/v3_0/aiFoundationApis.json |
Publishes the Console API schema. |
ui/src/api/generated/** |
Adds generated statistics client models and methods. |
ui/src/composables/use-usage-*.ts |
Manages filters, queries, polling, and pagination. |
ui/src/views/components/usage/** |
Implements statistics dashboards and call details. |
ui/src/views/UsageStatisticsView.vue |
Composes the statistics page. |
ui/src/views/ProviderManager.vue |
Adds the usage tab. |
ui/src/views/ProviderDetail.vue |
Standardizes timestamp formatting. |
ui/src/utils/usage*.ts |
Provides usage formatting and chart utilities. |
ui/src/**/__tests__/** |
Covers Console components and composables. |
openspec/changes/add-ai-usage-statistics/** |
Documents requirements, design, and tasks. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


What this PR changes
Adds AI usage statistics for calls made through the audited model wrappers (language, embedding, reranking, image generation). Usage is recorded to a local SQLite database and surfaced through a new Console page.
Statistical model
usageQualityreports how complete the token data is (REPORTED_COMPONENTS,REPORTED_TOTAL,PARTIAL,ESTIMATED,MISSING);accountedTotalTokensis derived from the best available source.Console API
GET /apis/console.api.aifoundation.halo.run/v1alpha1/usage-statistics/summary— totals with filter dimensions and coverageGET .../usage-statistics/trends?resolution=DAY|HOUR— time-bucketed execution trendsGET .../usage-statistics/calls?cursor=...&size=...— cursor-paginated call list with filters (status, provider, model, caller, feature, operation, date range)GET .../usage-statistics/calls/{id}— call detail with per-execution recordsGET .../usage-statistics/health— persistence health (restore status, queue depth, dropped events)POST .../usage-statistics/reset— clear statistics dataResilience
%DATA_DIR%; daily rotation uses the same backup scheme as plugin-seo-tools.Test plan
./gradlew buildpasses (backend tests included).pnpm lint,pnpm type-check,pnpm test:unit(39 files / 245 tests) pass.