Skip to content

fix(sentry-monitor): classify tool-call errors and fix release tag - #144

Merged
convyusboy merged 4 commits into
boonfrom
ridho/openclaw-fleet-tool-error-classification
Aug 22, 2026
Merged

convyusboy merged 4 commits into
boonfrom
ridho/openclaw-fleet-tool-error-classification

Conversation

@convyusboy

@convyusboy convyusboy commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Four Sentry groups on the OpenClaw fleet were long-standing paging noise:
tool-call validation failures, and a session-tree visibility denial, all
merged into grab-bag issues that hid real signal. Digging into the actual
event data (not just issue titles) showed the underlying causes were
different from what they looked like at a glance, and none of the four
original groups had produced an event in the prior 3 days once the real
root cause was traced.

Why This Change Was Made

  • sentry-monitor's release tag was wrong. It reported this
    plugin's own pinned manifest version (2026.5.18, never bumped), not
    the running app version, so 3624+ events across 90 days all carried one
    release tag and per-deploy regression tracking was silently broken.
    Adds hostVersion to the plugin API, sourced from the real app version.
  • A prior fingerprint fix traded one grab-bag for unbounded cardinality.
    Fingerprinting on raw error text created one Sentry issue per
    occurrence whenever the text contained a path, size, timestamp, or
    pixel count (one issue was literally titled from an ls -l line).
    normalizeFingerprintText now scrubs volatile tokens before
    fingerprinting; the raw text stays in the visible issue title.
  • No expected-vs-defect classification. Policy denials and
    model-argument errors paged as exceptions identical to real defects.
    after_tool_call captures now carry a structured errorKind
    (denied / invalid-input / timeout / internal / exit-error /
    upstream), derived only from signals the host already computes
    (result status, exec exit code, execution-started flag, middleware
    markers) -- never from message text. denied outcomes are no longer
    captured at all; invalid-input downgrades to a non-paging warning
    instead of an exception.
  • Validation errors lost all field detail. A multi-line validation
    error collapsed to its generic first line
    (Validation failed for tool "<name>":) for any single-line consumer.
    validateToolArguments now throws a typed ToolArgumentValidationError
    carrying a single-line summary of every field issue, surfaced via
    details.error.
  • edit/write/read rejected names their own render code already
    reads.
    The schemas hard-rejected Claude-Code-style file_path /
    old_string / new_string, even though each tool's TUI renderer
    already reads those exact names. Adds alias normalization via a new
    shared, non-mutating renameStringKeyAlias helper -- mutating the
    model's raw tool-call arguments in place (an earlier draft of this fix)
    would have corrupted the persisted conversation transcript.
  • Slack's error formatter decorated unrelated errors with a misleading
    scope list.
    It appended granted:/accepted: OAuth scope lists to
    any Slack platform error whenever the scope response headers were
    present -- but Slack sends those headers on every response, success or
    failure, so an unrelated error (e.g. file_update_failed) read as a
    scope mismatch that didn't exist. Now gated on needed, the field
    Slack only sets on an actual missing_scope failure.
  • The session-tree visibility denial message blamed the wrong cause.
    It always named tools.sessions.visibility=tree, even when a sandbox
    clamp silently overrode an operator's explicit non-tree config. Session
    tools (history/status/send/list) now share one
    resolveSessionVisibilityContext helper so the message can name the
    real cause when it's the clamp, not the config.

User Impact

  • Sentry alerts for after_tool_call now name the actual tool, error
    kind, and code instead of merging unrelated failures into one noisy
    issue, and no longer page on expected policy denials.
  • Models that emit Claude-Code-style tool-call argument names for
    edit/write/read now succeed instead of getting a generic
    "Validation failed" rejection.
  • A Slack file/message send failure no longer misreports itself as a
    scope-configuration problem when it isn't one.
  • A session-visibility denial in a sandboxed session now names the
    sandbox clamp instead of a config key the operator may have already
    set correctly.
  • No behavior change for any currently-working path; this is additive
    classification, message-fidelity, and alias-acceptance only.

Evidence

  • 733 tests passing across every touched surface: sentry-monitor
    (captures/format/register/dispatch), Slack send.ts,
    session-visibility.ts and its 4 call sites, edit/write/read
    tools, validateToolArguments, agent-loop, the after_tool_call
    hook wiring e2e test, and the plugin-sdk contract/loader suites.
  • Live-verified against the actual Sentry event data for the four
    original noisy groups: none had produced an event in the trailing 3
    days once traced to a shared root cause in the capture-grouping layer,
    and each has been resolved in Sentry with a written reason citing the
    specific fix here.
  • A code-review pass at high effort caught and this PR fixes: an
    argument-mutation bug in the original alias-handling draft that would
    have corrupted persisted tool-call transcripts, a missed call site
    (sessions-list-tool.ts) for the sandbox-clamp context, and a test
    mock that would have silently diverged from the new combined
    visibility-context helper -- all confirmed via passing tests, not just
    code inspection.

🤖 Generated with Claude Code


Summary by cubic

Classifies tool-call failures in sentry-monitor and sets Sentry’s release to the running app version to cut paging noise and stabilize grouping. Previously every tool-call error paged as an exception and release was the plugin version; now policy denials don’t capture, invalid inputs warn, exit codes/codes drive grouping, and release reflects hostVersion.

  • Sentry release tag: was this plugin’s version; now OpenClawPluginApi.hostVersion from api-builder for per-deploy regression tracking.

  • Tool-call classification: after_tool_call adds errorKind/errorCode/exitCode. denied is not captured; invalid-input is a warning; all others (incl. exit-error) remain exceptions.

  • Fingerprints: prefer errorCode/exitCode; otherwise scrub volatile text (paths/UUIDs/timestamps/sizes/dimensions). Other hooks (agent_end, message_sent, subagent_ended, cron_changed) also normalize.

  • Validation detail: validateToolArguments throws ToolArgumentValidationError with a single-line summary; agent-core surfaces it via details.error.

  • File tool aliases: edit/write/read accept file_path/old_string/new_string via non-mutating normalization; the edit live diff preview recognizes these aliases.

  • Slack errors: only append granted/accepted scopes when Slack sets needed (missing_scope), avoiding misleading scope lists on unrelated errors.

  • Session visibility: shared resolveSessionVisibilityContext names a sandbox clamp in per-row denials and list warnings when it forced tree, instead of blaming tools.sessions.visibility.

  • Review and rollout

    • Provide hostVersion if you construct OpenClawPluginApi manually.
    • Alerting shifts: expected denials are dropped; invalid-input is warning-level.
    • Grouping will change as fingerprints normalize and exit codes are preserved; adjust alert rules if they assumed exception-only.

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

Review in cubic

@claude

claude Bot commented Aug 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.

All reported issues were addressed across 35 files

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

Re-trigger cubic

Comment thread src/agents/tools/sessions-list-tool.ts Resolved
Comment thread extensions/sentry-monitor/src/format.ts Resolved
Comment thread src/agents/sessions/tools/edit.ts Resolved
Comment thread src/agents/sessions/tools/edit.ts Resolved
convyusboy and others added 2 commits August 21, 2026 21:45
…stop misreporting expected outcomes

The sentry-monitor plugin's `release` tag was this plugin's own pinned
manifest version, not the running app version, so every host on every
release reported the same tag and a per-deploy regression could never be
attributed. Adds `hostVersion` to the plugin API, sourced from the real
app version, distinct from each plugin's own `version`.

after_tool_call captures now carry a structured `errorKind`
(denied/invalid-input/timeout/internal/exit-error/upstream) derived from
signals the host already computes -- result status, exec exit code,
execution-started flag, middleware markers -- never from message text. A
policy/permission/visibility denial is no longer captured to Sentry at
all: the system worked as intended. A model argument-validation rejection
downgrades to a non-paging warning instead of an exception, since it's
real signal for a schema mismatch but not a host defect.

Fingerprints now scrub volatile tokens (paths, UUIDs, timestamps,
byte/pixel counts) before grouping, so the same underlying failure
recurring with different incidental detail lands in one Sentry issue
instead of one per occurrence.

Validation errors previously lost all field detail once collapsed to
their first line. `validateToolArguments` now throws a typed
`ToolArgumentValidationError` carrying a single-line `summary` of every
field issue, surfaced via `details.error` so structured lookups find it
first.

Separately: `edit`/`write`/`read` schemas rejected Claude-Code-style
`file_path`/`old_string`/`new_string` even though each tool's own render
code already reads those names. Adds alias normalization via a new
shared, non-mutating `renameStringKeyAlias` helper (mutating the model's
raw tool-call arguments in place would have corrupted the persisted
transcript).

Slack's error formatter appended granted/accepted OAuth scope lists to
any platform error whenever the scope response headers were present --
but Slack sends those headers on every response, success or failure, so
an unrelated error read as a scope mismatch that wasn't there. Now gated
on `needed`, the field Slack only sets on an actual missing-scope
failure.

The session-tree visibility denial message always named
tools.sessions.visibility=tree as the cause, even when a sandbox clamp
silently overrode an operator's explicit non-tree config. Session tools
now share one `resolveSessionVisibilityContext` helper so the message can
name the real cause.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…and aliasing

Six real issues found by review, each verified against the actual code
before fixing:

- An inline gateway exec-approval denial kept details.status: failed
  with no dedicated status, so it classified as upstream instead of
  denied and paged as an exception for an expected refusal. Adds a
  structured details.denied signal to that one result builder rather
  than sniffing the message text or overloading a shared status literal.
- sessions_list's separate visibility-metadata warning still named
  tools.sessions.visibility=tree as the cause even when a sandbox clamp
  was the actual reason; it now shares the same clamp-aware wording as
  the per-row denial message.
- A tool result reporting status: timed_out (underscore) fell through
  to upstream instead of timeout.
- The edit tool's live TUI diff preview reads the raw, in-flight
  streamed args before prepareArguments runs, so it never recognized
  the newly-accepted snake_case aliases and silently showed no preview.
  Reuses the existing alias normalizer on a render-local copy.
- A model sending both edits[] and top-level old_string/new_string
  had the top-level pair silently appended as an extra, unintended edit.
  The top-level alias now only applies when edits[] is absent.
- Fingerprinting a tool-call error by scrubbing all bare numbers made
  distinct exec exit codes collapse into one Sentry bucket whenever no
  errorCode was set. The exit code is now threaded through the hook
  event as its own field and preferred in the fingerprint.

Also fixes the two real CI failures from the initial PR: an oxlint
prefer-structured-clone violation in a new test, and a TS2339 from a
test-local type missing the new errorKind/errorCode fields. Bumps the
plugin-sdk public-surface budget (10390->10395 exports, 5212->5214
callable exports) to the exact counts after this PR's additive SDK
surface -- a deliberate, reviewed increase, not config drift.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@convyusboy
convyusboy force-pushed the ridho/openclaw-fleet-tool-error-classification branch from 248a45e to d190381 Compare August 21, 2026 14:47
Add a type-narrowing expectDeniedExecDetails helper for ExecToolDetails'
discriminated status union, and cast the deliberately-alias-shaped renderCall
args in edit.test.ts, fixing check-test-types failures introduced by the
prior PR-feedback commit.
The earlier as-never cast only covered the first positional args param to
renderCall; context.args carries the same alias-shaped literal and needs the
same treatment, per the TS2345 CI failure on the previous commit.

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

Solid cleanup of long-standing Sentry noise. Approving.

What I checked

  • hostVersion split from plugin version. Plumbed through api-builder from src/version.ts, additive on the plugin API surface (bumps the public-export budget by the exact 5/2 deltas — reviewed, not drift). Right call: 3624+ events reporting one release tag was silently breaking per-deploy regression tracking.
  • errorKind classification is structured, not text-sniffed. classifyToolCallErrorKind reads only status, details.denied, executionStarted, middlewareError, and exitCode — never error-string patterns. Precedence (denied → invalid-input → timeout → internal → exit-error → upstream) matches the comment; DENIAL_STATUSES is deliberately narrow (forbidden/denied/blocked) and matches readToolResultStatus's lowercase normalization.
  • The gateway exec-denial details.denied: true bridge. Nice fix — status: "failed" alone couldn't distinguish an approval denial from a real process failure, and the alternative (a new status literal) would ripple through isToolResultError. Structured field, contained blast radius.
  • Fingerprint normalization. normalizeFingerprintText runs before FINGERPRINT_NUMBER_RE so UUIDs/timestamps/paths/dimensions/filenames don't lose their tokens to the bare-number sweep. The exit-code threading (errorCode ?? exitCode ?? normalizeFingerprintText(error)) correctly keeps distinct exec exits in distinct buckets — the tests cover exit 1 vs 127 explicitly, which is the exact failure mode the earlier fix would have introduced.
  • Non-mutating alias helper. renameStringKeyAlias returns a new object; applyEditArgumentAliases clones the array + entries; the caller-mutation test on edit.test.ts guards it. The double invocation (prepareArguments + getRenderablePreviewInput) is correct because the live streamed preview never runs through prepareArguments — this was a real gap.
  • ToolArgumentValidationError.summary. Single-pass over TypeBox's one-shot iterator; details.error in agent-loop.ts gets the single-line form; the multi-line message is preserved on Error. Structured consumers see the field-level detail they need.
  • Slack scope decoration gated on needed. Correct — Slack sets needed only on missing_scope, and moving scopes/acceptedScopes inside the if (needed) block prevents them from ever appearing without it. The exact-equality assertion (not substring) on the non-scope error is the right proof.
  • Sandbox-clamp visibility context. resolveSessionVisibilityContext consolidates two calls into one; clampedFromSandbox threads through history/status/send/list; the list-tool warning wording distinguishes clamp vs config. The mock-diverge risk called out in the second commit was real and is now covered.
  • CI. All green (checks-node-*, CodeQL, guards, docs, lint, test-types, contracts). 733 tests as advertised across every touched surface, including the new e2e wiring test that asserts errorKind: "denied"/"invalid-input" end-to-end.
  • No blocking review or open threads. Cubic bot signed off; 8 self-review comments from you are annotations, not asks.

