Skip to content

refactor(storage): remove the unused legacy Usage session scanner - #4060

Merged
Astro-Han merged 5 commits into
apache:mainfrom
heeoneie:refactor/remove-legacy-usage-scanner
Aug 29, 2026
Merged

refactor(storage): remove the unused legacy Usage session scanner#4060
Astro-Han merged 5 commits into
apache:mainfrom
heeoneie:refactor/remove-legacy-usage-scanner

Conversation

@heeoneie

Copy link
Copy Markdown
Contributor

Summary

SettingsStore.usageStats and packages/storage/src/usage-stats-store.ts have no production consumer. Desktop reads Usage through the Runtime Host: the settings:usageStats handler in runtime-host-usage-ipc-main.ts resolves via loadUsageStats(deps.client, ...), and the only .usageStats( call site in the repository is window.maka.settings.usageStats(range, host) at settings-surface.tsx:636, which goes through that same Host path. @maka/core/usage-stats/* is a separate module and is untouched, as are SettingsStore itself and projectDesktopUsageStats.

Removing the scanner also removes the only import that pulled node:sqlite into ./settings-store's module graph — usage-stats-store.ts imported createSqliteSessionMetadataStore. public-entrypoints.test.ts fails on only the declared entrypoints load node:sqlite until './settings-store' leaves SQLITE_BACKED_ENTRYPOINTS, so that list is updated in the same change with the reason, as its own comment asks. A consumer importing @maka/storage/settings-store no longer pays the SQLite load.

usage-stats-store is not in packages/storage's exports map, so this is not a public-API change.

Refs #4059

Verification

Ran:

  • tsc -p packages/core/tsconfig.json and tsc -p packages/storage/tsconfig.json — clean.
  • biome lint packages/storage and biome format packages/storage — clean. The format run is what caught the collapsed type import in fd35428.
  • @maka/storage suite (node --test "dist/**/*.test.js"): 991 tests, 969 pass, 3 fail, 19 skipped.
  • The same suite on unmodified main in the same container: 995 tests, 973 pass, and the same 3 failures — rejects a second authority for the same storage root in another process, does not classify a SQLite write failure as a migration blocker, and an unmarked read-only workspace fails without leaving marker state. Two of them assert that a permission denial rejects, and my test process runs as root, so chmod does not deny it. Unrelated to this change.
  • Repository-wide grep for readUsageStats, usage-stats-store, and SettingsStore.usageStats: no remaining reference.

Not run: the Desktop build, Desktop tests, and e2e. The Electron postinstall and one registry dependency are blocked in my environment, so the Desktop side is verified by reference inspection only, not by execution. Worth a reviewer confirming npm --workspace @maka/desktop test.

AI use

Select exactly one:

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

Tool(s) and scope: Claude Opus 5 — call-site verification, the edits themselves, and running the checks above. Each commit carries a Generated-by: Claude Opus 5 trailer.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@github-actions github-actions Bot added the effort/L Under 1000 readable lines label Aug 28, 2026
@Astro-Han
Astro-Han force-pushed the refactor/remove-legacy-usage-scanner branch from fd35428 to 1c8d538 Compare August 29, 2026 09:48
SettingsStore.usageStats and packages/storage/src/usage-stats-store.ts have no production consumer. Desktop reads Usage through the Runtime Host client in runtime-host-usage-ipc-main.ts; the only .usageStats( call site in the repository is window.maka.settings.usageStats(range, host), which resolves through that same Host path.

Refs apache#4059

Generated-by: Claude Opus 5
Its only importer was SettingsStore.usageStats, removed in this branch.

Refs apache#4059

Generated-by: Claude Opus 5
These cover SettingsStore.usageStats and the legacy scanner only; both are gone.

Refs apache#4059

Generated-by: Claude Opus 5
usage-stats-store.ts held the only import that pulled node:sqlite into ./settings-store's module graph. With the legacy scanner gone that entrypoint is SQLite-free, so it leaves SQLITE_BACKED_ENTRYPOINTS -- updated in the same change with the reason, as the list's own comment asks.

Refs apache#4059

Generated-by: Claude Opus 5
…ne line

Dropping UsageRange and UsageStats leaves three specifiers, which biome format prints inline. Caught by `npx biome format packages/storage`.

Refs apache#4059

Generated-by: Claude Opus 5
@Astro-Han
Astro-Han force-pushed the refactor/remove-legacy-usage-scanner branch from 1c8d538 to e1f40e0 Compare August 29, 2026 10:00

@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.

Approved at exact head e1f40e073609ca506fa773dd3721f08af1689e94.

Codex assisted with call-site tracing, package-boundary analysis, and exact-head verification. I independently reviewed the final diff and commit messages and own this approval.

I verified that Desktop Usage remains Runtime Host-owned; the removed Storage scanner has no production consumer or supported external contract; ./settings-store no longer reaches node:sqlite; and the change introduces no replacement state or parallel path. The exact-head test and windows_recovery checks are green, the branch is mergeable, and there are no unresolved review threads. No P0–P3 findings.

@Astro-Han
Astro-Han merged commit 8237a9a into apache:main Aug 29, 2026
2 checks passed
liuxiaocs7 added a commit to liuxiaocs7/maka that referenced this pull request Aug 29, 2026
The Usage Statistics activity log's 任务 (Task) column showed
`未命名会话 · <id>` for every row. apache#3833 fixed this by carrying
`SessionHeader.name` through the old usage-stats-store.ts pipeline, but
apache#3697 moved usage onto the Runtime Host projection and apache#4060 deleted
that store — the new pipeline only carried `sessionId`, so
`UsageRequestLog.sessionName` was declared but never populated and the
UI always hit the untitled fallback.

Resolve the title on the Host, where every usage-bearing session is
reachable. HostUsagePricingCoordinator takes a session-title reader
(sessionStore.readHeaderSnapshot) and, per logs page, resolves the title
for each row's sessionId, emitting it as a new bounded `sessionTitle`
field on the LLM/tool usage projections. Reading the durable header by
id bypasses the catalog's role/preparing/ledger-v0 filters, so
reserved-role, coordination, and legacy sessions are named too; an
unreadable session is tolerated per-row and simply stays untitled. The
desktop layer copies `sessionTitle` onto `sessionName`; the renderer
(usageSessionDisplayLabel) already owns the untitled fallback.

Closes apache#4218

Generated-by: Claude Code (claude-opus-4-8)
liuxiaocs7 added a commit to liuxiaocs7/maka that referenced this pull request Aug 29, 2026
The Usage Statistics activity log's 任务 (Task) column showed
`未命名会话 · <id>` for every row. apache#3833 fixed this by carrying
`SessionHeader.name` through the old usage-stats-store.ts pipeline, but
apache#3697 moved usage onto the Runtime Host projection and apache#4060 deleted
that store — the new pipeline only carried `sessionId`, so
`UsageRequestLog.sessionName` was declared but never populated and the
UI always hit the untitled fallback.

Resolve the title on the Host, where every usage-bearing session is
reachable. HostUsagePricingCoordinator takes a session-title reader
(sessionStore.readHeaderSnapshot) and, per logs page, resolves the title
for each row's sessionId, emitting it as a new bounded `sessionTitle`
field on the LLM/tool usage projections. Reading the durable header by
id bypasses the catalog's role/preparing/ledger-v0 filters, so
reserved-role, coordination, and legacy sessions are named too; an
unreadable session is tolerated per-row and simply stays untitled. The
desktop layer copies `sessionTitle` onto `sessionName`; the renderer
(usageSessionDisplayLabel) already owns the untitled fallback.

Bump the Host compatibility epoch (68 → 69): the new projection field is
rejected by older Clients, so the same protocol version no longer
guarantees safe interoperability.

Closes apache#4218

Generated-by: Claude Code (claude-opus-4-8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/L Under 1000 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants