fix(agy): report the failure reason instead of echoing the answer - #1642
Open
junmo-kim wants to merge 1 commit into
Open
fix(agy): report the failure reason instead of echoing the answer#1642junmo-kim wants to merge 1 commit into
junmo-kim wants to merge 1 commit into
Conversation
A failed `result` envelope still carries the turn's answer in `response` — agy decodes that field from the complete buffer regardless of status. The driver used it as the failure text, so a failed turn delivered the whole answer a second time as an error event, right under the streamed copy. Read the reason from `error` instead, which is what agy actually reports there (e.g. "timeout waiting for response"), and keep the existing `agy turn failed: <status>` fallback when the envelope carries none.
There was a problem hiding this comment.
Findings
- No reportable issues found.
Summary
- Review mode: initial. Reviewed the full four-file diff; no correctness, security, regression, data-loss, performance, or maintainability issue met the 80% confidence threshold. A formal agy result-envelope schema was not found in repo/docs, so compatibility remains dependent on the observed CLI envelope shape.
Testing
- Not run (automation; PR code was not executed). Static inspection only; GitHub test and integration checks were still in progress at review time.
HAPI Bot
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.
Problem
On an
agysession, a turn that ends with a non-SUCCESSresultenvelopedelivers its answer twice: once as the streamed
agy_message, then again as anerror event right below it — the whole answer rendered as plain text with a ⚠
prefix.
The driver takes the failure text from
response:But
responseis the answer field. agy fills it from the completed bufferregardless of status, so on a failed turn it holds the same answer that already
went out through the delta stream. The reason for the failure is reported
separately, in
error, which the parser did not read at all.Measured on agy 1.1.13 (
--print-timeout 15sagainst a long prompt):{"event":"result","result":{"conversation_id":"…","status":"ERROR","response":"","error":"timeout waiting for response","duration_seconds":2.4,…}}responseis empty and the reason lives inerror. On a turn that producedtext before failing,
responsecarries that text instead — which is what endsup duplicated in the chat.
Change
agyNdjsonParser.ts: carryerrorthrough theresultenvelope (added toResultEnvelopeand to theresultstream event;nullwhen absent).agyHeadlessDriver.ts: read the failure text fromerrorrather thanresponse. The existingagy turn failed: <status>fallback still applieswhen the envelope carries no reason, so a failed turn stays visible.
The SUCCESS branch is untouched.
Tests
errorsurfaces it; the existing SUCCESS/FAILUREcases now assert
error: null.responseholds the answer reports theerrortext and never emits the answer as an error; a failed envelope with noerrorfalls back to the status; a timeout envelope surfacestimeout waiting for response.bun run test:cliandbun run typecheck:clipass.Note
#1629 fixes the same duplication on the SUCCESS path (where the guard comparing
the streamed text with the envelope misfires on mangled deltas). This one is the
failure path, which that guard never reaches. The two touch adjacent hunks of the
same file but do not depend on each other in either order.
AI disclosure per CONTRIBUTING: written with Claude Code (Opus 5).