Repository navigation
fix(events): ExpireEvents stalls on an event with invalid stored data - #841
Conversation
…d data Payload's beforeValidate field walk fills every absent field from the stored document, so beforeChange validates the merged whole. A four-key bookkeeping write was therefore checked as if an editor had re-submitted the entire event, and two production events whose stored contactPhone and images fail validators added after those rows were written could never be advanced, finished or logged. The reminder path also re-sent to a real manager every night: the exactly-once marker is persisted after the send, so the failing write lost it. The four validating write sites now go through one updateBookkeeping helper using unpublishAllLocales, the one supported argument that skips validation while still writing the main row and keeping the latest version row in step. draft: true skips validation too, but writes a version and no main row, so the event would keep its old stage and stay due forever. The trash write already had its own carve-out and is unchanged. A repeating per-event failure now reads apart from a one-off without opening the occurrence: the due watermark rides along from the due query, and the catch reports how many nights the event has sat past it plus a searchable expire_events.repeat tag. Refs #835 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0162ABvASJ6qMgA2qY1BRELm
A tightened Events validator no longer strands existing rows — and no longer stops the nightly job writing them either. That second half is the part a reader needs and neither file carried. Refs #835 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0162ABvASJ6qMgA2qY1BRELm
The repeat-failure heuristic is gone. resolveNextCheckAt arms a pre-adoption or finished event at a watermark already years in the past, so a first-ever examination of a stale imported row — the population this ticket is about — would have read as a repeat. The event id now rides as a Sentry tag instead: tags are indexed where contexts are not, so one event's occurrence history answers repeat-vs-one-off exactly, with nothing derived. Events gains a warning against localizeStatus. The root experimental flag is already on, so only Events omitting it keeps unpublishAllLocales from writing a draft status per locale on every nightly write. The image count derives from EVENT_IMAGE_LIMIT: against a literal 8, raising maxRows would leave the seed valid and the case vacuous. A missing version row now throws rather than returning, for the same reason. Seeding goes through one widened createDueEvent, and reload and the latest-version query are each defined once. Refs #835 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0162ABvASJ6qMgA2qY1BRELm
|
🚅 Deployed to the SahajCloud-pr-841 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the size of #835 and answers every AC. unpublishAllLocales is the right door: in [email protected] it is the only skipValidation case that still writes the main row.
One consequence is under-weighed. The fix lets the ladder run on the two broken events, so it now unpublishes them — and verify.ts:117 still validates (#842, open), while the in-place version write leaves nothing to restore. Sequence #842 first.
Findings
- should-fix —
ExpireEvents.ts:316— an invalid event can now be unpublished, with no way back. - consider —
ExpireEvents.ts:74— prose guards what the type could. - consider —
ExpireEvents.ts:350—dueSinceis unasked scope. - consider —
expire-events.int.spec.ts:469— a shadowedreload.
What was checked
#835, the PR body, ExpireEvents.ts, the spec, Events.ts, verify.ts. [email protected]: update.js, saveVersion.js, updateLatestVersion.js — skipValidation, the localizeStatus gate, the main-row write, unpublish overwriting the latest version.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The JSDoc carried the rule that `data` must not widen past the derived bookkeeping fields. The type carries it now: a fifth field fails typecheck rather than a reviewer, which matters because these writes skip validation. The four call sites already pass only these fields. Refs #835 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_015jPVXfk9jtfshVWZTSthZe
The describe block redefined the module-level `reload` with the same function — `trash` already defaults to false. Refs #835 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_015jPVXfk9jtfshVWZTSthZe
|
Addressed the adversarial review. Pushed Adopted
Open for you
Lean gate green, plus 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
The deploy-ordering thread is settled. No code change, so nothing was pushed. Adopted
Still open for you
🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
Changes
src/jobs/ExpireEvents/ExpireEvents.ts— oneupdateBookkeepinghelper behind the four sites; the due query carries each watermark for the failure report. Itsdatais typed to the four bookkeeping fields, so a fifth fails typecheck rather than a reviewer.src/collections/Events/Events.ts— comment only: a⚠against addinglocalizeStatus.tests/int/expire-events.int.spec.ts— five cases for the invalid-stored-data defect.Preview
The job has no admin surface and a PR preview carries no content, so there is nothing here to click through. The two pages that would show its effects, on an event you create yourself:
verificationStageand_status, the columns the job writesPREVIEW_ADMIN_PASSWORDReproducing the defect itself needs a db-layer write, which is what the integration cases do.
Test results
lint,typecheck,typecheck:tests, 2163 unit testsexpire-events.int.spec.ts(21),event-verification.int.spec.ts(28)Manual verification
EVENT_VERIFICATION_ENABLEDonce this merges. The ladder then unpublishes events 176 and 651, and until fix(events): verify must refuse invalid data, bookkeeping must not #842 lands there is no way back:verify.ts:117still validates, and the in-place version write leaves no published version to restore. The reviewer accepted that temporary breakage — the project is not live (thread) — so nothing gates on fix(events): verify must refuse invalid data, bookkeeping must not #842, which is itself blocked by this PR. Confirm 176 and 651 advance on the first run rather than failing it.147058729takes no occurrence newer than the deploy, ~48h after.Notes for reviewer
unpublishAllLocales: trueat all four sites, not thedb.updateOne+db.updateVersionpair. It is one supported argument, every hook keeps running, and row and version agree by construction.saveVersion({ unpublish })overwrites thelatest: truerow rather than appending, so after the job unpublishes an event there is no published version left to restore from. Both §2 options behave this way — it is inherent to keeping the version row in step. Flagging it because the ticket did not.⚠ Events.tsnow warns againstlocalizeStatus. The rootexperimental.localizeStatusflag is already on (payload.config.ts:82), so the only thing keepingunpublishAllLocalesfrom writing a per-locale draft status on every nightly write is Events omitting it. That was a one-line local edit away from a mass unpublish, with nothing at the edit site to say so.resolveNextCheckAtarms a pre-adoption orfinishedevent at a watermark already years past, so a stale imported row's first ever examination would read as a repeat — exactly the population this ticket is about. The event id as an indexed tag answers the question exactly instead, with nothing derived, and without splitting the existing Sentry issue.src/collections/Events/lifecycle/verify.ts:117writes with a plainpayload.update, so a manager clicking the reminder link on one of these events still gets a validation error. Filed separately rather than widened into this PR.dueSinceon the failure report belongs in this ticket. The deploy ordering is settled: no gating needed.Detail
Verified against
[email protected]innode_modules, not from the ticket's prose.collections/operations/utilities/update.js:154-157setsskipValidationfor exactly three inputs: a draft save with draft validation off, atrashcollection write carryingdeletedAt, andunpublishAllLocales. The first writes no main row, the second is whattrashEventalready rides — so the third is the only door, andupdateByID.js:135plumbs it through from the Local API.Why not gate the validators instead. A
req.contextflag the Events validators honour would not cover the images case:maxRowsis a built-in validator that no custom hook can opt out of.Performance. Per write, the version table sees two reads before and two after. The one dropped is
enforceMaxVersions'sORDER BY updated_at DESC OFFSET 100 LIMIT 1; the one added is an indexed limit-1.maxPerDoc: 100is injected by Payload's own sanitize, so that sweep really was firing on every old write. The nightly writes also stop appending a version row each, so the table no longer grows.Test fixture pre-mortem. The fixtures assume the stored paths are
contactPhoneandimagesat the document root, notdetails.*— checked againstsrc/collections/Events/Events.ts:226,319, whereDetailsis an unnamed tab. The image count derives fromEVENT_IMAGE_LIMIT(src/lib/utilities/eventImages.ts:18), so raisingmaxRowscannot leave the seed valid and the case vacuously green.Non-vacuity. Four of the five new cases were run against
origin/mainand fail there. The fifth — version-row parity — passes on both, because plainpayload.updatealso keeps the version in step by appending one; it guards the rejected raw-db.updateOnealternative, not the old code. The invalid-data cases also assert that the identical write through the public API is still refused, so they cannot pass for the wrong reason.Dismissed review findings. Lifting
updateBookkeepinginto a sharedsystemWritehelper coveringverify.ts,lib/registrations/fullness.tsandUserSubmissions/hooks/eventFeedback.ts— correct, but a wider change than this ticket, and filed instead. RewiringhumanDurationSinceto share day arithmetic — moot, the heuristic it would have served is gone.dueSincekept, against the review. The event id tag answers #835 §3 alone, butdueSincealso rides thelogger.warnatExpireEvents.ts:454, and whenpayload.findByIDis the throw site the watermark is the only fact about the event that loaded. Cost is oneselectkey and one cast. Open for the reviewer to overrule.Scope. Five commits, each separately revertable: the fix, the docs sync, the simplify pass, the
datatype pin, and the spec's shadowedreload. The Sentry tagging rides with the fix commit; reverting the fix would take it.Closes #835
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_015jPVXfk9jtfshVWZTSthZe