← Back to PRs

#22072: Fix responsePrefix {model} to use runtime model metadata

by graysurf open 2026-02-20 17:41 View on GitHub →
size: S
## Summary - Fix `{model}` interpolation in `messages.responsePrefix` to use runtime model metadata from the completed run, not only pre-run fallback candidate selection. - Add a regression test that simulates mismatch between fallback candidate and runtime `agentMeta`, and asserts the final selection callback is reconciled. ## Expected vs Actual - Expected: `[{model}]` in response prefix reflects the active runtime model used for the reply. - Actual (before): callback state could remain on fallback candidate metadata, producing a mismatched `{model}` value. ## Impact - Response headers are consistent with the runtime model recorded by `agentMeta`. - Prevents misleading model labels in prefixed replies when fallback selection metadata and runtime metadata diverge. ## Reproduction 1. Configure `messages.responsePrefix` with `{model}`. 2. Run a turn where fallback candidate selection and runtime `agentMeta` diverge. 3. Observe prefix model label before/after this patch. ## Issues Found | ID | Issue | Severity | Status | | --- | --- | --- | --- | | PR-22072-BUG-01 | `{model}` in response prefix may reflect fallback candidate instead of runtime model metadata. | medium | fixed | ## Fix Approach - In `runReplyAgent`, after `runAgentTurnWithFallback` returns, call `opts.onModelSelected` again using runtime `provider/model` from `runResult.meta.agentMeta` (with provider-prefix stripping when needed). - Keep existing pre-run callback behavior intact for fallback/streaming paths. ## Testing - `pnpm test src/auto-reply/reply/agent-runner.runreplyagent.test.ts` Fixes #20543 <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes `{model}` interpolation in response prefix to use runtime model metadata instead of fallback candidate selection. After `runAgentTurnWithFallback` completes, the code now calls `onModelSelected` again with the runtime `agentMeta.provider` and `agentMeta.model`, ensuring the response prefix displays the actual model used. The fix includes proper provider-prefix stripping (e.g., `anthropic/claude-opus-4-6` → `claude-opus-4-6`) and preserves the existing pre-run callback for streaming/fallback announcements. - Added runtime model reconciliation after agent execution completes - Strips provider prefix from model name when present - Includes regression test validating runtime metadata takes precedence over fallback candidate <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with no issues found - The implementation is clean and well-tested. The fix correctly reconciles runtime model metadata with a second callback after agent execution, follows existing codebase patterns for prefix stripping, includes proper null-coalescing fallbacks, and has comprehensive test coverage that validates the exact scenario described in the PR (fallback candidate diverging from runtime metadata). No logical errors, edge cases, or security concerns identified. - No files require special attention <sub>Last reviewed commit: 1e8c9e0</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs