Repository navigation
fix(native-chat): stop a collapsed run claiming success when a tool call failed - #21151
Conversation
…all failed A settled activity group drew its completion mark whenever no call in it was `running`. That is not a success test: a tool call is `running`, `completed` or `failed`, so a run whose call failed had nothing running, took the mark, and asserted success over a failure the reader could only find by expanding the run. Success is now stated rather than inferred. `nativeChatToolRunSucceeded` grants the mark only to a run that is settled, has nothing still running, and has no failed call — a call's own `failed` verdict or an error result, the same composite test the task-list, edit-card and ask-row readers already use. A call with no lifecycle state is neither, so legacy transcripts still settle. A collapsed run that did contain failures now says so in the header, as a quiet `N failed` in the header's own mono type with a spoken `Failed tool calls: N`. Text only: a tool error is routine work, so no destructive tint and no swapped glyph. The count is taken over every call in the run, not the latest.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change adds shared outcome evaluation for native chat tool runs. It counts failed calls from lifecycle and result data, avoids double-counting, and reports success only for settled runs without failures. The collapsed header now shows localized failure counts and displays a completion check only for successful runs. English strings and tests cover the new behavior. Priority: ⬇️ Low Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to The collapsed tool-run status change has no established remaining correctness or availability risk and is ready to merge after normal checks. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (2 skipped: 2 unsupported.) Full details: Description checkExplanation The description explains the bug, mechanism, user-visible behavior, testing, and visual proof. However, it omits the required linked issue, formal template sections, review checklist, and several required checklist confirmations. Resolution Add the required issue reference under “Linked Issue” using “Fixes #...”. Add or map content to the template sections, complete the Testing, Review, Agent skill upstream boundary, Notes, and Checklist sections, and confirm the required checks or state that CI will cover them.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Success is now stated, not inferred — the collapsed run header's
!hasRunningCalltick heuristic is replaced bynativeChatToolRunSucceeded, which grants the mark only to a run that is settled, has nothing running, and has no failed call.failedis neither running nor success, which is exactly the defect this closes. - Failure detection reuses the existing composite test —
countFailedToolCallspairs blocks withpairToolBlocksand treatscall.state === 'failed' || result?.isError === trueas a failure, matching the task-list, edit-card, and ask-row readers. State-less legacy calls still settle as before. - Header reports
N failed— counted over every call, not just the latest, rendered outside the truncating member list so a narrow pane cannot hide it, with a spokenFailed tool calls: N. Deliberately quiet text (no destructive tint, no swapped glyph). - New shared module + tests —
src/shared/native-chat-tool-run-outcome.tsand its unit tests; the existing failed-run component test was repurposed from asserting the buggy check to refusing it, and a clean-run positive control was added. - i18n —
components.native-chat.tool.failedCount/failedCallsLabeladded to the shared copy fallbacks, the runtime catalog, anden.json.
I ran the new shared unit tests plus the modified component test (55 passing) and the full native-chat renderer suite (161 files / 1600 passing). The PR's ablation shows the two behavioral tests fail on the base, so they pin the defect rather than merely passing at head.
A couple of non-blocking observations:
failedCallCountis not gated bystructuredActivityUi, unlike the check and category glyph beside it, soNativeChatResolvedView(showTurnStatus={false}) now surfacesN failed. That reads as intentional — failure should surface even where the done-mark is hidden — but no test coversstructuredActivityUi={false}in either direction.pairToolBlocksruns twice per render (once insidenativeChatToolRunSucceeded, once forcountFailedToolCalls). Negligible for real run sizes, but it is a duplicated O(n) pass if this ever lands in a hot path.- Mobile's
ToolRundraws no completion tick at all, so the false-success bug does not exist there; no parity follow-up is needed.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
The new Math.max failure count is exact for homogeneous runs but undercounts a run that mixes structured (state-bearing) and legacy (state-less) calls — a shape adopted / handed-off sessions can produce. The success verdict is unaffected (a real failure always pushes the count ≥ 1, so the tick is still withheld); only the new N failed badge under-reports.
Reviewed changes
- Outcome helpers consolidated —
countFailedToolCallsandnativeChatToolRunSucceededare replaced by a singlenativeChatToolRunOutcomereturning{ succeeded, failedCallCount }. - FIFO pairing dropped for a single pass — failure counting no longer re-pairs blocks with
pairToolBlocks; it talliesstate === 'failed'calls andisErrorresults separately and collapses them withMath.max, which fixes the mispairing that double-counted a failed call whose result block is omitted. - Tests rewritten against the new function — the two prior suites are merged, and a regression case for the omitted-result mispairing is added.
- Component and comment references updated to the renamed import and function.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // Structured lanes carry both signals for one failure; legacy lanes carry only the result. | ||
| const failedCallCount = Math.max(failedStateCount, errorResultCount) |
There was a problem hiding this comment.
Math.max assumes a run is homogeneous — either every call carries lifecycle state (structured lanes) or none do (legacy lanes). That is not true once a session mixes the two: legacyItemBody keeps multi-block legacy messages as state-less calls + isError results, while adopted/handed-off epochs append live structured items into the same journal and foldToolMessages merges them into one run. When a structured failed call has no result block (f0) and a state-less call has an error result (s), max(failedStateCount, errorResultCount) is short by min(f0, s) — e.g. it reports 1 failed for two failures. The tick verdict is safe (a real failure always makes the count ≥ 1), but the new badge can under-report the exact thing this PR added.
Technical details
# `Math.max` undercounts a mixed-lane run
## Affected sites
- `src/shared/native-chat-tool-run-outcome.ts:41-42` — `Math.max(failedStateCount, errorResultCount)` is exact only when `failedStateCount === 0` or `errorResultCount >= failedStateCount`, i.e. when no failed-state call is result-less alongside a state-less error result.
## Why the invariant breaks
- `journal-legacy-import.ts:230-259` — a single-block message becomes a state-bearing `kind:'tool-call'`; a multi-block message stays `kind:'message'` with raw state-less calls and `isError` results.
- `structured-agent-session-projection.ts:54-80` — emits the `tool-result` only inside `body.output ? [...] : []`, so a failed structured call with no output contributes to `failedStateCount` but not `errorResultCount`.
- `f0` producers: `structured-agent-session-dead-generation-settlement.ts:154-157` (running → failed, spreads the body unchanged, running calls have no output), `codex-structured-item-translation.ts:106-108,130,183` (failed command / fileChange / mcp with no output).
- Mixing: `structured-agent-session-adopted-import.ts:86` (`replaceEpochItems('legacy_import', …)`) then live structured items appended to the same epoch; `structured-agent-session-message-projection.ts:18-19` sends every item through `projectStructuredItemsToNativeChat`; `native-chat-tool-fold.ts:98-112` folds tool-only rows into the preceding assistant run.
## Concrete sequence
`[text, tool-call(a, no state), tool-call(b, no state), tool-result(error), tool-result(ok), tool-call(c, state:'failed')]`
source: two blocks fold from the legacy message, one `kind:'tool-call'` failed with no output from the structured lane.
`failedStateCount = 1`, `errorResultCount = 1` → reports `1`, true failures `2` (the state-less call that owns the error result, plus `c`).
## Required outcome
A state-bearing failed call is a failure even without a result; a state-less call's error result is a failure even alongside state-bearing calls. The count must reflect both without collapsing one into the other.
## Considered alternative
Reverting to `pairToolBlocks` per-pair counting restores this mixed case but reintroduces the omitted-result overcount the commit was written to remove (`[call a completed, call b failed, result error]` → 2). Using `callId` where present, or attributing error results only to state-less calls, would avoid both.
## Open question for the human
Is the mixed (legacy-import + live structured) lane expected to render in the same run, or is the two-shape split guaranteed never to fold into one header? If it can, a test built from `projectStructuredItemsToNativeChat` + `foldToolMessages` would pin it.
Electron QA — collapsed tool-run outcomes (PR head
|
Review status: readyReviewed through a fix loop and a clean independent follow-up at
Remaining QA gap: the Electron lane could not create a real structured SDK session to capture the successful The PR description has been updated to match the final mechanism. The branch is clean, matches the remote PR head, and is ready to merge. |
…all failed (stablyai#21151) * fix(native-chat): stop a collapsed run claiming success when a tool call failed A settled activity group drew its completion mark whenever no call in it was `running`. That is not a success test: a tool call is `running`, `completed` or `failed`, so a run whose call failed had nothing running, took the mark, and asserted success over a failure the reader could only find by expanding the run. Success is now stated rather than inferred. `nativeChatToolRunSucceeded` grants the mark only to a run that is settled, has nothing still running, and has no failed call — a call's own `failed` verdict or an error result, the same composite test the task-list, edit-card and ask-row readers already use. A call with no lifecycle state is neither, so legacy transcripts still settle. A collapsed run that did contain failures now says so in the header, as a quiet `N failed` in the header's own mono type with a spoken `Failed tool calls: N`. Text only: a tool error is routine work, so no destructive tint and no swapped glyph. The count is taken over every call in the run, not the latest. * fix(native-chat): count failed tool calls without result mispairing




The bug
A settled activity group drew its completion tick whenever no call in it was
running:stateis'running' | 'completed' | 'failed', so!runningis not success. A run whose tool callfailed had nothing running, took the tick, and asserted success over a failure the reader could
only find by expanding the run. That is what made a real user's failed background command look fine
at a glance.
The mechanism
Success is now stated rather than inferred.
nativeChatToolRunOutcome(newsrc/shared/native-chat-tool-run-outcome.ts) scans the run once for explicit failed lifecyclestates, error results, and calls still marked running. It uses the larger failure count because
structured producers emit both a failed state and an error result for the same call, while older
transcripts may carry only result errors. Counting those signals directly also prevents an
outputless completed call from taking the next call's error result through FIFO pairing.
The completion mark is granted only when the run is settled, has nothing still running, and has no
failure evidence. A call carrying no lifecycle
stateis neither a failure nor in flight, solegacy transcripts still settle as before. The collapsed header additionally reports
N failed,with a spoken
Failed tool calls: N. Text only, in the header's own muted mono type: a tool erroris routine work, so no destructive tint and no swapped glyph. Tool calls model no stopped state, so
none is invented here.
Ablation
The base is
fbe7b194b8(origin/mainat the time, and this branch's parent).Arm A — all four source files reverted to
origin/main, the new shared module removed from disk,tests kept at branch HEAD:
The 41 passing tests include the new
says nothing and keeps the mark when every call in the run succeeded— the positive control. It passes on main too, so the two red tests are catching thedefect rather than the suite merely being sensitive to one lever.
Arm B — everything at HEAD:
Test Files 3 passed (3) / Tests 70 passed (70).Before / after
Rendered from the real component with the real token stylesheet — the left panel is
origin/main's component verbatim, the right is this branch's, same blocks, same page.Colours verified with
getComputedStyle, not by eye:1 failed2 failedThe
N failedtext computes torgb(161, 161, 161)at11px— identical to thetext-muted-foregroundprobe and deliberately not thetext-destructivetoken, which resolvesto
rgb(255, 101, 104)on the same page. Chromium's accessible-name computation reports thecollapsed buttons as
… Failed tool calls: 1/… Failed tool calls: 2, so the failure isannounced and not only seen.
Gates
pnpm test(3 explicit files):Test Files 3 passed (3) / Tests 70 passed (70)pnpm test src/renderer/src/components/native-chat …:Test Files 162 passed (162) / Tests 1612 passed (1612)pnpm tc: exit 0pnpm run check:code-quality:changed:0 new finding(s) across 5 changed file(s)on all seven sub-gatesverify:localization-catalog,verify:localization-runtime-catalog,verify:localization-extraction,verify:localization-coverage,check:max-lines-ratchet: all exit 0. The two new keys were syncedwith
pnpm run sync:localization-runtime-catalogand added toen.json.NativeChatToolRun.tsxmeasured with a used-symbol probe: clean at +60 appended lines, tripsmax-linesat +80. No ratchet touched, no disable added.git diff origin/main...HEAD --name-only -- pnpm-lock.yaml mobile/pnpm-lock.yamlis empty.Note
#20519 also modifies
NativeChatToolRun.tsx(it adds abackgroundTasksprop and astandaloneRowslist). It does not touch the tick logic, so expect a textual conflict for whichever of the two lands
second; it is not resolved here.