Repository navigation
fix(profiling): keep fast-copy intent across faulthandler during warmup - #21230
gh-worker-dd-mergequeue-cf854d[bot] merged 11 commits into
Conversation
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.
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
There was a problem hiding this comment.
🟡 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
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 8075cdc | Docs | View more details | Give us feedback! |
BenchmarksBenchmark execution time: 2026-11-12 04:44:20 Comparing candidate commit 8075cdc in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 586 metrics, 9 unstable metrics, 1 flaky benchmarks without significant changes.
|
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.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit fd98a2a
There was a problem hiding this comment.
🔵 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
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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
left a comment
There was a problem hiding this comment.
This is complicated but it's good AFAICT.
|
This change is marked for backport to 4.17 and it does not conflict with that branch. |
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.
There was a problem hiding this comment.
💡 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".
…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>
…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)
…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)
…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


Description
Warmup clears
fast_copy_activewhile our SIGSEGV handler is still installed. Handler install/uninstall/reclaim keyed off that flag, sofaulthandler.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), usesfast_copy_handler_ops_enabled()for those handler ops, and publishesfast_copy_memory_desiredin internal metadata. It also pins the mid-warmup fork path: a child re-runs the warmup decision instead of inheritingfast_copy_active == falsefor life (gunicorn/celery prefork).Testing
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