Minor observations, non-blocking

  • FINGERPRINT_FILENAME_RE will also match 1.2.3-style version substrings as <file> (then the number pass would touch what's left). Groups deterministically either way — not a correctness bug, just noting it in case an issue title later reads oddly.
  • The !executionStarted classification precedes the timeout check. A pre-execution timeout (schema/argument-prep timing out) would classify as invalid-input rather than timeout. Not a realistic path in prepareToolCall, so this is fine — flag if that flow ever grows async work.

Ship it.

@convyusboy
convyusboy merged commit e04ffb4 into boon Aug 22, 2026
145 checks passed
@convyusboy
convyusboy deleted the ridho/openclaw-fleet-tool-error-classification branch August 22, 2026 02:31
convyusboy added a commit that referenced this pull request Aug 25, 2026
Cut a fork release containing the message_stop truncation-detection fix
from #143 and the sentry-monitor error-classification/release-tag rework
from #144.

Bump the gateway and published fork plugins in lockstep.
convyusboy added a commit that referenced this pull request Nov 20, 2026
…ationError's runtime identity (#339)

* fix(agent-core): stop depending on @openclaw/ai for ToolArgumentValidationError's runtime identity (ENG-23048)

ToolArgumentValidationError (added in #144 for sentry-monitor classification)
lives in packages/llm-core/src/validation.ts, which upstream's base-reset
(v2026.7.35, #307/#335/#336) recently extracted into the externally-resolved
@openclaw/ai package -- never bundled into the openclaw CLI tarball or the
standalone @openclaw/agent-core package, per tsdown.config.ts. Boon never
publishes its own @openclaw/ai, so any consumer installing openclaw plus a
normal @openclaw/ai from the public registry gets upstream's unpatched
package, which has never carried this class. The compiled openclaw package's
proxy chunk statically imports it as a value from "@openclaw/ai/validation",
crashing at module-evaluation time for any consumer touching
openclaw/plugin-sdk/agent-harness.

agent-loop.ts's only production use of the class is `.summary` via
instanceof, so switch to a structural check and a type-only import; the
agent-core validation.ts facade re-exports the type only. Type-only exports
erase at build time, so the bundler no longer needs a runtime binding for
this symbol from the externally-resolved @openclaw/ai.

Verified: packages/llm-core and packages/agent-core unit tests pass; `pnpm
build` dist no longer imports the class as a value from @openclaw/ai/validation;
oxlint and tsgo:core clean; plugin-sdk SDK-surface export budget unaffected;
and end-to-end by copying the fixed dist into a consumer repo
(anychat-boon-web) with the real, unpatched public @openclaw/ai still
installed -- a test that previously crashed on import now passes.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(agent-core): address cubic review feedback on PR #339

Trim both ToolArgumentValidationError comments to the short rationale (why
the check is structural, not why the package got externalized) per review
feedback on keeping changed-source comments focused. Also drop the
`instanceof Error` requirement from isToolArgumentValidationError: the check
only needs `name`/`summary`, and `instanceof Error` would reject a
cross-realm or plain-object error that otherwise carries both fields.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(agent-core): make ToolArgumentValidationErrorShape a local type, not a re-export (ENG-23048)

Published @openclaw/[email protected]'s dist/validation.d.mts exports only
validateToolArguments and validateToolCall -- no ToolArgumentValidationError
type, matching its missing value export. `export type { ... } from
"@openclaw/ai/validation"` resolved fine against the workspace-linked
@openclaw/ai (boon's own packages/ai), masking that a real external
consumer type-checking against the published registry package would hit
TS2305.

Define the minimal shape locally instead (just the `name`/`summary` fields
agent-loop.ts's structural guard reads), so the public .d.ts no longer
depends on the externally-resolved package's declarations at all. Verified
against the actual published @openclaw/[email protected] dist/validation.d.mts.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5 <[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