Repository navigation
fix(jobs): report a failed job run to Sentry - #1050
Merged
Merged
Conversation
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-1050
October 30, 2026 15:07
Destroyed
|
🚅 Deployed to the SahajCloud-pr-1050 environment in sahajcloud
1 service not affected by this PR
|
Contributor
|
This PR is stacked on 🤖 sydevs dispatcher |
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-1050
October 30, 2026 16:21
Destroyed
Ardnived
added a commit
that referenced
this pull request
Oct 30, 2026
…ted import as expected The owner's decisions on #1050's expected failures: - **A missing Lemonfox key, or a missing public R2 URL, is the deployment's gap.** It is expected on a preview or locally, where nothing configures them. In production it stays a plain `Error`, so a lost key or bucket URL still alerts. Production is the repo's own `isProductionDeployment()`, which reads Railway's environment name and never `NODE_ENV`, so a local production build counts as local. - **Lemonfox returning no speech** is an answer about the recording (music, silence), already shown on its row: always expected. - **An import deleted while it waited** is a manager's choice: always expected. The job now reads the import before its `try`, so a deleted row no longer reaches `failImport`. It used to try to mark the missing row and log "could not be marked" at error. "Address lookup is not configured" stays at `error`, as the owner chose. Co-Authored-By: Claude Opus 5.5 <[email protected]>
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-1050
October 30, 2026 17:03
Destroyed
Contributor
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
The job runner catches a task's throw, records it on the job row and a log line, and tells no one. `CleanupCollections`, `CleanupOrphanedMedia` and our other tasks therefore failed silently, as `schedulePublish` did before #1046. #1046's `schedulePublish` handler wrap becomes `installJobCapture` (`src/plugins/sentry/jobCapture.ts`), which wraps every task in `config.jobs.tasks`: ours and Payload's own. It reports with `capture_source: job` and tags `task` and `job_id`. - **Once per job, on its final attempt.** Payload has no final-failure hook that carries the error: `onFail` gets none and runs on every attempt. The handler does receive the job the runner hands it, whose `taskStatus` counts the task's prior tries. For a single-task job the runner retries task `'1'` until those reach the task's `retries`, so that comparison is the runner's own rule. A task run inside a workflow is not reported, since workflow retries also decide its last attempt and none is configured. A manual `runByID` of a job that already failed for good reports again. - **A cancelled job is not reported.** - **No input beyond what `schedulePublish` already sent.** Only its input adds a `target` and the scheduling manager. - **No double report.** A job's own writes carry no user, or a routed request, so the Local API wrapper stands down inside it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Some job failures are answers, not incidents: an import whose target region was deleted or whose uploader left, or a transcript whose recording was replaced mid-run or which has no Lemonfox key. Each is already shown to whoever needs it, so reporting it at `error` alerts for nothing. `ExpectedJobFailure` (`src/lib/jobs/expectedFailure.ts`) is the convention. A task throws it, with the message the job row should carry, in place of an `Error`. The job capture still reports it, at `warning`, so it stays visible without alerting anyone. Every other failure in these tasks, such as the geocoder being down or Lemonfox returning no speech, stays a plain `Error`, reported at `error`. Payload re-wraps any handler throw in a `TaskError` built from its message, so the job row, the import's error and the transcript's status read exactly as before. `importEvents` marks its two cases, and `transcribeMeditation` its two. The convention is documented in `src/AGENTS.md`'s jobs section and in `docs/architecture.md`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ted import as expected The owner's decisions on #1050's expected failures: - **A missing Lemonfox key, or a missing public R2 URL, is the deployment's gap.** It is expected on a preview or locally, where nothing configures them. In production it stays a plain `Error`, so a lost key or bucket URL still alerts. Production is the repo's own `isProductionDeployment()`, which reads Railway's environment name and never `NODE_ENV`, so a local production build counts as local. - **Lemonfox returning no speech** is an answer about the recording (music, silence), already shown on its row: always expected. - **An import deleted while it waited** is a manager's choice: always expected. The job now reads the import before its `try`, so a deleted row no longer reaches `failImport`. It used to try to mark the missing row and log "could not be marked" at error. "Address lookup is not configured" stays at `error`, as the owner chose. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ardnived
force-pushed
the
claude/fix-report-failed-job-runs
branch
from
October 30, 2026 17:34
d837720 to
ee9bd72
Compare
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-1050
October 30, 2026 17:34
Destroyed
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1046: the owner asked for our own jobs' failures to be reported, in a separate PR.
Summary
schedulePublish, through fix(admin): a failed document write in the admin reaches no one #1046's handler wrap, generalised rather than duplicated.ExpectedJobFailure). It is still reported, but atwarning. Seven cases are marked inimportEventsandtranscribeMeditation, two of them only outside production.Change outline
Flow — every task's handler, wrapped once at
onInitBehaviour — the final-attempt rule, read off the job the runner hands the handler
Behaviour — which failures a task marks as expected
Payload re-wraps any handler throw in a
TaskErrorbuilt from its message. So the job row, the import'serrorand the transcript'sstatusread exactly as before; only the Sentry level changes.Files
src/plugins/sentry/ +├── jobCapture.ts # installJobCapture, isFinalAttempt; the schedulePublish input helpers moved here ├── localApiCapture.ts # the writes and jobs.queue only; imports the schedule helpers └── captureFailure.ts # `job` source already; adds `task` and `job_id` tagsPreview
Nothing on a preview shows this change. It acts only when a job fails on its final attempt (see Manual verification). Railway may also build no preview for a PR whose base is not
main.Test results
sentry-admin-write-capture(23),admin-write-capture.int(4),meditation-transcription.int(37),event-imports.int(30),lemonfox-response(6),database-cast-errors,error-disclosure,manager-magic-linkEach rule was watched failing first, by removing it:
retries" cases fail. So does the int case, which runs the realverifyEmbedstask (retries: 1) through the real runner twice: no event on the first run, one on the second.schedulePublishonly (fix(admin): a failed document write in the admin reaches no one #1046's behaviour): the three cases for our own tasks fail.expected: false): "still reports a failure the task marked as expected, at warning" fails.Error: the two transcription cases and the two import cases fail.NODE_ENVtoo (deploymentEnvironment()): both "local build withNODE_ENV=production" cases fail.Error: the int case and thelemonfox-responseunit case fail.Manual verification
verifyEmbeds). Queue it, then run it withPOST /api/payload-jobs/runonce more than itsretries.NEXT_PUBLIC_SENTRY_DSNset, confirm no event on the earlier attempts, and exactly one on the last:capture_source: job,task: verifyEmbeds,job_id: <id>.Notes for reviewer
/api/payload-jobs/runstarted the job, so the Local API wrapper stands down inside a job.runByIDof a job that already failed for good runs it again and reports again, as the runner itself logs "max retries reached" again.docs/architecture.md. A failure the handler never sees is not reported:{ state: 'failed' }(none does)processingDeliverSubmissionscan carry a transport message that names a rejected recipient over SMTP. Production's Resend transport does not throw that way.reload()replaces the config without runningonInit, so in dev the wrap lasts until the first reload. Production does not reload.Local review
Pass on the owner's extra marks. No blockers. Adopted:
failImporttried to mark the missing row. The job now reads the import before itstry, and the case asserts nothing is logged.isProductionDeployment(), the repo's own predicate (Railway's name, neverNODE_ENV, perdocs/environment.md), instead ofdeploymentEnvironment(), which counted a local production build as production. A case pins it.configGap, and a comment still called no speech "a failed run like any other". Both fixed.Kept as is: the normalizer throws
ExpectedJobFailureitself. Its other caller is a seed script, where the class name changes nothing.Pass on the expected-failure convention. No blockers. Behaviour was confirmed unchanged for every consumer except the Sentry level. Adopted:
takeAwayRecordinghelper, with the key set, and describes the real race (two parallel reads).src/AGENTS.mdparagraph wrapped and given theimportEventspath, and the architecture sentence order fixed.Pass on the job capture. No blockers. Adopted:
{}. A schedulePublish-shaped input now goes to another task, and removing the gate fails it.reqis passed", and why the wrap must judge the final attempt itself (onFailgets no error)./api/payload-jobs/runmakes it a routed request.{ state: 'failed' }branch is dropped. No task returns it, and its syntheticErrorwould group every such task into one issue. It is listed as a limit instead.captureFailure.ts's capture sites, a misplaced comment in the int spec, and a duplicate JSDoc.🤖 Generated with Claude Code