← Back to Pull requests

chore(profiling): require on-CPU frame state when matching running asyncio task #22107

Closed
unknown closed this pull request without merging on Nov 25, 2026 23:42 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 21:03 UTC
Author

Description

On Python 3.14+, ThreadInfo::unwind_tasks reads asyncio_running_task before snapshotting tasks with get_all_tasks. If the running task suspends in between (or is between coro.send() returning and leave_task()), its coroutine snapshot is already suspended (is_on_cpu == false). Matching origin == running_task without checking is_on_cpu skipped stitching python_stack yet still charged the tick's CPU time to the task's suspended stack.

Now the 3.14+ branch also requires is_on_cpu, so a suspended snapshot falls through to the CPU-only thread sample with python_stack intact.

This also widens task_outside_burn in test_asyncio_cpu_time.py by 20 ms (two 10 ms ticks) so legitimate boundary ticks outside burn do not flake test_asyncio_cpu_time_taskgroup.

Customer impact

None beyond unreleased #22050, which already carries the release note for asyncio CPU time attribution.

Testing

  • Added ThreadInfoTaskTraversalTest.SuspendedRunningTaskDoesNotClaimCpuTime (fails without the threads.cc change, passes with it).

  • Native stack CTest on Python 3.15: 91/91 passed.

  • Python 3.15 + uvloop (df5925a36345): 14/14 asyncio profiler tests passed; across 60 repeated runs of taskgroup and gather, asyncio.sleep CPU misattributions dropped from 12/90 to 0/60.

  • scripts/lint checks, typing, and profiling-native-check passed.
  • Risks

    None. When a task suspends mid-snapshot, CPU time goes to a CPU-only thread sample holding python_stack.

    Additional Notes

    Follow-up to #22050.

    Diff: 194 lines (+145 / -49) across 2 files Reviewer: gyuheon0h Review duration: 159m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 194 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.315
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #22107"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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% (MEDIUM) · Higher = larger blast radius
    36%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 14.2% · Safe to merge
    14.2%