Skip to content

fix(agent): record the real outcome of a tool call as is_error - #848

Merged
huichen merged 1 commit into
mainfrom
feat/record-tool-outcome
Sep 25, 2026
Merged

huichen merged 1 commit into
mainfrom
feat/record-tool-outcome

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

What

tool_result_is_error was read in one place (session/records.rs) and written nowhere: Loop::new_tool_result built every tool_result block with is_error: false. Two consequences:

  • the phone's history rows showed every tool call as 已完成 (the lean history trim keeps isError precisely because foldToolEntry reads it);
  • the model was told is_error: false for 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 from execute_tools_sequential):

outcome is_error
agent raised an error for the call true
shell exited non-zero, not a soft fail true
bare grep/diff exit 1 (no-match signal) false
exit 0 / other tool without an error false
cancellation / interrupt placeholder false (unchanged)

tools::outcome_is_error(error, semantics) is the one verdict, reusing the existing is_soft_fail_command semantics (bare grep/diff/cmp/test/rg/findstr, and [). A signal-killed run with no numeric exit code stays false — the shell tool reports timeouts as Err, 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_error remains 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 carry is_error: true.
  • run_loop::tests::run_records_soft_fail_and_nonzero_shell_exit_is_error — same shell tool, 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 has is_error: true, a reloaded session hands true back 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.
  • Two interrupt/cancel tests now assert the placeholder stays 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).

`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
huichen enabled auto-merge (squash) September 25, 2026 18:04
@huichen
huichen merged commit a29d9b9 into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the feat/record-tool-outcome branch September 25, 2026 18:09
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant