Description
Goal
Review each cast at a metric boundary, decide whether it is correct for the metric's semantics, and
leave every retained cast with a native reason or replace it with a clearer expression.
Background
Two cast directions are involved. Aggregate outputs return f64 for gauges and averages, and the
tracker casts them to u64 (cast_sign_loss, cast_possible_truncation). Gauge inputs cast
usize counts to f64 (cast_precision_loss). Many of these are ordinary: a counter is an
integer, but its mean over time is a float, and a count far below 2^53 converts exactly. The
reasons were never recorded, so the review must state, per metric, whether the value is an integer
counter, a gauge, or an average, what its bounds are, and what the cast does at the edges.
Scope
In Scope
- Inventory Existing Clippy Allows #2158 entries A080-A087, A113-A114, A143-A154, A170, A178-A222, and A224-A227.
- Both directions:
f64aggregate output to integer, and integer count tof64gauge input. - Metric semantics and, where a bound or behavior changes, focused tests in HTTP core, UDP core,
UDP server, and swarm coordination registry as required by the owned entries. - For each owned entry: retain with a native
reason, replace with a clearer conversion, or fix a
demonstrated defect.
Out of Scope
- Protocol-width conversions owned by the wire-validation child issue.
- Domain conversions owned by the domain-contract child issue.
- A change to
torrust-metricsunless tracker-owned boundaries cannot express the required policy.
Architectural Decisions
- Related ADRs: None.
- ADRs to create: Create one only if metric aggregate semantics require a repository-wide API policy.
Design and Ownership Review
Not applicable: this work changes local conversion boundaries and does not introduce child
processes, asynchronous I/O, network readiness, resource cleanup, or reusable test fixtures.
Implementation Plan
| ID | Status | Task | Notes / Expected Output |
|---|---|---|---|
| T1 | TODO | Classify aggregate semantics | Record whether each owned value is an integer counter, gauge, or average, and its realistic bounds. |
| T2 | TODO | Judge each cast | Per entry: correct as-is, clearer alternative available, or defective. Record edge behavior (fractional, negative, non-finite, out of range). |
| T3 | TODO | Apply outcomes | Add native reasons to retained casts; implement and test alternatives or fixes where chosen. |
| T4 | TODO | Reconcile inventory | Update #2158 evidence by ID with each outcome. |
Commit Points
| Task | Coherent change set | Commit policy |
|---|---|---|
| T1-T2 | Review table in this specification | Commit after maintainer review of the outcomes. |
| T3 | One package's reasons, alternatives, and tests | Commit after focused validation and required review. |
| T4 | Inventory evidence for that package | Commit after focused validation and required review. |
Progress Tracking
Workflow Checkpoints
- Folder-style spec drafted in
docs/issues/open/2244-2243-review-metric-aggregate-conversions/ISSUE.md - Spec reviewed and approved by user/maintainer
- GitHub issue created and issue number added to this spec
- Spec-only PR merged into
developbefore implementation - Implementation completed
- Automatic verification completed (
linter all, relevant tests, and any pre-push checks) - Manual verification scenarios executed and recorded in issue-local
manual-verification-evidence.md - Acceptance criteria reviewed after implementation and updated with evidence
- Evidence-based implementation completion review recorded
- Committer verified spec progress is up to date before commit
- Issue closed and spec moved from
docs/issues/open/todocs/issues/closed/
Progress Log
- 2026-09-15 14:46 UTC - GitHub Copilot - Drafted from the Inventory Existing Clippy Allows #2158 metric aggregate design input - Awaiting maintainer review
- 2026-09-16 12:20 UTC - josecelano - Reframed as a review with retain-with-reason as a valid outcome - Chat decision
Acceptance Criteria
- Every owned entry has a recorded semantics classification, bounds, and outcome.
- Every retained cast carries a native
reasonstating its invariant. - Every changed conversion has a focused test for the stated bound or new behavior.
-
linter allexits with code0and relevant package tests pass.
Verification Plan
Automatic Checks
- Focused HTTP core, UDP core, UDP server, and swarm-registry tests for changed packages.
- Focused Clippy checks for changed packages.
linter alland required pre-push checks.
Manual Verification Scenarios
| ID | Scenario | Human-oriented command/steps | Expected Result | Status | Evidence |
|---|---|---|---|---|---|
| M1 | Inspect metric output | Run a local tracker with metric collection enabled and inspect the affected statistics endpoint or output. | Integer and average metrics match their documented semantics. | TODO | manual-verification-evidence.md section M1 |
Acceptance Verification
| AC ID | Status (TODO/DONE) |
Evidence |
|---|---|---|
| AC1 | TODO | Pending implementation. |
| AC2 | TODO | Pending tests. |
| AC3 | TODO | #2158 inventory evidence. |
| AC4 | TODO | Pending validation. |
Risks and Trade-offs
- Treating every cast as a defect leads to needless helpers and behavior changes. Retaining a
documented cast is a complete outcome. - Saturating, rejecting, rounding, and retaining floating values express different metric contracts.
Choose behavior per metric semantics rather than applying one conversion helper.
Implementation Completion Review
- Retrospective:
Not yet assessed - Create
implementation-retrospective.mdfromdocs/templates/IMPLEMENTATION-RETROSPECTIVE.mdin
this folder if the work invalidates an assumption, changes design materially, or yields a reusable
lesson; otherwise add a progress-log entry stating why none is needed.
References
- Related issues: Inventory Existing Clippy Allows #2158
- Related PRs: None
- Related ADRs: None
Activity
Merge #2247: docs(issues): add numeric conversion review bundle
Merge #2442: chore(issues): archive closed issue #2246 spec
test(udp-server): [torrust#2244] use an absolute tolerance for the ga…
docs(statistics): [torrust#2244] correct the float-to-integer cast re…
docs(pr-reviews): [torrust#2244] add the PR torrust#2552 review audit
docs(issues): [torrust#2244] correct the per-ID outcomes of ten inven…
docs(udp-server): [torrust#2244] say the averaged accessors round tow…
docs(issues): [torrust#2244] make the manual verification evidence re…
docs(issues): [torrust#2244] align the G3 outcome with the code and k…
docs(issues): [torrust#2244] correct the progress-log times of the im…
docs(pr-reviews): [torrust#2244] record the second review round in th…
docs(issues): [torrust#2244] name the revision of the committed-test …
docs(udp-server): [torrust#2244] end the averaged reason on a test, n…
5 remaining items
refactor(http-core): [#2244] document the counter-total metric conver…
refactor(udp-core): [#2244] document the counter-total metric conversion
refactor(udp-server): [#2244] document metric aggregate conversions
refactor(swarm-coordination-registry): [#2244] document inactive-coun…
docs(issues): [#2244] record metric conversion outcomes and verificat…
docs(issues): [#2244] record pre-push verification
chore(issues): archive closed issue #2244 spec and EPIC #2243 to docs…
Merge #2557: chore(issues): [#2243] archive the #2244 spec and close …
Merge torrust#2552: fix(udp-server): [torrust#2244] review metric agg…
Merge #2561: refactor(statistics): [#2560] adopt the exact counter su…
docs(issues): [#1349] re-measure the http core baseline after #2244
Merge #2558: docs(issues): [#1349] add the http-core coverage invento…
docs(issues): [torrust#2243] record that torrust#2560 adopted the met…
Merge #2579: docs(issues): record that #2560 adopted the metrics foll…