← Back to PRs

#19451: fix(errors): surface provider hint for role-ordering failures

by rafaelipuente open 2026-02-17 20:25 View on GitHub →
agents size: XS
Fixes #19260 - Root cause: `formatAssistantErrorText` rewrote all role-ordering errors (e.g. "400 unsupported role: developer") into a generic "Message ordering conflict" message, dropping the actual provider error and leaving users unable to diagnose the root cause (e.g. Moonshot/Kimi rejecting the `developer` role). - Fix: For plain-text role-ordering errors, append a sanitized single-line provider hint (max 200 chars) after the friendly message. JSON-wrapped errors retain the existing behavior (no raw JSON exposed). - Test: Added one regression test asserting that raw input "400 unsupported role: developer" produces output containing both "Message ordering conflict" and "Provider error: 400 unsupported role: developer", with no newlines and hint length <= 200. Made with [Cursor](https://cursor.com) <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR contains two independent fixes bundled into one: (1) a bug fix in `formatAssistantErrorText` (`src/agents/pi-embedded-helpers/errors.ts`) that surfaces the raw provider error text as a diagnostic hint when role-ordering failures come from non-JSON (plain-text) responses — directly addressing Moonshot/Kimi's `developer`-role rejection in issue #19260; and (2) a separate precedence fix in `buildStatusMessage` (`src/auto-reply/status.ts`) that correctly prefers the explicitly configured `agent.contextTokens` over any stale `contextTokens` stored in a session entry. - `errors.ts`: The new branch correctly distinguishes JSON-wrapped role errors (suppressed, as before) from plain-text ones (now appended as a sanitized, single-line, 200-char-capped hint). The brace-heuristic for JSON detection is consistent with the pattern used elsewhere in this file. - `errors.ts`: Minor nit — `const trimmedRaw = raw.trim()` on line 473 is redundant because `raw` is already `.trim()`-ed on line 438. - `status.ts`: The two-line precedence swap is correct and the new test validates the expected behavior. - Both test additions are well-scoped and follow existing conventions. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge; the changes are well-scoped, tested, and carry no correctness or security risk. - Both fixes are narrow and targeted. The `errors.ts` change only affects the text returned to users for role-ordering errors and introduces no new code paths that could fail silently. The sanitization (newline stripping + 200-char cap) prevents runaway output. The `status.ts` change is a straightforward operator-precedence fix with a direct regression test. The only issue found is a redundant `.trim()` call, which is purely cosmetic. - No files require special attention. <sub>Last reviewed commit: f6ccc80</sub> <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs