Skip to content

[metrics] Recalculate average after removing the last value - #301

Open
dajiaohuang wants to merge 1 commit into
tinyplex:mainfrom
dajiaohuang:fix/metrics-empty-average
Open

[metrics] Recalculate average after removing the last value#301
dajiaohuang wants to merge 1 commit into
tinyplex:mainfrom
dajiaohuang:fix/metrics-empty-average

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

Fixes #300.

Removing the last numeric value during an incremental average update divides by zero. If the same transaction subsequently adds another row, the intermediate nonfinite result survives until Metrics exposes it as undefined, despite the final table having numeric data.

Return undefined from the removal shortcut when its prior length is one. This uses the existing full-recalculation fallback on the final values, without changing public APIs or other aggregators.

The regression removes the sole row, adds two rows in one transaction, checks the final average and single listener notification, and verifies a later update.

Validation

  • New regression fails on freshly built main (f09e5a3b74) and passes with this patch.
  • npm run compileForTest passes.
  • Metrics and Queries: 281 tests pass. Istanbul records both branches of the added conditional (28 normal-path hits, 1 fallback hit).
  • Prettier, ESLint and git diff --check pass for the patch. CSpell passes for the production file; repository configuration excludes test files.
  • Expanded test/unit/core/other: 753 pass, 2 middleware synchronization tests fail (transformed data/value returning to the originator). Both fail identically after removing this patch and rebuilding main.
  • Full npm run preCommit could not complete on Windows: the spell stage fails with spawn npx ENOENT. Focused tests do not establish whole-repository 100% coverage.

Tested on Windows with Node.js v24.14.1. No dependencies or generated files changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Average metric becomes undefined after replacing rows in a transaction

1 participant