fix(workflows): add word boundary to context variable substitution regex#1256
fix(workflows): add word boundary to context variable substitution regex#1256
Conversation
…gex (#1112) Variable substitution for $CONTEXT, $EXTERNAL_CONTEXT, and $ISSUE_CONTEXT was matching as a prefix of longer identifiers like $CONTEXT_FILE, silently corrupting bash node scripts. Added negative lookahead (?![A-Za-z0-9_]) to CONTEXT_VAR_PATTERN_STR so only exact variable names are substituted. Changes: - Add negative lookahead to CONTEXT_VAR_PATTERN_STR regex in executor-shared.ts - Add regression test for prefix-match boundary case Fixes #1112 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes a bug in context variable substitution where patterns like Changes
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 Comprehensive PR ReviewPR: #1256 SummaryMinimal, targeted fix that adds a negative lookahead Verdict: ✅
🟢 Low Issues (Optional Test Additions)All three are test documentation improvements — none represent functional gaps. 1.
|
…titution Add three new test cases that complete coverage of the word-boundary fix from #1112: $ISSUE_CONTEXT with suffix variants, $ISSUE_CONTEXT with multiple suffixes, and contextSubstituted=false for suffix-only prompts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Review Fix ReportAll review findings addressed in commit Changes MadeFinding 1 (code-review + test-coverage): Extended the existing boundary test to include Finding 2 (test-coverage): Added new test Finding 3 (test-coverage): Added new test Finding 4 (test-coverage): Deferred per reviewer recommendation — Validation
|
Archon PR Validation ReportVerdict: APPROVE SummaryClean, minimal, correct fix. The negative lookahead Bug Confirmation
Fix Quality: 5/5IssuesNo blocking issues found. Minor SuggestionOther variable substitutions (e.g., Validated by archon-validate-pr workflow |
|
Credit to @txhno, who independently reported and fixed this first in #1166 before this PR was opened. Thank you for the catch and the clean fix — this PR carries the same one-line regex change plus additional regression tests (covering |
…gex (coleam00#1256) * fix(workflows): add word boundary to context variable substitution regex (coleam00#1112) Variable substitution for $CONTEXT, $EXTERNAL_CONTEXT, and $ISSUE_CONTEXT was matching as a prefix of longer identifiers like $CONTEXT_FILE, silently corrupting bash node scripts. Added negative lookahead (?![A-Za-z0-9_]) to CONTEXT_VAR_PATTERN_STR so only exact variable names are substituted. Changes: - Add negative lookahead to CONTEXT_VAR_PATTERN_STR regex in executor-shared.ts - Add regression test for prefix-match boundary case Fixes coleam00#1112 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test(workflows): add missing boundary cases for context variable substitution Add three new test cases that complete coverage of the word-boundary fix from coleam00#1112: $ISSUE_CONTEXT with suffix variants, $ISSUE_CONTEXT with multiple suffixes, and contextSubstituted=false for suffix-only prompts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…gex (coleam00#1256) * fix(workflows): add word boundary to context variable substitution regex (coleam00#1112) Variable substitution for $CONTEXT, $EXTERNAL_CONTEXT, and $ISSUE_CONTEXT was matching as a prefix of longer identifiers like $CONTEXT_FILE, silently corrupting bash node scripts. Added negative lookahead (?![A-Za-z0-9_]) to CONTEXT_VAR_PATTERN_STR so only exact variable names are substituted. Changes: - Add negative lookahead to CONTEXT_VAR_PATTERN_STR regex in executor-shared.ts - Add regression test for prefix-match boundary case Fixes coleam00#1112 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test(workflows): add missing boundary cases for context variable substitution Add three new test cases that complete coverage of the word-boundary fix from coleam00#1112: $ISSUE_CONTEXT with suffix variants, $ISSUE_CONTEXT with multiple suffixes, and contextSubstituted=false for suffix-only prompts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
substituteWorkflowVariables()usesCONTEXT_VAR_PATTERN_STRwith no word boundary or negative lookahead, causing$CONTEXT_FILEto match as$CONTEXT+_FILE, silently corrupting the variable to_FILEat runtime.CONTEXT,EXTERNAL_CONTEXT, orISSUE_CONTEXT(e.g.$CONTEXT_FILE,$ISSUE_CONTEXT_ID) receive a mangled script — no error is thrown, the bash command runs with wrong variable names, and fallback defaults may hide the corruption entirely.(?![A-Za-z0-9_])negative lookahead toCONTEXT_VAR_PATTERN_STRinexecutor-shared.ts; added a regression test inexecutor-shared.test.ts.$WORKFLOW_ID,$ARTIFACTS_DIR, etc.) are unaffected; no changes to context fetching, storage, or any other module.UX Journey
Before
After
Architecture Diagram
Before
After
Connection inventory:
CONTEXT_VAR_PATTERN_STRsubstituteWorkflowVariables()substituteWorkflowVariables()buildPromptWithContext()buildPromptWithContext()dag-executor.ts/executor.tsLabel Snapshot
risk: lowsize: XSworkflowsworkflows:executorChange Metadata
bugworkflowsLinked Issue
Validation Evidence (required)
bun run validatechecks passed on first run; new regression test added and passing.Security Impact (required)
Compatibility / Migration
Human Verification (required)
$CONTEXT(substituted) vs$CONTEXT_FILE(preserved) vs$EXTERNAL_CONTEXT_PATH(preserved) in a single call.$CONTEXTat end of string (no trailing char), followed by whitespace/newline/quote/colon — all still match.$ISSUE_CONTEXT_ID— now correctly left untouched.Side Effects / Blast Radius (required)
substituteWorkflowVariables()in@archon/workflows— used by every prompt node (bash, command, prompt, loop, approval, script). Impact is purely corrective.Rollback Plan (required)
2b0adc24(git revert 2b0adc24).$CONTEXT_FILEor similar begin producing_FILE-style mangled variable names; no error thrown.Risks and Mitigations
Summary by CodeRabbit
Bug Fixes
$CONTEXT_FILE).Tests