Skip to content

feat(sentry-monitor): tag captures with session_id (ENG-20876) - #256

Merged
william-antoline-boon merged 7 commits into
boonfrom
fix/eng-20876-sentry-session-id-tag
Oct 1, 2026
Merged

william-antoline-boon merged 7 commits into
boonfrom
fix/eng-20876-sentry-session-id-tag

Conversation

@william-antoline-boon

@william-antoline-boon william-antoline-boon commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Reliability Metric #5 (Sentry error rate, target <5/customer/session/day) has per-customer/day tracking live (account_id tag), but no per-session dimension — session_id was never an indexed tag, only ever landing in contexts.run, which Sentry does not search on. This is the prerequisite for the per-session/per-day dashboard.

  • Promotes the session-correlation value each capture builder already had available into a real session_id tag (not just contexts), for: model_call_ended, before_tool_call_hook_failed, message_sent (falls back to sessionKey, its only session identity), cron_changed, session_end.
  • after_tool_call: the event itself carries no session field, but the hook's ctx (PluginHookToolContext) does — threaded ctx through register.ts the same way agent_end already does, and added it as an optional 3rd param to buildAfterToolCallCapture.
  • agent_end already tagged session_id — no change needed there.
  • Deliberately left untouched: delivery_recovery_exhausted and subagent_ended. Neither has an existing session_id-shaped value to promote (only a sessionKey/targetSessionKey), and there's no prior precedent in this file for conflating those into session_id the way message_sent already does. subagent_ended is additionally ambiguous — its ctx exposes both a child and a requester session key, so tagging one as "the" session would be a guess. Flagging this here rather than silently expanding scope.

Test plan

  • node scripts/test-projects.mjs extensions/sentry-monitor — 103 tests pass (4 files), including 8 new cases covering every touched builder plus the ctx-threading path for after_tool_call
  • oxlint clean, oxfmt --check clean (via the repo's pre-commit hook)
  • Verified live against the two real Sentry issues cited in ENG-20876: confirmed the after_tool_call/invalid-input example matches buildAfterToolCallCapture's current output exactly (this codebase); confirmed the other example (JWT ENOENT, has account_id) is emitted by a different process (anychat-boon-web's loadBoonWebAuthEnv), so it's out of scope for "the gateway/agent process"

🤖 Generated with Claude Code


Summary by cubic

Adds the session_id tag to Sentry captures so errors group per-session, the prerequisite for the per-session/per-day dashboard behind Reliability Metric #5.

  • Tags session_id on model_call_ended, before_tool_call_hook_failed, message_sent (falls back to sessionKey), cron_changed, and session_end; threads the hook ctx through register.ts so after_tool_call tags it the same way agent_end already does.
  • delivery_recovery_exhausted and subagent_ended are left untouched — neither has a clean session_id-shaped value to promote.

Dependencies

  • Bumps the axios override to 1.20.0 (lockfiles regenerated) for five advisories; pins the feishu timeout-wrapper return types to Promise<any> to clear a type-parameter collision introduced by axios's new R generic.
  • Bumps the brace-expansion override to 5.0.12 (lockfiles regenerated) for two advisories.

Written for commit 269b10f. Summary will update on new commits.

Review in cubic

Reliability Metric #5 tracks per-customer/day error rate (account_id tag,
already live) but has no per-session dimension: session_id was only ever
in contexts, which Sentry does not index, so a session's errors could not
be searched for or grouped. Promotes the session correlation value each
builder already had available into an indexed tag, for model_call_ended,
before_tool_call_hook_failed, message_sent, cron_changed, session_end, and
after_tool_call (whose ctx carries sessionId even though the event itself
doesn't — threaded through register.ts the same way agent_end already
does). delivery_recovery_exhausted and subagent_ended are left untouched:
neither has an existing session_id-shaped value to promote, and inventing
one (which of two session keys subagent_ended's ctx exposes; conflating
sessionKey into session_id with no prior precedent for either hook) is a
bigger call than this ticket asks for.

103 tests pass (60 in captures.test.ts, 8 new), oxlint clean, oxfmt --check
clean.
@william-antoline-boon
william-antoline-boon requested a review from a team September 30, 2026 03:21
…-qhr7-859c-m2p7 / GHSA-6j4f-fj2g-mc7p

Two HIGH advisories published after the 5.0.9 pin (itself a fix for two
older brace-expansion DoS advisories) cover 5.0.9 too: unbounded recursion
on nested brace groups (<5.0.11) and in parseCommaParts (<5.0.10). Moves
the pnpm-workspace.yaml override to 5.0.12 and regenerates pnpm-lock.yaml
+ the root npm-shrinkwrap.json. pnpm-audit-prod (security-fast's gate)
now reports no high-or-higher advisories in production dependencies.

Unrelated to this branch's actual change (session_id tagging) — this was
failing on any current PR against boon, caught while getting CI green.
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • extensions/feishu/npm-shrinkwrap.json
  • extensions/msteams/npm-shrinkwrap.json
  • extensions/slack/npm-shrinkwrap.json
  • pnpm-lock.yaml
  • pnpm-workspace.yaml

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfile, shrinkwrap, or workspace dependency policy changes are present.
  • Treat package-lock.json and npm-shrinkwrap.json diffs as security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Dependency graph changes noted

This PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin or a member of @openclaw/openclaw-secops.

  • Current SHA: 269b10fc42bb07290b33a20f57c720fdecaeffae
  • Trusted actor: @william-antoline-boon
  • Trusted role: pull request author; repository admin

Security review is still recommended before merge when the dependency graph change is intentional.

@boon-hermes-bot boon-hermes-bot 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.

Approve — covers d8e57f2f specifically

Verified end-to-end at head d8e57f2f58. All claims in the body hold against the code; local test run, typecheck, and CI are green.

Numbered verifications (evidence-backed)

  1. Every claimed builder change is present, nothing more. captures.ts at head: session_id tag added to model_call_ended (event.sessionId), before_tool_call_hook_failed (event.sessionId), message_sent (event.sessionKey), cron_changed (event.sessionId), session_end (event.sessionId); after_tool_call gets it via the new optional ctx?: Pick<PluginHookToolContext, "sessionId">. agent_end already had the tag (line 131) — "no change needed" is true.
  2. Deliberately-untouched claims hold. buildDeliveryRecoveryExhaustedCapture and buildSubagentEndedCapture are byte-identical to base; subagent_ended's ctx (PluginHookSubagentContext) indeed carries both childSessionKey and requesterSessionKey, so declining to tag one as "the" session is correct, not lazy.
  3. The ctx contract is real at every layer. PluginHookToolContext.sessionId exists (hook-types.ts:633). The handler map already typed after_tool_call: (event, ctx: PluginHookToolContext). Both core call sites populate it: embedded-agent-subscribe.handlers.tools.ts:1678 passes sessionId: ctx.params.sessionId, and harness/hook-helpers.ts:40 passes sessionId when present. The register.ts threading mirrors agent_end line-for-line.
  4. message_sent's sessionKey-as-session_id is consistent, not a conflation. contexts.run for that hook was already runContext(event.runId, event.sessionKey) on base — the tag mirrors the existing session identity slot rather than inventing one. The code comment says exactly this.
  5. No empty-tag facets. pruneTags drops undefined/"", so events without a session emit no session_id tag. Tags don't touch fingerprints, so existing issue grouping cannot fragment.
  6. Ticket AC (ENG-20876) met with the right mechanism. The ticket asks for a searchable session_id tag "wherever the gateway/agent process initializes Sentry". Per-event tagging on the sentry-monitor builders is the only correct mechanism for a multi-session gateway process (a global init-time tag is impossible), and it unblocks the per-session/per-day dashboard. The out-of-scope claim for the JWT-ENOENT example is verified: loadBoonWebAuthEnv lives in anychat-boon-web (src/transport/boon-web/jwt-verify.ts), a different process with its own Sentry init.
  7. Tests green locally: node scripts/test-projects.mjs extensions/sentry-monitor → 103 passed (4 files) at head, matching the body's count exactly.
  8. RED-GREEN proof: with captures.ts/register.ts swapped to base, exactly the 6 new it blocks fail (6 failed / 54 passed); restoring head returns 103/103. The new tests genuinely pin the new tags.
  9. Typecheck clean: pnpm tsgo:extensions exits 0 in a fresh worktree at head.
  10. Dependency bump verified, not trusted: brace-expansion override 5.0.9 -> 5.0.12 is consistent across pnpm-workspace.yaml, pnpm-lock.yaml, and npm-shrinkwrap.json; the shipped integrity hash matches the npm registry for 5.0.12. 5.0.12 covers both new advisories (fixes landed in 5.0.10 and 5.0.11).
  11. CI green at the exact reviewed head: CI, Dependency Guard, Security Sensitive Guard, OpenGrep — PR Diff, CodeQL Critical Quality all success at d8e57f2f (verified via actions/runs). Zero open review threads.
  12. Boundary rules respected: the plugin imports only openclaw/plugin-sdk/types per extensions/AGENTS.md; no core internals, no config-surface changes, no merge-risk surface from the ClawSweeper policy list.

Non-blocking nit

  • Body says "8 new cases"; the diff adds 6 new it blocks plus tag assertions on 2 existing before_tool_call_hook_failed tests (6 new + 2 augmented = 8 touched). Explained drift, wording only.

Reviews from this host post as augusteo, not the Slack bot name.

…session-id-tag

# Conflicts:
#	npm-shrinkwrap.json
#	pnpm-lock.yaml
#	pnpm-workspace.yaml
@william-antoline-boon

Copy link
Copy Markdown
Collaborator Author

@boon-hermes-bot Thanks for the verification pass. Re the non-blocking nit: you're right, the PR description's "8 new cases" was imprecise — it's 6 new it blocks (covering model_call_ended, after_tool_call x2, message_sent, cron_changed, session_end) plus 2 augmented assertions on the existing before_tool_call_hook_failed tests. Wording only, no code change needed.

Separately: this PR just went through a merge-conflict round with boon (0afad4a) — another PR (#257) landed an equivalent brace-expansion fix in parallel (pinned 5.0.11 vs my 5.0.12), and a brand-new axios advisory (GHSA-c29m-xwm3-cm6r et al., fixed at 1.20.0) surfaced during the merge. Deferred to boon's existing brace-expansion pin and bumped axios 1.18.1 -> 1.20.0 the same way. All 103 sentry-monitor tests + pnpm-audit-prod + shrinkwrap consistency re-verified at the new head.

…w R generic

axios 1.20.0's request/get/post/... methods gained a new R generic
(R = AxiosResponseDefault, an unexported sentinel) so callers can override
the response type. createTimeoutHttpInstance's wrapper methods assign
plain arrow functions against Lark.HttpInstance's own generic method
signature (request<T=any, R=T, D=any>(...): Promise<R>) with no explicit
type arguments on either side. Under contextual inference the two
same-named R type parameters collide, and axios's conditional response
type (R extends AxiosResponseDefault ? AxiosResponse<...> : R) never
reduces, so TS2322 fires on all 8 wrapper methods (check-prod-types,
check-test-types, check-additional-extension-package-boundary).

Pinning each wrapper's return type to `Promise<any>` (Lark's own default
when its R is left unspecified) breaks the collision without changing
behavior — these are pure pass-through wrappers, runtime shape is
unaffected either way.

Verified: pnpm tsgo:core, tsgo:extensions, tsgo:core:test,
tsgo:extensions:test, and test:extensions:package-boundary:compile (117
extensions) all clean. Feishu's own suite (72 files / 962 tests) and
sentry-monitor's (103 tests) still green.
check-lint (both the plain and bundled-extension shard) flagged the
previous fix's 8 inline `Promise<any>` return annotations against
no-explicit-any. Consolidated to one local `WrapperResponse` type alias
with a single oxlint-disable, so the literal `any` token appears once
instead of eight times.

Separately, checks-node-bundle-infra-small-4 failed because
src/infra/npm-managed-root.test.ts asserts the real pnpm-workspace.yaml
override value for axios via toMatchObject — it had "1.18.1" hardcoded
from before this branch's security bump; updated to "1.20.0".

Verified: pnpm lint --threads=8, run-bundled-extension-oxlint.mjs,
tsgo:extensions, test:extensions:package-boundary:compile, the specific
npm-managed-root.test.ts (27/27), and feishu's + sentry-monitor's full
suites all green.
…llowlist

test/scripts/lint-suppressions.test.ts inventories every production
oxlint-disable via an explicit allowlist (both an overall list and a
no-explicit-any-specific one) so a new suppression can't slip in
unnoticed. The previous commit's WrapperResponse suppression in
extensions/feishu/src/client.ts was real and intentional but wasn't on
either list yet. Added in the position `git grep` actually returns it
(extensions/ sorts before src/, and bitable.ts before client.ts).

Verified: test/scripts/lint-suppressions.test.ts passes (3/3) against
the real git-tracked suppression set.
@william-antoline-boon
william-antoline-boon merged commit 176e9c3 into boon Oct 1, 2026
145 checks passed
@william-antoline-boon
william-antoline-boon deleted the fix/eng-20876-sentry-session-id-tag branch October 1, 2026 04:24
convyusboy added a commit that referenced this pull request Oct 2, 2026
…263)

Root version, 135 plugin manifests synced via scripts/sync-plugin-versions.ts
(pnpm plugins:sync), root + 68 extension npm-shrinkwrap.json version fields
and openclaw peerDependency ranges bumped, CHANGELOG section for boon.49.

Shipping: #246 (tool-result aggregate budget scales with context window
instead of a fixed 256k-char cap, so long tool-heavy sessions stop reading
their own successful calls as failures and compaction actually fires on real
pressure), #253/ENG-20866 (Chrome MCP handshake/navigate timeouts raised for
real npx cold-start cost, unblocking browser-handoff live attach), #256/
ENG-20876 (session_id promoted to a real Sentry tag for the per-session
reliability dashboard), #260/ENG-20968 (msteams SharePoint/OneDrive download
failures surfaced through MediaFailures instead of silently dropped), #261/
ENG-21009 (Sentry node 8.49 -> 10.75.3, clearing ~12 medium Vanta/Inspector
findings from its pinned otel/Prisma instrumentation chain), plus undici/
brace-expansion/axios security bumps and markdown-it/dompurify/golang.org/x/net
dependency bumps.

Base = 2026.6.11-boon.48. Gateway plus @openclaw/slack, @openclaw/msteams and
@openclaw/diagnostics-prometheus bumped in lockstep; only @openclaw/msteams
source changed in this train (#260), so a fleet-msteams.sh pass is needed on
Teams hosts alongside the gateway roll.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants