Skip to content

fix(sentry-monitor): fingerprint hook captures and surface real Python exception text - #133

Merged
convyusboy merged 2 commits into
boonfrom
worktree-quizzical-stirring-marshmallow
Aug 19, 2026
Merged

convyusboy merged 2 commits into
boonfrom
worktree-quizzical-stirring-marshmallow

Conversation

@convyusboy

@convyusboy convyusboy commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Sentry issue OPENCLAW-FLEET-H4 had 403 occurrences over ~1 month, 0 users impacted, generically titled "Error: Traceback (most recent call last):" — but pulling the underlying events showed it was actually a grab-bag of completely unrelated tool failures: Python tracebacks, web fetch failed (403/404), memory_search timed out, An API error occurred: thread_not_found, cron job not found, Action send requires a target, etc., all merged into one noisy issue.

Why This Change Was Made

Every sentry-monitor capture (after_tool_call, model_call_ended, agent_end, message_sent, subagent_ended, cron_changed) is dispatched via client.captureException(new Error(capture.message), scope) from a single fixed call site in extensions/sentry-monitor/src/dispatch.ts. Because the JS stack trace is identical for every capture of a given hook, Sentry's stack-based grouping merges all of them into one issue regardless of message content — hiding real signal behind noise.

A secondary bug compounded this for Python exec failures: normalizeToolErrorText (src/agents/embedded-agent-subscribe.tools.ts) took only the first line of raw tool output as the error string. For a Python traceback, the first line is always the generic Traceback (most recent call last): header — the actual ExceptionType: message is the last line — so every distinct Python exec failure reported identical, useless text even in isolation.

User Impact

Sentry issues for the after_tool_call (and sibling) hooks now split by their real cause (tool name, provider/model, outcome, message) instead of all landing in one bucket, and Python exec failures surface the actual exception instead of a generic traceback header. This is telemetry/observability-only — no runtime/product behavior changes for end users.

Evidence

  • Root cause confirmed live via Sentry search_events on OPENCLAW-FLEET-H4: 20 sampled events showed wildly different underlying messages (traceback, web fetch 403/404, memory_search timeout, thread_not_found, cron job not found, etc.) all grouped under the same issue.
  • Added an explicit Sentry fingerprint to every capture builder in extensions/sentry-monitor/src/captures.ts, threaded through dispatch.ts's SentryScopeContext.
  • Fixed normalizeToolErrorText to use the last non-empty line when text is a Python traceback.
  • 89 tests passing (63 in extensions/sentry-monitor, 26 in src/agents/embedded-agent-subscribe.tools.test.ts), including new regression tests proving distinct tools/errors fingerprint differently and traceback extraction picks the right line. Ran via vitest run against the scoped configs (test/vitest/vitest.extensions.config.ts, test/vitest/vitest.agents.config.ts) since the repo's shared local heavy-check lock was held by tsgo in another worktree.
  • Formatted with oxfmt.

Follow-up tracked in ENG-18309 (Linear): live post-deploy verification that new occurrences actually split, and what to do with the old already-merged OPENCLAW-FLEET-H4 bucket.


Summary by cubic

Splits Sentry issues for hook captures by adding explicit fingerprints and surfaces real Python exceptions. Previously, all captures for a hook grouped under one JS stack; now each capture sets a fingerprint from distinguishing fields, and Python exec errors use the real exception line.

  • Add fingerprint to every capture builder, pass it through dispatch.ts, and compute it via fingerprintOf (e.g., for model_call_ended: provider, model, errorClass, httpStatus, failureKind, errorCategory; for tools: tool + error text).
  • Fix normalizeToolErrorText to use the last non-empty line of Python tracebacks and ignore exec status trailers (e.g., “Command exited with code N”, timeouts); keep the first line for other multi-line outputs.
  • Tests cover fingerprinting (including httpStatus distinctions) and traceback parsing. No runtime or API behavior changes. No migration required.
  • Post-deploy: verify issues split as expected for OPENCLAW-FLEET-H4 (ENG-18309).

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

Review in cubic

…n exception text

Every after_tool_call/model_call_ended/etc. capture was thrown via `new
Error(message)` at one fixed call site, so Sentry's stack-based grouping
merged unrelated tool/hook failures into a single noisy issue regardless
of message content. Add an explicit fingerprint per capture builder so
distinct failures split into their own issues.

Also fix normalizeToolErrorText to use the last line of a Python
traceback (the actual exception) instead of the generic
"Traceback (most recent call last):" header line.
@claude

claude Bot commented Aug 19, 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 8 files

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

Fix all with cubic | Re-trigger cubic

Comment thread extensions/sentry-monitor/src/format.ts Resolved
…aceback extraction

- Include httpStatus in the model_call_ended fingerprint so same-classification
  failures with different HTTP causes (e.g. Bedrock 503 vs a gateway 502) still
  split into separate issues.
- Skip the exec tool's appended exit-status trailer ("Command exited with code
  N", "Command timed out...", "Command aborted...") when picking a Python
  traceback's real last line, so that trailer text isn't mistaken for the
  actual exception.
- Drop a PR-specific issue reference from a permanent code comment.

@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, well-scoped telemetry fix.

Root cause is correctly nailed: every capture is thrown via new Error(message) from one fixed call site per hook, so Sentry's stack-based grouping merged unrelated failures into one bucket — confirmed live on OPENCLAW-FLEET-H4. The explicit fingerprint per capture builder (single reused fingerprintOf helper, threaded through dispatch.ts SentryScopeContext) is the right fix, and httpStatus in the model_call_ended fingerprint correctly splits Bedrock 503 vs gateway 502.

The normalizeToolErrorText last-line-of-traceback fix is well-handled — the ^\(?Command\b/i trailer regex correctly skips exec's appended exit/timeout/abort status lines without clobbering a real CommandError:, and non-traceback multi-line output still keeps the first line.

Verified independently: checked out the branch and ran both scoped suites — extensions/sentry-monitor (64) + embedded-agent-subscribe.tools (28) = 92 passing, including the new regression tests for distinct fingerprints and traceback extraction. Telemetry-only, no runtime/product behavior change, no migration, no secrets. Post-deploy split verification tracked in ENG-18309.

tests: sentry-monitor 64 + agents 28 passed · scope observability-only · no migration · signed

@convyusboy
convyusboy merged commit 23a9ede into boon Aug 19, 2026
149 of 154 checks passed
@convyusboy
convyusboy deleted the worktree-quizzical-stirring-marshmallow branch August 19, 2026 10:27
Willi8910 added a commit that referenced this pull request Aug 20, 2026
Version-bump-only release cutting the seven commits merged to boon since
v2026.6.11-boon.19: #129 (deliver an attachment when prose is fused onto the
MEDIA: path), #131 (stop mislabeling sanctioned silent NO_REPLY finals as
delivery failures, ENG-18092), #133 (fingerprint sentry-monitor hook captures
and surface the real Python exception line), #130 (docs cross-link), and the
#36 / #77 / #113 dependency bumps.

Bumps the gateway plus @openclaw/slack, @openclaw/msteams, and
@openclaw/diagnostics-prometheus to 2026.6.11-boon.20 in lockstep across all 8
manifests, and adds the CHANGELOG entry. No code changes.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@convyusboy
convyusboy restored the worktree-quizzical-stirring-marshmallow branch August 26, 2026 05:22
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