Skip to content

fix(errors): report true operation outcome, not false terminal failure — kill/remove + non-terminal tool errors (ENG-15627 §5b/G4) - #53

Merged
monac24 merged 6 commits into
boonfrom
eng-15627-operation-outcome-status
Jul 16, 2026
Merged

monac24 merged 6 commits into
boonfrom
eng-15627-operation-outcome-status

Conversation

@monac24

@monac24 monac24 commented Jul 16, 2026 •

Copy link
Copy Markdown

Related: ENG-15627 (§5b — operation-outcome vs session-state)
Supersedes #51 and #52 (consolidated into one reviewable unit).

What Problem This Solves

Two instances of the same lie: the runtime reports the mechanical outcome of an operation with no knowledge of the agent's intent or whether work actually continued — so the user sees a hard "failed" when nothing failed.

  1. Agent-requested process kill/remove → "⚠️ 🧰 Process failed." An agent intentionally, successfully tearing down a background session it started was reported as a failure.
  2. A tool error mid-turn while the agent is still working → "⚠️ ✉️ Message failed." When a (transient/middleware) tool error happens after the assistant already produced a reply and prior tools completed, core marks it non-terminal — but the banner still read terminal. This is the "message failed while the agent is still working in the background" report.

Why This Change Was Made

§5b — kill/remove (bash-tools.process.ts):

  • kill/remove success → details.status: "completed" (was "failed"); isToolResultError (the ⚠️-banner predicate) no longer fires.
  • SIGKILL fallback records the session as "killed" (agent-requested), not "failed".
  • Genuine failures (no pid, not backgrounded) still return failed.

G4 — non-terminal tool errors (payloads.ts):

  • The non-terminal decision (hasUserFacingAssistantReply && middlewareError) is computed once and drives both the visible text and the payload metadata (previously the metadata said non-terminal while the text said failed).
  • Non-terminal case renders a tool-name-free continuation marker: ↻ A step didn't complete, but I kept going (2 steps completed) — no ⚠️, no "failed", and crucially no leaked internal tool name (the "message" delivery tool is plumbing, meaningless to a user). The real intermediate content is the assistant's actual reply, already emitted alongside it.
  • Terminal failures (no reply, or non-middleware mutating failures) keep the existing ⚠️ <tool> failed banner.

Scoped: this fixes the two concrete customer-visible instances. The full OperationOutcome type (disposition/agency/terminality) and the subagent-still-working case are follow-ups.

User Impact

An agent tearing down its own process, or hitting a transient tool hiccup during an otherwise-successful turn, no longer emits a false "failed" to the user. Genuine failures are unchanged; group/channel silence and verbose raw-detail are unchanged.

Evidence

  • TDD RED→GREEN for every change, asserted against isToolResultError and the payload metadata — the exact predicates that drive the ⚠️ banner.
  • Full agents-tools (989), agents-embedded-agent (1536), and cron (1174) shards green; process + payloads suites green (96 combined). oxlint clean.

🤖 Generated with Claude Code


Summary by cubic

Fixes false “failed” banners by reporting the true outcome of operations. Agent-requested process teardown now shows success, and non-terminal tool errors render as a continuation status with correct completed-step counts, aligned with Linear ENG-15627 §5b/G4.

  • Bug Fixes
    • Process tool: kill/remove return details.status: "completed" on success; SIGKILL fallback records "killed" (not "failed"). poll/log on a killed session map to details.status: "completed". Genuine inability to terminate/remove still returns failed.
    • Non-terminal tool errors (after an assistant reply): show a tool-name-free continuation line — “↻ A step didn't complete, but I kept going (N steps completed)” — with no “⚠️” or “failed”. Verbose mode appends “: ”. The non-terminal decision drives both the text and the payload metadata.
    • Accurate step counts: count only successfully completed tools using per-call outcomes, including multiple-error turns (legacy falls back to length-1). Preserve each call’s errored flag across streaming via normalize-tool-metas; types and tests updated to cover this.

Written for commit bc99b01. Summary will update on new commits.

Review in cubic

monac24 and others added 3 commits July 15, 2026 18:38
… (ENG-15627 §5b)

The process tool's `kill` and `remove` success paths returned
details.status:"failed", and the SIGKILL fallback recorded the session as
"failed". isToolResultError treats "failed" as an error, so a deliberate,
successful agent-requested teardown rendered "⚠️ 🧰 Process failed" in the
channel — reporting the mechanical outcome with no knowledge of the agent's
intent (the operation-outcome-vs-session-state problem in the ENG-15627 spec
§5b).

- kill success → details.status:"completed" (was "failed"); a genuine
  inability to terminate still returns via failText earlier.
- remove success → details.status:"completed" (was "failed").
- SIGKILL fallback records the session as "killed" (agent-requested), not
  "failed", on both paths.

Tests assert isToolResultError(result) === false for successful kill/remove
(the exact predicate that drives the ⚠️ banner) and that the fallback records
status:"killed". The genuine-failure paths (no pid, not backgrounded) still
return failed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…s, not "⚠️ … failed" (ENG-15627 G4)

When a tool errored but the turn kept going — the assistant already produced a
reply and prior tools completed — buildEmbeddedRunPayloads still emitted a
terminal "⚠️ ✉️ Message failed" banner, even though core marked it
nonTerminalToolErrorWarning=true. That is the over-eager lie: it reads as a hard
failure while work actually continued (the "message failed while the agent is
still working" report).

Reframe the non-terminal case as a progress step that names what completed:
"↻ ✉️ Message didn't complete — continued (2 steps completed)". No ⚠️, no
"failed". The non-terminal decision is computed once and drives both the visible
text and the payload metadata (previously the metadata said non-terminal while
the text said failed). Terminal failures (no reply, or non-middleware mutating
failures) keep the existing "⚠️ <tool> failed" banner unchanged.

Reports the operation outcome as an intermediate status instead of a false
terminal error — the G4 half of the ENG-15627 error-conveying guardrails.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-15627 G4)

The intermediate-status line named the internal tool ('↻ ✉️ Message didn't
complete') — but the tool identity (esp. the 'message' delivery tool) is
plumbing, meaningless and misleading to a user. Replace with a tool-name-free
continuation marker: '↻ A step didn't complete, but I kept going (N steps
completed)'. The real intermediate content is the assistant reply already
emitted alongside it.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@claude

claude Bot commented Jul 16, 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.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/agents/bash-tools.process.ts Resolved
@monac24

monac24 commented Jul 16, 2026

Copy link
Copy Markdown
Author

🔍 PR Review Summary (Claude superpowers + Codex adversarial)

Reviewed at commit c44e4ce.

🟡 Findings posted inline

  • payloads.ts:590 — the non-terminal reframe drops the tool identity + errorSuffix even in /verbose / operator mode, a diagnosability regression vs. the old ⚠️ <tool> failed: <error>. Distinct from cubic's P2.

Cross-checked against existing review (not re-raised — both valid, worth addressing before merge)

  • cubic P1 (bash-tools.process.ts:649) — the new killed registry status is still mapped back to failed by the poll/log path (payloads.ts lines ~413/534: status === "completed" ? "completed" : "failed") and isToolResultError still classifies killed as an error. Confirmed valid: the action result is fixed (kill/remove now return completed), but a later process poll/log on that same session still renders it as failed. If the intent is "agent-requested aborts never read as terminal failure," those two consumers need the killed case too.
  • cubic P2 (payloads.ts:592) — completedToolCount: params.toolMetas.length overcounts because toolMetas can include the failed/pending call. Confirmed valid: the count should exclude the erroring tool.

Methodology

  • Traced the full non-terminal path: middlewareError origin (tool-result-middleware.ts:buildMiddlewareFailureResult — a post-processing failure, "Tool output unavailable due to post-processing error", NOT an underlying-operation failure) → isNonTerminalWarning gate → text/metadata emit → deliver.ts isError routing. Verified the reframe is correctly scoped to middlewareError only, so real mutating write/delete failures (which surface as status:"failed"/error, not middlewareError) are not mis-softened — a genuine strength.
  • Verified isError: true retention on the continuation payload is correct (it gates sendTextOnlyErrorPayloads delivery routing; the nonTerminalToolErrorWarning metadata is the real recoverable-marker), and that reply payloads do not feed back into the agent transcript, so the reframed text cannot mislead the model in later turns.
  • Codex adversarial half could not run: the local @openai/codex install is broken — its native binary (codex-darwin-arm64/vendor/.../codex) is missing, so codex exec (and even codex --version) fail with ENOENT. Not a security block, just a broken install. Fix locally with npm install -g @openai/codex. This review is Claude-only as a result.

Strengths

  • The middlewareError-only scoping is the right call — it precisely targets presentation-layer hiccups without softening real failures.
  • Keeping isError: true while adding nonTerminalToolErrorWarning preserves delivery semantics; only the copy changed.
  • Dropping the internal tool name from user-facing copy is correct.

— Generated with Claude Code

…bose detail (ENG-15627 §5b/G4)

Three review findings from the adversarial review of #53:

- cubic P1: a killed session polled/logged after the kill still rendered as
  "failed". Add mapFinishedStatusToResultStatus() so both the poll and log
  finished-session paths map registry status "killed" → result "completed"
  (agent-requested termination is not a terminal failure). "killed" is produced
  only by the agent-requested kill/remove paths in this registry, so this can't
  mask an unexpected kill.
- cubic P2: the "N steps completed" count used toolMetas.length, which includes
  the failing call (pushed unconditionally). Count completed prior steps as
  max(0, length - 1).
- review (verbose): the non-terminal reframe dropped the tool identity + error
  detail even in /verbose full. Append "<tool>: <error>" to the continuation
  line when warningPolicy.includeDetails is set, so operators keep the detail
  while the default user copy stays tool-name-free.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@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.

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

@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. Reviewed the full diff against ENG-15627 §5b/G4.

§5b (process kill/remove): kill/remove success now returns details.status:"completed", so isToolResultError (the exact ⚠️-banner predicate) no longer fires on a deliberate teardown. Verified against the predicate source — it keys on status==='failed'|...|'killed', so mapping to completed is the correct defuse. Genuine failures (no pid / not backgrounded) still return failed via failText before these paths. SIGKILL fallback records the finished-session as killed (agent-requested), and mapFinishedStatusToResultStatus collapses that to completed on later poll/log — so the registry's killed never leaks out as a tool-result status that would re-trip the banner. The killed-poll/log test locks that in.

G4 (non-terminal tool errors): the non-terminal decision (hasUserFacingAssistantReply && middlewareError) is computed once and drives both the visible text and the metadata flag — fixes the prior text/metadata disagreement. Continuation copy is tool-name-free (no leaked message/✉️ plumbing), no ⚠️, no "failed". Step count correctly excludes the failing call (toolMetas.length - 1). Verbose retains tool+error detail for operator debug.

Well-scoped, TDD RED→GREEN asserted against the real predicates, no secrets in history, no migrations/API-contract/backward-compat risk, tests green (989/1536/1174 shards + 96 combined), oxlint clean. The full OperationOutcome type + subagent-still-working case are correctly deferred as stated follow-ups. Ship it.

monac24 and others added 2 commits July 16, 2026 14:28
…(ENG-15627 G4 review)

Follow-up to the PR #53 review: the "(N steps completed)" count used
`toolMetas.length - 1`, which assumes exactly one failure. With more than one
transient/middleware error in a turn (e.g. bash ok, read errored, message
errored) it overcounted (said 2, only 1 completed).

Tag each pushed toolMeta with its `errored` outcome (handlers.tools.ts, from the
already-computed `isToolError`) and count only non-errored tools in payloads.ts.
Falls back to the previous `length - 1` only when no entry carries an `errored`
flag (legacy callers). Threaded `errored?` through the state, attempt, and
payload toolMeta types.

Test: three tools with two errored → asserts "1 step completed".

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…alization boundary (ENG-15627 G4 review)

The prior commit tagged each toolMeta with its `errored` outcome and counted
completed tools by it — but `runEmbeddedAttempt` re-normalizes toolMetas before
they reach `buildEmbeddedRunPayloads`, and that inline map dropped `errored`. So
in the real streaming flow the flag never survived and the payload builder
always hit the `length - 1` fallback (the very bug the flag was meant to fix).

Extract the normalization into `normalize-tool-metas.ts` (so the carried field
set is unit-tested) and carry `errored` forward. Behavior otherwise identical:
same tool-name filter, replaySafe default, async-task passthrough.

Test: normalizeToolMetas preserves `errored` for multi-failure turns, omits it
for legacy untagged entries, drops nameless entries, carries async fields.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@monac24
monac24 merged commit f87169e into boon Jul 16, 2026
146 of 147 checks passed
@monac24
monac24 deleted the eng-15627-operation-outcome-status branch July 16, 2026 21:59
monac24 added a commit that referenced this pull request Jul 16, 2026
Bump version to capture on top of boon.3:
- #53 (ENG-15627 §5b/G4): report true operation outcome, not false terminal
  failure — kill/remove + non-terminal tool errors.
- #54: surface the Bot Framework/Graph HTTP body on msteams send failures.

Base = 2026.6.11-boon.3 (1bfc850). No code change in this commit — version bump
only; the fixes are already merged on boon.

Co-authored-by: Claude Opus 4.8 <[email protected]>
monac24 added a commit that referenced this pull request Jul 16, 2026
The prepack changelog gate (scripts/package-changelog.mjs) requires a matching
## <version> section; the boon.4 version bump (#57) omitted it, failing
boon-release.yml at the pack step. Add the section (#53 operation-outcome, #54
msteams send-failure body). Verified locally: extractCurrentPackageChangelog finds it.

Co-authored-by: Claude Opus 4.8 <[email protected]>
insomnius pushed a commit that referenced this pull request Jul 22, 2026
…rail (ENG-16330) (#62)

* feat(errors): intelligent-messaging core — outcome-aware surfacing classifier + path trail (ENG-16330)

Pure-logic core (no wiring yet) for extending #53's outcome-awareness to the
recovered-non-zero-exec class: classifyToolSurfacing (passthrough | immediate |
buffer-recoverable), a per-turn error buffer that on turn-SUCCESS hides the recovered
⚠️ failed badges and emits a human-readable path trail, on turn-FAILURE flushes them
as real failures (no #53/#47/#48/#50 regression), and sanitizeGeneratedSessionName
(salty-shore → "a background command"). Model-facing isToolResultError untouched.

10/10 unit tests green. Handler/turn-close wiring (handleToolExecutionEnd buffer +
handleMessageEnd flush) follows in the next commit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* feat(errors): wire intelligent-messaging buffer into tool-end + turn-close (ENG-16330)

Wires the tested core into the streaming path:
- handlers.types: add per-turn `intelligentMessagingBuffer?: TurnErrorBuffer` to state (+ Pick).
- handleToolExecutionEnd: classifyToolSurfacing → a "buffer-recoverable" exec/tmux/process
  error is recorded to the per-turn buffer instead of emitting the live ⚠️ badge (terminal
  auth/quota/delivery errors + non-recoverable tools still emit immediately; model-facing
  isToolResultError unchanged).
- handleMessageEnd (turn close): resolve the buffer — success (normal stopReason + non-empty
  reply, confabulation guard) → emit a neutral path-trail note; failure → flush honest failure
  badges (no #53/#47/#48/#50 regression); clear buffer to prevent double-emit.

Verified: 107/107 tests green (10 new intelligent-messaging + 97 existing handler/media, no
regression); tsc + oxlint clean on all changed files.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(errors): don't skip after_tool_call hook when buffering a recoverable error (ENG-16330)

The buffer branch early-returned before the after_tool_call plugin-hook fire +
stream boundary, so a buffered recoverable exec/process error suppressed the hook
(broke after-tool-call.fires-once + owned-tool-runtime-contract tests). Gate ONLY
the emitToolResultOutput call on the buffering decision (if/else); the hook + stream
boundary now run in all cases. Buffering defers the channel badge only, never plugin hooks.

Verified: the 2 previously-failing agents-core tests + core + handler tests → 87/87 green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(errors): address cubic review on ENG-16330 turn-close buffer resolution (PR #62)

- P1: only resolve the buffer on a TERMINAL assistant outcome (stop/end_turn); a
  toolUse (in-progress) turn leaves the buffer intact so continuing tool steps + the
  real final reply still reach it — no premature failure flush mid-turn.
- P1: clear the buffer at the suppressVisibleAssistantOutput (commentary) early return
  so a commentary-phase turn's buffered errors can't leak into the next turn.
- P2: gate both path-trail + failure-badge emissions on ctx.shouldEmitToolOutput()
  (respect non-full verbosity / output-disabled).
- P2: success guard now accepts a media-only silent reply (cleanedText empty + hasMedia)
  as a valid successful turn, not a false failure.
- P2: add a test for the looksTerminal branch (recoverable tool + terminal signal
  unauthorized/forbidden/quota/invalid_api_key → "immediate", not buffered).

Verified: 88/88 green (core + the 2 prior-regression tests + handlers); tsc + oxlint clean.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* test(errors): cover tmux buffer-recoverable classification (cubic P2, PR #62)

tmux is in RECOVERABLE_TOOL_NAMES alongside exec/process but was untested;
add the missing classifyToolSurfacing case. 12/12 green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(errors): flush buffered failures on ALL terminal outcomes; keep buffer across commentary steps (cubic P1 round 2, PR #62)

Two round-2 P1s from cubic, both my prior over-correction:

- terminalOutcome was `stop || end_turn`, so error/abort/length/max_tokens turns
  silently DROPPED buffered non-zero tool failures. `toolUse` is the only CONTINUING
  outcome — flip to `stopReason !== "toolUse"` so every terminal result resolves the
  buffer; the turnSucceeded guard already picks success (path trail) vs. failure
  (honest badges).
- clearing the buffer at the suppressVisibleAssistantOutput (commentary) early return
  dropped earlier-in-turn recoverable errors before the real terminal reply could
  surface them. A commentary step is mid-turn, not a boundary — leave the buffer
  intact (same as the non-assistant/transcript-only return); only the terminal
  outcome resolves/clears it.

Verified: 89/89 green (core + handlers + the 2 prior-regression tests); tsc clean.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
convyusboy added a commit that referenced this pull request Jul 22, 2026
…inal status (ENG-16330)

The user-facing "⚠️ 🧰 Process: <session> failed" badge is built at
buildEmbeddedRunPayloads (payloads.ts) from ctx.state.lastToolError, NOT by
emitToolResultOutput. A backgrounded exec/process/tmux session that exits
non-zero but which the agent recovers from — the turn still produces a real
reply — rendered a terminal "failed" badge, giving the user the wrong
intuition ("the agent broke").

Widen shouldMarkNonTerminalToolErrorWarning from middlewareError-only to also
treat a recovered exec/bash/process/tmux error as non-terminal. The caller
already gates this on hasUserFacingAssistantReply, so the reframe only fires
when the turn actually produced a reply; on a reply-less genuine failure the
honest "⚠️ … failed" badge still surfaces (no #53/#47/#48/#50 regression).
write/edit/message stay strict — a failed write with a "done" reply is still
flagged as confabulation.

Reuses the shipped ENG-15627 G4 continuation note ("↻ A step didn't complete,
but I kept going"); no new copy, no raw generated session names.

Supersedes the buffer approach in PR #62, which intercepted emitToolResultOutput
(live streamed output) — a different sink from the badge, so the badge was
never reached.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
convyusboy added a commit that referenced this pull request Jul 23, 2026
…inal status (ENG-16330) (#64)

* fix(errors): reframe recovered exec/process/tmux failures as non-terminal status (ENG-16330)

The user-facing "⚠️ 🧰 Process: <session> failed" badge is built at
buildEmbeddedRunPayloads (payloads.ts) from ctx.state.lastToolError, NOT by
emitToolResultOutput. A backgrounded exec/process/tmux session that exits
non-zero but which the agent recovers from — the turn still produces a real
reply — rendered a terminal "failed" badge, giving the user the wrong
intuition ("the agent broke").

Widen shouldMarkNonTerminalToolErrorWarning from middlewareError-only to also
treat a recovered exec/bash/process/tmux error as non-terminal. The caller
already gates this on hasUserFacingAssistantReply, so the reframe only fires
when the turn actually produced a reply; on a reply-less genuine failure the
honest "⚠️ … failed" badge still surfaces (no #53/#47/#48/#50 regression).
write/edit/message stay strict — a failed write with a "done" reply is still
flagged as confabulation.

Reuses the shipped ENG-15627 G4 continuation note ("↻ A step didn't complete,
but I kept going"); no new copy, no raw generated session names.

Supersedes the buffer approach in PR #62, which intercepted emitToolResultOutput
(live streamed output) — a different sink from the badge, so the badge was
never reached.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(errors): drop inert tmux from recoverable exec class (ENG-16330, cubic P2)

tmux is neither in MUTATING_TOOL_NAMES nor exec-like, so resolveToolErrorWarningPolicy
already sets showWarning=false (no badge at all) once a reply exists — it never reached
shouldMarkNonTerminalToolErrorWarning. Listing it was dead code implying a path that
never fires. Remove it and document why it's intentionally absent. Recovered
exec/bash/process reframe unchanged; 60/60 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* revert(errors): unwind #62 buffer/path-trail; keep single payloads.ts reframe (ENG-16330)

#62 (merged) buffered the emitToolResultOutput call and added a turn-close '🔧
Recovered…' path-trail note — but that is a DIFFERENT sink from the actual badge.
The '⚠️ 🧰 Process: <session> failed' badge is built in buildEmbeddedRunPayloads
(payloads.ts) from ctx.state.lastToolError, which handleToolExecutionEnd still sets
unconditionally regardless of the buffer. So on boon today the badge STILL fires
alongside #62's new note — the user gets both, and the headline symptom is unfixed.

This PR's payloads.ts reframe fixes the real sink. Keeping #62's machinery on top
would emit two redundant recovery notes (🔧 + ↻) and leaves two overlapping paths
for one behavior. Per one-canonical-path policy, unwind #62:
- delete src/agents/intelligent-messaging.ts + its test
- restore the 3 handler files (messages/tools/types) to pre-#62 state

Net result: one seam — shouldMarkNonTerminalToolErrorWarning reframes recovered
exec/bash/process errors on a successful turn into the shipped G4 note; reply-less
genuine failures keep the honest badge; write/edit/message stay strict.

60/60 payloads.errors + 69/69 handlers.tools green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

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.

1 participant