nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] The agent-eval harness runs against the user's real config: it rewrites their saved default model and runs their global hooks

Open addyCooks opened this issue 1 month ago • 2 comments

Description

benchmarks/agent/harness.ts starts the CLI for each run with your full environment and no config override (harness.ts:387). Every run saves the provider and model it used to your preferences, so benchmarking changes the default model you use in the app. Your global agents.config.json (hooks, system prompt, MCP servers, formatters) is also active during the measured runs, so results depend on whoever runs them.

Environment

  • OS: Windows 11 (10.0.26300)
  • Node version: 22.22.3
  • Nanocoder version: 1.31.0 (main at 9d88dda7)
  • Provider: Ollama
  • Model: qwen2.5:1.5b

Steps to Reproduce

  1. Use a config dir whose nanocoder-preferences.json has "lastProvider":"MyOtherProvider","lastModel":"my-favourite-model", and whose agents.config.json has a session-start hook that writes a marker file.
  2. Run npx tsx benchmarks/agent/run.ts --fixture single-file-edit --runs 1 --provider Ollama --model qwen2.5:1.5b with NANOCODER_CONFIG_DIR pointing at that dir.
  3. Read the preferences file and look for the marker file.

Expected Behavior

The benchmark uses its own temporary config (only the provider block) and leaves the user's files untouched.

Actual Behavior

BEFORE: {"lastProvider":"MyOtherProvider","lastModel":"my-favourite-model", ...}
AFTER:  {"lastProvider":"Ollama","lastModel":"qwen2.5:1.5b",
         "providerModels":{"MyOtherProvider":"my-favourite-model","Ollama":"qwen2.5:1.5b"}, ...}
global hook marker file: my-personal-global-hook-ran

Suggested Fix

  • In runOnce (harness.ts, the execFileAsync('node', args, {... env ...}) call near line 387), set NANOCODER_CONFIG_DIR to a fresh temporary folder per run, copy only the provider block into it, and delete it in the existing finally. Print a note in benchmarks/agent/README.md.
  • Optional: harness.ts:443 stores a missing usage value as 0 (usage.totalTokens ?? 0); null would stop medians from reading as free runs. I could not trigger this now that #1671 is merged.
  • Add a test with a fake CLI that records the env it receives.

Additional Context

  • Harness: #1544 (merged). Open request: #1197.
  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

addyCooks avatar Oct 13 '26 12:10 addyCooks

I confirmed that runOnce currently passes the parent process environment to the CLI without isolating its config directory. I would like to take #1744: I will give each run a fresh config directory, carry over only the provider configuration needed for the selected run, and add an offline stub-CLI regression proving user preferences and hooks are not exposed or changed. I will keep validation local and will not run live model calls.

ducanhnguyen223 avatar Oct 13 '26 23:10 ducanhnguyen223

Thanks for the PR @ducanhnguyen223! For future contributions, please comment on the issue first and wait to be assigned before opening a PR. This avoids duplicate work. Also include "Closes #" in the PR description. We'll review this one, but please follow this process from the next issue onward.

addyCooks avatar Nov 03 '26 17:11 addyCooks