← Back to Pull requests

feat: accept expressions for datagen lengths, counts and latencies #1052

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 10, 2026 22:37 UTC
Author

Part of #449.

Old behavior: every length, count and latency knob in data is a fixed value or a Distribution block. New behavior: each one also takes an expression string. A length or count must be provably whole-numbered, so the config says how a draw is rounded. Every field has a range, and the expression must provably stay in it. Distribution blocks compile to expressions, so the datagens read one form.

data:
  type: synthetic
  input_distribution: "Max(floor(Min(LogNormal(6, 0.5), 4096)), 1)"
  multimodal:
    image:
      count: "Poisson(2)"
      insertion_point: "Beta(2, 5)"

data:
  type: synthetic_agentic
  synthetic_agentic:
    turns_per_session: "Min(1 + Poisson(2), 8)"
    input_tokens_per_turn: "Max(floor(Min(LogNormal(7.5, 0.4), 6000)), 1)"
    tool_call_latency_sec: "Uniform(0.1, 0.4)"

Fields that now accept an expression:

data.input_distribution                  # synthetic and random types only
data.output_distribution                 # synthetic and random types only

data.shared_prefix.system_prompt_len
data.shared_prefix.question_len
data.shared_prefix.output_len

data.multimodal.{image,video,audio}.count
data.multimodal.{image,video,audio}.insertion_point
data.shared_prefix.multimodal.{image,video,audio}.count
data.shared_prefix.multimodal.{image,video,audio}.insertion_point

data.conversation_replay.dynamic_system_prompt_len
data.conversation_replay.turns_per_conversation
data.conversation_replay.input_tokens_per_turn
data.conversation_replay.output_tokens_per_turn
data.conversation_replay.tool_call_latency_sec

data.synthetic_agentic.input_tokens_per_turn
data.synthetic_agentic.output_tokens_per_turn
data.synthetic_agentic.turns_per_session
data.synthetic_agentic.tool_loop_depth
data.synthetic_agentic.sub_agents_per_spawn
data.synthetic_agentic.tool_catalog_size_per_agent
data.synthetic_agentic.parallel_tool_calls_per_step
data.synthetic_agentic.tool_call_latency_sec
data.synthetic_agentic.user_think_time_sec
data.synthetic_agentic.context_compaction.trigger_tokens
data.synthetic_agentic.context_compaction.target_tokens

Not in the list: data.shared_prefix.question_distribution and data.shared_prefix.output_distribution still take a block only. No field here allows t.

Changes:
Every field above takes a string alongside its existing forms and is checked when the config loads.
A length or count expression must be provably integer-valued: a discrete variable like Poisson(2), or a continuous one under floor(), ceiling() or floor(... + 1/2). A rejected one gets the floor() form to paste.
Each field has a range, checked at load for numbers and expressions alike and stated at the end of its description. Token lengths, turns and compaction tokens are at least 1. system_prompt_len, dynamic_system_prompt_len, counts and seconds are at least 0. insertion_point is within [0, 1]. An expression that is not provably in range gets the Max(..., m) form to paste.
The dataset types reject an expression for input_distribution / output_distribution. They filter on the block's min and max, which an expression does not define.
sample_values / value_ceiling: one sampling path and one worst-case path for any numeric knob. Seconds keep fractions.
Budget checks (multi-turn prompt budget, synthetic_agentic max_model_len) read an expression's provable upper bound from Expression.bounds. floor(Min(Max(Normal(50, 10), 1), 99)) fits a 99-token budget. floor(Normal(50, 10)), or anything the bounds walk can't reason about, is rejected.
Docs: checked examples in config.md, conversation_replay.md and synthetic_agentic.md, and in docs/expressions.md these fields' rows and a checked "Whole numbers" section.
Tests: one accept/reject table over every expression field, with a guard that fails on a field without a row, a check that a number outside the range is rejected, and a check that each description states its range.
e2e: test_expression_lengths.py runs the CLI against the absorber with both synthetic length fields set to expressions and checks every prompt length and max_tokens on the wire against the expression's bounds. A second run checks the CLI refuses a continuous length and sends nothing.

Other changes:
Fix: tool-call latency and user think time were sampled as integers, so 0.3s became 0s, despite both code comments saying otherwise. They now keep fractional seconds.
Fix: a field that takes a model or a string had lost its nested CLI flags (--data.input_distribution.mean 600). Both forms work now, and setting the whole value and one of its fields together is an error.

Known gaps, not addressed here:
A few sympy.stats constructors load and then fail on the first draw, because SymPy has no numpy sampler for them. Seen so far: Weibull, Bernoulli, and Triangular unless its mode equals its upper bound. Holding on these until someone asks.

  • A Piecewise mixture samples correctly but has no provable bounds, so the fields with a budget check reject it.
  • Tests that used a continuous expression on a length now wrap it in floor() and give it a lower bound, per the rules above. The whole-number and range helpers live in #1062.

    Split out of #829, which keeps the rate half. This half does not depend on #823.

    Ran clean locally: the license check, ruff check, ruff format --check, mypy --strict, the type-escape ratchet and both doc sync checks. Both tests in e2e/tests/test_expression_lengths.py pass. pytest tests passes apart from test_datagen_imports_without_zstd, which fails the same way on main locally.

    This PR was written in part with the assistance of generative AI.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: rishabhsinha17 Review duration: 28491m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1052"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%