← Back to Pull requests

Delimit strings in attribute hashing #9508

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 16, 2026 05:19 UTC
Author

Strings were written into the attribute digest without a length, so neighbouring strings had no boundary between them. Different attribute sets could produce the same Distinct.

For example []string{"ab", "c"} and []string{"a", "bc"} hash to the same value, and so do {a="x", bc=1} and {a="xb", c=1}. In sdk/metric that means measurements with those attributes are aggregated into a single stream.

This prefixes every hashed string (keys, string values, string slice elements, byte slices and map keys) with its length, and every slice and map with its element count, so nested collections have a boundary too. TestHashStringBoundaries and TestHashCollectionBoundaries fail on main and pass with the change. Hash values are not persisted anywhere, so changing them is safe.

I ran go test -race for the root module, sdk and sdk/metric, and golangci-lint on the root module. The extra framing costs hashing time but no allocations. On my laptop (Apple M1, 10 interleaved runs of main and this branch, -benchtime=300ms) the hash benchmarks are about 8 to 15 ns slower per hashed value, around 40% on the geomean, and NewSet goes from about 282 ns to 349 ns. Allocations are unchanged everywhere (0 for hashing, 1 for NewSet). The machine was not idle, so the spread is wide; a second run gave the same picture with a +46% geomean.

<details>
<summary>benchstat, sec/op</summary>

                                       │   main.txt    │                 pr.txt                 │
                                       │    sec/op     │     sec/op      vs base                │
HashKVs/All-8                            1.656µ ±   7%    2.216µ ±   8%  +33.83% (p=0.001 n=10)
HashKVs/BoolTrue-8                       22.61n ± 262%    30.73n ±  33%  +35.92% (p=0.023 n=10)
HashKVs/BoolFalse-8                      22.88n ±  24%    31.11n ±   6%  +35.99% (p=0.002 n=10)
HashKVs/BoolSliceLen0-8                  17.95n ±  17%    30.46n ±  52%  +69.67% (p=0.000 n=10)
HashKVs/BoolSliceLen1-8                  22.91n ±  62%    39.83n ±  37%  +73.85% (p=0.000 n=10)
HashKVs/BoolSliceLen2-8                  32.46n ±  23%    42.66n ±  46%  +31.41% (p=0.001 n=10)
HashKVs/BoolSliceLen3-8                  40.79n ± 124%    48.27n ±  12%  +18.34% (p=0.015 n=10)
HashKVs/BoolSliceLen5-8                  68.77n ± 393%    77.24n ±  31%        ~ (p=0.075 n=10)
HashKVs/IntNegative-8                    23.34n ± 327%    30.39n ±  10%  +30.21% (p=0.023 n=10)
HashKVs/IntZero-8                        23.55n ±  83%    31.37n ±  20%  +33.23% (p=0.019 n=10)
HashKVs/IntSliceLen5-8                   68.22n ±  40%    76.51n ±  53%        ~ (p=0.105 n=10)
HashKVs/IntSliceLen1-8                   23.47n ±  39%    40.83n ±  96%  +73.95% (p=0.001 n=10)
HashKVs/Int64One-8                       22.64n ± 411%    30.41n ± 158%        ~ (p=0.075 n=10)
HashKVs/Int64-8                          22.70n ± 555%    30.40n ± 120%        ~ (p=0.105 n=10)
HashKVs/Int64SliceLen4-8                 57.93n ± 418%    70.29n ±  83%        ~ (p=0.085 n=10)
HashKVs/Int64SliceWithZero-8             61.65n ± 403%    70.33n ±  70%        ~ (p=0.247 n=10)
HashKVs/Int64SliceLen0-8                 18.65n ± 433%    30.59n ± 150%        ~ (p=0.075 n=10)
HashKVs/Int64SliceLen2-8                 31.27n ± 442%    41.84n ±  76%        ~ (p=0.075 n=10)
HashKVs/Int64SliceLen3-8                 40.51n ± 477%    45.65n ± 162%        ~ (p=0.075 n=10)
HashKVs/Float64-8                        24.98n ± 442%    30.39n ±  16%        ~ (p=0.089 n=10)
HashKVs/Float64Large-8                   22.98n ± 383%    30.55n ±   4%        ~ (p=0.190 n=10)
HashKVs/Float64SliceLen4-8               60.29n ±  77%    68.38n ±   2%        ~ (p=0.315 n=10)
HashKVs/Float64SliceLarge-8              58.92n ±  12%    69.28n ±   7%  +17.58% (p=0.001 n=10)
HashKVs/Float64SliceLen0-8               18.13n ±  37%    30.12n ±   8%  +66.13% (p=0.001 n=10)
HashKVs/Float64SliceLen1-8               23.99n ±  35%    40.32n ±  12%  +68.09% (p=0.000 n=10)
HashKVs/Float64SliceLen2-8               29.87n ±  38%    42.12n ±   5%  +41.05% (p=0.000 n=10)
HashKVs/Float64SliceLen3-8               40.03n ±  13%    46.65n ±   6%  +16.54% (p=0.001 n=10)
HashKVs/StringFoo-8                      20.01n ±  18%    31.89n ±   4%  +59.33% (p=0.000 n=10)
HashKVs/StringBar-8                      20.74n ±  16%    32.03n ±   7%  +54.40% (p=0.000 n=10)
HashKVs/StringSliceLen0-8                18.00n ±  12%    29.91n ±   2%  +66.19% (p=0.000 n=10)
HashKVs/StringSliceLen2-8                30.09n ±   8%    52.82n ±  10%  +75.57% (p=0.001 n=10)
HashKVs/StringSliceLen3-8                32.15n ±  16%    62.69n ±  10%  +95.01% (p=0.000 n=10)
HashKVs/StringSliceLooksLikeIntSlice-8   22.61n ±  22%    43.05n ±   4%  +90.40% (p=0.000 n=10)
HashKVs/StringSliceLen5-8                55.27n ±  14%    98.06n ±  10%  +77.45% (p=0.000 n=10)
HashKVs/ByteSliceFoo-8                   20.46n ±  16%    32.02n ±   1%  +56.46% (p=0.000 n=10)
HashKVs/ByteSliceLooksLikeIntSlice-8     22.82n ±   7%    33.57n ±   1%  +47.08% (p=0.000 n=10)
HashKVs/SliceLen0-8                      17.80n ±   9%    29.88n ±   2%  +67.79% (p=0.000 n=10)
HashKVs/SliceLen1-8                      33.44n ±   6%    46.51n ±  20%  +39.08% (p=0.000 n=10)
HashKVs/SliceLen2-8                      47.87n ±  13%    56.25n ±  35%  +17.51% (p=0.000 n=10)
HashKVs/SliceLen3-8                      64.59n ±  14%    77.36n ±  32%  +19.77% (p=0.000 n=10)
HashKVs/SliceLen4-8                      79.74n ±   8%    89.37n ±  88%  +12.08% (p=0.000 n=10)
HashKVs/SliceLen5-8                      92.33n ±   5%   105.85n ±  33%  +14.64% (p=0.000 n=10)
HashKVs/SliceNested-8                    151.9n ±   6%    202.1n ±  49%  +33.00% (p=0.000 n=10)
HashKVs/MapLen0-8                        17.60n ±   5%    30.55n ±  32%  +73.58% (p=0.000 n=10)
HashKVs/MapLen2-8                        55.78n ±   5%    81.50n ±  44%  +46.11% (p=0.000 n=10)
HashKVs/MapNested-8                      132.8n ±   4%    185.1n ±  19%  +39.33% (p=0.000 n=10)
HashKVs/EmptyValue-8                     17.89n ±   5%    22.15n ±  12%  +23.81% (p=0.000 n=10)
HashValueSlice/Len2-8                    39.39n ±   5%    49.59n ±  47%  +25.88% (p=0.001 n=10)
HashValueSlice/Len5-8                    74.90n ±  17%    86.77n ±  23%  +15.83% (p=0.011 n=10)
HashValueSlice/Len8Nested-8              189.8n ±   9%    239.3n ±  25%  +26.14% (p=0.000 n=10)
HashValueMap/Len2-8                      46.45n ±  10%    67.03n ±  16%  +44.29% (p=0.000 n=10)
HashValueMap/Len5-8                      97.78n ±  14%   136.85n ±  20%  +39.95% (p=0.000 n=10)
HashValueMap/Len8Nested-8                251.8n ±   7%    351.9n ±  26%  +39.73% (p=0.000 n=10)
Hasher-8                                 56.06n ±  12%    77.30n ±  21%  +37.90% (p=0.000 n=10)
NewSet-8                                 282.2n ±  12%    348.7n ±  19%  +23.55% (p=0.000 n=10)
geomean                                  42.26n           58.56n         +38.58%

                                       │   main.txt   │               pr.txt                │

</details>

Diff: 650 lines (+487 / -163) across 8 files Reviewer: pellared Review duration: 2022m
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
0.52
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
42%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #9508"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 43.0% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 52% (MEDIUM) · Higher = larger blast radius
52%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 43.0% · Lower = rushed or shallow review
43.0%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 29.7% · Safe to merge
29.7%