Repository navigation
fix(ui): use precise hourly message counts for Peak Error Hours - #49396
Conversation
Greptile SummaryThis PR fixes the Peak Error Hours widget which previously showed an identical error rate (the session-wide average) for every hour. The backend ( Confidence Score: 5/5Safe to merge — the timezone math is correct, the fallback path is preserved and tested, and no pre-existing behavior is regressed. All findings are P2 or lower. The core fix is sound: UTC quarter-hour indices are computed with getUTCHours()/getUTCMinutes() on the backend and converted correctly to local or UTC hour buckets on the frontend. The previously flagged timezone bug is verifiably resolved in the current commit. Tests cover the important edge cases. No files require special attention. Reviews (2): Last reviewed commit: "fix: use precise hourly message counts f..." | Re-trigger Greptile |
e216c6d to
12df2fe
Compare
12df2fe to
c64700f
Compare
|
@hxy91819 Just a gentle bump — would appreciate any directional feedback on this when you have a moment. Happy to adjust the approach. |
|
@greptile-apps review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c64700f121
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Nice catch on the proportional-allocation math — that's a subtle one and the 96-bucket quarter-hour UTC encoding is the right shape for a widget that has both Local and UTC toggles. Two small things before merge:
Optional: the quarter-hour aggregation block in |
c64700f to
39f4076
Compare
@hxy91819 Thanks for catching these! All three points addressed (amended into the original commit):
|
a2b8763 to
1978829
Compare
|
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Keep open. Current main still computes Peak Error Hours by proportionally allocating session-wide Best possible solution: Keep this PR open for maintainer review. The best path is to land this PR or an equivalent fix that adds backend per-bucket message/error counts, uses them in What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against b85edb3f0cf6. |
1978829 to
5a104e6
Compare
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
The Peak Error Hours widget displayed identical error rates for all hours because the legacy algorithm distributed errors proportionally across session time spans. This produced misleading data (e.g., every hour showing 9.89%) instead of highlighting actual error-heavy periods. Changes: - Add SessionHourlyMessageCounts type with quarterIndex field (0-95) representing UTC-based 15-minute buckets for timezone-accurate hour conversion — covers all global UTC offsets (±15/30/45 min) - Collect per-quarter-hour message/error counts in loadSessionCostSummary using getUTCHours()/getUTCMinutes() with UTC day keys (formatUtcDayKey) - Prefer precise quarterly data in buildPeakErrorHours for both local and UTC views, falling back to proportional allocation for sessions without quarterly data - Fix DST bug: replace single getTimezoneOffset() with new Date(Date.UTC(...)).getHours() for DST-aware local hour mapping - Extract accumulateMessageCounts helper to deduplicate daily/hourly message count aggregation logic - Guard hourlyMessageCounts with .length check before including in summary (consistent with dailyLatency/dailyModelUsage pattern)
5a104e6 to
fbbf43b
Compare
|
Merged via squash.
Thanks @konanok! |
…claw#49396) Merged via squash. Prepared head SHA: fbbf43b Co-authored-by: konanok <[email protected]> Co-authored-by: hxy91819 <[email protected]> Reviewed-by: @hxy91819
…claw#49396) Merged via squash. Prepared head SHA: fbbf43b Co-authored-by: konanok <[email protected]> Co-authored-by: hxy91819 <[email protected]> Reviewed-by: @hxy91819
…claw#49396) Merged via squash. Prepared head SHA: fbbf43b Co-authored-by: konanok <[email protected]> Co-authored-by: hxy91819 <[email protected]> Reviewed-by: @hxy91819
…claw#49396) Merged via squash. Prepared head SHA: fbbf43b Co-authored-by: konanok <[email protected]> Co-authored-by: hxy91819 <[email protected]> Reviewed-by: @hxy91819
Summary
session-cost-usage.ts) and precise hour-level aggregation with proper timezone conversion in the frontend (usage-metrics.ts). The legacy proportional-allocation algorithm is preserved as a fallback for sessions without granular data..jsonlsession files are re-scanned on each load.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Security Impact (required)
NoNoNoNoNoRepro + Verification
Environment
~/.openclaw/openclaw.jsonSteps
openclaw gateway run --allow-unconfiguredExpected
Actual (before fix)
After fix
Local timezone
UTC timezone
Evidence
Tests added (20 total, all pass):
Backend (
src/infra/session-cost-usage.test.ts— 11 tests):00:14Z → index 0,00:15Z → index 1,06:30Z → index 26,23:59Z → index 95)loadSessionCostSummarypipelineFrontend (
ui/src/ui/views/usage-metrics.test.ts— 9 tests):hourlyMessageCounts→ falls back to legacy proportional algorithmHuman Verification (required)
openclaw gateway run), opened Control UI, navigated to Usage → Peak Error Hours. Confirmed that different hours now show different error rates. Toggled Local / UTC and verified hour labels shift correctly.Review Conversations
Compatibility / Migration
YesNoNo—loadSessionCostSummaryre-scans raw.jsonltranscript files on every call (not cached), so all existing sessions produce precise hourly data immediately.Failure Recovery (if this breaks)
hourlyMessageCountsis absent or empty, so reverting the backend change alone is also safe.Risks and Mitigations
SessionCostSummaryobjects in memory.new Date().getTimezoneOffset()is called once perbuildPeakErrorHoursinvocation; DST transitions mid-session could shift some hours by ±1.