Skip to content

fix(interpreter): bound recursive prompt expansion - #2671

Merged
chaliy merged 1 commit into
mainfrom
codex/prompt-expansion-guard
Oct 11, 2026
Merged

chaliy merged 1 commit into
mainfrom
codex/prompt-expansion-guard

Conversation

@chaliy

@chaliy chaliy commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Bounds recursive prompt expansion so the reported self-referential payload can no longer recurse without limit. Root cause: `` re-enters prompt decoding on every cycle (expand_word -> prompt_transformation -> expand_prompt_string -> expand_word) with no depth tracking, so a self-referential value recurses until the native stack overflows and aborts the host process.

Reported vector (default promptvars on):

x='${x@P}'; echo "${x@P}"

Changes

  • Depth guard on the shared prompt-decode path: nesting deeper than 8 fails closed with a bounded message instead of recursing; depth unwinds on exit.
  • Recursion budget pre-charged before UTF-8 decode; decoded input charged so hostile overlong prefixes cannot hide from the cap; child re-parse shares the active budget/depth and fails closed on a poisoned budget.
  • Cancellation honored through prompt evaluation.
  • ExecutionMode::for_prompt(): prompt path can never enable nested execution.
  • Limits docs/callouts, spec case, knowledge updates.

Before / After

  • Before (per report): the payload above recurses without bound until the native stack overflows and the process aborts.
  • After (verified at merge commit): the same payload exits 1 in ~10ms with a 118-byte actionable diagnostic (resource limit exceeded: maximum prompt expansion depth exceeded (8)); stdout empty; subsequent invocations run normally. 7/7 new prompt_resource_tests pass (self/mutual cycles, finite chains, depth boundary ok/rejected, sibling independence, session recovery, shared budget), plus 6 prompt unit, 81 tool/limits, 203 parser tests; cargo fmt --check and cargo clippy -p bashkit --all-targets clean.

Tests

cargo test -p bashkit --test integration prompt_resource (7 passed)
cargo test -p bashkit --lib prompt (6 passed), limits (81 passed), parser (203 passed)

Produced by yolop

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 839c036 Commit Preview URL

Branch Preview URL
Oct 10 2026, 11:40 PM

@chaliy
chaliy merged commit c6fd211 into main Oct 11, 2026
49 checks passed
@chaliy
chaliy deleted the codex/prompt-expansion-guard branch October 11, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant