fix(#6764): fail when agent definition name mismatches requested name - #6766
fix(#6764): fail when agent definition name mismatches requested name#6766fullsend-ai-coder[bot] wants to merge 5 commits into
Conversation
Claude Code resolves --agent by the frontmatter name: field, not the filename. When the harness config names an agent "coder" but the definition declares name: "code", Claude silently falls back to the default agent — producing an unconstrained run with none of the intended agent behavior. Add validateAgentName() to ClaudeRuntime.Bootstrap that reads the agent definition, parses the frontmatter name: field, and returns an error when it does not match the requested agent name. Add the same check inline in PiRuntime.Bootstrap (which already parses the definition). When the definition has no frontmatter or no name: field, validation is skipped — the runtime uses its own resolution chain. The error message includes both names and advises updating the harness config or definition frontmatter. Closes #6764
|
🤖 Finished Review · ✅ Success · Started 7:54 PM UTC · Completed 8:10 PM UTC Commit: Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $6.08 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Risk Assessment: moderate (2/5) DetailsSmall focused bug fix (5 files, 188 lines) by a bot author with no protected or security-sensitive paths; elevated Tier 2 churn and fix history in the runtime package is offset by low Tier 1 metadata signals and strong Tier 3 issue alignment. Score unchanged from prior assessment. Previous runRisk Assessment: moderate (2/5) DetailsSmall focused bug fix (4 files, 183 lines) by a bot author with 50% test file ratio and no protected or security-sensitive paths; elevated Tier 2 fix/revert history is offset by low Tier 1 metadata signals and well-scoped issue alignment. Score unchanged from prior assessment. Previous run (2)Risk Assessment: moderate (2/5) DetailsSmall focused bug fix (4 files, 188 lines) by a bot author with 50% test file ratio and no protected or security-sensitive paths; elevated Tier 2 fix/revert history is offset by low Tier 1 metadata signals and well-scoped issue alignment. Score unchanged from prior assessment. Previous run (3)Risk Assessment: moderate (2/5) DetailsSmall focused bug fix (4 files, 183 lines) by a bot author with 50% test file ratio and no protected or security-sensitive paths; elevated Tier 2 fix/revert history (9.5 avg) is offset by low Tier 1 metadata signals and well-scoped issue alignment. |
ReviewFindingsLow
Previous runReviewFindingsLow
Next steps:
Previous run (2)ReviewFindingsLow
Next steps:
Previous run (3)ReviewFindingsMedium
Low
Next steps:
|
|
/fs-fix is there any way to reduce code duplication here? |
|
🤖 Fix · Commit: |
|
🤖 Finished Fix · ✅ Success · Started 8:14 PM UTC · Completed 8:20 PM UTC Commit: Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $1.18 |
…lication The agent-name-mismatch validation logic and error message were duplicated between validateAgentName (claude.go) and inline code in PiRuntime.Bootstrap (pi_bootstrap.go). Extract a shared checkAgentName helper that both call sites delegate to. Addresses review feedback on #6766
🔧 Fix agent — iteration 1 (human-triggered)Extracted shared checkAgentName helper to eliminate duplicated agent-name-mismatch validation logic and error message between claude.go and pi_bootstrap.go. All existing tests pass unchanged. Fixed (1):
Tests: passedNext steps:
|
|
🤖 Finished Review · ✅ Success · Started 8:22 PM UTC · Completed 8:40 PM UTC Commit: Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $4.26 |
|
🤖 Finished Fix · ✅ Success · Started 8:42 PM UTC · Completed 8:49 PM UTC Commit: Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $1.48 |
- Rename checkAgentName to validateAgentNameMatch to follow the established validate* naming convention in the package - Shorten mismatch error message to terse ASCII diagnostic matching the existing fmt.Errorf style in the package - Log a warning to stderr when parsePiAgent fails in validateAgentName so operators have visibility into structural definition issues Addresses review feedback on #6766
🔧 Fix agent — iteration 2 (bot-triggered)Addressed all 3 review findings: renamed checkAgentName to validateAgentNameMatch for naming consistency, shortened error message to terse ASCII diagnostic, and added stderr warning when parsePiAgent fails. Fixed (3):
Tests: passedNext steps:
|
|
🤖 Finished Review · ✅ Success · Started 8:51 PM UTC · Completed 9:06 PM UTC Commit: Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $3.64 |
|
🤖 Finished Fix · ✅ Success · Started 9:08 PM UTC · Completed 9:15 PM UTC Commit: Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $1.53 |
Move validateAgentNameMatch and validateAgentName from claude.go to bootstrap.go alongside BootstrapInput — both are cross-runtime bootstrap helpers, and the codebase convention places shared helpers in their own files (cf. sanitize.go). Align the stderr message with the package's label-style prefix convention: "Agent name validation: skipped for ..." replaces the precedent-less "warning: skipping ..." prefix. Addresses review feedback on #6766
🔧 Fix agent — iteration 3 (bot-triggered)Addressed both review findings: moved shared validation helpers from claude.go to bootstrap.go for proper code organization, and aligned the stderr message format with the package's label-style prefix convention. Fixed (2):
Tests: passedNext steps:
|
|
🤖 Finished Review · ✅ Success · Started 9:17 PM UTC · Completed 9:33 PM UTC Commit: Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $4.90 |
Superseded by updated review
|
/fs-fix fix the open code duplication (code-organization) finding |
|
🤖 Finished Fix · ✅ Success · Started 5:14 PM UTC · Completed 5:25 PM UTC Commit: Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $2.22 |
… duplication Remove the validateAgentName file-reading wrapper from bootstrap.go and inline its logic in ClaudeRuntime.Bootstrap. This leaves a single shared helper (validateAgentNameMatch) that both runtimes call directly with pre-extracted names, eliminating the duplicated read→parse→validate pattern between the wrapper and PiRuntime.Bootstrap. Addresses #6766
🔧 Fix agent — iteration 4 (human-triggered)Removed validateAgentName wrapper from bootstrap.go to eliminate code duplication between the wrapper and PiRuntime.Bootstrap. Both runtimes now call validateAgentNameMatch directly. Updated tests to cover the shared comparison helper. Fixed (1):
Tests: passed
Decision points
Next steps:
|
Summary
Validate that the agent definition's frontmatter
name:field matches the requested agent name during Bootstrap, for both the Claude and Pi runtimes. Previously, a mismatch (e.g., harness config sayscoderbut the definition declaresname: code) caused the runtime to silently fall back to the default agent, producing an unconstrained run with none of the intended agent behavior.Changes
validateAgentName()ininternal/runtime/claude.gothat reads the agent definition, parses the YAML frontmattername:field, and returns an error when it doesn't match the requested namevalidateAgentName()fromClaudeRuntime.Bootstrapbefore uploading the agent definitionPiRuntime.Bootstrapafter parsing the agent definition (avoids a redundant file read since pi already parses the definition)name:field, validation is skipped — the runtime uses its own resolution chainTesting
TestValidateAgentName— table-driven tests covering match, mismatch, empty requested name, no frontmatter, empty frontmatter name, and nonexistent fileTestBootstrap_AgentNameMismatch/TestBootstrap_AgentNameMatch— integration tests for Claude runtime BootstrapTestPiRuntimeBootstrap_AgentNameMismatch/TestPiRuntimeBootstrap_AgentNameMatch— integration tests for Pi runtime Bootstrapinternal/runtime/...tests passvalidateAgentNamefunctionCloses #6764
Post-script verification
agent/6764-validate-agent-name)dc0f8e15488fc816f9464c63e644e17de549edd1..HEAD)