Bound adaptive Gauss-Kronrod recursion and work #2958
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 603 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.383
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2958"
general
weight: 0.35
Jackmeson1
GaussKronrodAdaptivecan recurse until the stack overflows. One96579fd4, when the error estimate of an intervalmisses the tolerance,
integrateRecursivelysplits the interval and halves the tolerance, with no check that the splitstill advances or that the halved tolerance is still representable, and no bound on the recursion depth. The default
evaluation limit is
Null<Size>(), a very large finite cap that does not prevent these deep-recursion failures.Standalone reproduction I ran on Linux with gcc 13.3 (not part of this PR), each case in a child process:
| Call |
e96579fd4| This PR ||---|---|---|
|
GaussKronrodAdaptive(1e-10),1e5exp(x)on [0, 1] | segmentation fault | throws "maximum subdivision depth exceeded" after 3855 evaluations ||
GaussKronrodAdaptive(1e-12),100cos(x)on [0, 10] | segmentation fault | the same ||
GaussKronrodAdaptive(1e-15),exp(x)on [0, 1] | segmentation fault | the same ||
GaussKronrodAdaptive(1e-10, 10000),1e5exp(x)on [0, 1] | throws "maximum number of function evaluations exceeded" after 9975 evaluations | throws "maximum subdivision depth exceeded" after 3855 evaluations ||
GaussKronrodAdaptive(1e-8, 100),x == 0.5 ? 1e8 : 0on [0, 1] | returns 0 after 45 evaluations | the same |The last row is a control: the first estimate samples the spike, but after one split neither half samples it.
This PR keeps the existing acceptance test and adds checks before further subdivision, together with limits on
recursion and work:
maxFunctionEvaluationspassed to theconstructor now means a budget of 1000000 evaluations (documented on the constructor;
setMaxEvaluationsisunchanged).
The quadrature formula and the acceptance comparison are unchanged. The new depth and work limits can reject requests
that previously returned a value. Which check fires first can differ between platforms: on Windows with MSVC 19.41
the first three calls above stop at the subdivision-progress check after 795 to 810 evaluations.
Tests. In
test-suite/integrals.cpp, next totestGaussKronrodAdaptive:testGaussKronrodAdaptiveUnattainableAccuracy: the first three calls above throwErrorwithin 10000 evaluations.testGaussKronrodAdaptiveAttainableAccuracy: the spike control (exactly 0 after 45 evaluations);1e5(e − 1)and100*sin(10)to 1e-8 and 1e-9, and a reversed interval; an explicit 15-evaluation limit that still throws theevaluation-limit error.
testGaussKronrodAdaptiveEvaluationBudget: an integrator constructed with the default evaluation limit reportsmaxEvaluations() == 1000000; with a budget of 60, an integrand whose halves both need subdivision is called exactly60 times before the error;
setMaxEvaluations(Null<Size>())still stores the sentinel.testGaussKronrodAdaptiveNoSubdivisionProgress: an interval between adjacent representable values, checking anexact zero result, a constant integral within a roundoff tolerance, and the subdivision error when refinement is
needed.
testGaussKronrodAdaptiveLimits: the depth, tolerance-underflow and default evaluation-limit errors.From a configured and built Linux CMake build directory, run:
With the new tests added to the unchanged
e96579fd4library (Windows, MSVC 19.41),UnattainableAccuracyandLimitsabort with a stack overflow on their first integration.
NoSubdivisionProgressaborts on its third integration, afterthe zero and constant controls pass.
EvaluationBudgetfails (maxEvaluations()is 2147483647, and the integrand iscalled 75 times);
AttainableAccuracypasses there, as a control. All five pass with the fix.I also ran
IntegralTests,CmsTests,CmsNormalTests,LiborMarketModelTests,LiborMarketModelProcessTestsandHestonModelTests, which pass on Windows with MSVC 19.41 (C++17) and on Linux with gcc 13.3, Boost 1.83, Release andQL_COMPILE_WARNING_AS_ERROR=ON(no warnings). Library callers include the conundrum pricer, the legacy LMMcovariance implementations, and
FourierIntegration::gaussKronrod, which is available to Heston-family engines. TheHeston tests exercise its Gatheral and Andersen–Piterbarg paths.
AI disclosure: this was prepared with AI assistance (Claude Code and OpenAI Codex).
🤖 Generated with Claude Code