# clamp checkpoint token delta overflow

`119afdc`·

peyton-alt·3w ago·2 files·+55 added/-9 removed

## Sessions

70741de008a8View transcript

## Changes

2

- cmd/entire/cli

- Mcheckpoint_tokens.go+31/-8

- Msessions_test.go+24/-1

```
55 unmodified lines

...
```

```
func newCheckpointTokensCmd() *cobra.Command {
...
}

func buildCheckpointMetricDelta(baseline, current int) *checkpointTokensMetricDelta {
    change := saturatingIntSub(current, baseline)
    delta := &checkpointTokensMetricDelta{
        Baseline:  baseline,
        Current:   current,
        Change:    current - baseline,
        Direction: checkpointDeltaDirection(current - baseline),
        Change:    change,
        Direction: checkpointDeltaDirection(change),
    }
    if baseline != 0 {
        percent := float64(delta.Change) * 100 / float64(baseline)
...
}

func saturatingIntSub(a, b int) int {
...
}

func maxInt() int {
    return int(^uint(0) >> 1)
}

func minInt() int {
    return -maxInt() - 1
}

func checkpointDeltaDirection(change int) string {
    switch {
    case change < 0:
        return "down"
    case change > 0:
        return "up"
    default:
        return "unchanged"
    }
}

func TestBuildCheckpointMetricDeltaClampsChangeOverflow(t *testing.T) {
...
}

func TestCheckpointTokensCmd_ComparisonUnavailableWhenBaselineTokenDataMissing(t *testing.T) {
    repo, _ := runExplainAutoTestRepo(t)
    ctx := context.Background()
}

```
