Skip to content

fix(events): ExpireEvents stalls on an event with invalid stored data - #841

Merged
sydevs-bot merged 5 commits into
mainfrom
claude/fix-835-expire-events-validation
Sep 22, 2026
Merged

sydevs-bot merged 5 commits into
mainfrom
claude/fix-835-expire-events-validation

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The nightly job's four validating write sites now bypass document validation, so an event whose stored data fails a validator is still advanced, finished and logged.
  • A reminder is no longer re-sent every night: the exactly-once marker's write was the one that failed.
  • A per-event Sentry failure now carries the event id as a tag, so one event's occurrence history separates a nightly repeat from a one-off.

Changes

  • src/jobs/ExpireEvents/ExpireEvents.ts — one updateBookkeeping helper behind the four sites; the due query carries each watermark for the failure report. Its data is typed to the four bookkeeping fields, so a fifth fails typecheck rather than a reviewer.
  • src/collections/Events/Events.ts — comment only: a ⚠ against adding localizeStatus.
  • 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:

  • Events list — verificationStage and _status, the columns the job writes
  • Admin login — PREVIEW_ADMIN_PASSWORD

Reproducing the defect itself needs a db-layer write, which is what the integration cases do.

Test results

  • Lean gate: ✓ lint, typecheck, typecheck:tests, 2163 unit tests
  • Targeted specs: 49 passed — expire-events.int.spec.ts (21), event-verification.int.spec.ts (28)
  • Build: N/A — Railway builds the preview

Manual verification

  1. Re-enable EVENT_VERIFICATION_ENABLED once 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:117 still 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.
  2. Confirm Sentry 147058729 takes no occurrence newer than the deploy, ~48h after.
  3. In the admin, open an event the job has since unpublished and confirm its version history reads acceptably — see the trade under Notes.

Notes for reviewer

  • The §2 choice the ticket left open: unpublishAllLocales: true at all four sites, not the db.updateOne + db.updateVersion pair. It is one supported argument, every hook keeps running, and row and version agree by construction.
  • It costs version history on the unpublishing advance. saveVersion({ unpublish }) overwrites the latest: true row 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.ts now warns against localizeStatus. The root experimental.localizeStatus flag is already on (payload.config.ts:82), so the only thing keeping unpublishAllLocales from 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.
  • AC4 is met differently than the ticket proposed. A consecutive-failure count cannot be derived: resolveNextCheckAt arms a pre-adoption or finished event 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.
  • fix(events): ExpireEvents stalls on an event with invalid stored data #835 stays user-visible through the verify link, and that is not fixed here. src/collections/Events/lifecycle/verify.ts:117 writes with a plain payload.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.
  • One review thread is open for you, not for the bot. Whether dueSince on the failure report belongs in this ticket. The deploy ordering is settled: no gating needed.
Detail

Verified against [email protected] in node_modules, not from the ticket's prose. collections/operations/utilities/update.js:154-157 sets skipValidation for exactly three inputs: a draft save with draft validation off, a trash collection write carrying deletedAt, and unpublishAllLocales. The first writes no main row, the second is what trashEvent already rides — so the third is the only door, and updateByID.js:135 plumbs it through from the Local API.

Why not gate the validators instead. A req.context flag the Events validators honour would not cover the images case: maxRows is 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's ORDER BY updated_at DESC OFFSET 100 LIMIT 1; the one added is an indexed limit-1. maxPerDoc: 100 is 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 contactPhone and images at the document root, not details.* — checked against src/collections/Events/Events.ts:226,319, where Details is an unnamed tab. The image count derives from EVENT_IMAGE_LIMIT (src/lib/utilities/eventImages.ts:18), so raising maxRows cannot leave the seed valid and the case vacuously green.

Non-vacuity. Four of the five new cases were run against origin/main and fail there. The fifth — version-row parity — passes on both, because plain payload.update also keeps the version in step by appending one; it guards the rejected raw-db.updateOne alternative, 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 updateBookkeeping into a shared systemWrite helper covering verify.ts, lib/registrations/fullness.ts and UserSubmissions/hooks/eventFeedback.ts — correct, but a wider change than this ticket, and filed instead. Rewiring humanDurationSince to share day arithmetic — moot, the heuristic it would have served is gone.

dueSince kept, against the review. The event id tag answers #835 §3 alone, but dueSince also rides the logger.warn at ExpireEvents.ts:454, and when payload.findByID is the throw site the watermark is the only fact about the event that loaded. Cost is one select key and one cast. Open for the reviewer to overrule.

Scope. Five commits, each separately revertable: the fix, the docs sync, the simplify pass, the data type pin, and the spec's shadowed reload. 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

…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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-841 September 22, 2026 16:00 Destroyed
@railway-app

railway-app Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-841 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Sep 22, 2026 at 4:29 pm UTC
1 service not affected by this PR
  • mailpit

@sydevs-bot

sydevs-bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 22:20Z address-review · attempt 1 · session · done
  • 22:20Z address-review · attempt 1 · session
  • 16:17Z address-review · attempt 1 · session · done
  • 16:17Z address-review · attempt 1 · session
  • 16:09Z adversarial-review · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🧐 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 — dueSince is unasked scope.
  • consider — expire-events.int.spec.ts:469 — a shadowed reload.

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

Comment thread src/jobs/ExpireEvents/ExpireEvents.ts Resolved
Comment thread src/jobs/ExpireEvents/ExpireEvents.ts Resolved
Comment thread src/jobs/ExpireEvents/ExpireEvents.ts Resolved
Comment thread tests/int/expire-events.int.spec.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 22, 2026
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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-841 September 22, 2026 16:24 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review. Pushed a3247af.

Adopted

Open for you

Lean gate green, plus expire-events.int.spec.ts (21).

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 22, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 22, 2026 16:32
@sydevs-bot
sydevs-bot requested a review from Ardnived September 22, 2026 16:32
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Sep 22, 2026
Comment thread src/jobs/ExpireEvents/ExpireEvents.ts Resolved
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 22, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 22, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

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

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 22, 2026
Merged via the queue into main with commit 881a0f0 Sep 22, 2026
55 of 59 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-835-expire-events-validation branch September 22, 2026 22:31
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Sep 22, 2026

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-841 — a3247af6 Deployed Sep 22, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(events): ExpireEvents stalls on an event with invalid stored data

3 participants