Skip to content

Fix process spawn#5634

Merged
mabdinur merged 10 commits into
masterfrom
marco/issue-5621-process-spawn
May 19, 2026
Merged

Fix process spawn#5634
mabdinur merged 10 commits into
masterfrom
marco/issue-5621-process-spawn

Conversation

@marcotc

@marcotc marcotc commented Apr 23, 2026

Copy link
Copy Markdown
Member

Fixes #5621

What does this PR do?

  • Fixes SpawnMonkeyPatch: one-time prepend, super(*inject_envs(args)), merge env_provider when first arg is a Hash, otherwise prepend provider env only (correct MRI inheritance and unsetenv_others).
  • Uses ::Hash === with a short note ([BUG]: datadog-2.31.0 monkey-patches Process.spawn and interferes with Ferrum #5621 shadowing); adds/keeps regression specs (fork shapes, env output parsing, unsetenv_others).
  • Renames kwarg to env_provider; RBS apply!void. Branch includes latest master spawn regression coverage.

Motivation

2.31.0’s Process.spawn patch broke real callers (e.g. Ferrum) and mishandled some MRI env/option cases; we need safe forwarding and no fake full-ENV when unsetenv_others applies.

Change log entry

Yes. Fix Process.spawn monkey patch for MRI-correct env merging (incl. Ferrum-style calls) and unsetenv_others without injecting a synthetic full ENV.

Additional Notes:

How to test the change?

bundle exec rspec spec/datadog/core/utils/spawn_monkey_patch_spec.rb
bundle exec rake "steep:check[lib/datadog/core/utils/spawn_monkey_patch.rb,sig/datadog/core/utils/spawn_monkey_patch.rbs]"

@dd-octo-sts

dd-octo-sts Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Thank you for updating Change log entry section 👏

Visited at: 2026-05-19 16:16:57 UTC

@dd-octo-sts dd-octo-sts Bot added the core Involves Datadog core libraries label Apr 23, 2026
@marcotc marcotc changed the title Marco/issue 5621 process spawn Fix process spawn Apr 23, 2026
@dd-octo-sts

dd-octo-sts Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Typing analysis

Note: Ignored files are excluded from the next sections.

Untyped methods

This PR introduces 1 untyped method and 1 partially typed method, and clears 1 untyped method and 1 partially typed method.

Untyped methods (+1-1)Introduced:
sig/datadog/core/utils/spawn_monkey_patch.rbs:11
└── def spawn: (*untyped args) -> untyped
Cleared:
sig/datadog/core/utils/spawn_monkey_patch.rbs:11
└── def spawn: (*untyped args, **untyped opts) -> untyped
Partially typed methods (+1-1)Introduced:
sig/datadog/core/utils/spawn_monkey_patch.rbs:14
└── def self.inject_envs: (untyped args) -> ::Array[untyped]
Cleared:
sig/datadog/core/utils/spawn_monkey_patch.rbs:14
└── def self.inject_lineage_envs: (untyped args) -> ::Array[untyped]

If you believe a method or an attribute is rightfully untyped or partially typed, you can add # untyped:accept on the line before the definition to remove it from the stats.

Comment thread sig/datadog/core/utils/spawn_monkey_patch.rbs Outdated

@mabdinur mabdinur 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.

Thanks for opening this PR 😄.

Can we update the PR and add a changelog? Also we need to address some failing tests. I'd love to get this fix out as soon as possible

Comment thread lib/datadog/core/utils/spawn_monkey_patch.rb Outdated
Comment thread spec/datadog/core/utils/spawn_monkey_patch_spec.rb Outdated
@ivoanjo

ivoanjo commented May 6, 2026

Copy link
Copy Markdown
Member

Hey @mabdinur @marcotc since this is still an active regression, what's missing to land this?

Comment thread lib/datadog/core/utils/spawn_monkey_patch.rb

@eregon eregon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The 3 fixes look good (::Hash, no kwargs splitting, not setting extra env vars if user passes unsetenv_others: true).
It's a little bit harder to review because of the rename, that's not ideal for a bug fix PR but not too bad.
From my side I think this is good to go besides adding a test for the unsetenv_others: true since that is a fix that seems not covered with tests currently.

Comment thread lib/datadog/core/utils/spawn_monkey_patch.rb
mabdinur and others added 3 commits May 19, 2026 12:13
Retain branch Process.spawn refactor (inject_envs, env_provider) and fold in
master issue #5621 ::Hash clarification as documentation on inject_envs.

Co-authored-by: Cursor <[email protected]>
…ers test

Addresses PR review (filter_map for /usr/bin/env parsing, unsetenv_others coverage,
apply! typed as void).

Co-authored-by: Cursor <[email protected]>
origin/master added fork regression cases with lineage_envs_provider; align with
SpawnMonkeyPatch.apply!(env_provider:) and refresh the comment.

Co-authored-by: Cursor <[email protected]>
@mabdinur
mabdinur marked this pull request as ready for review May 19, 2026 16:23
@mabdinur
mabdinur requested a review from a team as a code owner May 19, 2026 16:23
@datadog-official

datadog-official Bot commented May 19, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 88.24%
Overall Coverage: 97.09% (-0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c7adf84 | Docs | Datadog PR Page | Give us feedback!

@pr-commenter

pr-commenter Bot commented May 19, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-05-19 16:40:39

Comparing candidate commit c7adf84 in PR branch marco/issue-5621-process-spawn with baseline commit f0cfa4f in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 46 metrics, 0 unstable metrics.

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 ----------------------------------'

Comment thread lib/datadog/core/utils/spawn_monkey_patch.rb
@mabdinur
mabdinur merged commit fb5da24 into master May 19, 2026
589 checks passed
@mabdinur
mabdinur deleted the marco/issue-5621-process-spawn branch May 19, 2026 18:37
@dd-octo-sts dd-octo-sts Bot added this to the 2.34.0 milestone May 19, 2026
eregon added a commit that referenced this pull request May 20, 2026
…s-test

Add mixed Symbol + Integer keys regression test for #5634
@Strech Strech mentioned this pull request May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Involves Datadog core libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: datadog-2.31.0 monkey-patches Process.spawn and interferes with Ferrum

6 participants