Skip to content

feat(sentry): watch cron jobs: Sentry Crons check-ins and ping URLs on the Crons tab and over MCP - #385

Merged
roxblnfk merged 7 commits into
masterfrom
feat/sentry-crons
Nov 24, 2026
Merged

roxblnfk merged 7 commits into
masterfrom
feat/sentry-crons

Conversation

@roxblnfk

Copy link
Copy Markdown
Member

🔍 What was changed

  • The Crons tab of the Sentry section works: GET /api/crons, GET /api/crons/{slug}/checkins in the shape frontend 1.42.0 reads, DELETE /api/crons/{slug}, and the sentry.stored push of kind cron. The tab is always shown now; its job page shows the runs, output, traces and ping URLs.
  • Check-ins come as check_in envelope items, the Sentry cron HTTP endpoint /api/{id}/cron/{slug}/{key}/, or the ping URLs /ping/{slug}, /start, /fail (?schedule=&tz=&margin=&max_runtime=&project=, body kept as the job's output, last 10 KB). The monitor is upserted from monitor_config as Sentry does.
  • list_crons MCP tool, a console line per check-in (no "no renderer" line), trap test sends SDK and ping check-ins, /api/projects lists the projects of monitors too. /ping/... requests are no longer HTTP dumps.

How it works

  • A check-in opens a run (in_progress) or closes it by check_in_id; a ping without an ID closes the newest started ping run. The next slot is the first after the start of the last run, or after now when that has passed.
  • About once a second, while the UI or MCP runs: no check-in within the margin → missed (not while a run is in progress); a run past its max runtime → timeout; slots that fell while the loop did not run (machine asleep) → one unknown row.
  • Clearing the Sentry section drops runs and keeps monitors (they keep expecting slots); 200 monitors, 100 runs each.

Review notes

Deliberate differences from buggregator/server 2.14, which was used only for the wire contract:

  • Schedules: slots are wall times of the monitor zone; a time skipped by DST is no slot, a repeated one is one slot of a fixed-hour job (both for *-hour jobs); interval of days or more keeps the wall time and clamps month ends (Jan 31 + 1 month = Feb 28). @every is rejected, as Sentry does.
  • Slugs are slugified as Sentry does (Reports Send → reports-send, max 50) instead of rejected; margin and max runtime are 1–40 320 minutes (Sentry's range), not ≥ 0.
  • A repeated in_progress extends the run's max runtime (Sentry heartbeat); each run keeps the timeout it started with; a finished run is final.
  • The next slot counts from the start of the run, not from the closing check-in, so an interval job does not drift by its duration.
  • A full store evicts the least recently active monitor instead of answering 429; there is no PUT /api/crons/{slug} (the UI does not call it; ping query and monitor_config configure a monitor).
  • One monitor per slug and project whatever the environment; failure_issue_threshold/recovery_threshold are ignored since Trap raises no issues.

Checklist

  • How was this tested:
    • Unit tests added: schedules with DST and zones, missed/timeout/unknown with a controlled clock, ingest, endpoints, projects and clearing, MCP tool, console
    • Unit, Arch and Acceptance suites run locally (only the known ProtobufCasterTest failures), psalm (only the known Run.php errors), structarmed, markdownlint
    • Tested manually: trap -p18311 --ui=18311 --mcp=18311, envelopes, cron HTTP endpoint and pings; a 1-minute interval job went missed, a 1-minute ping run timed out; Crons tab and every job page in headless Chromium with no errors but the known /api/update and queues 404s; a new ping showed on the open tab without a reload; list_crons over MCP

Documentation

docs/sentry.md (new Crons section), docs/web-ui.md, docs/mcp.md, docs/cli.md, docs/http-dump.md, and the trap skill (SKILL.md, references/mcp.md, references/integrations.md).

…sed and timed-out runs on the Crons tab and over MCP

The Crons tab of the bundled UI got 404 from `/api/crons` and stayed hidden. Trap now takes `check_in` envelope items, the Sentry cron HTTP endpoint `/api/{id}/cron/{slug}/{key}/` and the ping URLs `/ping/{slug}[/start|/fail]` the job page shows, upserts the monitor from its `monitor_config` as Sentry does (a field left out keeps its value, `null` resets it), and keeps 200 monitors with 100 runs each in the telemetry store. While an event consumer runs, the main loop checks them about once a second: a slot without a check-in within the margin is missed, a run in progress past its max runtime times out, and slots that fell while the loop did not run (the machine slept) make one unknown row; each change reaches the UI by the `sentry.stored` push of kind `cron`.

Crontabs and intervals follow the Sentry spec and real cron rather than the Go server: slots are wall times of the monitor's zone, a time skipped by clocks going forward is no slot and one they repeat is one slot of a fixed-hour job, intervals of a day or longer keep the wall time and clamp month ends, slugs are slugified as Sentry does, margin and max runtime are 1 to 40 320 minutes, an `in_progress` again extends a run, the next slot counts from the start of the run, and each run keeps the timeout it began with. Clearing the Sentry section deletes runs and keeps the monitors; `DELETE /api/crons/{slug}` deletes one. `/api/projects` lists the projects of monitors too, `list_crons` reads them over MCP, the console prints a line per check-in with the reason a config was ignored, and `trap test` sends SDK and ping check-ins.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added enhancement New feature or request tests Changes in the tests labels Nov 23, 2026
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.41010% with 78 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.07%. Comparing base (9ff91cf) to head (9a05530).

Files with missing lines Patch % Lines
src/Module/Sentry/Mcp/ListCrons.php 57.14% 30 Missing ⚠️
src/Server/Telemetry/Cron/CheckIn.php 0.00% 15 Missing ⚠️
src/Server/Command/Test.php 0.00% 8 Missing ⚠️
src/Server/Telemetry/Cron/MonitorConfig.php 78.57% 6 Missing ⚠️
src/Module/Sentry/Frontend/EnvelopeMapper.php 16.66% 5 Missing ⚠️
src/Module/Sentry/Http/CronTrap.php 96.51% 3 Missing ⚠️
src/Module/Sentry/Module.php 0.00% 3 Missing ⚠️
src/Server/Telemetry/Cron/Crons.php 97.69% 3 Missing ⚠️
src/Module/Sentry/Console/SentryEnvelope.php 84.61% 2 Missing ⚠️
src/Module/Sentry/Console/CheckInLine.php 97.14% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #385      +/-   ##
==========================================
+ Coverage   80.78%   81.07%   +0.29%     
==========================================
  Files         441      453      +12     
  Lines       17813    18490     +677     
==========================================
+ Hits        14390    14991     +601     
- Misses       3423     3499      +76     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

… downtimes, late runs and clock changes

An interval is 1 minute to 10 years: a huge value from an SDK made `next()` throw in the main loop, or return the same slot so `miss()` looped forever. The checker now stops expecting a monitor whose schedule does not move on, and a failure of one monitor or of a listener no longer stops Trap.

A downtime makes one `unknown` row per monitor whatever the checks after it, and the next slot is the first after Trap woke up, so a long sleep takes one step per monitor instead of one per slot. The next slot counts from the start of the newest run, so an older run that ends late no longer moves it back into a false miss; a crontab run that starts less than a minute (and less than the margin and a quarter of the period) before its slot counts for that slot, for hosts whose clock runs ahead. Interval slots count from their anchor, so a daily slot moved by a change of clocks does not move the ones after it; the crontab search stops at each change of clocks, as Pacific/Chatham jumps at :45; a clock set back keeps the checks going; a heartbeat extends a run by the max runtime the run started with. `?` is a whole day field only.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
…eeps and `list_crons` returns

A ping body of any size is taken and keeps its last 10 KB; the cron HTTP API keeps its 1 MB limit. An environment keeps 64 characters, a trace ID only 32 hex digits, and the output of all runs 8 MB. `list_crons` returns the last 1 024 bytes of an output, and it and the web UI API find a slug as the job sent it. A `monitor_config` that is no object gets `400` from the HTTP API and is ignored with a warning from an SDK; a `check_in` item that is no object says why it is dropped. The MCP instructions name `list_feedback` and `list_crons`, and the docs and the skill say that `/ping/...` is no HTTP dump and that port 8000 takes pings.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
…f its changes, and take an early run by the gap before its slot

A monitor whose schedule fails, a check that fails and a listener that throws are logged in the console instead of passing silently, and a listener that throws for one project no longer keeps the other projects and listeners from being told of their timed-out and missed runs.

A run that starts before a crontab slot counts for that slot only if the slot before is more than four times as far back, so with `0,1 * * * *` a run late for :00 no longer hides a missed :01. A JSON list sent as a check-in says it is no object. The docs and the skill state the 64M limit of a chunked ping body, the max runtime a heartbeat keeps, and the skill now has the clock-skew rule, the next slot after a downtime, the 10-year interval cap, the caps of an environment and a trace ID and the 1 MB limit of the cron HTTP API.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
…r one slot only

A listener that throws on stored traces, logs, metrics, feedback or check-ins is logged and the next listener is still told, as for the cron checks. A run that starts shortly before a crontab slot while the slot before still waits for its run is the run of that slot, so with `* * * * *` a run at 12:00:50 after none for 12:00 no longer skips 12:01. The docs and the skill say "less than a minute before", which slot a late run stays with, and that only the cron HTTP API rejects a `monitor_config` that is no object.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/mcp.md
#	docs/sentry.md
#	docs/web-ui.md
#	skills/trap/references/mcp.md
#	src/Module/Sentry/Module.php
#	tests/Unit/Module/Frontend/UiControllersTest.php
#	tests/Unit/Module/Mcp/Protocol/McpServerTest.php
@roxblnfk
roxblnfk marked this pull request as ready for review November 24, 2026 06:17
@roxblnfk
roxblnfk requested a review from a team November 24, 2026 06:17
@roxblnfk
roxblnfk merged commit 5cb5927 into master Nov 24, 2026
@roxblnfk
roxblnfk deleted the feat/sentry-crons branch November 24, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tests Changes in the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant