Skip to content

fix(schedule): report a row that fails to make once per version - #295

Closed
ChiragAgg5k wants to merge 1 commit into
mainfrom
fix/schedule-poison-row-reports-once
Closed

ChiragAgg5k wants to merge 1 commit into
mainfrom
fix/schedule-poison-row-reports-once

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What

Scheduler::reconcile() caches no entry for a row whose Source::make() throws, so the same row is reported again on every pass. Reconcile runs on a timer, so a row the source keeps listing and this scheduler keeps refusing reports forever.

The refusal is now pinned to the version that earned it: one report per version, and an edit that moves the version is tried again on the next sync rather than waiting for a restart. The memo is evicted with the row, on a full snapshot or when it goes inactive.

Why

Found by auditing the noisiest ongoing Sentry issues on Appwrite Cloud. CLOUD-3QW1 is 3,485 events since Sep 5 and still firing, roughly one every five minutes — and every one of them is the same row. A single function schedule holds the cron expression 22-3, which Trigger\Cron refuses, and schedule.functions.reconcile has been reporting it on every pass since.

Nothing is hidden by this. The row still reports once, with the same message and stack, and reports again if someone edits it and it still fails.

Why not change the parser instead

I first wrote this as a change to Trigger\Cron to accept 22-3 as a wrap around the field, and closed it. 22-3 is not portable cron. cronie's get_range(), the reference implementation, is

for (i = low_; i <= high_; i += step)
    set_element(bits, low, high, i);

which sets nothing when low > high — the job silently never runs. Its only special case is if (low_ > high_ && high_ == 0) high_ = 7;, a narrow Sunday fixup for 5-0, not general wrapping. npm cron-parser rejects the range outright. croniter wraps, but it is the outlier.

Accepting the wrap would also have started running a production function that has not executed since it was created, six times a day, on a project that never asked for a behaviour change.

The noise was never really about the parser: this row would have kept reporting on every pass whatever Cron accepted, and so will the next one.

Tests

Two cases in packages/schedule/tests/ReconcileTest.php, both seen red with the src/ hunk reverted:

  • a row that keeps failing is reported once across three reconciles, and make() is called once — so the row is skipped, not merely reported more quietly
  • a row edited to a version that makes cleanly is registered and starts producing occurrences, without a second report

bin/monorepo check schedule, bin/monorepo test schedule (97 unit + 9 e2e) and bin/monorepo validate all pass.

ReconcileTest's error collector moves off an anonymous class in the same commit: PHPStan reads no value type from the @var list<string> on its property, and bin/monorepo check schedule failed on main because of it. CI selects packages by change, so this branch is what makes that job run.

Still open, outside this PR

The one Cloud row is data, not code — it needs its schedule cleared or its owner told, and this change only stops it shouting. Appwrite's Task\Validator\Cron already rejects 22-3 on write, so no new row can reach this state; the existing one predates that validator.

A source of truth can hold a row nothing here accepts -- a schedule
written before the parser tightened, say. Reconcile runs on a timer and
cached no entry for such a row, so the same row was reported again on
every pass for as long as it sat there. One Appwrite Cloud function
schedule on an unparseable cron expression produced 3,485 Sentry events
in twelve days, roughly one every five minutes, all of them the same row.

Pin the refusal to the version that earned it. The row still surfaces
once, so nothing is hidden, and an edit that moves the version is tried
again on the next sync rather than waiting for a restart. The memo is
evicted with the row, on a full snapshot or when it goes inactive.

The test helper moves off an anonymous class because PHPStan reads no
value type from the `@var list<string>` on its property, which failed
`bin/monorepo check schedule` on main.
@github-actions

Copy link
Copy Markdown

Benchmark results

schedule — dispatch and reconcile at scale (4 cores, 10000 schedules: 30% cron / 70% interval, 30 ticks)

stage scale p50 ms max ms
reconcile: full snapshot, cold (every row made) 10000 rows 29.98 29.98
reconcile: full snapshot, warm (version diff) 10000 rows 1.01 4.34
tick + commit (one minute of coverage) 10000 schedules 29.48 38.52
cron next occurrence: leap-day expression 1000 windows 70.82 70.82

115680 occurrences dispatched, 3856 per tick average. Selecting one minute of coverage spends 0.049% of the 60s tick interval.

Shared CI runners — treat absolute numbers as rough, compare modes within a run. Commit cb24851.

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.

1 participant