Repository navigation
fix(agent): record the real outcome of a tool call as is_error - #848
Merged
Merged
Conversation
`tool_result_is_error` was only ever read, never written: the executed tool loop built every `tool_result` block with `is_error: false`, so a failed call reached the transcript as a success and the model was told `is_error: false` for a command that had failed. Record the real verdict at the single place a tool result becomes a message (`Loop::new_tool_result`, called from `execute_tools_sequential`): - the agent raised an error for the call, or - a shell command exited non-zero for a reason other than the bare grep/diff "no match" signal (reusing `is_soft_fail_command`). `tools::outcome_is_error` is the one verdict shared by the persisted block and the live context. Cancellation and interrupt placeholders stay `false` — they are cancellations, not tool failures. Prompt impact (intended): failed tool results now carry `is_error: true` in the model context; the Anthropic adapter passes the flag through.
huichen
enabled auto-merge (squash)
September 25, 2026 18:04
huichen
added a commit
that referenced
this pull request
Sep 25, 2026
… shape (#855) The render fixtures froze the pre-#848/#849 wire: every history `tool_result` spelled out `isError` — `false` on the exit-127 failure and on the successes (which never carry a flag now), and `true` only on a hand-authored probe row. `lean-render-history` asserted that shape, so it would have stayed green against a page the phone no longer receives. - the full fixture records the real failure (`isError: true` on the exit-127 call) and omits the uninformative flag everywhere else (#849); - the lean page is regenerated through the shipping trim, and the generator's self-check asserts the shape on both the full page and its trimmed form; - both history scenarios flip: the exit-127 row reads 运行失败 (its command still arrives through the on-open fetch #851 added) and the soft-fail grep reads 已运行. lean-render-full-history's single failing row is that same recorded failure. Verified in the real mobile render surface: all five lean scenarios pass, the two new assertions were falsified (dropping the fetch trigger and restoring the old `isError: false` shape each fail the step), and the live full-feed `failed === 2` check still holds.
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.
What
tool_result_is_errorwas read in one place (session/records.rs) and written nowhere:Loop::new_tool_resultbuilt everytool_resultblock withis_error: false. Two consequences:isErrorprecisely becausefoldToolEntryreads it);is_error: falsefor calls that had failed — the Anthropic adapter passes the flag through (agent/src/llm/adapters/anthropic.rs).This records the real verdict at the single place a tool result becomes a message (
new_tool_result, called fromexecute_tools_sequential):is_errortruetrueexit 1(no-match signal)falsefalsefalse(unchanged)tools::outcome_is_error(error, semantics)is the one verdict, reusing the existingis_soft_fail_commandsemantics (baregrep/diff/cmp/test/rg/findstr, and[). A signal-killed run with no numeric exit code staysfalse— the shell tool reports timeouts asErr, which does set the flag.Prompt impact (intended, explicitly decided)
Failed tool results now enter the model context as
is_error: true. This is a deliberate correction of agent behaviour (the model can see that a command failed), agreed before implementation. Successes are unchanged;is_errorremains absent from the serialized block when false, so no bytes are added for the common case.Tests
tools::tests::tool_outcome_is_error_records_real_failures_and_soft_fails— verdict table above, including exit 2 from grep and a piped exit 1.run_loop::tests::run_records_failing_tool_result_is_error— a real scripted run: transcript, the next model request, and the persisted block (agent_message_to_entry) all carryis_error: true.run_loop::tests::run_records_soft_fail_and_nonzero_shell_exit_is_error— sameshelltool, grep exit 1 → false, cargo exit 101 → true.session::manager::tests::stored_tool_result_is_error_round_trips_to_history_and_prompt— SQLite round-trip: stored block hasis_error: true, a reloaded session handstrueback to the model; a success stays unflagged.rpc::commands::session_lifecycle_tests::get_session_entries_marks_failed_tool_result_is_error— the history-page wire payload (isError) the phone reads.false.Checks (1.97, the pinned toolchain)
cargo fmt -p future-agent --check,cargo clippy -p future-agent --all-targets -- -D warnings,cargo test -p future-agent(lib 1881 passed, integration all green).