Skip to content

fix(agent-service): classify error-prefixed tool results as failed - #9259

Merged
bobbai00 merged 3 commits into
apache:mainfrom
oliarmak-web:fix/tool-error-status
Nov 18, 2026
Merged

bobbai00 merged 3 commits into
apache:mainfrom
oliarmak-web:fix/tool-error-status

Conversation

@oliarmak-web

@oliarmak-web oliarmak-web commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Tool failures returned as [ERROR] strings and SDK-generated tool-error parts must be persisted as failures so subsequent agent turns receive the correct status. This change builds stored results from step content, matches results to calls by toolCallId, and reuses normalized failure status to prevent delegate execution after rejected modifications. A shared isErrorResult predicate keeps string classification beside createErrorResult.

Thrown errors are stored as readable messages so they survive JSON snapshots and appear in subsequent context. Calls without a recorded result are marked failed. History formatting uses the normalized isError flag.

Regression coverage includes error-prefixed output, SDK-rejected calls, reordered results, throwing tools (Error, string and null values), length-limited calls that never execute, and suppression of execution after rejected modifications.

Any related issues, documentation, discussions?

Closes #9120

Related: #9244, whose tool-history presentation relies on accurate persisted failure status.

How was this PR tested?

From agent-service:

  • bun test: 347 passed, 0 failed
  • bun run typecheck: passed
  • bun run format:check: passed
  • git diff --check: passed

The new behavior assertions reproduced the failures before the production fix. Validation used Bun 1.3.3 and the repository’s frozen lockfile. The full test run required local socket access for the server tests. GitHub CI results remain separate from these local checks.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

👋 Thanks for your first contribution to Texera, @oliarmak-web!

If you're looking for a good place to start, browse issues labeled starter-task; they're scoped to be approachable for newcomers.

You can drive common housekeeping yourself by commenting one of these commands on its own line:

  • Issues. Comment /take to assign an open issue to yourself, or /untake to release it. You can find unclaimed work with the search filter is:issue is:open no:assignee.
  • Sub-issues. To link issues into a parent/child hierarchy, comment /sub-issue #5166 #5222 on the parent to attach those children (or /unsub-issue #5166 #5222 to detach them). From a child issue, comment /parent-issue #5166 to set its parent, or /unparent-issue to clear it (the current parent is detected automatically). References may be written as #5166 or as a bare 5166; cross-repository references are not supported.
  • Pull requests (author only). Comment /request-review @user to request a review from someone, or /unrequest-review @user to withdraw that request.

Each command must match exactly: /take this will not work, only /take does. For the full contribution flow, see CONTRIBUTING.md.

@Yicong-Huang Yicong-Huang added release/v1.3 back porting to release/v1.3 release/v1.2 back porting to release/v1.2 labels Nov 2, 2026
@github-actions
github-actions Bot requested review from mengw15 and xuang7 November 2, 2026 19:22
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. A release/* label nominates a backport target; the branch's release manager approving this PR is what sends the fix there. The required Backport Approvals check stays red until every label below is approved, so each manager either approves or removes their own label — which is why the labels left on a merged PR are exactly the branches it reached.

Release branch Analysis
🚫 release/v1.3 Label was removed earlier (opt-out); not re-added. Re-add it by hand if this fix should be backported here after all — the branch's release manager then has to approve before this PR can merge.
🚫 release/v1.2 Label was removed earlier (opt-out); not re-added. Re-add it by hand if this fix should be backported here after all — the branch's release manager then has to approve before this PR can merge.

Auto-label run.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @shaynhornik, @bobbai00
    You can notify them by mentioning @shaynhornik, @bobbai00 in a comment.

@oliarmak-web

Copy link
Copy Markdown
Contributor Author

/request-review @bobbai00

@oliarmak-web

Copy link
Copy Markdown
Contributor Author

/request-review @yrenat

@github-actions
github-actions Bot requested a review from bobbai00 November 2, 2026 19:23

@bobbai00 bobbai00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 1 must-fix · 1 advisory · 0 polish: fixes the [ERROR] case from #9120; tool calls the SDK rejects still show as succeeded.

Correctness (1)

  • agent-service/src/agent/texera-agent.ts:587: SDK-rejected tool calls never get a result, so they still render as succeeded (must-fix, see inline)

Simplifications (1)

  • agent-service/src/agent/texera-agent.ts:591: inline [ERROR] prefix and a producer-less object branch; use one shared predicate (advisory, see inline)
Verification trace

Traced ai 7.0.58: StepResult.toolResults keeps only tool-result parts, and generateText records a call that fails input validation or names an unregistered tool as an invalid tool call plus a tool-error part. Reproduced on this branch with the spec's MockLanguageModelV4: modifyOperator without summary and deleteOperator with {} each leave toolResults: [] and render (succeeded) on the next turn, and in delegate mode the rejected modifyOperator still triggers /api/execution/7/0/run. The PR's own suite passes locally at the head (313/313, tsc --noEmit and prettier clean); the CI build workflows are still awaiting approval.

Comment thread agent-service/src/agent/texera-agent.ts Resolved
Comment thread agent-service/src/agent/texera-agent.ts Resolved
@oliarmak-web

Copy link
Copy Markdown
Contributor Author

Implemented the requested follow-up in 8a34611f0:

  • preserve SDK-generated tool-error parts as failed results
  • match calls and results by toolCallId
  • reuse normalized failures to suppress delegate execution
  • centralize [ERROR] classification in isErrorResult
  • cover rejected calls, reordered results, and the shared predicate

Validation:

  • bun test: 315 passed, 0 failed
  • tsc --noEmit: passed
  • Prettier check for the changed files: passed

/request-review @bobbai00

@xuang7

xuang7 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Removing release/v1.2: agent context quality, not a data defect.

@xuang7 xuang7 removed the release/v1.2 back porting to release/v1.2 label Nov 16, 2026
@oliarmak-web

Copy link
Copy Markdown
Contributor Author

Thanks, @xuang7, for clarifying the v1.2 backport decision.

Rebased onto current main and resolved the conflicts in a35e1ab92, preserving the newer tool-history details alongside the failure classification changes. Updated the PR description to match the implementation.

Validation: bun test (344 passed, 0 failed), bun run typecheck, bun run format:check, and git diff --check all pass. GitHub workflows still require maintainer approval.

@bobbai00, could you take another look at the updated branch?

Comment written by OpenAI Codex on the account owner’s behalf.

@bobbai00 bobbai00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 2 resolved · 0 open · 4 new (4 new = 4 newly introduced · 0 late catches): both round-1 findings are fixed; one new must-fix.

Correctness (2)

  • agent-service/src/agent/texera-agent.ts:604: thrown tool errors are stored as objects and render as {} (must-fix, see inline)
  • agent-service/src/agent/util/context-utils.ts:127: a call the SDK never ran still reads (succeeded) (advisory, see inline)

Simplifications (1)

  • agent-service/src/agent/texera-agent.ts:605: the [ERROR] fallback and its #9120 test are now redundant (advisory, see inline)

Polish: 1 quick touch-up (see inline comments).

Verification trace

Checked against ai 7.0.173 at this head. Rejected calls (modifyOperator without summary, an unregistered tool, deleteOperator with {}) now read (failed) with the SDK's message and trigger no delegate run. A tool that throws keeps the raw Error: Stop during a delegate-mode executeOperator shows Error: {} on the next turn, and the suggested change at line 604 shows The operation was aborted. instead. bun test (344/344), tsc --noEmit and prettier pass at this head and with the change; CI builds still await approval.

Comment thread agent-service/src/agent/texera-agent.ts Resolved
Comment thread agent-service/src/agent/texera-agent.ts Resolved
@oliarmak-web

Copy link
Copy Markdown
Contributor Author

Addressed all four round-2 comments in 7cf765e6e:

  • Store thrown Error messages, or stringify non-Error throws, before persisting results. Regression tests cover Error, string and null throws, stored JSON, and the next model context.
  • Mark calls with no result as failed. A regression verifies a complete tool call with finish reason length never executes and is shown as failed on the following turn.
  • Remove the redundant [ERROR] history fallback and its obsolete test; keep classification in isErrorResult.
  • Rename the SDK-rejected modifyOperator test and correct the outdated no-result comments.

Validation: bun test (347 passed, 0 failed), bun run typecheck, bun run format:check, and git diff --check all pass. The PR description is updated.

@bobbai00, could you review the updated branch?

Comment written by OpenAI Codex on the account owner’s behalf.

@bobbai00 bobbai00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 4 resolved · 0 open · 2 new (2 new = 1 newly introduced · 1 late catch): all four round-2 findings are fixed; two optional touch-ups remain.

Simplifications (1)

  • agent-service/src/agent/util/context-utils.ts:153: a rejected call's whole input stays in every later prompt (advisory, see inline)

Polish: 1 quick touch-up (see inline comments).

Verification trace

Checked at this head against ai 7.0.173. Stop during a delegate-mode executeOperator now reaches the next turn as - executeOperator (failed) with The operation was aborted., a complete call under finish reason length reads (failed), and SDK-rejected calls are unchanged. Reverting either fix fails the new tests (2 and 4 failures). bun test (347/347), tsc --noEmit and prettier pass; CI builds still await approval.

@bobbai00
bobbai00 enabled auto-merge November 18, 2026 18:46
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.61%. Comparing base (7adc729) to head (7cf765e).
⚠️ Report is 23 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9259   +/-   ##
=========================================
  Coverage     91.61%   91.61%           
  Complexity     5047     5047           
=========================================
  Files          1284     1284           
  Lines         57036    57045    +9     
  Branches       7420     7420           
=========================================
+ Hits          52251    52260    +9     
  Misses         2914     2914           
  Partials       1871     1871           
Flag Coverage Δ *Carryforward flag
access-control-service 77.44% <ø> (ø) Carriedforward from 7adc729
agent-service 99.56% <100.00%> (+<0.01%) ⬆️
amber 85.34% <ø> (ø) Carriedforward from 7adc729
computing-unit-managing-service 64.05% <ø> (ø) Carriedforward from 7adc729
config-service 87.73% <ø> (ø) Carriedforward from 7adc729
file-service 82.16% <ø> (ø) Carriedforward from 7adc729
frontend 96.42% <ø> (ø) Carriedforward from 7adc729
notebook-migration-service 83.77% <ø> (ø) Carriedforward from 7adc729
pyamber 98.50% <ø> (ø) Carriedforward from 7adc729
workflow-compiling-service 78.30% <ø> (ø) Carriedforward from 7adc729

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bobbai00
bobbai00 added this pull request to the merge queue Nov 18, 2026
Merged via the queue into apache:main with commit af58667 Nov 18, 2026
27 checks passed
@oliarmak-web

Copy link
Copy Markdown
Contributor Author

Could you confirm which tests or agent workflows exercise #9259, and whether it has reached a release? If you have observed error-prefixed tool results being handled correctly because of this fix, could you share a concrete example or public reference?

Comment prepared with OpenAI Codex assistance and posted on the account owner’s behalf.

Ma77Ball pushed a commit to Ma77Ball/texera that referenced this pull request Nov 21, 2026
…pache#9259)

### What changes were proposed in this PR?

Tool failures returned as `[ERROR]` strings and SDK-generated
`tool-error` parts must be persisted as failures so subsequent agent
turns receive the correct status. This change builds stored results from
step content, matches results to calls by `toolCallId`, and reuses
normalized failure status to prevent delegate execution after rejected
modifications. A shared `isErrorResult` predicate keeps string
classification beside `createErrorResult`.

Thrown errors are stored as readable messages so they survive JSON
snapshots and appear in subsequent context. Calls without a recorded
result are marked failed. History formatting uses the normalized
`isError` flag.

Regression coverage includes error-prefixed output, SDK-rejected calls,
reordered results, throwing tools (Error, string and null values),
length-limited calls that never execute, and suppression of execution
after rejected modifications.

### Any related issues, documentation, discussions?

Closes apache#9120

Related: apache#9244, whose tool-history presentation relies on accurate
persisted failure status.

### How was this PR tested?

From `agent-service`:

- `bun test`: 347 passed, 0 failed
- `bun run typecheck`: passed
- `bun run format:check`: passed
- `git diff --check`: passed

The new behavior assertions reproduced the failures before the
production fix. Validation used Bun 1.3.3 and the repository’s frozen
lockfile. The full test run required local socket access for the server
tests. GitHub CI results remain separate from these local checks.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed tool calls are marked as succeeded (isError is always false)

6 participants