Skip to content

Add DI condition/template evaluation wall-time timeout (RFC C4) - #6223

Draft
p-datadog wants to merge 3 commits into
masterfrom
di-eval-timeout
Draft

Add DI condition/template evaluation wall-time timeout (RFC C4)#6223
p-datadog wants to merge 3 commits into
masterfrom
di-eval-timeout

Conversation

@p-datadog

@p-datadog p-datadog commented Aug 20, 2026

Copy link
Copy Markdown
Member

Implements backlog item eval-timeout (DEBUG-6078). RFC area: C4 (condition/template evaluation wall-time timeout). Design: design/eval-timeout.md in p-datadog/claude-projects.

What

Bounds condition (when) and template-segment evaluation wall-time. When the budget is exhausted mid-evaluation, the evaluation is aborted and surfaced as an evaluation-error snapshot with no captured user data — the same shape a runtime condition error already produces — so a pathological expression (ReDoS regex, huge collection filter) cannot stall the instrumented method or leak a fully-captured snapshot.

How

  • New setting max_time_to_evaluate_ms (env DD_DYNAMIC_INSTRUMENTATION_EVALUATION_TIMEOUT_MS, default 50 ms — RFC upper bound, conservative).
  • Cooperative deadline check in Evaluator#filter/#all/#any every 64 items, raising a new DI::Error::EvaluationTimeout (subclass of ExpressionEvaluationError so the existing condition-eval-failed callback produces the error snapshot with no captures).
  • The deadline lives on the per-invocation Context#deadline_ns (avoids racing the shared Evaluator instance across threads). Resolved before condition eval in both instrumenter hit paths and before template eval in ProbeNotificationBuilder.
  • EvaluationTimeout increments a dynamic_instrumentation.evaluation_timeouts telemetry counter and logs at debug.

Non-goals / follow-ups

  • The pre-existing per-matches regex bound (MATCHES_TIMEOUT_SECONDS = 0.5, 500 ms) is left unchanged: regex backtracking runs in the C regexp engine and cannot be cooperatively interrupted, so lowering it 10–50× is a customer-visible regression on legitimate regex conditions. It exceeds the RFC 10–50 ms evaluation range; aligning it is deferred.
  • Global DI time budget (RFC C9), canonical guardrail telemetry (RFC Appendix B) — design-phase, absent in every tracer.

Tests

Local (Ruby 3.3.12): evaluator, instrumenter, probe_notification_builder, capture_expression_evaluator, instrumenter_circuit_breaker, serializer, probe specs — 373 examples, 0 failures. standard/steep deferred to PR CI.

