mirror of
https://github.com/stablyai/orca.git
synced 2026-11-15 18:37:24 +00:00
Run local usage services in a supervised backend process (#40792)
* Move local usage services into a supervised backend process * Own usage recovery and worker retirement lifetimes * Preserve answered usage data during background refresh * Run independent usage scans concurrently in the backend * Limit backend startup paths to the delegated usage service * Show usage failures through backend recovery * Include usage failure strings in the English catalog * Keep usage update details beside refresh failures * Resolve usage freshness failure from the final producer snapshot * Retain the forced refresh completion requirement * Keep managed backend failures out of application crash reports * Preserve usage recovery boundaries across backend reconnects * Match the backend RPC cancellation signal in the usage seam proof * Avoid serializing backend requests before port delivery * Keep receiving request validation in the boundary schemas * test: align usage transport coverage with renderer project * fix: preserve unknown usage state and renderer retirement * fix(usage): revalidate tracking before scan admission * fix(usage): retry failed backend startup on demand * test(usage): isolate stale backend ownership checks
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { codexOpenCodeTokenSessions } from '../usage/reporting/token-usage/agent-token-usage'
|
||||
import { app } from 'electron'
|
||||
import { join } from 'node:path'
|
||||
import type {
|
||||
OpenCodeUsageBreakdownKind,
|
||||
@@ -11,7 +10,7 @@ import type {
|
||||
OpenCodeUsageSnapshot,
|
||||
OpenCodeUsageSummary
|
||||
} from '../../shared/opencode-usage-types'
|
||||
import type { UsageWorktreeSource } from '../usage/worktree-attribution/usage-worktree-metadata'
|
||||
import type { UsageStoreHost } from '../usage/usage-store-host'
|
||||
import type {
|
||||
OpenCodeUsageDailyAggregate,
|
||||
OpenCodeUsagePersistedState,
|
||||
@@ -32,32 +31,19 @@ import {
|
||||
import { UsageProviderStoreLifecycle } from '../usage/provider-lifecycle/usage-provider-store-lifecycle'
|
||||
import { splitUsageCacheFileViaWorker } from '../usage/scan-worker/usage-scan-worker-spawn'
|
||||
|
||||
let _openCodeUsageFile: string | null = null
|
||||
|
||||
export function initOpenCodeUsagePath(): void {
|
||||
_openCodeUsageFile = join(app.getPath('userData'), 'orca-opencode-usage.json')
|
||||
}
|
||||
|
||||
function getOpenCodeUsageFile(): string {
|
||||
if (!_openCodeUsageFile) {
|
||||
_openCodeUsageFile = join(app.getPath('userData'), 'orca-opencode-usage.json')
|
||||
}
|
||||
return _openCodeUsageFile
|
||||
}
|
||||
|
||||
export class OpenCodeUsageStore extends UsageProviderStoreLifecycle<
|
||||
'processedDatabases',
|
||||
OpenCodeUsagePersistedState,
|
||||
'hasAnyOpenCodeData'
|
||||
> {
|
||||
constructor(store: UsageWorktreeSource) {
|
||||
super(store, {
|
||||
constructor(host: UsageStoreHost) {
|
||||
super(host, {
|
||||
tokenUsage: {
|
||||
provider: 'opencode',
|
||||
selectSessions: (state) => codexOpenCodeTokenSessions(state.sessions)
|
||||
},
|
||||
logTag: '[opencode-usage]',
|
||||
resolveCacheFile: getOpenCodeUsageFile,
|
||||
resolveCacheFile: () => join(host.userDataPath, 'orca-opencode-usage.json'),
|
||||
createDefaultState: getDefaultState,
|
||||
normalizeState: normalizePersistedState,
|
||||
sourceKey: 'processedDatabases',
|
||||
|
||||
Reference in New Issue
Block a user