fix(agents): harden structured error-code classification edge cases#1663
Merged
Merged
Conversation
Post-merge review of #1653 found gaps in the error-code seam: unknown codes could cross-classify via string prefixes, NaN slipped past the null guard, new-format log strings were unclassifiable when the code field was lost, non-standard JSON-RPC errors were truncated to "unknown error", and bare llm-auth log lines from older agent binaries regressed to the generic exit message. Unknown structured codes are now authoritative (generic, no string matching), codes embedded in the message are recovered, the full JSON error object is preserved when message is absent, and bare-prefix promotion is restored with synthetic codes.
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.
Post-merge review of #1653 surfaced several edge cases in the structured error-code seam where classification silently degrades or misfires. This PR closes them.
lastErrorCodethe UI doesn't recognize returns generic copy immediately instead of falling through to string-prefix matching, so a future code (e.g. a rate-limit classification) whose message happens to start withllm auth:can no longer render the relay-membership copy.Number.isFiniteguards replace the!= nullchecks, soNaN(from a non-numericpayload.code) is treated as no-code rather than entering the switch.friendlyAgentLastErrornow recovers the code embedded in the message via the"Agent reported error (code N): "Display format before falling back to legacy prefixes.buzz-acpno longer truncates non-standard JSON-RPC errors to"unknown error": when themessagefield is missing or non-string, the full JSON object is preserved (e.g.{"code":-32000,"data":"quota exceeded"}). The duplicated extraction at the prompt and steer read loops is folded into oneagent_error_from_jsonhelper.llm auth:/llm model not found:log-line promotion is restored inmeaningful_agent_error_from_logwith synthetic codes (-32001/-32002), so older agent binaries that log unwrapped prefixes surface a classified error instead of the generic "harness exited with status N".AgentErrormatch arm in the transport-error branch ofhandle_prompt_resultis removed by hoisting a singleerror_codeextraction above both branches.friendlyAgentLastError.ts(the old one described the pre-fix(agents): surface provider errors structurally instead of raw dumps #1653 architecture), doc comments onAgentLogError, thepromotes_unwrapped_llm_authtest asserts promotion again (matching its name), new coverage for the legacy log format, and the E2E fixture uses the new-format error string.Related: #1653