← Back to Pull requests

fix(profiling): leave out partial asyncio task stacks read during a task switch #22272

Open
unknown opened this pull request with 197 lines diff across 2 files
View on GitHub
unknown unknown commented on Dec 01, 2026 23:47 UTC
Author

Description

Fixes the flaky test_deep_suspended_task_keeps_innermost_frames.

The sampler reads a task's coroutine chain, then its frames. If the task resumes or finishes in between, some frames are already cleared. TaskInfo::unwind stopped at the first unreadable frame but kept the frames read before it, which got stitched onto the event loop frames.

  • TaskInfo::unwind now leaves out all of a task's coroutine frames when one can't be read. The sample keeps its wall time.

  • The test skips samples with no frames, which happen when the thread stack read also fails in that tick. It still checks every non-empty sample.

  • Adds native tests.
  • Customer impact

    A task sample taken while the task resumes or finishes no longer shows a truncated coroutine stack under the event loop frames.

    Testing

    CPython 3.14, env b0d11c843434, 4 parallel loops of 400 runs, DD_TEST_CPUS=0.5, host under load:

  • Before: 8 failures in 4,800 runs (7 empty samples, 1 truncated stack; 2 of 3 batches had debug logging).

  • After: 0 failures in 3,200 runs. Under the same load, the old test still failed 1 in 1,600 with only the native fix.

  • The new native test fails without the fix and passes with it on 3.9, 3.12 and 3.14.

  • Asyncio profiling tests pass on 3.9, 3.12, 3.14 and 3.15.
  • Risks

    If a frame stays unreadable, that task's samples lose all coroutine frames. No benchmark covers stack unwinding and only the failure path changed.

    Additional Notes

    test_suspended_task_does_not_inherit_running_sibling_frames has a different cause, addressed by #22037.

    Diff: 197 lines (+147 / -50) across 2 files Reviewer: gyuheon0h Review duration: 5457m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.36) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 197 lines diff across 2 files
    0.36
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.316
    Real PR Conversation Timeline
    1 comments
    "Review active on #22272"
    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: 36.1% (MEDIUM) · Higher = larger blast radius
    36.1%
    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: 20.6% · Safe to merge
    20.6%