Skip to content

Commit 589a09e

Browse files
runningcodeclaude
andauthored
chore(ai): Add java-sdk-review Warden skill (#6822)
* chore(ai): Add java-sdk-review Warden skill The org code-review skill only reports generic bugs and does not know sentry-java's conventions. java-sdk-review covers the SDK rules that need reading beyond the changed lines: concurrency, test coverage of new behavior, public API surface, Android and ProGuard, and integration lifecycle. It reports at medium and up and never blocks a merge. Verification moves from the defaults onto check-code-attribution, so the new skill keeps Warden's second verification pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(ai): Leave tool-decidable checks out of java-sdk-review Formatting, unused imports, and banned calls are decided by Spotless, detekt, Error Prone, and Android Lint. A model reviewing them only adds noise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ref(skills): Narrow java-sdk-review test coverage findings A backtest on October and November PRs found 1 of 7 test coverage findings worth a comment. Report only behavior shipped with no test at all, fixes without a regression test, uneven sibling modules, and auto-configuration conditions the change adds itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): Review androidMain sources and re-entrant lock calls Run java-sdk-review on src/androidMain too, so changes to sentry-compose get reviewed. Add the AGENTS.md rule against holding a lock across calls that can re-enter the SDK, which deadlock and show up as ANRs on Android. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6be9581 commit 589a09e

4 files changed

Lines changed: 198 additions & 8 deletions

File tree

‎.claude/skills/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
!btrace-perfetto/**
1111
!check-code-attribution/
1212
!check-code-attribution/**
13+
!java-sdk-review/
14+
!java-sdk-review/**
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
name: java-sdk-review
3+
description: Reviews sentry-java pull requests against the SDK's own conventions and contracts that need reading beyond the changed lines - concurrency, test coverage of new behavior, public API surface, Android and ProGuard, integration lifecycle. Use for PR review in sentry-java. Not for generic bugs, security, or code attribution, which other skills cover.
4+
allowed-tools: Read Grep Glob
5+
---
6+
7+
# sentry-java review
8+
9+
You review one changed hunk of the Sentry Java/Android SDK against the rules below. The SDK runs
10+
inside customers' apps, so a mistake here becomes their crash, hang, or data leak.
11+
12+
Other reviewers already cover the rest. Do not report:
13+
14+
- Generic correctness bugs. The `code-review` skill covers those.
15+
- Security issues. The `security-review` skill covers those.
16+
- License headers and `THIRD_PARTY_NOTICES.md`. The `check-code-attribution` skill covers those.
17+
- Anything a tool decides without judgment: formatting and import order (Spotless), unused imports
18+
and code, banned calls or imports (detekt, Error Prone, Android Lint), compile errors, the contents
19+
of generated `.api` files, PR title format, or missing changelog entries (Danger).
20+
- Rules the `decision-model-linter` checks from one file's changed lines, such as broad catches,
21+
PII gating, and test assertions. See `lint/suites/`.
22+
- Anything the diff did not introduce or make worse. Existing code that breaks a rule is not
23+
precedent, but it is not this PR's finding either.
24+
25+
## How to work
26+
27+
1. Read the hunk and enough of the file to know what changed and who calls it.
28+
2. Read the matching rule file in `.cursor/rules/` for the area the change touches (`api`, `options`,
29+
`scopes`, `offline`, `opentelemetry`, ...).
30+
3. Check each rule below that applies. Use Grep and Glob to find callers, other threads that touch
31+
the same state, the tests, and ProGuard files. Test files are never sent to you as hunks, so look
32+
them up yourself.
33+
4. Report a finding only when you can name the rule, the line, and what goes wrong. If the code, a
34+
comment, or the PR already handles it, there is no finding.
35+
36+
## Rules
37+
38+
### Concurrency
39+
40+
The SDK uses plain Java concurrency primitives, and `Sentry.init` can run on any thread, including
41+
the Android main thread during app startup.
42+
43+
- A field written on one thread and read on another without a lock must be `volatile`. A plain read
44+
is a data race, not just a stale value.
45+
- Lazy initialization of a field reachable from several threads must be thread-safe.
46+
- Iterating over or changing a shared collection, such as span data, while other threads may change
47+
it.
48+
- Submitting to an executor from code that may already run on that executor's thread. It can
49+
deadlock or reorder work.
50+
- Holding a lock across any call that can re-enter the SDK: finishing a span or transaction,
51+
capturing an event, logging through `options.getLogger()`, any `ISpan` or `IScopes` call, or a
52+
user callback or listener. Event processors take their own locks and call back into SDK
53+
components, so the locks are taken in opposite orders and deadlock. On Android that is usually an
54+
ANR. Read what is needed under the lock and make the call after releasing it.
55+
- Moving such a call out of a lock can break an operation that was atomic only because the lock
56+
spanned it. The fix is a second lock that serializes the callers and that the re-entrant path
57+
never takes, not widening the original lock again.
58+
- Shutting down or awaiting an executor, or doing I/O, while holding a lock.
59+
- State guarded by a lock must be written and serialized under that same lock everywhere.
60+
- Two locks that another path takes in the opposite order.
61+
- New disk I/O, network calls, or lock waits reachable from the Android main thread or from an init
62+
path. Reflection, class loading, regex compilation, and eager allocation added to an init path
63+
count too.
64+
- One operation that sometimes runs inline and sometimes gets posted to a queue. That breaks
65+
ordering across threads.
66+
- Shared state published only after the operation it describes has started, so concurrent readers
67+
see a gap.
68+
- Reading the same mutable shared field several times for decisions in one pass. Read it once.
69+
- In JVM and shared modules, including `sentry` core, new locks use `AutoClosableReentrantLock`, not
70+
`synchronized`, which pins virtual threads on JDK 21-23. Android-only modules
71+
(`sentry-android-*`) use `synchronized`.
72+
- A new class whose threading model is not obvious needs it stated in its Javadoc.
73+
74+
### Test coverage of new behavior
75+
76+
Report a missing test only in these cases:
77+
78+
- New customer-facing behavior (a component, an integration, an option) ships with no test that
79+
exercises it at all. An untested branch in otherwise tested code is not a finding.
80+
- A `fix` PR has no regression test that would fail without the fix. If the diff does not make
81+
that clear, ask the author to confirm.
82+
- A feature added to sibling integration modules (versions of the same library, `javax` and
83+
`jakarta` variants) is tested in some of them and not the others.
84+
- New auto-configuration adds its own class or property condition and has no test for the "class
85+
missing, feature enabled" case. A condition inherited from an enclosing configuration does not
86+
count.
87+
- A new field on an `io.sentry.protocol` class needs serialization, deserialization, and a
88+
round-trip test. A new protocol context class needs a copy-constructor test like the existing
89+
ones.
90+
91+
Internal refactors that keep behavior the same do not need new tests.
92+
93+
### Public API surface
94+
95+
- New constructors and methods stay `private` or package-private unless code outside the package
96+
needs them.
97+
- New classes and methods not meant for customers need `@ApiStatus.Internal`. New unstable API needs
98+
`@ApiStatus.Experimental`.
99+
- Removing public API, changing its signature, or changing a public class's superclass or
100+
interfaces is a breaking change. Deprecate first and keep a bridge. This does not apply to
101+
`@ApiStatus.Internal` API.
102+
- Do not deprecate public API when the only replacement is `@ApiStatus.Internal`. Users have
103+
nothing to migrate to, and `-Werror` builds break.
104+
- New features are opt-in through `SentryOptions` or a namespaced options class, not public mutable
105+
fields on an integration. If a new feature is on by default, ask "are you sure?".
106+
- Silently changing a default, a sampling rate, or a feature toggle needs a deprecation or a
107+
`CHANGELOG.md`/`MIGRATION.md` note that says what integrators need to do.
108+
109+
### Android, ProGuard, and module boundaries
110+
111+
- The core `sentry` module is Java 8 and must not reference Android or JVM-only APIs. Reach platform
112+
code through `Platform`, `LoadClass`, or a separate module.
113+
- Constructing a class that calls APIs newer than `minSdk` must be guarded by
114+
`BuildInfoProvider.getSdkInfoVersion()`.
115+
- New reflection, and class names looked up by string at runtime, need matching ProGuard keep rules.
116+
- New `ManifestMetadataReader` reads follow the existing access pattern. The Sentry Android Gradle
117+
Plugin's manifest optimization depends on it.
118+
- Code that exists because the Sentry Android Gradle Plugin rewrites bytecode must say so in a
119+
comment, so it is not changed by accident.
120+
121+
### Integrations and instrumentation
122+
123+
- Anything an integration registers during init (callbacks, receivers, listeners, executors) must be
124+
undone in its `close()`.
125+
- New integrations register with `IntegrationUtils.addIntegrationToSdkVersion(...)`.
126+
- Automatic spans set an origin with `SpanOptions.setOrigin` matching `[A-Za-z0-9_.]` and use a
127+
standard span op. Every started span is finished on all paths, including error paths.
128+
- A wrapper around a third-party listener or factory keeps that type's documented contract,
129+
including one instance per lifecycle and callbacks that arrive out of the usual order. A
130+
deliberate deviation is documented in the wrapper's Javadoc or KDoc.
131+
- Errors in instrumented user code still reach the host app's handlers. Instrumentation must not
132+
swallow them, and must not capture an error the global handlers will also report.
133+
- When the SDK drops data early (rate limit, sampling, backoff, full queue), it records a client
134+
report with the matching discard reason.
135+
136+
### State and contracts
137+
138+
- A method that returned a defensive copy must not start returning internal mutable state.
139+
- Value objects shared as static constants stay immutable. Do not add setters to them.
140+
- Changing class loading or initialization timing must not break static initializers that rely on
141+
running early, such as background native library loading.
142+
- When a change weakens a guarantee that a class's Javadoc states (atomicity, durability,
143+
thread-safety), the Javadoc must be updated.
144+
145+
## Severity
146+
147+
| Level | Use for |
148+
|---|---|
149+
| high | Can crash or hang the host app, deadlock, corrupt or lose captured data, or break binary compatibility for customers. |
150+
| medium | Any other rule above broken in a way a customer can hit, and missing tests for new customer-facing behavior. |
151+
| low | Do not use. Findings below medium are not reported, so either the finding matters or there is none. |
152+
153+
## Output
154+
155+
For each finding, give the rule it breaks, the line, the concrete way it goes wrong (which thread,
156+
which caller, which customer setup), and the smallest fix.

‎agents.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ source = "path:.agents/skills/btrace-perfetto"
2323
[[skills]]
2424
name = "check-code-attribution"
2525
source = "path:.agents/skills/check-code-attribution"
26+
27+
[[skills]]
28+
name = "java-sdk-review"
29+
source = "path:.agents/skills/java-sdk-review"

‎warden.toml‎

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ version = 1
66
# getsentry Warden CI only provides WARDEN_OPENROUTER_API_KEY; pinning an
77
# anthropic/* model fails auth.
88

9-
# Warden's schema does not support per-skill verification config; this is the only
10-
# placement available. Disabled for attribution policy checks: a second verifier
11-
# pass often rejects valid header/NOTICES mismatches (e.g. "NOTICES still documents it").
12-
[defaults.verification]
13-
enabled = false
14-
159
# Warden's schema does not support per-skill chunking config; these patterns apply
16-
# globally but are tuned for check-code-attribution. Attribution checks need the full
17-
# file header and a NOTICES cross-check — not isolated diff hunks.
10+
# to every skill. They were tuned for check-code-attribution, which needs the full
11+
# file header and a NOTICES cross-check — not isolated diff hunks. java-sdk-review
12+
# also benefits from whole files: its rules depend on fields, locks and callers
13+
# outside the changed lines.
1814
[[defaults.chunking.filePatterns]]
1915
pattern = "**/*.api"
2016
mode = "skip"
@@ -94,6 +90,11 @@ ignorePaths = [
9490
"warden.toml",
9591
]
9692

93+
# Disabled for attribution policy checks: a second verifier pass often rejects valid
94+
# header/NOTICES mismatches (e.g. "NOTICES still documents it").
95+
[skills.verification]
96+
enabled = false
97+
9798
[[skills.triggers]]
9899
type = "pull_request"
99100
actions = ["opened", "synchronize"]
@@ -102,3 +103,30 @@ failCheck = false
102103

103104
[[skills.triggers]]
104105
type = "local"
106+
107+
# sentry-java conventions and contracts that need reading beyond the changed lines.
108+
# Rules that a model can check from one file belong in decision-model-linter instead.
109+
[[skills]]
110+
name = "java-sdk-review"
111+
paths = ["**/src/main/**", "**/src/androidMain/**"]
112+
ignorePaths = [
113+
# Samples and test helpers ship no SDK API.
114+
"sentry-samples/**",
115+
"sentry-android-integration-tests/**",
116+
"sentry-test-support/**",
117+
"sentry-system-test-support/**",
118+
]
119+
incremental = true
120+
maxTurns = 30
121+
# Report only: Warden comments on PRs but does not block merges.
122+
failOn = "off"
123+
reportOn = "medium"
124+
125+
[[skills.triggers]]
126+
type = "pull_request"
127+
actions = ["opened", "synchronize", "reopened"]
128+
requestChanges = false
129+
failCheck = false
130+
131+
[[skills.triggers]]
132+
type = "local"

0 commit comments

Comments
 (0)