You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(usage): count usage from linked hosts (rebased from #456) - #560
Rebase of #456 by @1zun4 onto current main (5d7232a) — the original lives on the author's fork, and no rebase came after the maintainer's request, so this replacement carries the same change forward. All credit to @1zun4; this PR changes nothing about the feature, only its base.
What it does (from #456): Settings → Usage now counts tokens and cost from every linked host, not only this machine. Each host's daemon reads its own transcripts (listUsageTranscripts / readUsageRecords, link ops, older daemons answer 501 and are listed as needing an update); main keeps a copy in usage.db (schema v5 — the three usage tables are dropped and rebuilt from transcripts, by design: usage.db is only a cache), so an offline host keeps its last numbers. A new Host breakdown shows each machine's share and last sync time, project rows name their host, and refresh re-reads every host with that host's models.yml prices. getUsageReport moved to lib/usage-report.ts (usage-service stays daemon-loadable under Node, where bun:sqlite does not exist). Refreshing Usage now also applies changed prices and reports failures instead of silently keeping stale numbers.
Rebase notes: the CHANGELOG entry is fresh (written against the current ## [Unreleased]), not the original's stale one. All other hunks applied onto the new main with context verified; the only adaptations were line offsets. The 6 new usageConfig.host* keys are present in all four locales (en/ja/zh-CN/zh-TW).
Tests run (fresh tree on the new main, bun test --parallel):
lib/usage-db.test.mjs, lib/usage-service.test.mjs, lib/hosts/usage-sync.test.mjs, lib/hosts/session-ops-usage.test.mjs, lib/hosts/hub.test.mjs, lib/hosts/daemon.test.mjs, components/UsageConfig.hosts.test.mjs, lib/i18n.test.mjs: 227 pass, 1 fail — the single failure is in-flight real preparations block native daemon updates… (Host install is not an owned, writable release directory), which also fails on pristine main here, i.e. a pre-existing environment failure, unrelated to this change.
npm run typecheck: clean. npm run lint: 0 errors, 7 warnings, all in files this PR does not touch (AppShell, RecordingDeck, useDictation).
Before merge:#456's head never had a Verify CI run, and this replacement needs one too — a fresh Verify run must go green on all three platforms before merging.
Supersedes #456, which will be closed once this is open.
Summary by CodeRabbit
New Features
Usage reports now include linked hosts, with host and project breakdowns and visible sync statuses.
Host usage remains available while a host is offline. Refreshing usage applies edited prices to existing sessions, and refresh errors appear alongside the last report.
Older linked hosts are identified when an update is needed.
Bug Fixes
Usage records with implausible values are excluded from reports.
No actionable comments were generated in the recent review.
Walkthrough
Usage reports now combine local and linked-host usage. The change adds host-side transcript listing and paged reads, host-scoped persistence and synchronization, and host status and breakdown information in the usage interface.
Changes: Linked-host usage reporting
Layer / File(s)
Summary
Usage parsing and data contracts lib/usage-types.ts, lib/usage-service.ts, lib/usage-service.test.mjs
Usage record parsing now checks numeric limits and supports strict read errors. The report function moves to lib/usage-report.ts, and usage types describe transcript pages and host status.
The host lists stamped session and artifact transcripts and serves bounded, paged usage records. Inventory modes handle unreadable paths, and the hub validates operation results.
Host-scoped storage and report aggregation lib/usage-db.ts, lib/usage-types.ts, lib/usage-db.test.mjs
The database stores transcript stamps and usage rows by host, tracks sync times, and includes host and project breakdowns. Local refresh and report aggregation are updated.
Linked-host synchronization and report entry point lib/hosts/usage-sync.ts, lib/hosts/usage-sync.test.mjs, lib/usage-report.ts, app/api/usage/route.ts, AGENTS.md
The report path pulls linked-host usage with batching, a per-host TTL, and a bounded wait. Completed reads are stored; failed pulls retain stored usage.
Host breakdown and sync status display components/UsageConfig.tsx, components/UsageConfig.hosts.test.mjs, lib/i18n/locales/*.json, CHANGELOG.md
The interface adds host breakdown rows, linked-host labels on project rows, sync-state messages, and polling while a host is syncing. Localized strings and changelog entries describe the updates.
ompweb-dev/ompweb#416 — Both PRs change the usage report flow and UsageConfig refresh behavior.
Suggested reviewers:andrebrait, broglah1
Merge Risk: Minimal · up to f69c8
Usage now includes linked hosts, with per-host breakdown, offline fallback to the last synced numbers, and an update notice for older hosts. I found no concrete merge-blocking defect. Before merging, confirm the cross-platform Verify run the author asked for.
Security architecture risk: Moderate · up to 5b619
A linked machine can affect how usage from other machines is counted, and large histories can slow shared services. Rolling back without resetting the usage cache can also produce misleading totals. The change reviewed here does not establish a sign-in bypass or loss of original transcripts.
Retained concerns
Medium · security · inferred: A linked host that knows another host's entry ID and timestamp can report a matching record that wins the global deduplication ordering. Its writes stay in its own host partition, but the report can exclude the genuine row from another host, including the local machine. The base deduplicated local copies; this PR extends that decision to independently controlled sources without proving that matching records have common provenance.
Medium · security · inferred: The new pull limits individual messages and batches, not the total work attributable to one host. On the daemon, the time check does not cover the initial inventory or bound a single synchronous transcript parse. On the server, a linked peer can keep a pull active across valid pages and grow retained data beyond one page; the HTTP timeout stops waiting, not the pull. This can contend with unrelated work in the shared daemon or reporting server.
Medium · reliability · inferred: Rolling back the server binary while keeping the v5 database does not restore local-only cache semantics. The base reader accepts the newer version, reads stamps and deletes by path without a host key, and its forced refresh clears remote records and stamps. Depending on the first request after rollback, it can count retained remote data as local usage or discard cached history that an offline host cannot promptly restore. Original transcripts are not deleted.
Security review details
Security Blast Radius
inferred — A caller admitted to the existing Usage route can now trigger work across the installation's registered, connected hosts and read combined usage metadata. A linked host supplies records only to its own cache partition, but shared reporting logic and server capacity extend its possible impact beyond that partition.
Security Findings and Attack Paths
inferred — Host-record validation checks type and numeric plausibility, not cross-host entry identity. As a result, accepting a record into its own host partition does not prevent it from influencing which other hosts' records are counted.
Trust Boundaries and Controls
observed — The Usage route is not exempted from the existing web gate or browser-origin policy. Password-enabled deployments require a valid session or trusted proxy header; password-disabled deployments retain the existing ungated-by-password behavior but now return linked-host usage.
Resilience and Maintainability Implications
observed — Normal revocation removes the registry record, closes the link, and fails pending operations. Cache pruning is a separate report-time step rather than part of revocation; a new link receives a fresh ID and does not inherit the old cache partition.
Hardening Proposals
proposed — Scope deduplication to a host unless the server can verify that records on different hosts are copies of the same original. Enforce cumulative per-host work and storage budgets on the receiving side rather than relying solely on daemon paging.
proposed — Give the host-aware cache a versioned path or define a rollback procedure that isolates the v5 cache before starting a v3 reader, preserving it separately if offline history is needed after a later re-upgrade.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "feat(usage): count usage from linked hosts (rebased from #456)" matches the main change. The PR adds linked-host usage counting to the Usage report, including per-host totals, host sync sta…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "feat(usage): count usage from linked hosts (rebased from #456)" matches the main change. The PR adds linked-host usage counting to the Usage report, including per-host totals, host sync state, and the usage.db schema update. The "(rebased from #456)" suffix is a reference only and does not describe the change.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: a62005bd-d352-4015-a2fa-456aa25b5ebf
Commits
Reviewing files that changed from the base of the PR and between 5b61984 and f69c8b3.
Files selected for processing: 1
CHANGELOG.md
Files skipped from review as they are similar to previous changes: 1
CHANGELOG.md
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Superseded by #570, which recreates this PR as a fresh branch from current main (08717b6).
Why a new PR instead of a push here: this branch's CHANGELOG entries and main's were both inserted at the same ## [Unreleased] anchor, so Git's 3-way merge conflicts regardless of the branch tip's content. #570 re-applies the same 25 files onto current main with the CHANGELOG resolved (all of main's entries kept, the two usage entries appended), and also picks up #566's chatInput.toolset* locale keys in en/zh-TW. #570 reports mergeable: true, mergeable_state: clean.
Closing this PR; the work continues in #570 (which credits #456 by @1zun4 through this PR).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebase of #456 by @1zun4 onto current main (5d7232a) — the original lives on the author's fork, and no rebase came after the maintainer's request, so this replacement carries the same change forward. All credit to @1zun4; this PR changes nothing about the feature, only its base.
What it does (from #456): Settings → Usage now counts tokens and cost from every linked host, not only this machine. Each host's daemon reads its own transcripts (
listUsageTranscripts/readUsageRecords, link ops, older daemons answer 501 and are listed as needing an update); main keeps a copy inusage.db(schema v5 — the three usage tables are dropped and rebuilt from transcripts, by design: usage.db is only a cache), so an offline host keeps its last numbers. A new Host breakdown shows each machine's share and last sync time, project rows name their host, and refresh re-reads every host with that host'smodels.ymlprices.getUsageReportmoved tolib/usage-report.ts(usage-service stays daemon-loadable under Node, wherebun:sqlitedoes not exist). Refreshing Usage now also applies changed prices and reports failures instead of silently keeping stale numbers.Rebase notes: the CHANGELOG entry is fresh (written against the current
## [Unreleased]), not the original's stale one. All other hunks applied onto the new main with context verified; the only adaptations were line offsets. The 6 newusageConfig.host*keys are present in all four locales (en/ja/zh-CN/zh-TW).Tests run (fresh tree on the new main,
bun test --parallel):lib/usage-db.test.mjs,lib/usage-service.test.mjs,lib/hosts/usage-sync.test.mjs,lib/hosts/session-ops-usage.test.mjs,lib/hosts/hub.test.mjs,lib/hosts/daemon.test.mjs,components/UsageConfig.hosts.test.mjs,lib/i18n.test.mjs: 227 pass, 1 fail — the single failure isin-flight real preparations block native daemon updates…(Host install is not an owned, writable release directory), which also fails on pristine main here, i.e. a pre-existing environment failure, unrelated to this change.npm run typecheck: clean.npm run lint: 0 errors, 7 warnings, all in files this PR does not touch (AppShell, RecordingDeck, useDictation).Before merge: #456's head never had a Verify CI run, and this replacement needs one too — a fresh Verify run must go green on all three platforms before merging.
Supersedes #456, which will be closed once this is open.
Summary by CodeRabbit