Skip to content

fix(errors): intelligent messaging — outcome-aware surfacing + path trail (ENG-16330) - #62

Merged
insomnius merged 6 commits into
boonfrom
eng-16330-intelligent-messaging
Jul 22, 2026
Merged

insomnius merged 6 commits into
boonfrom
eng-16330-intelligent-messaging

Conversation

@monac24

@monac24 monac24 commented Jul 21, 2026 •

Copy link
Copy Markdown

What

Extends the error-guardrails work (#53/ENG-15627 §5b + #47/#48 + #50) to the recovered-non-zero-exec class: a backgrounded exec/tmux/process session that exits non-zero but which the agent recovers from (the turn continues and produces a real answer) no longer renders a misleading ⚠️ 🧰 Process: <session-name> failed to the channel. Instead the user sees an accurate path-trail note ("🔧 Recovered from a file lookup and continued").

Why

Observed live post-boon.5 (error-guardrails active): gandalf ⚠️ Process: salty-shore failed, power-solutions triage find … failed. salty-* are auto-generated bg-exec session names. The user gets the wrong intuition ("the agent broke") when the truth is "a sub-step hit a recoverable error; the agent handled it and is on-path." #53 already suppressed this for the process kill/remove case; this reaches the class it didn't.

How

New src/agents/intelligent-messaging.ts (pure, unit-tested):

  • classifyToolSurfacing → passthrough | immediate | buffer-recoverable. Recoverable = exec/tmux/process error that is not terminal; terminal signals (auth/quota/delivery: allocation_exhausted, unauthorized, …) surface immediately, never buffered.
  • createTurnErrorBuffer — per-turn buffer; .resolve({turnSucceeded}) → on success hides the badges + returns a path trail, on failure flushes them as honest failure badges.
  • sanitizeGeneratedSessionName — salty-shore → "a background command" (no raw generated names in user-facing text).

Wiring:

Model-facing isToolResultError is unchanged — the model still sees the true non-zero exit; only the channel-surfacing layer changes.

Tests

  • intelligent-messaging.test.ts: 10 unit tests (classifier, buffer success/failure/empty, name sanitization, trail synthesis).
  • Full run: 107/107 green (10 new + 97 existing handlers.tools + handlers.tools.media — no regression). tsc + oxlint clean on all changed files.

Follow-ups

  • Batch into the next boon.N so it reaches the fleet.
  • Design doc: gandalf-manager docs/superpowers/specs/2026-07-20-intelligent-messaging-design.md.

🤖 Generated with Claude Code


Summary by cubic

Outcome-aware intelligent messaging: recovered non‑zero exec/tmux/process errors are buffered and, on a successful turn, shown as a short path‑trail note instead of a ⚠️ … failed badge. Terminal errors still surface immediately; model-facing error semantics are unchanged.

  • New Features

    • Added intelligent-messaging core (classifier, per-turn buffer, path‑trail synthesis) and sanitized generated session names in user-facing text.
    • Integrated into handlers: buffer recoverable errors in handleToolExecutionEnd; resolve in handleMessageEnd on all terminal outcomes (anything except toolUse), count non-empty text or media‑only replies as success, and gate emissions via ctx.shouldEmitToolOutput().
    • Meets ENG-16330: successful turns avoid false failure badges; failed turns flush honest badges.
  • Bug Fixes

    • Buffering defers only the channel badge; it no longer skips after_tool_call hooks or the stream boundary.
    • Avoid drops and leaks: ignore non-assistant/transcript‑only and toolUse message_end events; keep the buffer across suppressed‑output commentary steps; resolve on all terminal outcomes (including error/abort/length/max_tokens) and clear after resolution.

Written for commit 3488c91. Summary will update on new commits.

Review in cubic

monac24 and others added 2 commits July 20, 2026 16:46
…assifier + 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]>
…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]>
@claude

claude Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@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

All reported issues were addressed across 5 files

Linked issue analysis

Linked issue: ENG-16330: Intelligent Messaging — outcome-aware status (improve on error guardrails)

Status Acceptance criteria Notes
✅ Successful turn with recovered non-terminal sub-failure shows success to the user (no ⚠️ failed badge); instead a short path-trail note is emitted. Code buffers recoverable exec/process/tmux errors (classifyToolSurfacing → "buffer-recoverable"), records them per-turn, and at turn close emits a synthesized path-trail when the turnSucceeded guard is true. Unit tests exercise the buffer → success path.
✅ A genuinely failed turn still shows an honest, coded failure message (no regression of prior guardrails). Buffered entries are flushed as failure badges when resolve({turnSucceeded: false}) is used; the handler emits those badges on failure, preserving honest failure surfacing.
⚠️ Confabulated success (agent claims success but expected tool never ran/errored) remains flagged (confabulation guard preserved). The PR includes a confabulation guard at turn-close (requires a non-empty final reply and stopReason) and states model-facing error semantics are unchanged. However, this change focuses on buffering/re-surfacing of recoverable errors; there is no new explicit confabulation-detection logic in the added module — it appears to rely on existing guardrails. Evidence for preservation is present but indirect, so this is partly verified here.
✅ No internal generated session names or raw filesystem/tool error strings leak into the user-facing reply. Synthesized path-trail sanitizes generated session names (replaces adjective-noun names with a generic phrase) and reduces step summaries to user-friendly phrases; tests assert sanitized output and absence of raw session names.

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

…able 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]>

@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 — traces cleanly to ENG-16330 and fulfills the outcome-aware-suppression goal.

Correctness

  • classifyToolSurfacing buffers only recoverable exec/tmux/process errors; terminal signals (allocation_exhausted/unauthorized/quota/…) correctly short-circuit to immediate, so auth/quota/delivery failures are never silenced.
  • handleMessageEnd resolution has a sound confabulation guard (normal stopReason and non-empty final reply), and clears the buffer to prevent double-emit on a later message_end. cleanedText/assistantMessage are in scope at the insertion point.
  • Model-facing isToolResultError left unchanged — the model still sees the true non-zero exit; only the channel badge defers.

Regression safety

  • Only the emitToolResultOutput call is gated; the after_tool_call hook + stream boundary still fire in both branches (the 3rd commit specifically fixes the hook-suppression regression, restoring after-tool-call.fires-once + owned-tool-runtime-contract).
  • No #53/#47/#48/#50 regression: failed turns flush honest failure badges.

Tests / quality

  • 10 new pure-logic unit tests cover classifier, buffer success/failure/empty, name sanitization, trail synthesis; 107/107 green, tsc + oxlint clean. No secrets in diff or commit history, no migrations, no breaking API changes.

Minor (non-blocking): in message_end mode the path-trail note emits just before onBlockReplyFlush completes the final chunk — cosmetic ordering only since it's a tool-status surface, not the block reply.

Good code — ship it.

monac24 and others added 2 commits July 20, 2026 17:35
…lution (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]>
… 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]>

@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 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

…uffer 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]>
@insomnius

Copy link
Copy Markdown

✅ End-to-end tested live on a Boon trial host

Built this branch as openclaw-2026.6.11-boon.6 (full npm pack, PR code verified compiled into the dist bundle), deployed it to a Boon trial EC2 host (boon-agent7-pilot, upgraded boon.5 → boon.6), and exercised the recovered-non-zero path through the real Slack channel surface.

Repro

Prompt to the agent in Slack:

start a backgrounded exec session (background:true) running ls /definitely-not-here-xyz — it exits non-zero. When that background job fails, recover and tell me the current working directory, then confirm you moved past the failed step.

Result (verbatim from the channel)

The agent backgrounded the exec (auto-named session sharp-glade), the poll returned a non-zero exit (code 2), it recovered, and the turn closed with:

🔧 Recovered from a background step and continued.
  • ✅ Path-trail note emitted on the successful turn (🔧 Recovered from a background step and continued.).
  • ✅ No misleading ⚠️ 🧰 … failed badge surfaced — the exact false-failure signal this PR targets.
  • ✅ Generated session name sanitized — the raw sharp-glade name is not leaked into the user-facing line (renders "a background step").
  • ✅ Model still saw the true non-zero exit (agent explicitly acknowledged "exit code 2") — model-facing error semantics unchanged, as designed.

Notes

  • The path-trail line and the flushed failure badge are both gated behind the tool-output surface (effective verboseLevel: full); confirmed by flipping the host to full and re-running. The badge-suppression itself holds regardless of verbose.
  • Journal-level inspection on the host confirmed the buffer was populated via the exec(background) → process(poll, isError, exit 2) path and classified buffer-recoverable, then resolved to a path trail on the successful turn — matching the intended design.

Unrelated CI note

security-fast is red due to 4 pre-existing production-dependency advisories (tar CRITICAL GHSA-23hp-3jrh-7fpw, axios/brace-expansion/tar HIGH). This PR changes only src/agents/*.ts and adds a test — no package.json/lockfile changes — so these advisories are inherited from the boon base branch, not introduced here. All code/type/lint/contract checks pass.

@insomnius insomnius 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. End-to-end tested live on a Boon trial host (boon.6): recovered non-zero backgrounded exec surfaces the 🔧 path-trail note instead of a false ⚠️ failed badge, generated session name sanitized, model still sees the true non-zero exit. All bot review feedback (cubic P1/P2) addressed; gandalfboon approved. security-fast is red only on pre-existing base dependency advisories (tar/axios/brace-expansion) — this PR changes only src/agents/*.ts + a test, no manifest/lockfile changes.

@insomnius
insomnius merged commit c33dabb into boon Jul 22, 2026
147 of 150 checks passed
@insomnius
insomnius deleted the eng-16330-intelligent-messaging branch July 22, 2026 13:30
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 22, 2026
… 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]>
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.

2 participants