System test Test_Debugger_Evaluation_Timeout_Line_Probe (DataDog/system-tests#7287) is missing_feature until the Ruby weblog gains the /debugger/expression/strings and /debugger/snapshot/limits fixtures and line mappings and the manifest is flipped (separate system-tests work).

@dd-octo-sts

dd-octo-sts Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

👋 Hey @DataDog/ruby-guild, please fill "Change log entry" section in the pull request description.

If changes need to be present in CHANGELOG.md you can state it this way

**Change log entry**

Yes. A brief summary to be placed into the CHANGELOG.md

(possible answers Yes/Yep/Yeah)

Or you can opt out like that

**Change log entry**

None.

(possible answers No/Nope/None)

Visited at: 2026-08-20 22:24:44 UTC

@dd-octo-sts dd-octo-sts Bot added the debugger Live Debugger (+Dynamic Instrumentation, +Symbol Database) label Aug 20, 2026
@dd-octo-sts

dd-octo-sts Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Typing analysis

Note: Ignored files are excluded from the next sections.

Untyped methods

This PR introduces 1 partially typed method, and clears 1 partially typed method. It increases the percentage of typed methods from 70.06% to 70.09% (+0.03%).

Partially typed methods (+1-1)Introduced:
sig/datadog/di/context.rbs:31
└── def initialize: (probe: Probe, settings: Datadog::Core::Configuration::Settings, serializer: Serializer, ?locals: Hash[Symbol, untyped]?, ?target_self: Object?, ?path: String?, ?caller_locations: Array[Thread::Backtrace::Location]?, ?serialized_entry_args: Hash[Symbol, untyped]?, ?entry_capture_expressions: Hash[String, untyped]?, ?entry_capture_evaluation_errors: Array[Hash[Symbol, String]]?, ?return_value: Object?, ?duration: Float?, ?exception: Exception?, ?deadline_ns: Integer?) -> void
Cleared:
sig/datadog/di/context.rbs:29
└── def initialize: (probe: Probe, settings: Datadog::Core::Configuration::Settings, serializer: Serializer, ?locals: Hash[Symbol, untyped]?, ?target_self: Object?, ?path: String?, ?caller_locations: Array[Thread::Backtrace::Location]?, ?serialized_entry_args: Hash[Symbol, untyped]?, ?entry_capture_expressions: Hash[String, untyped]?, ?entry_capture_evaluation_errors: Array[Hash[Symbol, String]]?, ?return_value: Object?, ?duration: Float?, ?exception: Exception?) -> void

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.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Aug 20, 2026

Copy link
Copy Markdown

Pipelines  Tests

⚠️ Warnings

🚦 21 Pipeline jobs failed

Static Analysis | standard/lint — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

2 style offenses detected: missing parentheses in ternary expression at spec/datadog/di/el/evaluator_spec.rb:237 and an extra blank line at spec/datadog/di/instrumenter_spec.rb:2137.

Static Analysis | steep/typecheck — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Type error in lib/datadog/di/el/evaluator.rb:43:12: Cannot allow method body have type (nil | bool) because declared as type bool

Unit Tests | Ruby 2.6 / build & test (standard) [0] — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

78 tests failed due to missing required environment variable 'DD_DYNAMIC_INSTRUMENTATION_EVALUATION_TIMEOUT_MS'.

View all 21 failed jobs.

📋 Copy fix prompt
CI on my pull request is failing. Help me find and fix the root cause of each failing job below — they were flagged as caused by changes in this PR, so focus on the diff. For each job, explain the failure and propose a fix.

Before you start, set up the Datadog software-delivery tooling so you can
query the CI data yourself:

1. Check whether you already have the Datadog software-delivery MCP tools
   (e.g. a `search_datadog_ci_pipeline_events` tool) and the `unblock-pr` skill.
2. If either is missing, STOP and ask me for permission before installing
   anything. Do not install or run anything until I have said yes.
3. Only with my explicit approval, set up the Datadog software-delivery MCP
   server and skills by following:
     https://docs.datadoghq.com/getting_started/software_delivery_mcp_tools/
   then restart so the skill is picked up.
4. If I decline, skip all of the above and work from the context below alone.

Then run /unblock-pr — it will pull the CI data itself. The job context below is what we already know.

If /unblock-pr is not available — because I declined the setup above, or it did not install — work from the context below instead.

Datadog has already classified this failure as caused by changes in this PR.
Take that as given and work the fix:

1. Locate the change. Diff this branch against its base and find the change
   that produces this error. Explain the mechanism, don't just name a file:
     git fetch origin && git diff $(git merge-base origin/master HEAD)...HEAD
2. Reproduce it locally. Run the failing job's command or test before
   proposing anything.
3. Propose the smallest fix that addresses the root cause — not a workaround,
   not a broadened assertion, not a disabled or skipped test.
4. Re-run the same command to confirm, and say exactly what you ran.
5. If the failure turns out to be intermittent rather than deterministic, say
   so plainly instead of "fixing" it — that is a flaky test, and patching it
   hides the problem.

If the right move is to re-run the job rather than change code, use the job
link in the context below. For GitHub Actions: `gh run rerun <run-id> --failed`,
where the run ID is the number after `/runs/` in that URL (not the trailing
number, which is the job ID).

Branch: di-eval-timeout

Static Analysis | standard/lint
Commit: b390d6c4de29431c4bef0833c3c18b703e143ab4
Error (code / quality):
2 style offenses detected: missing parentheses in ternary expression at spec/datadog/di/el/evaluator_spec.rb:237 and an extra blank line at spec/datadog/di/instrumenter_spec.rb:2137.
CI job: https://github.com/DataDog/dd-trace-rb/actions/runs/32736764674/job/97461499132

Static Analysis | steep/typecheck
Commit: b390d6c4de29431c4bef0833c3c18b703e143ab4
Error (code / build):
Type error in lib/datadog/di/el/evaluator.rb:43:12: Cannot allow method body have type `(nil | bool)` because declared as type `bool`
CI job: https://github.com/DataDog/dd-trace-rb/actions/runs/32736764674/job/97461499093

Unit Tests | Ruby 2.6 / build & test (standard) [0]
Commit: b390d6c4de29431c4bef0833c3c18b703e143ab4
Error (code / test):
78 tests failed due to missing required environment variable 'DD_DYNAMIC_INSTRUMENTATION_EVALUATION_TIMEOUT_MS'.
CI job: https://github.com/DataDog/dd-trace-rb/actions/runs/32736765039/job/97461476806

Plus 4 more failing jobs not shown here.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

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

…erators

Add a wall-time deadline check to Evaluator#filter, #all, #any (every
EVALUATION_DEADLINE_CHECK_INTERVAL items) that raises a new
DI::Error::EvaluationTimeout (subclass of ExpressionEvaluationError)
when the per-invocation deadline is exceeded. The deadline lives on the
per-invocation Context (Context#deadline_ns) to avoid racing the shared
Evaluator instance across application threads. nil deadline preserves
existing unbounded behavior.
…e eval

Add the max_time_to_evaluate_ms setting (env
DD_DYNAMIC_INSTRUMENTATION_EVALUATION_TIMEOUT_MS, default 50) and
resolve a per-invocation deadline (Context#deadline_ns) before
condition evaluation in both instrumenter hit paths and before template
segment evaluation in ProbeNotificationBuilder. An EvaluationTimeout is
surfaced through the existing condition-eval-failed callback as an
evaluation-error snapshot with no captures, with a telemetry counter
and debug log.
Evaluator cooperative-timeout tests (filter/all/any with deadline in
the past, no deadline, far-future deadline, and deadline crossed midway
via a stubbed clock). Instrumenter condition-timeout test asserting an
over-budget condition produces an evaluation-error snapshot with no
captures via the existing callback, plus an evaluation_timeouts telemetry
counter. Builder settings double defaults max_time_to_evaluate_ms to nil.
@pr-commenter

pr-commenter Bot commented Aug 24, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-24 14:34:38

Comparing candidate commit 6983411 in PR branch di-eval-timeout with baseline commit 9616dec in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 1 performance regressions! Performance is the same for 48 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 ----------------------------------'

scenario:profiling - Allocations ()

  • 🟥 throughput [-233453.429op/s; -193782.948op/s] or [-7.195%; -5.972%]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debugger Live Debugger (+Dynamic Instrumentation, +Symbol Database)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants