Skip to content

Fix prompt path resolution when CWD differs from project root#474

Merged
simonrosenberg merged 3 commits intomainfrom
fix/prompt-path-use-absolute-paths
Mar 3, 2026
Merged

Fix prompt path resolution when CWD differs from project root#474
simonrosenberg merged 3 commits intomainfrom
fix/prompt-path-use-absolute-paths

Conversation

@simonrosenberg
Copy link
Collaborator

Summary

  • Fixes prompt template path resolution in all 6 run_infer.py files. The old code used p.relative_to(Path.cwd()) which raises ValueError when the process is launched from a directory other than the project root (e.g. when running as an installed package via NeMo Evaluator).
  • Extracts duplicated logic into a shared add_prompt_path_argument() utility in benchmarks/utils/args_parser.py, replacing ~14 identical lines in each file with a single function call.

Extracted from #455 (NeMo Evaluator Integration).

Files changed

File Change
benchmarks/utils/args_parser.py New add_prompt_path_argument(parser, caller_file) function
benchmarks/swebench/run_infer.py Use shared utility
benchmarks/swtbench/run_infer.py Use shared utility
benchmarks/swebenchmultimodal/run_infer.py Use shared utility
benchmarks/swefficiency/run_infer.py Use shared utility
benchmarks/multiswebench/run_infer.py Use shared utility
benchmarks/commit0/run_infer.py Use shared utility

Before / After

# Before (broken when CWD != project root):
prompt_dir = (Path(__file__).parent / "prompts").resolve()
choices = [str(p.relative_to(Path.cwd())) for p in prompt_dir.glob("*.j2")]
default_prompt_path = prompt_dir / "default.j2"
assert default_prompt_path.exists(), ...
parser.add_argument("--prompt-path", ..., choices=choices, default=str(default_prompt_path))

# After (single line per benchmark):
parser = get_parser()
add_prompt_path_argument(parser, __file__)

Validation

All benchmarks pass on the nemo-evaluator branch (which includes this change):

Test plan

  • Verify --prompt-path argument still works when running from the project root
  • Verify --prompt-path argument works when running from a different directory (the bug this fixes)
  • Verify --help still lists available prompt templates

🤖 Generated with Claude Code

The old code used `p.relative_to(Path.cwd())` which raises ValueError
when the process is launched from a different directory than the project
root. Replace with `str(p)` (absolute paths) and extract the duplicated
logic into `add_prompt_path_argument()` in args_parser.py.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Acceptable - Solves Real Problem, but with Trade-offs

Good: Fixes actual bug (ValueError when CWD ≠ project root) and eliminates code duplication.

Issues:

  1. UX regression: Help shows ugly absolute paths instead of clean relative ones
  2. Breaking change risk: Existing users passing relative paths will fail validation
  3. Missing tests: Bug fix without regression tests

See inline comments for specifics.

simonrosenberg and others added 2 commits March 3, 2026 06:51
- Use bare filenames in --help (via metavar) instead of absolute paths
- Accept bare filenames, relative paths, and absolute paths via custom
  type function for backwards compatibility
- Drop argparse choices in favor of runtime validation with clear error
  messages listing available templates
- Add tests/test_prompt_path.py with 7 test cases covering: default
  value, bare filename, absolute path, different CWD (the original bug),
  invalid template, missing default.j2, and relative path resolution

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Clean refactor that fixes a real bug

Eliminates 84 lines of duplication while fixing ValueError when CWD ≠ project root. Path resolution logic is pragmatic, tests cover real scenarios (not mocks), and backwards compatibility is preserved.

Previous review concerns (UX regression, breaking changes) were properly addressed. Ready to ship.

@simonrosenberg simonrosenberg merged commit 71407ca into main Mar 3, 2026
3 checks passed
@simonrosenberg simonrosenberg deleted the fix/prompt-path-use-absolute-paths branch March 3, 2026 11:52
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.

2 participants