Skip to content

Auto-adjust cost histogram bucket intervals (#436)#490

Merged
joelteply merged 1 commit intomainfrom
fix/cost-widget-auto-interval
Mar 26, 2026
Merged

Auto-adjust cost histogram bucket intervals (#436)#490
joelteply merged 1 commit intomainfrom
fix/cost-widget-auto-interval

Conversation

@joelteply
Copy link
Contributor

Summary

  • Server-side autoInterval() picks optimal bucket width based on time range: 1h→5m, 6h→15m, 24h→1h, 72h→3h, 7d→6h, 30d→1d
  • Targets 12-24 buckets for visual clarity at any zoom level
  • Removed duplicated interval maps from ContinuumMetricsWidget and MetricsDetailWidget — single source of truth in AICostServerCommand
  • Callers can still override with explicit interval param

Closes #436.

Test plan

  • TypeScript compilation passes
  • Visual verification: cost dashboard shows appropriate bucket granularity at each time range

Server-side autoInterval picks optimal bucket width: 1h→5m, 6h→15m,
24h→1h, 72h→3h, 7d→6h, 30d→1d. Targets 12-24 buckets for visual
clarity at any zoom level. Removed duplicated interval maps from both
ContinuumMetricsWidget and MetricsDetailWidget — single source of truth
in AICostServerCommand.

Closes #436.
Copilot AI review requested due to automatic review settings March 26, 2026 10:20
@joelteply joelteply merged commit 2197e44 into main Mar 26, 2026
2 of 4 checks passed
@joelteply joelteply deleted the fix/cost-widget-auto-interval branch March 26, 2026 10:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes time-series histogram bucket sizing for the cost dashboard by moving “adaptive interval” selection to the ai/cost server command, allowing widgets to omit client-side interval maps while preserving the ability to override with an explicit interval.

Changes:

  • Add server-side autoInterval() selection and use it when params.interval is not provided.
  • Remove duplicated client-side intervalMap logic from the two metrics widgets.
  • Keep support for explicit interval overrides via the existing command parameter.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/widgets/metrics-detail/MetricsDetailWidget.ts Removes client-side interval mapping so the server chooses bucket width automatically.
src/widgets/continuum-metrics/ContinuumMetricsWidget.ts Removes duplicated adaptive interval map and relies on server defaults.
src/commands/ai/cost/server/AICostServerCommand.ts Introduces autoInterval(spanMs) and uses it to pick a default interval for time-series generation.
Comments suppressed due to low confidence (1)

src/commands/ai/cost/server/AICostServerCommand.ts:305

  • parseIntervalToMs() accepts intervals like "0m"/"0h" (regex allows 0), which makes intervalMs = 0 and will cause an infinite loop in generateTimeSeries() (bucketStart never advances). Please validate that the parsed value is >= 1 (or that intervalMs > 0) and throw a clear error otherwise.
  private parseIntervalToMs(interval: string): number {
    const match = interval.match(/^(\d+)(m|h|d|w)$/);
    if (!match) {
      throw new Error(`Invalid interval format: ${interval}. Use "5m", "1h", "6h", "1d", "1w"`);
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


/**
* Auto-select bucket interval based on time range span.
* Targets 12-24 buckets for visual clarity at any zoom level.
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The docstring claims this targets 12–24 buckets, but the current mapping can exceed that (e.g., 7d with 6h => 28 buckets; 30d with 1d => 30 buckets). Please update the comment to reflect the actual behavior/target range so future callers don’t rely on an incorrect guarantee.

Suggested change
* Targets 12-24 buckets for visual clarity at any zoom level.
* Aims for a reasonable number of buckets for visual clarity (typically
* around a dozen to a few dozen), but may exceed 24 buckets for longer
* ranges (e.g., ~28 buckets for 7d@6h, ~30 buckets for 30d@1d).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cost/metrics widgets: auto-adjust time segments for visual clarity

2 participants