[STF] Scope-guard batch 2: leak windows, wrong flavors, host-register UB #11224
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 296 lines diff across 3 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.341
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #11224"
general
weight: 0.35
andralex
Second PR of the scope-guard hardening campaign that began with #11187, from the same audit of all 148
SCOPEsites.Real defects
01-axpy-places.cuarmed one guard after two 256 MB allocations, so abad_allocfrom the second leaked the first. Now one guard per resource, each armed immediately.scalartest fixture instream_ctx.cuhfreed a buffer that was still registered viacudaHostRegisterwhenlogical_dataconstruction threw (freeing registered memory is undefined). A second guard declared after the registration unregisters before the earlier guard frees, relying on reverse-order execution.parallel_forleftnew args_towned by nobody across calls that can throw. Rather than guard each window, the tuple is now held by aunique_ptrandrelease()d at each ownership handoff — to the ctx resource on the graph path, to the host callback on the stream path.This also closes a leak the guard formulation left open. The graph path set its
args_adoptedflag beforectx.add_resource(), so a throw fromadd_resource()skipped the delete. That leaks rather than double-frees, becauseparallel_for_args_resourcefreesargsonly when its callback runs — its destructor does not — so a resource that never reaches the context never frees anything. Releasing only afteradd_resource()returns covers both throw sites, with no flag and no guard.Wrong flavors, now that a throwing guard body aborts with a report rather than terminating silently (#11187):
SCOPE(exit).finalize()submits pending work and synchronizes, which is neither meaningful nor safe on a context being torn down by an exception.Rebased onto #11226. The
cfd.cuandpretty_print.cuhfixes from the original version of this PR are gone from the diff: they split a checkedfcloseinto aSCOPE(success)/SCOPE(fail)pair, and #11226 has since collapsed that same pair into a singleSCOPE(exit, failing). Main's version supersedes them.Not changed, deliberately: the device-restore guards in the places layer (
cudaSetDevice(prev_dev)and the primary-context release). After #11187 a failure there aborts with a report, which is the right outcome, since continuing would run subsequent work on the wrong device.🤖 Generated with Claude Code