Repository navigation
Conversation
resolveVariables() matched only the first {{ \w+ }} placeholder per pass
(regex without the g flag). When that first placeholder referenced an
undefined variable, no replacement happened in the pass, the do-while
loop ended, and every later placeholder in the same string was silently
left unresolved - even when its variable was defined. The behavior was
order-dependent: 'Hello {{ undefined_var }} and {{ name }}' kept the
literal '{{ name }}', while 'Hello {{ name }} and {{ undefined_var }}'
resolved the first placeholder.
Substitute every placeholder whose variable is defined in one pass with
a global regex and a function replacer (keeps $&/$'/$` literals and
skipped-var bookkeeping); placeholders whose variable is undefined stay
untouched for the final nunjucks render, as before.
Fixes promptfoo#12240
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12248 +/- ##
=======================================
Coverage 89.82% 89.83%
=======================================
Files 1054 1054
Lines 93222 93285 +63
Branches 33119 33134 +15
=======================================
+ Hits 83736 83799 +63
Misses 9486 9486
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a874e42563
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8705192914
ℹ️ 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".
There was a problem hiding this comment.
👍 All Clear
Reviewed changes to variable resolution and prompt rendering behavior, plus related tests. The updates improve placeholder handling and cycle detection without adding new tools or expanding capabilities. Based on the diff, no medium-or-higher LLM security issues were identified.
Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ee4014412
ℹ️ 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".
| const value = variables[key] as string; | ||
| let referencesSkipped = false; | ||
| // A replacer function keeps `$&`, `$'` and `` $` `` in the value literal. | ||
| const newValue = value.replace(regex, (placeholder: string, varName: string) => { |
There was a problem hiding this comment.
Cap acyclic fan-out before global replacement
Even though the new scans block cycles, an acyclic fan-out such as a0: '{{a1}}{{a1}}' through a32 with final a32: 'x' leaves cyclicVars empty, so this global replacement attempts to expand the compact map to 2^32 characters within the five passes; even depth 24 materializes 16,777,216 characters. The old one-match-per-key loop stayed bounded, so a generated or untrusted vars file can now throw RangeError or exhaust the evaluator before any downstream prompt-length check runs; enforce an expansion/output budget before constructing newValue.
AGENTS.md reference: AGENTS.md:L370-L372
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b05ddd1. Both substitution phases share a cumulative expansion budget of 8,388,608 UTF-16 code units. Each replacement checks its contribution before the expanded string is assembled. Exceeding the budget produces an evaluation error that names the variable. I verified the 32-level acyclic case in both input orders and checked that the CLI reports the limit in its exported result. The regression tests also cover repeated skipped payloads.
| if (!resolveSkipped && newValue.includes('{{')) { | ||
| // Replacement fragments can assemble placeholders absent from the | ||
| // original value, so check the updated dependency graph as well. | ||
| cyclicVars = findCyclicVariables(variables, ordinaryVars, regex); |
There was a problem hiding this comment.
Avoid rebuilding the full graph for every replacement
When a vars map contains many values like {{known}} {{missing}}, each successful substitution leaves the pre-existing {{missing}} text and therefore invokes findCyclicVariables once for every entry even though no dependency edge was introduced. Since each invocation scans every variable, resolution becomes quadratic per eval (for example, 2,000 such columns cause 2,000 full graph builds); update only the changed dependencies or distinguish newly assembled placeholders from pre-existing unresolved ones.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b05ddd1. The resolver caches each variable's direct dependencies and updates only the changed entry. It reruns cycle detection when a substitution introduces a dependency that was neither present in the original value nor inherited from an inlined alias. In the 2,000-column reproduction, full cycle checks dropped from 2,001 to one with identical output. The fragment-assembled cycle tests also pass.
There was a problem hiding this comment.
👍 All Clear
Reviewed changes to variable resolution and prompt rendering paths that feed into provider.callApi. The PR adds cycle detection and expansion limits, and adjusts how skipped variables are handled. No LLM security-relevant capabilities (tools, external I/O, execution sinks) were added or modified. As a result, no actionable LLM security vulnerabilities were identified.
Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more
There was a problem hiding this comment.
👍 All Clear
Reviewed changes to variable resolution and prompt rendering logic, plus associated tests. The updates add bounds and cycle detection and adjust how unresolved/skip variables are handled. Based on the diff, there are no new LLM-integrated capabilities, tools, or execution sinks that create security risk. No LLM security vulnerabilities were identified.
Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more
There was a problem hiding this comment.
👍 All Clear
Reviewed variable substitution and prompt construction changes, along with related tests that exercise evaluate/renderPrompt flows. The PR adds cycle detection, own-property checks, and bounded expansion, which are defensive. Based on the diff, there are no new LLM security risks involving tool execution, data exfiltration, or secrets exposure.
Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more
Summary
Variable composition can stop at an undefined placeholder and leave later, defined placeholders unresolved. Resolve all defined references while preserving undefined placeholders for the final template render.
Fixes #12240.
Behavior
Hello {{undefined_var}} and {{name}}, withname: Alice, becomesHello {{undefined_var}} and Alice.{{prefix}} {{payload}}, withprefix: '{{greeting}}', now produces the greeting followed by the literal payload. Template expressions inside skipped payloads remain untouched.Validation
RangeError: Invalid string lengthfor{ a: '{{a}}{{a}}' }; the patched resolver leaves the value unchanged. A second bounded check confirms fragment-assembled cycles also stop expanding instead of raisingRangeError.npm run tsc,npm run l,npm run f, andgit diff --checkpassed. Lint reports only existing complexity warnings in unchanged functions.tsdownandpostbuild, then ran four localechoevaluations with--no-cache. Exported JSON confirms all four passed with no errors: partial substitution after an undefined reference, ordinary context next to a literal skipped payload, bounded cyclic composition, and a cycle assembled from replacement fragments.Disclosure
Prepared with AI assistance. The regression tests and CLI checks reported above were executed locally.