Skip to content

Use the fully correct delegation pattern for the Process.spawn monkey patch#5791

Merged
eregon merged 5 commits into
masterfrom
fully-correct-delegation-spawn
May 21, 2026
Merged

Use the fully correct delegation pattern for the Process.spawn monkey patch#5791
eregon merged 5 commits into
masterfrom
fully-correct-delegation-spawn

Conversation

@eregon

@eregon eregon commented May 20, 2026

Copy link
Copy Markdown
Member
  • RSpec mock expectations check this properly, example failures with incorrect delegation:
  On 4.0 when delegating with just (*args)
  expected: ({"DD_LINEAGE_PROBE" => "lineage-value-zzz"}, ["echo", "test"], {2 => 1, out: "/dev/null"}) (keyword arguments)
       got: ({"DD_LINEAGE_PROBE" => "lineage-value-zzz"}, ["echo", "test"], {2 => 1, out: "/dev/null"}) (options hash)
  On 2.7 when delegating with just (*args) and no ruby2_keywords:
  expected: ({"DD_LINEAGE_PROBE"=>"lineage-value-zzz"}, ["echo", "test"], {2=>1, :out=>"/dev/null"})
       got: ({"DD_LINEAGE_PROBE"=>"lineage-value-zzz"}, ["echo", "test"], {2=>1}, {:out=>"/dev/null"})

On top of #5790 because it needs that fix to test properly.

What does this PR do?
Use the fully correct delegation pattern for the Process.spawn monkey patch

Motivation:
Correctness even if someone else monkey patches Process.spawn and they expect to receive keyword arguments if the original caller passed some.

Change log entry

None

Additional Notes:

The good old way (no AI)

How to test the change?

Test added.

@eregon
eregon requested a review from a team as a code owner May 20, 2026 12:05
@dd-octo-sts dd-octo-sts Bot added the core Involves Datadog core libraries label May 20, 2026
@dd-octo-sts

dd-octo-sts Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Typing analysis

Note: Ignored files are excluded from the next sections.

steep:ignore comments

This PR introduces 1 steep:ignore comment.

steep:ignore comments (+1-0)Introduced:
lib/datadog/core/utils/spawn_monkey_patch.rb:23

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented May 20, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 55.26%
Overall Coverage: 97.07% (-0.03%)

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

@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: 65248d7d77

ℹ️ 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".

Comment thread spec/support/synchronization_helpers.rb
@eregon
eregon force-pushed the fully-correct-delegation-spawn branch from b6b5671 to 888f37d Compare May 20, 2026 12:13
@ivoanjo
ivoanjo enabled auto-merge May 20, 2026 15:54
@ivoanjo
ivoanjo disabled auto-merge May 20, 2026 15:54
@eregon

eregon commented May 20, 2026

Copy link
Copy Markdown
Member Author

Let's merge #5790 first to have a clearer history (and possibly rebase after)

Comment thread lib/datadog/core/utils/spawn_monkey_patch.rb
eregon and others added 5 commits May 21, 2026 11:26
* Before this, all mock expectations would be ignored,
  since they are checked after the `after` hooks run,
  but the fork only ran the passed block and stopped before any `after` hook.
* RSpec::Mocks.with_temporary_scope creates a separate scope
  so only child process mock expectations are checked there.
  RSpec::Mocks.with_temporary_scope does the same RSpec::Mocks.verify after calling the block.
* We cannot confuse the last Hash with the env Hash as there is always a command to run in between.
* The check was somewhat brittle as it assumed specific types for the keys.
… patch

* RSpec mock expectations check this properly, example failures with incorrect delegation:
  On 4.0 when delegating with just (*args)
  expected: ({"DD_LINEAGE_PROBE" => "lineage-value-zzz"}, ["echo", "test"], {2 => 1, out: "/dev/null"}) (keyword arguments)
       got: ({"DD_LINEAGE_PROBE" => "lineage-value-zzz"}, ["echo", "test"], {2 => 1, out: "/dev/null"}) (options hash)
  On 2.7 when delegating with just (*args) and no ruby2_keywords:
  expected: ({"DD_LINEAGE_PROBE"=>"lineage-value-zzz"}, ["echo", "test"], {2=>1, :out=>"/dev/null"})
       got: ({"DD_LINEAGE_PROBE"=>"lineage-value-zzz"}, ["echo", "test"], {2=>1}, {:out=>"/dev/null"})
@eregon
eregon force-pushed the fully-correct-delegation-spawn branch from d117d8d to 0e7fd56 Compare May 21, 2026 09:27
@pr-commenter

pr-commenter Bot commented May 21, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-05-21 09:53:07

Comparing candidate commit 0e7fd56 in PR branch fully-correct-delegation-spawn with baseline commit 50fc341 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 ----------------------------------'

@eregon
eregon merged commit 8babdc4 into master May 21, 2026
593 checks passed
@eregon
eregon deleted the fully-correct-delegation-spawn branch May 21, 2026 10:02
@dd-octo-sts dd-octo-sts Bot added this to the 2.34.0 milestone May 21, 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.

5 participants