Skip to content

fix(profiling): keep fast-copy intent across faulthandler during warmup - #21230

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 11 commits into
mainfrom
vlad/fastcopy-1-warmup-faulthandler
Nov 12, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 11 commits into
mainfrom
vlad/fastcopy-1-warmup-faulthandler

Conversation

@vlad-scherbich

@vlad-scherbich vlad-scherbich commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Warmup clears fast_copy_active while our SIGSEGV handler is still installed. Handler install/uninstall/reclaim keyed off that flag, so faulthandler.enable() in the window took the handler unnoticed and the warmup deadline pinned the process to the syscall copy for life.

This PR adds persistent fast_copy_desired (untouched by warmup), uses fast_copy_handler_ops_enabled() for those handler ops, and publishes fast_copy_memory_desired in internal metadata. It also pins the mid-warmup fork path: a child re-runs the warmup decision instead of inheriting fast_copy_active == false for life (gunicorn/celery prefork).

Testing

  • new unit tests (faulthandler during warmup; fork during warmup)

Risks

None.

Additional Notes

Stack: 1/3 (includes mid-warmup fork pin). Next: sticky foreign takeover (#21232).

https://datadoghq.atlassian.net/browse/PROF-15995

Pre-review checklist

  • The changes have been tested in real services in staging
  • The PR does not result in new crashes

Warmup clears fast_copy_active while our SIGSEGV handler is still installed.
Handler ops keyed off that flag, so faulthandler.enable() in the window took
the handler unnoticed and the warmup deadline pinned syscall copy for life.

Add persistent fast_copy_desired and gate install/uninstall/reclaim on
fast_copy_handler_ops_enabled(). Publish desired in internal metadata.
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/internal/datadog/profiling/dd_wrapper/include/profiler_stats.hpp  @DataDog/profiling-python
ddtrace/internal/datadog/profiling/dd_wrapper/src/profiler_stats.cpp    @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/echion/echion/vm.h             @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/echion/vm.cc               @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/sampler.cpp                @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/stack.cpp                  @DataDog/profiling-python
releasenotes/notes/profiling-fast-copy-mid-warmup-fork-15886547dcf91a47.yaml  @DataDog/apm-python
releasenotes/notes/profiling-fast-copy-warmup-faulthandler-3f1c8a4d92b7e05a.yaml  @DataDog/apm-python
tests/profiling/collector/test_copy_memory_stats.py                     @DataDog/profiling-python
tests/profiling/collector/test_utils.py                                 @DataDog/profiling-python

@vlad-scherbich
vlad-scherbich requested a balanced review from Copilot October 23, 2026 18:18
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 77 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 77 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=120)
ddtrace.llmobs._telemetry -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)
ddtrace.llmobs._integrations.typesafe -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)
ddtrace.llmobs._integrations.vllm -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)
ddtrace.llmobs._utils -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=118)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unimplemented metadata assertions and regressions in foreign-handler reclamation and copy-strategy recovery remain unresolved.

3 open issues
What changed in this PR

This PR separates fast-copy intent from its active state so the stack profiler can coordinate with faulthandler during startup warmup and later resume fast memory copying.

Changes:

  • Adds persistent fast-copy intent and uses it to gate signal-handler operations.
  • Exposes desired-state metadata and adjusts startup and failure handling.
  • Adds a warmup regression test, polling helper, and release note.
File Description
tests/​profiling/​collector/​test_utils.py Adds fast-copy state polling.
tests/​profiling/​collector/​test_copy_memory_stats.py Adds metadata assertions and warmup regression coverage.
releasenotes/​notes/​profiling-fast-copy-warmup-fork-3f1c8a4d92b7e05a.yaml Documents the warmup fix.
ddtrace/​internal/​datadog/​profiling/​stack/​src/​stack.cpp Updates handler gating, runtime intent, and metadata seeding.
ddtrace/​internal/​datadog/​profiling/​stack/​src/​sampler.cpp Updates warmup decisions and startup failure handling.
ddtrace/​internal/​datadog/​profiling/​stack/​src/​echion/​vm.cc Initializes persistent fast-copy intent.
ddtrace/​internal/​datadog/​profiling/​stack/​echion/​echion/​vm.h Defines intent state and handler-operation gating.
ddtrace/​internal/​datadog/​profiling/​dd_wrapper/​src/​profiler_stats.cpp Copies and serializes desired-state metadata.
ddtrace/​internal/​datadog/​profiling/​dd_wrapper/​include/​profiler_stats.hpp Declares desired-state metadata storage and accessors.

