Skip to content

fix(agents): derive legacy tool counts from surfaced failures - #208

Merged
Willi8910 merged 2 commits into
boonfrom
williamlie/eng-19407-honest-tool-completion-counts
Sep 8, 2026
Merged

Willi8910 merged 2 commits into
boonfrom
williamlie/eng-19407-honest-tool-completion-counts

Conversation

@Willi8910

@Willi8910 Willi8910 commented Sep 8, 2026 •

Copy link
Copy Markdown

What Problem This Solves

The tool-failure digest assumed exactly one failure whenever a producer supplied tool metadata without per-call outcome flags. With two surfaced failures across three such records, the user-facing note incorrectly said one step did not finish and that 2 of 3 steps completed.

Current producer inventory:

  • src/agents/embedded-agent-subscribe.handlers.tools.ts records errored and status: "blocked" for embedded-runner calls; run/normalize-tool-metas.ts preserves both fields before payload construction.
  • extensions/codex/src/app-server/event-projector.ts records terminal errored and blocked outcomes for Codex app-server calls.
  • src/agents/cli-runner.ts calls the shared payload builder with empty toolMetas and no failure record for source-reply mirroring, so that path cannot create a failure digest.
  • Outcome-less metadata remains only at compatibility boundaries: direct buildEmbeddedRunPayloads callers that supply legacy lastToolError/toolFailures, and normalized attempt records received from older or custom sources that omitted outcome flags.

Why This Change Was Made

The digest already owns the filtered list of failures that are safe and appropriate to surface. For outcome-less metadata, it now derives the failed count from that evidence, infers a total large enough to represent missing metadata, and computes completed steps from those values. Explicit errored and blocked-call behavior is unchanged.

The public ToolFailureDigest shape is unchanged, so channel renderers such as AnyChat receive internally consistent counts without a paired compatibility change.

User Impact

A legacy turn with two recorded failures and three tool records now reports two unfinished steps and 1 of 3 completed. A turn with no surfaced failures still produces no digest or step note.

Evidence

TDD RED before the implementation:

  • Digest expected 1 completed but received 2.
  • Missing metadata expected total 2 but received 0.
  • Payload expected two unfinished steps but rendered one and claimed 2 of 3 completed.

Fresh verification:

  • node scripts/run-vitest.mjs run src/agents/tool-failure-digest.test.ts src/agents/embedded-agent-runner/run/payloads.errors.test.ts — 90 tests passed.
  • node scripts/run-oxlint.mjs on the three touched files — passed.
  • oxfmt check on the three touched files — passed.
  • Core production tsgo — passed.
  • Core test tsgo — passed.
  • git diff --check — passed.

Linear: https://linear.app/getboon/issue/ENG-19407/openclaw-countcompletedtools-fabricates-one-step-didnt-finish-on-a


Summary by cubic

Fixes the tool-failure digest so legacy producer metadata without per-call outcome flags no longer fabricates a completion count. Previously the digest assumed exactly one failure (length - 1) whenever no errored flag was present, which could label a fully clean turn as having one unfinished step; it now derives the failed count from the surfaced failure list and computes completed steps from that.

Behavior

  • Total tool count is inferred as the larger of the metadata count and the surfaced failure count; completed is total minus surfaced failures.
  • Explicit errored or blocked outcomes keep their existing behavior.
  • The public ToolFailureDigest shape is unchanged, so channel renderers get consistent counts without a paired compatibility change.
  • A legacy turn with two failures and three tool records now reports "2 steps didn't finish" and "1 of 3 steps completed"; a turn with no failures still emits no digest.

Addresses ENG-19407.

Written for commit 1cbe4b1. Summary will update on new commits.

Review in cubic

@Willi8910
Willi8910 requested a review from a team September 8, 2026 06:36
@claude

claude Bot commented Sep 8, 2026

Copy link
Copy Markdown

Claude Code is working…

I'll analyze this and get back to you.

View job run

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cubic analysis

No issues found across 3 files

Linked issue analysis

