fix: unify agent vitals reporting across UI and API (fixes #7)#20
Open
kagura-agent wants to merge 1 commit intoopen-gitagent:mainfrom
Open
fix: unify agent vitals reporting across UI and API (fixes #7)#20kagura-agent wants to merge 1 commit intoopen-gitagent:mainfrom
kagura-agent wants to merge 1 commit intoopen-gitagent:mainfrom
Conversation
…ent#7) Root cause: UI and API computed vitals independently, causing inconsistent values across surfaces: 1. Uptime: UI used browser page-load time (Date.now() at load) while API returned process.uptime(). Opening the page 30min after server start meant they'd permanently differ by 30 minutes. 2. CPU: API used cumulative process.cpuUsage() divided by total uptime, giving a lifetime average instead of instantaneous utilization. 3. No shared snapshot: each API call computed mem/cpu/uptime at slightly different instants, so concurrent readers could see different values. Fix: - Add centralized getVitalsSnapshot() with 1s cache — all surfaces (API, UI, future log consumers) read the same frozen snapshot - Use delta-based CPU measurement for accurate instantaneous readings - UI now syncs uptime from server response (resets on each 2s poll), with 1s local interpolation for smooth display - Remove client-side vitalsStart/Date.now() uptime calculation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Agent vitals (CPU, memory, uptime, tokens) are reported inconsistently between the dashboard UI and the API endpoint. Different surfaces show different values, causing confusion about the agent's actual state.
Root Causes
Uptime mismatch: UI computed uptime from
Date.now()at page load (browser time), while API returnedprocess.uptime()(server process time). Opening the dashboard 30 minutes after server start meant they'd permanently differ by 30 minutes.CPU calculation: API used cumulative
process.cpuUsage()divided by total process lifetime, giving a lifetime average instead of instantaneous utilization — misleading when comparing against the UI's 2-second poll interval.No shared snapshot: Each API call independently computed
process.memoryUsage(),process.cpuUsage(), andprocess.uptime()at slightly different instants, so concurrent consumers (multiple browser tabs, external API clients) could see divergent values.Fix
getVitalsSnapshot()with 1-second cache — all surfaces (API, UI, future log consumers) read the same frozen snapshot within any 1s windowprocess.hrtime.bigint()for accurate instantaneous CPU readings instead of lifetime averagesvitalsStart = Date.now()uptime calculation entirely.tsfield (unix-ms) so consumers know exactly when the snapshot was takenChanges
src/voice/server.ts: AddVitalsSnapshotinterface,getVitalsSnapshot()with caching and delta CPU. Replace inline vitals computation in/api/vitalshandler.src/voice/ui.html: RemovevitalsStart, usevitalsServerUptimesynced from API. Add uptime sync inpollSystemVitals().Fixes #7