Review effort: Balanced

@datadog-official

datadog-official Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 8075cdc | Docs | View more details | Give us feedback!

@pr-commenter

pr-commenter Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-12 04:44:20

Comparing candidate commit 8075cdc in PR branch vlad/fastcopy-1-warmup-faulthandler with baseline commit feebb4b in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 586 metrics, 9 unstable metrics, 1 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-679.228ns; +728.059ns] or [-6.312%; +6.766%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1879.521ns; +1797.587ns] or [-9.348%; +8.940%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1800.569ns; +1751.482ns] or [-9.306%; +9.052%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-392.163ns; +321.551ns] or [-8.940%; +7.330%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-205.448ns; +228.833ns] or [-7.570%; +8.431%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-90.292ns; +89.632ns] or [-6.039%; +5.995%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4554.219ns; +4857.009ns] or [-8.928%; +9.522%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1070.176ns; +854.494ns] or [-9.876%; +7.886%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-65.024µs; +47.456µs] or [-11.052%; +8.066%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:packagespackageforrootmodulemapping-cache_off

Keep faulthandler reclaim during warmup, but stop reclaiming after a
latched syscall fallback so foreign handlers stay untouched. Clear
failed_safe_copy on successful strategy switches so start() can recover,
drop foreign_takeover metadata asserts until that field lands, and fix
clang-format blanks that failed prechecks.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Native signal-handler lifecycle changes need human review supported by platform-specific runtime validation unavailable in this review.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Native signal-handler ownership and platform-specific recovery transitions require runtime regression results and final human review.

No open issues 🎉

Review effort: Balanced

@vlad-scherbich

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T04:25:21.858149Z 8075cdc New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 90c4902bfb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@vlad-scherbich
vlad-scherbich requested a balanced review from Copilot October 23, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Native signal-handler ownership and fallback lifecycle changes need human review supported by platform-specific regression results.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

An unresolved foreign-handler reclamation path and safety-sensitive native lifecycle changes require correction and human validation.

1 open issue

Review effort: Balanced

@vlad-scherbich
vlad-scherbich requested a review from a team October 28, 2026 12:18

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Persistent fast-copy intent supports faulthandler handler recovery during warmup, while the fallback latch blocks desired-only reclamation afterward. The completed static review returned no reportable findings.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit fd98a2a

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Source-only review could not establish crash safety for native signal-handler coordination and Linux copy-failure recovery, which require release-wheel runtime validation covering warmup, handler swaps, fork, and unavailable syscalls.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@KowalskiThomas KowalskiThomas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall no strong concerns, but the code is really hard to understand (not your fault, it's just... really complicated, this part of the codebase)

So I have a few questions about naming etc. I should also make some kind of state machine about that when I get a chance.

Match Sticky: field language for syscall fallback, and keep Desired as
reclaim intent that survives warmup rather than a user-wants framing.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ab1b8b8eb9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@KowalskiThomas KowalskiThomas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is complicated but it's good AFAICT.

@github-actions

Copy link
Copy Markdown
Contributor

This change is marked for backport to 4.17 and it does not conflict with that branch.
The command used to test backporting was

git fetch origin 4.17 && git checkout origin/4.17 && git checkout -b backport-21230-to-4.17 && git cherry-pick -x --mainline 1 645a4d6fcef9aae9d4d6d1e344d938dc659b4d9d

A child forked during warmup inherited fast_copy_active == false and never
upgraded. Prefork workers hit this window. Pin the child upgrade path; the
desired-flag mechanism is already on the base branch.
Keep the faulthandler note on the base PR file; claim only the fork delta here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8075cdc9aa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit c1198df into main Nov 12, 2026
546 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the vlad/fastcopy-1-warmup-faulthandler branch November 12, 2026 17:07
github-actions Bot added a commit that referenced this pull request Nov 12, 2026
…up (#21230)

## Description

Warmup clears `fast_copy_active` while our SIGSEGV handler is still installed. Handler install/uninstall/reclaim keyed off that flag, so `faulthandler.enable()` in the window took the handler unnoticed and the warmup deadline pinned the process to the syscall copy for life.

This PR adds persistent `fast_copy_desired` (untouched by warmup), uses `fast_copy_handler_ops_enabled()` for those handler ops, and publishes `fast_copy_memory_desired` in internal metadata. It also pins the mid-warmup fork path: a child re-runs the warmup decision instead of inheriting `fast_copy_active == false` for life (gunicorn/celery prefork).

## Testing

* new unit tests (faulthandler during warmup; fork during warmup)

## Risks

None.

## Additional Notes

Stack: **1/3** (includes mid-warmup fork pin). Next: sticky foreign takeover (#21232).

https://datadoghq.atlassian.net/browse/PROF-15995

## Pre-review checklist

- [ ] The changes have been tested in real services in staging
- [ ] The PR does not result in new crashes

Co-authored-by: vlad.scherbich <vlad.scherbich@datadoghq.com>
(cherry picked from commit c1198df)

Co-authored-by: Vlad Scherbich <vlad.scherbich@datadoghq.com>
taegyunkim pushed a commit that referenced this pull request Nov 12, 2026
…up [backport 4.17] (#21723)

Backport #21230 to 4.17

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Vlad Scherbich <vlad.scherbich@datadoghq.com>
vlad-scherbich added a commit that referenced this pull request Nov 16, 2026
…up (#21230)

Warmup clears `fast_copy_active` while our SIGSEGV handler is still installed. Handler install/uninstall/reclaim keyed off that flag, so `faulthandler.enable()` in the window took the handler unnoticed and the warmup deadline pinned the process to the syscall copy for life.

This PR adds persistent `fast_copy_desired` (untouched by warmup), uses `fast_copy_handler_ops_enabled()` for those handler ops, and publishes `fast_copy_memory_desired` in internal metadata. It also pins the mid-warmup fork path: a child re-runs the warmup decision instead of inheriting `fast_copy_active == false` for life (gunicorn/celery prefork).

* new unit tests (faulthandler during warmup; fork during warmup)

None.

Stack: **1/3** (includes mid-warmup fork pin). Next: sticky foreign takeover (#21232).

https://datadoghq.atlassian.net/browse/PROF-15995

- [ ] The changes have been tested in real services in staging
- [ ] The PR does not result in new crashes

Co-authored-by: vlad.scherbich <vlad.scherbich@datadoghq.com>
(cherry picked from commit c1198df)
vlad-scherbich added a commit that referenced this pull request Nov 16, 2026
…up (#21230)

Warmup clears `fast_copy_active` while our SIGSEGV handler is still installed. Handler install/uninstall/reclaim keyed off that flag, so `faulthandler.enable()` in the window took the handler unnoticed and the warmup deadline pinned the process to the syscall copy for life.

This PR adds persistent `fast_copy_desired` (untouched by warmup), uses `fast_copy_handler_ops_enabled()` for those handler ops, and publishes `fast_copy_memory_desired` in internal metadata. It also pins the mid-warmup fork path: a child re-runs the warmup decision instead of inheriting `fast_copy_active == false` for life (gunicorn/celery prefork).

* new unit tests (faulthandler during warmup; fork during warmup)

None.

Stack: **1/3** (includes mid-warmup fork pin). Next: sticky foreign takeover (#21232).

https://datadoghq.atlassian.net/browse/PROF-15995

- [ ] The changes have been tested in real services in staging
- [ ] The PR does not result in new crashes

Co-authored-by: vlad.scherbich <vlad.scherbich@datadoghq.com>
(cherry picked from commit c1198df)
vlad-scherbich added a commit that referenced this pull request Nov 21, 2026
…up [backport 4.15] (#21240)

## Description

Backport of #21230 to 4.15 (same squash as #21723).

Cherry-pick `c1198df465`. Conflict in `sampler.cpp`: kept 4.15's
foreign-handler log lines (no ownership APIs on this branch); took PR1's
`seed_fast_copy_profiler_stats()` + `sampler_active_.store(false)` on
the no-fallback stop path.

## Testing

Unit tests from source for faulthandler-during-warmup and mid-warmup
fork.

## Risks

Same as #21230 / #21723.

## Additional Notes

Manual rewrite onto current `4.15` after the automated/draft tip went
DIRTY.

## Pre-review checklist

- [ ] The changes have been tested in real services in staging
- [ ] The PR does not result in new crashes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants