Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/decision-model-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Decision model lint

on:
pull_request:
types: [opened, reopened, synchronize, labeled, unlabeled]

concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true

permissions: {}

jobs:
lint:
name: Decision model lint
# Never pull_request_target, which would give a pull request's code the key. Forks get no
# secrets, so skip them. Every label change re-runs the lint, because a skipped run would
# replace the last result.
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: write # to keep one comment with the findings
steps:
# The pull request's merge commit and its first parent: HEAD^1..HEAD is what it changes.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 2
persist-credentials: false

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '24'

- run: npm ci --prefix lint --ignore-scripts

- name: Lint
env:
OPENROUTER_API_KEY: ${{ secrets.WARDEN_OPENROUTER_API_KEY }}
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.number }}
LABEL: Override decision model lint
OVERRIDDEN: "${{ contains(github.event.pull_request.labels.*.name, 'Override decision model lint') }}"
run: |
report="$RUNNER_TEMP/decision-model-lint.md"
status=0
lint/node_modules/.bin/decision-model-linter --config lint/decision-model-linter.config.ts \
--base HEAD^1 --format markdown > "$report" || status=$?

# Only 1 means findings; any other failure means the linter did not finish.
if [ "$status" -eq 1 ] && [ "$OVERRIDDEN" = true ]; then
printf '\nThe `%s` label keeps these errors from failing the check.\n' "$LABEL" >> "$report"
elif [ "$status" -eq 1 ]; then
printf '\nThese errors fail the check; fix the code to resolve them. If you and a reviewer are confident an error is wrong, a person can add the `%s` label to pass the check while the findings stay reported. Agents should never add this label.\n' "$LABEL" >> "$report"
elif [ "$status" -gt 1 ] && [ "$OVERRIDDEN" = true ]; then
printf 'The linter did not finish (exit %s), and the `%s` label passes the check anyway; see the job log.\n' "$status" "$LABEL" >> "$report"
fi

marker='<!-- decision-model-linter -->'
comment=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" --paginate \
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"$marker\"))) | .id" | head -n 1)
body=
if [ -s "$report" ] && { [ "$status" -le 1 ] || [ "$OVERRIDDEN" = true ]; }; then
body=$(printf '%s\n%s' "$marker" "$(cat "$report")")
elif [ "$status" -eq 0 ] && [ -n "$comment" ]; then
body=$(printf '%s\nNo findings on the latest commit.' "$marker")
fi
if [ -n "$body" ] && [ -n "$comment" ]; then
gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment" -f body="$body" > /dev/null
elif [ -n "$body" ]; then
gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -f body="$body" > /dev/null
fi
cat "$report" >> "$GITHUB_STEP_SUMMARY"

if [ "$status" -ne 0 ] && [ "$OVERRIDDEN" = true ]; then exit 0; fi
exit "$status"
Comment on lines +61 to +77

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment API write failure bypasses the lint status gate

If a GitHub comment create or update fails, -e exits before the intended status gate: an otherwise-clean run with an existing comment fails, and an override cannot pass failed lint. The comment lookup pipeline does not have the claimed pipefail behavior because this step uses GitHub Actions’ default shell.

Evidence
  • The step does not specify shell:, so GitHub Actions uses its default Bash shell with -e, not -o pipefail.
  • When lint succeeds and an existing bot comment is found, lines 66–70 set a “No findings” body and make an unguarded PATCH request. For a failed lint with the override label, lines 64–72 likewise write the report before reaching the override gate.
  • A nonzero result from either direct gh api write exits the script under -e, skipping lines 76–77; thus a comment-write failure can fail a clean check or prevent the override from taking effect. The lookup pipeline’s status is instead the final head status without `pipefail.

Identified by Warden · code-review · YQX-HGT

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ agents.lock

# Warden local run logs
.warden/logs/

# decision-model-linter dependencies
lint/node_modules/
41 changes: 41 additions & 0 deletions lint/decision-model-linter.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Questions a decision model answers about each changed file on a pull request. Rules here need only
// the changed lines of one file, and need judgment: anything a parser can decide (banned calls or
// imports, formatting, unused code) belongs in Spotless, detekt, Error Prone, or Android Lint. Rules
// that need reading across files belong in the Warden `java-sdk-review` skill.
import type { Config, Model } from "@sentry/decision-model-linter";

import android from "./suites/android.ts";
import gradle from "./suites/gradle.ts";
import instrumentation from "./suites/instrumentation.ts";
import kotlinInterop from "./suites/kotlin-interop.ts";
import publicApi from "./suites/public-api.ts";
import resources from "./suites/resources.ts";
import safety from "./suites/safety.ts";
import tests from "./suites/tests.ts";

const jev = {
provider: "openrouter",
name: "typesafe/jev-1.13",
apiKey: process.env.OPENROUTER_API_KEY,
maxInputTokens: 32_768,
} satisfies Model;

export default {
model: jev,
threshold: 0.7,
// A file the model could not check must never look like a clean pass.
unchecked: "error",
ignores: [
"**/build/**",
"**/generated/**",
// Samples and test helpers ship no SDK code.
"sentry-samples/**",
"sentry-android-integration-tests/**",
"sentry-test-support/**",
"sentry-system-test-support/**",
// Build logic is not SDK code; only the gradle suite lints it again.
"build-logic/**",
"buildSrc/**",
],
suites: { safety, tests, publicApi, kotlinInterop, android, instrumentation, resources, gradle },
} satisfies Config;
14 changes: 14 additions & 0 deletions lint/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// The linter's globs have no brace expansion, so each extension is its own glob.
export const MAIN_JAVA = ["**/src/main/**/*.java"];
export const MAIN_KOTLIN = ["**/src/main/**/*.kt"];
export const MAIN_SOURCES = [...MAIN_JAVA, ...MAIN_KOTLIN];
export const TEST_SOURCES = [
"**/src/test/**/*.java",
"**/src/test/**/*.kt",
// Also matches flavor source sets such as `androidTestReplay`.
"**/src/androidTest*/**/*.java",
"**/src/androidTest*/**/*.kt",
// Spring and servlet modules run tests against a real server in these source sets.
"**/src/integrationTest*/**/*.java",
"**/src/integrationTest*/**/*.kt",
];
25 changes: 25 additions & 0 deletions lint/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions lint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"type": "module",
"devDependencies": {
"@sentry/decision-model-linter": "0.3.0"
}
}
25 changes: 25 additions & 0 deletions lint/suites/android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Suite } from "@sentry/decision-model-linter";

import { yesNo } from "../yes-no.ts";

export default {
files: ["sentry-android*/**/src/main/**/*.java", "sentry-android*/**/src/main/**/*.kt"],
context: { minSdk: "The SDK's minSdk is 21." },
rules: {
missingRequiresApi: yesNo(
"Do the new lines add a class or method that calls Android APIs newer than `minSdk` and only runs " +
"on those API levels, without `@RequiresApi`?",
"Code that only runs above minSdk is missing `@RequiresApi`.",
"The new lines call no API newer than minSdk, or are annotated `@RequiresApi`.",
"Annotate it with `@RequiresApi(...)` so Lint catches callers that don't check the SDK version.",
),
redundantNewApiSuppression: yesNo(
"Do the new lines add `@SuppressLint(\"NewApi\")` or `@SuppressWarnings(\"NewApi\")` to code where an " +
"SDK version check already guards the call?",
"A NewApi suppression is added where a version check already guards the call.",
"The new lines add no NewApi suppression, or the suppression is needed.",
"Remove the suppression. The version check already satisfies Lint, and the suppression would hide " +
"future unguarded calls.",
),
},
} satisfies Suite;
29 changes: 29 additions & 0 deletions lint/suites/gradle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Banned calls such as `afterEvaluate`, `tasks.create`, or string dependency coordinates belong in
// detekt, not here: a parser decides them without a model.
import type { Suite } from "@sentry/decision-model-linter";

import { yesNo } from "../yes-no.ts";

export default {
files: ["**/*.gradle.kts", "build-logic/**/*.kt", "buildSrc/**/*.kt"],
// The config ignores build logic for the SDK suites; lint it again here.
ignores: ["!build-logic/**", "!buildSrc/**"],
rules: {
configurationCacheHazard: yesNo(
"Do the new lines read a hard-coded local path (such as `~/.m2` or a user directory), or read " +
"`project`, system properties, or environment variables at execution time in a way that breaks " +
"the configuration cache?",
"Build logic reads local paths or breaks the configuration cache.",
"The new lines read no local paths and stay configuration-cache compatible.",
"Use providers (`providers.environmentVariable`, `layout`) and avoid machine-specific paths.",
),
raisedSupportFloor: yesNo(
"Do the new lines raise `minSdk`, the Java or JVM target level, or the lowest supported version of " +
"a framework the SDK integrates with?",
"A support floor is raised.",
"No support floor is raised.",
"Raising a support floor drops customers. Make sure the PR calls it out and `CHANGELOG.md` (and " +
"`MIGRATION.md` if needed) says so.",
),
},
} satisfies Suite;
40 changes: 40 additions & 0 deletions lint/suites/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { Suite } from "@sentry/decision-model-linter";

import { MAIN_KOTLIN, MAIN_SOURCES } from "../files.ts";
import { yesNo } from "../yes-no.ts";

export default {
files: MAIN_SOURCES,
rules: {
firstHeaderValueOnly: yesNo(
"Do the new lines read an HTTP header that may appear more than once (such as `Cookie`, " +
"`Set-Cookie`, or `baggage`) and use only its first value?",
"Only the first value of a header that can repeat is processed.",
"The new lines read no repeatable header, or process every value.",
"Process every value of this header; it can appear more than once.",
),
replacesThirdPartyBaggage: yesNo(
"Do the new lines remove or overwrite the whole `baggage` header when adding Sentry's entries, " +
"instead of merging with existing third-party entries?",
"Third-party baggage entries are dropped when Sentry's are added.",
"The new lines don't touch baggage, or merge with existing entries.",
"Merge Sentry's entries into the existing `baggage` header instead of replacing it.",
),
coroutineCancellationAsError: yesNo(
"Do the new lines, in coroutine instrumentation, treat `CancellationException` as an error (mark the " +
"span as errored or capture it) instead of setting `SpanStatus.CANCELLED` and rethrowing?",
"Coroutine cancellation is treated as an error.",
"The new lines don't handle coroutine cancellation, or handle it as cancellation.",
"Handle `CancellationException` separately: set `SpanStatus.CANCELLED` and rethrow it.",
{ files: MAIN_KOTLIN },
),
wastedWork: yesNo(
"Do the new lines do measurement, allocation, or other expensive work on a hot path (per span, per " +
"event, per frame, per request) before checking whether the result is needed, for example when " +
"there is no active span or the feature's option is disabled?",
"Work is done on a hot path even when its result is thrown away.",
"The new lines check whether the work is needed first, or are not on a hot path.",
"Check first, and skip the work when its result would be discarded.",
),
},
} satisfies Suite;
19 changes: 19 additions & 0 deletions lint/suites/kotlin-interop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Suite } from "@sentry/decision-model-linter";

import { MAIN_JAVA } from "../files.ts";
import { yesNo } from "../yes-no.ts";

export default {
files: MAIN_JAVA,
rules: {
mismatchedAccessors: yesNo(
"Do the new lines add or change a Java getter or setter whose pair uses a different type (boxed " +
"versus primitive, such as `Boolean` and `boolean`) or a name that doesn't match (`isX` with " +
"`setY`, `getX` with `setX` taking another type)?",
"A getter and setter pair don't match, so Kotlin can't combine them into one property.",
"Every new getter and setter shown matches its pair, or there are none.",
"Use the same type and matching names for the getter and setter, so Kotlin callers get a single " +
"property instead of a getter and a separate `setX(...)` call.",
),
},
} satisfies Suite;
26 changes: 26 additions & 0 deletions lint/suites/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Suite } from "@sentry/decision-model-linter";

import { MAIN_SOURCES } from "../files.ts";
import { yesNo } from "../yes-no.ts";

export default {
files: MAIN_SOURCES,
rules: {
missingApiStatus: yesNo(
"Do the new lines add a public class, interface, or method that is not meant for customers (for " +
"example in a `util` or `internal` package according to the file path) without " +
"`@ApiStatus.Internal`, or new API described as unstable without `@ApiStatus.Experimental`?",
"New public API is missing `@ApiStatus.Internal` or `@ApiStatus.Experimental`.",
"New public API is annotated as intended, or the new lines add no public API.",
"Mark API not meant for customers `@ApiStatus.Internal`, and unstable API `@ApiStatus.Experimental`. " +
"Anything else becomes public API we must keep binary compatible.",
),
testOnlyWithoutAnnotation: yesNo(
"Do the new lines add a constructor, method, or setter that is evidently there only for tests " +
"(named or commented as such) without `@TestOnly`?",
"Test-only code in production sources is missing `@TestOnly`.",
"The new lines add no test-only code, or it is annotated `@TestOnly`.",
"Annotate it with `@TestOnly`, or inject the collaborator through the constructor instead.",
),
},
} satisfies Suite;
67 changes: 67 additions & 0 deletions lint/suites/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Resources, time, and code that will be misread without a comment.
import type { Suite } from "@sentry/decision-model-linter";

import { MAIN_SOURCES } from "../files.ts";
import { yesNo } from "../yes-no.ts";

export default {
files: MAIN_SOURCES,
rules: {
leakOnPartialRelease: yesNo(
"Do the new lines release several resources (streams, files, executors, receivers, callbacks) in one " +
"block so that a failure releasing one leaves the others unreleased?",
"A failure releasing one resource leaks the rest.",
"The new lines release each resource independently, or release at most one.",
"Release each resource in its own `finally` (or try-with-resources), so one failure does not leak the others.",
),
replacedCloseableNotClosed: yesNo(
"Do the new lines add a setter or assignment that replaces a closeable resource (executor, stream, " +
"transport) without closing the old one or documenting that the caller must?",
"A closeable resource is replaced without closing the old one.",
"The new lines replace no closeable resource, or close or document the old one.",
"Close the resource being replaced, or document that the caller owns it.",
),
heldSdkExecutor: yesNo(
"Do the new lines store the SDK's executor (`getExecutorService()` or `getTimerExecutorService()`) " +
"in a field, or capture it in a long-lived object, instead of reading it from the options each " +
"time it is used?",
"The SDK's executor is held instead of read from the options when used.",
"The new lines don't hold the SDK's executor, or only read it into a local variable before using it.",
"Read the executor from the options each time. The options replace the no-op executor when the SDK " +
"starts, and re-init closes and replaces it, so a held reference can run nothing or a closed executor.",
),
timeoutOnWorkerExecutor: yesNo(
"Do the new lines schedule a timeout or deadline (a callback that fires if something hasn't " +
"happened in time) on `getExecutorService()` rather than `getTimerExecutorService()`?",
"A timeout is scheduled on the worker executor.",
"The new lines schedule no timeout, or schedule it on `getTimerExecutorService()`.",
"Schedule timeouts on `options.getTimerExecutorService()`. On the worker executor they queue behind " +
"cached envelopes and other work, and fire late.",
),
unitlessQuantity: yesNo(
"Do the new lines add a numeric field, parameter, or method for a time or size whose name has no " +
"unit (`Ms`, `Millis`, `Nanos`, `Seconds`, `Bytes`) and whose type does not carry one?",
"A time or size quantity has no unit in its name or type.",
"Every new time or size quantity names its unit, or there are none.",
"Add the unit to the name, for example `timeoutMs` or `maxSizeBytes`.",
),
unclearClock: yesNo(
"Do the new lines add a timestamp or duration without making clear (by name, type, or comment) " +
"whether it comes from the wall clock or a monotonic clock?",
"A new time value leaves its clock type unclear.",
"The new lines add no time values, or each one makes its clock clear.",
"Use `EpochClock` for wall-clock timestamps and `MonotonicTicker` for durations, and make the clock " +
"clear in the name.",
),
unexplainedWorkaround: yesNo(
"Do the new lines add code whose reason is not obvious and that a future maintainer would likely " +
"revert or simplify by mistake (a workaround, a `WeakReference`, resetting state, holding a " +
"redundant reference, disabling a cache) without a comment explaining why?",
"Non-obvious code has no comment explaining why it is there.",
"The new lines are self-explanatory, or carry a comment explaining why.",
"Add a comment explaining why this is needed, so it is not reverted later.",
// High threshold: "needs a comment" is easy to over-report.
{ threshold: 0.9 },
),
},
} satisfies Suite;
Loading
Loading