Skip to content

fix(desktop): align usage statistics with Daily Review - #3761

Open
testikun wants to merge 3 commits into
apache:mainfrom
testikun:codex/issue-3695-usage-alignment
Open

fix(desktop): align usage statistics with Daily Review#3761
testikun wants to merge 3 commits into
apache:mainfrom
testikun:codex/issue-3695-usage-alignment

Conversation

@testikun

Copy link
Copy Markdown
Contributor

Summary

Fixes #3695

Usage Statistics now reads the selected Runtime Host's unified usage projection, matching Daily Review's legacy + canonical model-call accounting.

  • Added a Host-scoped usage:stats IPC projection.
  • Reused one concrete time window for summary, buckets, and every activity-log page.
  • Preserved host-scoped session keys, ignored stale responses after Host changes, and kept unknown session/cost values explicit.
  • Renamed the mixed view to Activity log and tracked aborted tool calls separately from errors.
  • Kept the existing Runtime Host authority and pricing semantics unchanged.

中文摘要

使用统计现在直接读取当前选中的 Runtime Host 统一用量投影,与 Daily Review 使用相同的 legacy + canonical 统计口径;同时补齐分页读取、Host 切换防旧数据回写、未知字段展示和中止工具调用的独立统计,不改变 Runtime Host 权威或定价逻辑。

Verification

  • npm run format:check
  • npm run lint
  • npm --workspace @maka/core run build
  • npm --workspace @maka/runtime-host run build
  • npm --workspace @maka/storage run build
  • npm --workspace @maka/desktop run build:main
  • Desktop main/preload typechecks
  • Focused regression: runtime-host-usage-stats.test.js (passed)
  • git diff --check

The repository-wide typecheck still reports existing unrelated errors in packages/ui and the CLI's @maka/eval resolution. The storage SQLite test suite was not runnable with the available Node v20 runtime because node:sqlite is unavailable; the repository requires Node >=22.19.0.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: OpenAI Codex analyzed issue #3695, designed the bounded Host-scoped projection, implemented the IPC/renderer changes, added regression coverage, and ran the listed verification. The human contributor remains responsible for review and submission.

Checklist

  • Tests cover the change and fail without it
  • Focused lint, format, build, and typecheck checks pass locally

Does this PR entail a change in behavior?

  • Yes — Usage Statistics now uses the selected Runtime Host authority and exposes aborted/unknown activity explicitly
  • No

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this head and found no blocking code issues.

Usage statistics are now aligned to the Host projection (single window for summary/buckets/logs, paginated fetch, host-switch stale guard). The fix correctly reuses the Daily Review projection and handles aborts/tool counts.

Machine gate: test is failure on session-effect-two-client-uds (likely environmental flake, unrelated to desktop usage IPC), so not green — not mergeable yet. No P0-P2 in code.

简体中文代码无阻断,CI 红待作者重跑。

@testikun

Copy link
Copy Markdown
Contributor Author

Investigated the red CI check on this PR. The failure is in the pre-existing packages/runtime-host test session-effect-two-client-uds.test.ts, with Recap provider outcome is unknown; it is unrelated to the usage IPC/statistics files changed here.

I rebuilt @maka/runtime-host locally and ran the failing test repeatedly, including concurrent stress runs (360 total executions), without reproducing the failure. No code change is warranted in this PR for an unrelated environmental/concurrency flake; the failed check needs a GitHub rerun by someone with repository Actions permission.

简体中文 这次 CI 红灯来自主干已有的 Runtime Host recap 双客户端测试,与本 PR 的 usage 改动无关。本地构建并压力运行 360 次均通过,建议直接重跑该 check。

Generated-by: OpenAI Codex

@testikun

Copy link
Copy Markdown
Contributor Author

Follow-up fix pushed in da77a7cf4.

The recap coordinator now rechecks the durable result when it finds an intent but no in-memory active effect. This closes the small race where the first result probe observes the result before publication, the intent is then visible, and an exact retry could otherwise be classified as outcome_unknown even though the result has become durable. Conflicts still fail closed, and provider work is not repeated.

Local verification: @maka/runtime-host typecheck passed; the recap coordinator tests and the two-client UDS test passed; 100 targeted recap runs passed; format and lint passed.

The original CI log also contained an unrelated Host registration/startup race in another test, so the full CI result still needs to be observed after this head.

简体中文 在发现 intent 但内存中没有 active effect 时重新读取 durable result,避免结果刚写入期间的精确重试被误判为 outcome_unknown。provider 不会重复调用,冲突仍然 fail closed。

Generated-by: OpenAI Codex

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this head and found a blocking issue.

[P1] settings.usageStats() forwards wrapped Result as raw stats — crashes Settings → Usage

runtime-host-usage-ipc-main.ts:87-92 returns {ok:true, data:UsageStats} via tryReconnectableReadResult, but preload.ts:2629-2633 declares Promise<UsageStats> and returns the wrapper unwrapped. Renderer reads stats.logs.length on the wrapper → Cannot read properties of undefined and crash. Hosted test: FAILURE (32920709908) on Settings accessibility.

Fix: unwrap success Result in preload (keep reconnectable error semantics) or change contract to Result and handle in renderer; add regression test.

简体中文设置页的 Usage 数据被包了一层导致崩溃。

Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@testikun
testikun force-pushed the codex/issue-3695-usage-alignment branch from da77a7c to c415d99 Compare August 26, 2026 05:34
@testikun

Copy link
Copy Markdown
Contributor Author

Fixed the P1 in c415d9936, rebased onto the latest apache/main (e6db07e96).

The Runtime Host usage:stats IPC intentionally returns a reconnectable Result<UsageStats> envelope. The preload bridge now unwraps successful Host reads before returning them to Settings, and converts projected failures into an Error while preserving reconnectable transport failures as rejected promises. The local settings:usageStats path is unchanged.

Added regression coverage for:

  • successful and failed Result unwrapping;
  • the preload Host usage contract;
  • the existing usage projection adapter.

Verification:

  • Desktop main build: passed
  • preload typecheck: passed
  • targeted tests: 4/4 passed
  • Settings accessibility E2E (every settings page exposes named actionable controls): passed
  • repository lint: passed

The full workspace dependency build still reports pre-existing packages/ui type mismatches on this latest main; no UI package files are changed by this PR.

简体中文 已修复 P1:Host usage IPC 返回的 Result 包装现在由 preload 正确解包,Settings 收到真正的 UsageStats;普通错误会转成异常,可重连传输错误仍保持 reject 语义。设置页无障碍 E2E 已通过。

Generated-by: OpenAI Codex

testikun added 3 commits August 26, 2026 13:42
The Runtime Host usage IPC intentionally returns a reconnectable Result envelope. Unwrap successful host reads in preload and surface projected failures as errors so Settings receives UsageStats instead of the envelope. Add regression coverage for both result handling and the preload contract.

Generated-by: OpenAI Codex
@testikun
testikun force-pushed the codex/issue-3695-usage-alignment branch from c415d99 to 428fd04 Compare August 26, 2026 05:45
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.

fix(desktop): align Usage Statistics counts with Daily Review

2 participants