Repository navigation
feat(events): enforce one lifecycle table for events and submissions - #1135
Conversation
Which stage moves exist lived in a hook, a job, two endpoints and a vote-counting hook, and only a manager's submission review was checked at all. A move no reader could find was a move nobody could refuse: the stage column is `admin.readOnly`, which is the admin UI alone, so any manager holding `events: update` could PATCH it to any value and nothing applied what the new stage implied. `src/lib/stateMachine/` is the table, its lookup and its claim, and nothing else — a machine that ever needs actions or timers wants XState instead. Each writer now names itself, and one `beforeChange` guard per machine refuses and reports the rest. Two behaviour changes ride on it, both from #1120: - a draft on a reminder stage gets no watermark, so a class its manager has hidden is not chased (decision 3); - assigning a manager to an unverified or denied class publishes it as well as verifying it (decision 4). And the verify link and endpoint now refuse a finished class, which is what `syncVerificationOnSave` already decided for the save path: extending the schedule is the move, and that save verifies it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWNkBmFdb8R9xG91MT
`reviewMove` answers for a manager's own write and returns `none` for a request carrying no manager — which was the whole gate on screening, delivery, the block endpoint and the repeat-signup fold. Each could write any status from anywhere, and nothing said which moves they were for. They now name themselves and go through `transition()`, and the table is their gate. The review buttons are built from the same table, so a button and the guard behind it cannot name different sets. Adds the first move that was not there before: an admin may send a `failed` contact, subscribe or registration row again, which re-queues the delivery job the way releasing a refused row already does (#1120 decision 2). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWNkBmFdb8R9xG91MT
Five facts about a stage were spelled in more than one place, and each extra spelling was free to disagree with the others: - the admin banner's stage map was a `Partial`, so a stage added later gets no banner and nothing says so; - the sidebar bucket was a `switch` with a `default:`, the shape that once labelled both pre-adoption stages "verified" (#624); - the two overdue sets were two literal lists, one wider than the other for a real reason nothing enforced — both now derive from the ladder; - "still collecting feedback" was written out at four surfaces; - the registration status sets restated the vocabulary, inactive-first, which is the direction where a status added later silently holds a seat. Also requires a registration create to name its session: a row without one is invisible to the follow-up query for ever, so the registrant attends and is never asked how it went (#1120 decision 5). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWNkBmFdb8R9xG91MT
A `failed` row is in no list anybody reads: it is not a refusal, so no spam surface holds it, and it is not open for review, so no reviewer meets it. The only way to find one was to query the collection by hand. Admin home open items and the admin digest now carry them — Sahaj Atlas rows only, since We Meditate gets its own home in #1119 — and an admin can send one again from the row itself. Also carries the class's own details into the adoption email: what it says, how complete the listing is, and whether the community had flagged it. One email, not a second one beside the first (#1120 decision 4). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWNkBmFdb8R9xG91MT
Four review lenses over the branch. What they found, and what changed: - A write could name itself `review` or `admin` and skip `reviewMove`'s grant check entirely, because `resolveActor` accepted every actor in the table. Only a writer with no person behind it may be named now. - The event brief now rides on an opt-in: `summarizeGrants` is also what the anonymous preview sign-in picker calls, once per account, and it renders none of it. The brief itself no longer calls `buildEventEmailDetails`, whose one query counts registrations this email does not print. - `applyVerification` kept the document its own write returned, rather than re-reading the row it had just written. - The ladder walk, the admin list path and the count-and-link note each had a second spelling; `LADDER_STEPS`, `listPath` and `countNote` are the one. - `RESEND_FROM` was derived through three predicates to rediscover one state, and would have widened silently; it is named beside the move it belongs to. - `targetsFor` and `originsFor` had no production caller between them, the guard's `actorFromRequest` seam had no non-trivial instance, and `judgeTransition`'s third verdict was never read apart from its second. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWNkBmFdb8R9xG91MT
Also two findings from the review pass that are worth their own lines: an explicit `null` target is now judged like any other, rather than read as "the write left the column alone"; and the invitation preview grew the scenario that shows a class's brief, which is what makes the new state reviewable. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWNkBmFdb8R9xG91MT
|
🚅 Deployed to the SahajCloud-pr-1135 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
Four doc conflicts, all from #1134 landing its own perf figures beside ours. tests/PERF.md's session table is append-only, so both sides' rows are kept and #1121's is renumbered to follow #1131's five. The counts every consumer states are re-measured on the merged tree rather than picked from either side: 269 files and 3608 tests, which is neither branch's figure. The code merged clean. The overlap worth proving was #1134's feed spec against this branch's new stage guard — it drafts and republishes events, which the guard now judges. It passes, as do event-verification and expire-events. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYHvmSpGVjJWjBz3oJ
|
Merged
The counts were the only real decision. Both sides moved them from 266 / 3555, so neither figure survives the merge. I re-measured on the merged tree — 269 files / 3608 tests — and wrote that into PERF.md and its three consumers, which The overlap worth proving: #1134's feed spec drafts and republishes events, which this branch's new stage guard now judges. It passes (22), as do The PR body's "267 files, 3592 tests" is that session's figure, now superseded by the row above. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is large because the ticket is: all nine sections are asked for, the joined script fix is declared, and I found no refactor smuggled in beside them. countNote.ts is the one new piece the ticket did not ask for.
The table pays its rent. can is the only lookup, two guards are the only gate, and every set the PR claims to have derived reproduces the literal it replaced. It sits on updateIfUnchanged rather than a second atomic write — the right call, and not the one the ticket's Notes describe.
Two defects, both one line, both in the behaviour built on top rather than in the table.
Findings
- should-fix —
grantSummary.ts:406:flaggedfires on one denial, so the email can tell a manager a listed class was taken off the map. - should-fix —
eventFeedback.ts:193: thewritecallback dropsexpect, leaving theunverified → deniedwrite unconditional. - consider —
stateMachine/actor.ts:13: the docblock names areq.userfallbackresolveActordoes not have. - consider —
atlasOverview/countNote.ts:12: two callers, six lines each, collection hard-coded — neither generic nor folded in.
What was checked
Read on the branch: both machines, all four stateMachine/ files, both guards and their order in Events.ts, every transition caller, watermark, stages, status.ts, openItems, grantSummary, lifecycle-table.spec.ts.
Re-derived by hand, each matching its old literal: OVERDUE_QUERY_STAGES → escalated/urgent/expired, OVERDUE_STATUS_STAGES → reminded/escalated/urgent, MERGEABLE_STATUSES → accepted/pending/failed.
One refusal I expected and could not reach: restoring a trashed denied event returns at the pre-adoption branch, ahead of the hook:save → unverified move RE_SAVE_FROM omits.
Previews not opened: the PREVIEW_ACCESS_* pair is unset.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The invitation's flagged line tells a new manager attendees could not find the class and it was taken off the map. It fired on `denials > 0`, while what takes a listing down is `computeCommunityVerdict` — five denials and a Wilson upper bound under 0.5. One dissenter among twenty confirmations therefore produced an email about an unpublishing that never happened. The predicate is the one that made the decision, so the sentence and the stage it describes cannot disagree again. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZBZomK3wD6hYJGcEr
`transition` builds a claim naming the stage the caller read; this one's `write` callback destructured it away, so the `unverified → denied` write was unconditional. The window is a manager adopting the class while its votes are counted. The write then reaches `guardVerificationStage` with a stage no `community` move starts from, and the refusal it throws rolls back the visitor's own vote inside this unguarded hook — the failure #842 closed. Claimed, the row is re-selected at write time and the write simply reports that it did not land. Pinned in the unit lane rather than the integration one: the race is between a read and a write, so the assertion is that the claim reaches `payload.update` at all. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZBZomK3wD6hYJGcEr
`resolveActor` reads the declared actor and nothing else, so a write naming none answers `null`. The docblock promised a `req.user` fallback behind it, which sent a reader looking for a branch no module has — and made the two collections' opposite handling of that case look like a single shared rule. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZBZomK3wD6hYJGcEr
Two callers, both in this directory, each saving six lines — and the collection was hard-coded while the sentence was a callback, so it was neither a general helper nor an abstraction either caller was shorter for. The ticket asked for the failed-delivery row and its words, not a layer beneath them. What it did carry is the `null`-for-zero convention, which both callers now state at their own return. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZBZomK3wD6hYJGcEr
Two cases joined the unit lane, so PERF.md's canonical count and the three docs that quote it move together — `perf-figures-pinned.spec.ts` reddens on any one of them lagging. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZBZomK3wD6hYJGcEr
|
Three critic threads,
Gate ✓ lint, format, typecheck ×2, unit (270 / 3673), sixteen int specs. Security review ✓ nothing above its bar. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`main` (#1127) and this branch each appended measurement rows to `tests/PERF.md` under their own ordinals, and the four #1131 rows reached both sides at different indices. Keeps `main`'s numbering, which already carries those four, and appends this branch's three #1121 rows after it. No row is dropped or renumbered, and the session's own measurement is recorded beside them. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWtuecC3drMgcCJUso
|
Merged Kept Lean gate ✓ — lint, format, both typechecks, unit lane 271 files / 3685 tests (126 s). 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
A create was never judged, so the table declared every later step of a lifecycle and not where one begins: `stateMachineField`'s `defaultValue` said where a row opened, and nothing refused a new row created straight into a terminal state no writer may ever move it to. #1121 §2 lists a `proposal` writer this machine dropped for the same reason — it only ever creates a class, so a table of moves had no row for it. A machine now declares `opensAt`, which the column takes as its `defaultValue` and which stands for every writer, plus an `opens` row per other state naming the writers that may author one. `judgeOpening` judges a create against those rows, sharing the move judgement's own row pick so the two cannot answer a writer differently. A missing or unlisted value is left to the column: it is `required` and its options are the machine's states, so refusing here would report a person's validation mistake as a writer the table was not told about. The openings that exist: a class opens `verified`, `unverified` to a `proposal` (an accepted submission with no manager named), and any stage to an `import`. A submission opens `pending`, and any status to an `import`. Two writers therefore name themselves where they did not. The class import shares one write context with the dry validation pass it runs first — `fieldErrors` runs Payload's own field `beforeChange` pass, and the stage guard is one of those hooks, so a pass given a different context refused a class the create would have written. The Atlas seed's registration upsert authors `accepted`, and `scripts/preview-event-emails` authors an escalated class and a settled sign-up; both named nobody and would now be refused. Reviewer's call on #1135: option A, build it here. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVEDwt82zbosDvsneg
|
Answered the one open thread: a create is unjudged — you chose A, so it is built here in A machine declares It turned up two live gaps in this PR's own guard. The class import's dry validation pass runs the same field hooks as its create, so a different context there refused a class the create would have written — one Full integration lane ✓ — 107 files, 1917 tests. Lean gate ✓. The new 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
Your approving review carries only its opening words — "Would it make sense to ". The rest did not post. I built nothing on it rather than guess at the rest. Nothing else on this PR waits: all seven review threads are resolved, the branch is level with Finish the question and I will take it. Reply with ⚠ Your approval stands and the merge gate is satisfied, so this may merge before you reply. Your point then needs its own ticket. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
scripts/preview-manager-emails.ts, which threw onmain, so this PR has previews.Change outline
The stage column on
eventsand the status column onuser-submissionseach walk a fixed setof values, and before this each writer decided for itself what it was allowed to do.
Contract — one lifecycle, declared as its moves and its openings
A machine is declared once: the column it governs, its states, where a row may open, every
(from, to, by)that is legal, which writers may name themselves, and how a request's personresolves. The column is built from it, default and guard included, so the options, the generated
union and the refusals cannot name different sets.
Two tables use it, each beside its owner:
Flow — how a state change is made now
Every writer names itself, and the guard reads that name off the write's own context.
⚠ A write may only name a writer with no person behind it:
reviewandadminare resolvedfrom the request, never from a claim, so naming one cannot skip the grant check in
person.Behaviour — what the table made it safe to change
Contract — one definition per stage rule
Five facts had more than one spelling, each free to disagree with the others.
Files — what is new
Files — what is gone
Preview
Delivery failedrowData: CI fills every preview from
seeds/preview-fixture, which carries afailedcontact row.Not verified from this session —
PREVIEW_ACCESS_CLIENT_ID/PREVIEW_ACCESS_CLIENT_SECRETare unset here, so the Cloudflare Access gate in front of the preview cannot be passed.
Email previews
Contract impact
src/payload-types.tschanges by one JSDoc line — theevents.managerdescription now saysadoption publishes. The consumers that sync it (
sydevs/WeMeditateWeb,sydevs/SahajAtlasWeb)pick it up in the bot's contract-sync PR after this merges. No response shape changes.
⚠ One refusal is new on a client-facing create and deliberately carries no error code: a
registration naming no session answers 400 with a message alone, because
EventRegistrationErrorCodeis a file three repos sync and the widget cannot produce thisrefusal — it has always sent the session the visitor picked. Adding a code would be a consumer
sync for a case no consumer can reach.
Test results
.claude/skills/pr-prep/check.sh— lint, format, typecheck, typecheck:tests, unit (119 s)the review pass; since then
event-feedback,atlas-overviewanddigests(45) cover what movedthe two others are
doc-citations, fixed by staging the new file, andics-builder, whichfails only in this machine's local timezone and passes under
TZ=UTC); integration ✓user-submissions-review-lifecycle(42),event-verification(39),expire-events(26),block-user,screen-submissions,user-submissions-repeat-registration,atomic-writes,digests.pnpm generate:typeswrites no diff, so the schema is unchanged.tests/unit/lifecycle-table.spec.ts(47 — every review decision, per person and intake,plus
judgeOpening), plus cases innext-check-at,open-item-status,manager-invite,expire-events,event-verification,atlas-overview,digests,user-submissions-review-lifecycle,user-submissions-registration-gatemainwas merged, the actor key scoped and the skip flag keyed: lean gate ✓ (lint,format, both typechecks, unit lane 270 files / 3673 tests); integration ✓
user-submissions-review-lifecycle,user-submissions-create,screen-submissions,event-verification,expire-events,atomic-writes,event-feedback,atlas-overview,digests,block-user,user-submissions-registration-gate,events,event-imports,user-submissions-repeat-registration,preview-fixture-import,seed-importer-preload0d67d0c): lean gate ✓ (lint, format, both typechecks,unit lane 271 files / 3692 tests, 109 s). Full integration lane ✓ — 107 files, 1917 tests.
The three new
where a class may opencases go red with the create branch of the guardremoved, and the refusal case is the one the reviewer named.
pnpm db:migrations:create … --skip-emptywrote nothing.Manual verification
failedcontact or registration row — Send again is offered, the rowreturns to
pending, and its log reads "Queued for delivery again". As a non-admin reviewerthe button is absent, and a hand-rolled
PATCHis refused.one save. An incomplete draft refuses with its own validation errors instead.
re-verifies and the cycle restarts.
verified. APATCH-style create namingexpiredis refused onverificationStage.Notes for reviewer
transition()ANDs the state as read intothe write's own
whereeverywhere else, the community denial included.applyVerificationand the repeat-signup fold take an id-addressed write through the samefunction instead: the first must keep
Forbiddenas a throw, and thewhereform narrows byaccess rather than throwing, so
POST :id/verifywould answer 200 to a manager it means torefuse; the second reads the row back, which a boolean cannot give it.
restoreVersion.js, which runs the fieldbeforeChangepass as anupdatewithoriginalDoc,so the column's guard sees it — the review pass claimed the opposite. It reads as correct (a restore should not silently rewind a lifecycle)
but it is a behaviour change nobody asked for, so it is worth your eye.
guard.tsthread, and they turned up two live gaps.The class import's dry validation pass (
fieldErrors) runs Payload's own fieldbeforeChangepass over a built class, and the stage guard is one of those hooks — so a pass given a
different context refuses a class the create would have written.
importWriteContext()is nowthe one context both use. And the Atlas seed's registration upsert authors
acceptedwhilenaming no writer, as did
scripts/preview-event-emails; both are named now.transition()is built onupdateIfUnchanged(fix(jobs): stop jobs overwriting state that changed mid-run #1116), notpayload.db.updateOne. Theticket's Notes describe a claim-then-update pair; fix(jobs): stop jobs overwriting state that changed mid-run #1116 shipped the guarded single write
instead, for the reason its own docblock gives — both callers need the hooks the operation
carries. One write, same guarantee.
a move naming no writer also refuses a test setting up a state, so ~12 integration fixtures
write the column beneath the hooks (
setLifecycleState) — and a create cannot do that, so afixture authoring any state but the machine's
opensAtnamesimporton its own context.testData.createEventand eight specs' own create helpers declare it once each. Every casethat asserts a move still makes it through that writer's own path.
its bar; its two hardening notes are taken — an explicit
nulltarget is judged rather thanread as "no move", and the declarable-actor set excludes the humans. It ran again over the
merged branch and found nothing above its bar:
req.contextis unreachable from a request body(
createPayloadRequesthard-codes it), a fieldbeforeChangecannot be skipped byoverrideAccessor a narrow patch, a version restore is judged, and the admin-only resend isrefused server-side for a reviewer. Its one finding was the bulk-accept skip above. The
openings commit touches no path in
securityReview.triggerPatternand only narrows what acreate may write, so it was not re-run:
proposaljoinsdeclarablewith no move of its ownand one opening strictly below the default.
reviewMoveis now rows, not a second predicate. What it owned that a bare(from, to, by)row could not state — the action name, the reviewability gate, the grant check, the refusal
wording — is now a row's
name,whenandrefusal, plus the machine'sperson. A refusal aperson can fix on another field (the region an accept needs) is reported there and not sent to
Sentry; every other refusal still is.
beforeChangebefore the field pass (
collections/operations/utilities/update.js), so a guard on the columnalways judges the patch every collection hook produced, and a column cannot be mounted without
it.
importactor — a seed writes through the hooks on purpose, so a fixture bypass there would skip the
screening queue and the fullness recompute it needs; un-deriving the overdue sets — the
ticket asked for exactly that.
Detail
What the draft rule does not change.
expiredkeeps its trash countdown, because beingunpublished is that stage's own doing. Only stages that send reminders go quiet.
Rows written before the rule existed. The watermark leaves a draft out of the due query from
its next save on, so
ExpireEventsalso clears the watermark of a draft it still finds — that iswhat makes the criterion true without a backfill. It carries a
shortcut:line naming when itcan go.
Why
describeEventsis opt-in.summarizeGrantsis also what the anonymous preview sign-inpicker calls, once per listed account, up to 25 of them in series — and it renders none of the
brief. The brief also composes its own three lines rather than calling
buildEventEmailDetails,whose one query counts registrations this email does not print.
Why a create's missing or unlisted value is left alone. The column is
requiredand itsoptions are the machine's states, so Payload's own validator answers both, naming the field. A
refusal here would report a person's validation mistake as a writer the table was not told
about — and it would reach Sentry as an incident.
Closes #1121
🤖 Generated with Claude Code
https://claude.ai/code/session_01Mg9rjVEDwt82zbosDvsneg