refactor(agent): decouple nvm bootstrap from agent Run/InstallMCP commands#76
Open
zpzjzj wants to merge 2 commits into
Open
refactor(agent): decouple nvm bootstrap from agent Run/InstallMCP commands#76zpzjzj wants to merge 2 commits into
zpzjzj wants to merge 2 commits into
Conversation
…ate Exec Previously `nodeRuntimeCommandWithGuard` packed the nvm/Node bootstrap and the agent's real command (`claude -p`, `codex exec --json`, MCP install) into a single multi-line shell script handed to one `rt.Exec` call. When the bootstrap failed (curl timeout to nvm installer, sha256 mismatch, nvm install errors against an offline mirror), the failure surfaced as a `claude-code run failed` / `codex run failed` and bootstrap stderr was concatenated into `result.Stderr`, which then fed `providerAuthFailureSignal` and `providerRateLimitSignal` — widening their false-positive surface. Replace the wrapper with `ensureNodeRuntime`, which runs only the bootstrap as its own `rt.Exec` (short-circuited by `if command -v <cli>; then exit 0`). Run/InstallMCP call it first, then Exec the agent command separately. Each Exec now has its own exit code, stderr, stdout; bootstrap failures wrap as `node bootstrap failed: ...` and never reach the agent's stderr buffer or `stdout.json` artifact. `qodercli` is unaffected — it never used the wrapper. Fixes #72
The new ensureNodeRuntime call path returned `nil, err` on bootstrap failure, breaking the existing convention (post-Exec error path) of always returning a SessionResult with Engine/ExitCode/DurationMs so the evaluator can record telemetry for failed cases. Build a minimal SessionResult before the error return, matching the surrounding pattern. Self-review catch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Splits the nvm/Node bootstrap and the agent invocation into two distinct
rt.Execcalls so failures can be cleanly attributed and the agent's stderr buffer stays free of bootstrap noise.Fixes #72
Problem
nodeRuntimeCommandWithGuard(internal/agent/node_install.go) packed the bootstrap and the agent's real command (claude -p,codex exec --json,claude mcp add,codex mcp add) into a single multi-line shell script handed to onert.Execcall. Consequences:nvm installerrors against an offline mirror) surfaced asclaude-code run failed: .../codex run failed: .... Hard to triage without reading the wrapped script.result.Stderr, which is then scanned byproviderAuthFailureSignal/providerRateLimitSignal— widening their false-positive surface.stdout.jsonartifacts.Installfailed or wasn't called, masking what should be a clear "Install was never called" failure.Fix
New
ensureNodeRuntime(ctx, rt, cliBin, opts)helper runs only the bootstrap as its ownrt.Exec. The script's first line short-circuits withexit 0whencommand -v <cli>succeeds, so the happy path is one extracommand -vcheck with no output.claude_code.go:127nodeRuntimeCommandWithGuard("claude", ...)(Run)ensureNodeRuntime→ Execclaude_code.go:72nodeRuntimeCommandWithGuard("claude", ...)(MCP)InstallMCPcallsensureNodeRuntimeonce before the per-server loopcodex.go:236(Run)ensureNodeRuntime→ Execcodex.go:136,:171(MCP stdio / http+bridge)InstallMCPnodeRuntimeCommandWithGuardandnodeRuntimeCommandare removed — no remaining production callers.qodercliis untouched (it never used the wrapper).Errors from
ensureNodeRuntimewrap withnode bootstrap failed: ...so they're trivially distinguishable from agent run failures in result handling and signal detectors. Bootstrap stderr no longer reachesresult.Stderrof the agent Exec.A follow-up commit (
de46509) preserves the existing convention of returning a non-nilSessionResult{Engine, ExitCode: 1, DurationMs}on bootstrap failure, so the evaluator still records telemetry for failed cases.Test plan
go build ./...go test ./...(full suite green)make verify(gofmt + vet + revive + golangci-lint, 0 issues)internal/agent/node_install_test.go: script shape (CLI short-circuit at top), Exec-error wrapping, non-zero-exit wrapping with stderr surfacing, empty-cliBin guardclaudeCodeTestRuntime,codexTestRuntime) recognize bootstrap commands by content sniffing and short-circuit them so existinglastCommand/execResultassertions still observe the agent commandrt.Execcalls (bootstrap + run) and thatstdout.jsoncontains only stream-json from claudeNVM_SOURCEto an unreachable host; failure should reportnode bootstrap failed:rather thanclaude-code run failed:🤖 Generated with Claude Code