Linked issue: ENG-19407: [openclaw] countCompletedTools fabricates "one step didn't finish" on a fully clean turn

Status Acceptance criteria Notes
⚠️ Enumerate which producers reach countCompletedTools without setting errored on any meta The PR identifies embedded-runner and Codex producers as explicit-outcome producers and describes remaining compatibility-boundary shapes, but it does not clearly enumerate the specific outcome-less producers.
⚠️ A turn with zero recorded failures never yields a step-note claiming a step didn't finish The PR explicitly claims that turns with no surfaced failures produce no digest or step note, but the shown diff does not add a direct zero-failure step-note regression test.
✅ tool-failure-digest.test.ts covers the no-errored producer path explicitly The added test supplies three tool metadata records without errored flags and verifies counts derived from two surfaced failures; a second test covers empty metadata.

Re-trigger cubic

@Willi8910

Copy link
Copy Markdown
Author

@cubic-dev-ai Re review feedback (#5138311514, addressed in 1cbe4b1): the PR now enumerates each current producer and the remaining outcome-less compatibility paths. Added a direct payload-boundary regression proving outcome-less metadata with zero recorded failures emits no step note; focused coverage is now 90 passing tests.

@gandalfboon gandalfboon Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved — clean fix.

Bug: legacy toolMetas.length - 1 fallback fabricated one failure whenever a producer omitted per-call outcomes, so a turn with 2 surfaced failures across 3 records reported "1 step didn't finish · 2 of 3 completed" — wrong on both counts.

Fix derives from the surfaced-failure list already owned by the digest: totalToolCount = max(toolMetas.length, surfacedFailureCount), completedToolCount = total − surfaced. Explicit errored/status: blocked outcomes take the same branch as before.

Regression check:

  • Public ToolFailureDigest shape unchanged → AnyChat and other channel renderers get consistent counts without a paired change.
  • Only in-tree consumer is buildNonTerminalToolStatusText, which is arithmetic over the pair — internally consistent.
  • didNotFinishCount = max(1, …) floor is preserved, so the note still names at least one step for empty-metadata legacy callers.
  • Verified locally: node scripts/run-vitest.mjs run src/agents/tool-failure-digest.test.ts src/agents/embedded-agent-runner/run/payloads.errors.test.ts — 90 passed.
  • CI green across all required shards.

Ship it.

@Willi8910
Willi8910 merged commit 841552f into boon Sep 8, 2026
149 of 150 checks passed
@Willi8910
Willi8910 deleted the williamlie/eng-19407-honest-tool-completion-counts branch September 8, 2026 15:03
william-antoline-boon added a commit that referenced this pull request Sep 9, 2026
…211)

## Release 2026.6.11-boon.39

Surfaces a swallowed before_tool_call hook failure to Sentry + the durable
audit trace so the ENG-19492 incident class is diagnosable after the fact.

### Contents (merged onto `boon` since boon.38)
- **#209 (ENG-19492)** — emit a `before_tool_call_hook_failed` observability
  hook (genuine handler exception only, never a policy veto), paged by
  sentry-monitor, and thread the real error text into boon-core's audit_trace
  as an optional `detail` field. Requires boon-core companion getboon/boon#14629
  (merged + live) which accepts the new field. Non-hook pipeline failures are
  classified separately.
- **#208** — derive legacy tool counts from surfaced failures.

### Release prep
- Root version boon.38 -> boon.39; lockstep regenerated (211 files:
  135 plugin package.json + 70 npm-shrinkwrap.json + SDK/config baselines).
  All release-preflight --check steps pass.
- CHANGELOG.md `## 2026.6.11-boon.39` section added.

### After merge
Tag `v2026.6.11-boon.39` -> `boon-release.yml`. Fleet is pinned to boon.36, so
a roll also picks up boon.37 (#194-#198) and boon.38 (#201, #202, #205).


Claude-Session: https://claude.ai/code/session_01AMjtZJAWLVBwa5Dtc4oNog

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

3 participants