#19451: fix(errors): surface provider hint for role-ordering failures
agents
size: XS
Cluster:
Error Handling Improvements
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
#7163: fix #7151
by vivganes · 2026-02-02
82.7%
#15109: fix: distinguish transient API errors from billing errors
by jwchmodx · 2026-02-13
79.3%
#8175: fix: suppress raw API errors for non-owners
by Rakshi2609 · 2026-02-03
78.9%
#18907: Fix: Improve browser error messages to avoid misleading agents
by jriff · 2026-02-17
78.1%
#13318: fix(agents): prevent sanitizeUserFacingText from rewriting conversa...
by hleliofficiel · 2026-02-10
78.0%
#9173: Fix: Improve error messaging for API rate limits and billing errors
by vishaltandale00 · 2026-02-04
77.7%
#12974: fix: intermittent (no output) reported by users
by vincentkoc · 2026-02-10
77.6%
#8661: fix: display rate limit errors correctly instead of as context over...
by dbottme · 2026-02-04
77.4%
#19412: fix(status): prefer configured contextTokens over session entry
by rafaelipuente · 2026-02-17
77.4%
#14368: fix: skip auth profile cooldown on format errors to prevent provide...
by koatora20 · 2026-02-12
77.1%