Skip to content

feat(sentry-monitor): tag agent_end with run/session correlation ids - #182

Merged
holywend merged 1 commit into
boonfrom
wendy/sentry-agent-end-correlation-tags
Sep 3, 2026
Merged

holywend merged 1 commit into
boonfrom
wendy/sentry-agent-end-correlation-tags

Conversation

@holywend

@holywend holywend commented Sep 3, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Resolves a problem where an operator holding a turn's correlation id could not find the corresponding fleet Sentry event.

When a customer agent turn fails, agent_end reports it to Sentry. The event carried run_id — but only in contexts, which Sentry does not index. Tags are indexed; contexts are payload you can read after you have already found the event.

run_id is boon-core's dispatch_ref: minted per turn, sent to the box as run_id / X-Request-Id, printed in the Slack stall alert, and tagged on boon-core's own Sentry events. So the operational path — "I have a dispatch_ref from an alert, what did the box say about that turn?" — dead-ended. You could only browse the fleet project by host and timestamp and hope.

session_id was similarly unavailable: runContext(runId, sessionId, callId) has always accepted a sessionId, and every caller passed only runId, so the field was permanently undefined. It resolves the box's own session file.

Why This Change Was Made

Promoting run_id to a tag closes the round trip between the control plane's view of a turn and the box's. session_id and agent_id come from PluginHookAgentContext — the hook's existing second argument, which already carries them.

That last point is the design constraint worth noting: no change to src/plugins/hook-types.ts. That file is upstream-owned and this fork is far behind upstream, so touching it would add merge-conflict surface for no benefit. The ctx parameter is optional, so every existing call site stays valid.

User Impact

Operator-facing only; no runtime behavior change for agents or end users.

Deliberately additive, and each property is pinned by a test:

  • Emits zero new events. agent_end already fired on every failed turn — this only enriches what was already sent. No new Sentry noise.
  • Cannot fragment existing issues. Sentry groups on fingerprint, which is untouched. Tags are metadata.
  • No empty facets. pruneTags drops undefined/empty, so a run without these ids emits nothing. An empty-string tag would still create a searchable facet, which is worse than the tag being absent.

Evidence

Behavior proof, all against the changed surface:

Check Result
node scripts/run-vitest.mjs extensions/sentry-monitor/src/captures.test.ts extensions/sentry-monitor/src/register.test.ts 62/62 passed
oxfmt --check on the 3 changed files clean
node scripts/run-oxlint.mjs clean, exit 0
pnpm tsgo:extensions exit 0

Six new tests written before the implementation (RED confirmed — 3 failing on the new behavior, then green):

  • run_id appears in tags, not only contexts
  • session_id + agent_id are taken from the hook context
  • session_id populates the run context whose slot already existed
  • correlation tags are omitted entirely when the ids are absent
  • the fingerprint is byte-identical with and without ctx, so issues do not fragment
  • existing agent_end behavior (success ignored, error message, message count) unchanged

Note on local commands: pnpm test extensions/sentry-monitor fanned out and timed out at 10 minutes on this machine, so per the root guide I used scripts/run-vitest.mjs for narrow explicit-file proof. Broader proof should come from CI/Testbox rather than a local full run.


Summary by cubic

Tags agent_end Sentry events with run_id, session_id, and agent_id so operators can find a failed turn's fleet event by the correlation id from an alert, instead of browsing by host and timestamp. run_id was previously only in contexts, which Sentry doesn't index. session_id and agent_id come from the hook's existing context argument, so no upstream type changes are needed.

  • Adds run_id, session_id, and agent_id as tags; session_id also populates the existing run-context slot.
  • The ctx parameter is optional, so all existing call sites remain valid.
  • Emits no new events, doesn't change the fingerprint (so existing issues don't fragment), and omits tags when ids are absent.

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

Review in cubic

An agent_end failure could only be read AFTER you found it, never found BY
the id you already had.

run_id was in `contexts`, which Sentry does not index. It is boon-core's
`dispatch_ref`: minted per turn, sent to the box as run_id / X-Request-Id,
printed in the Slack stall alert, and tagged on boon-core's own Sentry
events. So an operator holding a dispatch_ref from an alert could not search
the fleet project for the box's side of that same turn. Promoting it to a tag
closes the round trip.

Also fills in session_id, whose plumbing already existed and was never used:
runContext(runId, sessionId, callId) has always taken a sessionId, and every
caller passed only runId, so the field was permanently undefined. It resolves
the box's session file. agent_id comes along for free.

The ids come from PluginHookAgentContext, the hook's existing second
argument, which already carries sessionId/agentId — so this needs no change
to src/plugins/hook-types.ts. That matters: hook-types is upstream-owned and
the fork is far behind upstream, so touching it would add merge-conflict
surface for no benefit. The ctx parameter is optional, keeping every existing
call site valid.

Deliberately additive only:

- Emits ZERO new events. agent_end already fired on every failed turn; this
  only enriches what was already being sent. No new noise.
- Does not touch `fingerprint`, so existing issues cannot fragment. Sentry
  groups on fingerprint, not tags. A test pins this.
- pruneTags drops undefined/empty, so a run without these ids emits no empty
  facets — an empty-string tag would still create a searchable facet, which
  is worse than the tag being absent. A test pins this too.

Verified: 62/62 in captures + register suites via scripts/run-vitest.mjs;
oxfmt clean; oxlint clean; `pnpm tsgo:extensions` exit 0.
@claude

claude Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@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 on the checked-out branch. Every claim in the description checks out against the code:

  • PluginHookAgentContext in src/plugins/hook-types.ts already carries sessionId/agentId — no upstream-owned type touched, as promised.
  • agent_end hook signature in hook-types.ts already passes ctx as the second arg; the register.ts change is just plumbing it through.
  • runContext(runId, sessionId, callId) in format.ts already accepts sessionId — the slot really was there and unused.
  • pruneTags drops undefined/empty, so a run without correlation ids emits no empty facets (test pins this).
  • fingerprintOf is called with the same args → grouping unchanged (test pins this too).
  • Zero new emit sites; only enrichment of an event that already fired on every failed turn.

Local proof: node scripts/run-vitest.mjs extensions/sentry-monitor/src/captures.test.ts extensions/sentry-monitor/src/register.test.ts → 62/62 passed.

CI: all completed jobs green; remaining shards still running but nothing failing. Claude PR Review's CANCELLED is a rerun artifact, not a red.

The reasoning (indexed tags vs unindexed contexts closing the dispatch_ref round-trip from a Slack stall alert to the fleet Sentry event) is the right lens on why this matters. Small, additive, well-tested. Ship it.

@holywend
holywend merged commit f34db7b into boon Sep 3, 2026
139 of 141 checks passed
@holywend
holywend deleted the wendy/sentry-agent-end-correlation-tags branch September 3, 2026 05:51
insomnius added a commit that referenced this pull request Sep 3, 2026
…186)

Cut the boon.34 fork release. Carries ENG-19115 fix (#185): read the
gateway-audience OBO from the inbound ctx, not the persisted sessionCtx
-- the per-turn token was being dropped, so the tier-1 internal-test
meter-skip never fired. Plus #182 (sentry-monitor correlation ids).

release:prep synced the lockstep extension versions + regenerated
release artifacts (plugin inventory/reference docs, shrinkwraps,
plugin-sdk API baseline, bundled-channel-config metadata).
insomnius added a commit that referenced this pull request Sep 3, 2026
#186 bumped the version but omitted the CHANGELOG.md section, so the
boon-release.yml prepack (scripts/package-changelog.mjs) hard-fails with
"CHANGELOG.md does not contain a release section for 2026.6.11-boon.34"
and no fleet tarball is built. Add the boon.34 section (covers #185
ENG-19115 OBO ctx fix, #182, #181) to unblock the release.
convyusboy added a commit that referenced this pull request Nov 18, 2026
…am fix available

picomatch <=4.0.7 is vulnerable to catastrophic backtracking on
single-branch repeated extglobs like +(*a) (confirmed locally: exponential
blowup, ~7s at n=30). The advisory lists no first_patched_version, and the
one linked PR (micromatch/picomatch#194) is unmerged and explicitly out of
scope for this exact shape per its own author.

Patch [email protected] and @4.0.4 (the two versions reachable in the
production dependency closure, via vite/vitest/tinyglobby under
extensions/qa-lab's @copilotkit/aimock) to treat a branch with a bare
top-level star alongside other content as risky and literalize it - the
same safety/correctness trade-off picomatch's own prior ReDoS mitigation
(#182) already makes for mixed star/qmark branches. A branch that is
nothing but stars (e.g. +(*)c) stays safe, matching existing tested
behavior.

Verified against picomatch's own upstream test suites at both versions:
1981/1983 and 1973/1975 passing. The only two newly-failing assertions
(*(a*|b) matching "ax", */*(W*, *)* matching a benign short string)
independently reproduce as themselves exponential against an adversarial
input on the unpatched code - two more instances of the same unfixed bug
the suite never exercised adversarially, not false positives in this patch.

Documents the override in pnpm-audit-prod.mjs's existing
AUDIT_ADVISORY_VERSION_OVERRIDES mechanism; remove once picomatch ships a
real fix.

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.

2 participants