Repository navigation
feat(atlas): open-items homes, per-role digests, simpler preferences - #1083
Conversation
`spam` is the machine's refusal, and nothing recorded an admin agreeing with it — so a refused registration stayed `spam` for ever and could not leave the admin's open-items list. `confirmed_spam` is that agreement: it counts a spam strike like `spam`, ages out on the same 90-day window, and drops the row out of `INACTIVE_STATUSES` so the seat stays free. Settling one is an admin's call on every intake, not a reviewer's on a proposal, so `reviewMove` answers it ahead of its proposal gate and `WorkflowButtons` grows an `ungatedStages` map for the stages a slot's every kind of document shares — gated out, a `spam` registration reached no stage at all and kept its plain Save button. Also: the seven role-filtered notification preference rows that replace the four, with one default resolver every reader shares; a `digestWatermarks` column the job alone may write; the daily `atlas-snapshots` counts the homes and the statistics email compare against; and PR #1052's `registration-refusals` collection, its intake hook and the screening write, without its job, template or preference row. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
Three homes and one email showed the same work in four vocabularies, so `src/lib/atlasOverview/` now owns every word a reader sees about an open item, and the loaders answer for one role at a time rather than for a user — a manager who runs a class, looks after a region and administers the map does three jobs on three paces. `SendDigests` replaces `SendRegistrationDigests` and PR #1052's job: one 07:00 UTC schedule decides Daily, Weekly and Monthly, because three schedules would send a Weekly manager two emails on a Monday the 1st. Per-role, per-key watermarks on `Managers.digestWatermarks` keep it exactly-once, clamped to one period so re-enabling a muted section does not deliver six months at once. `deliverProposal` keeps its routing and then reads the recipient's own `new_proposals` pace, so only the moment of delivery moves. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
Each home opened on a list of things rather than a list of problems: the program home showed every program, the admin home showed a "Needs attention" row that was everyone else's work, and a region manager had no home at all — `dashboardChoiceFor` gave them their whole subtree as "Your programs". All three now open on the same ordered open-items list, built from Payload's own `Table`, `Pill`, `Button` and `Pagination`, with the filters drawn as the Tabs field's own tab buttons. Every next step is a link to an edit view that already exists; no endpoint, action or hook is added for any of them. `src/lib/atlasOverview/filters.ts` is split out of `status.ts` so a `'use client'` component can name a filter without pulling the loaders — and through them `@/lib/env/server` — into an admin browser chunk, which `client-bundle-safety` caught and which fails on the Railway deploy rather than in CI. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
Four statements the generator cannot know to write, three of which are the difference between a deploy and a boot crash-loop: - job rows naming `sendRegistrationDigests` are deleted before `up` rebuilds the two `task_slug` enums without it, and `down` owes the same for the two slugs this adds — the rebuild's final cast throws on any surviving row; - `confirmed_spam` rows go back to `spam` before `down` shrinks the status enum, for the same reason; - preferences are rewritten, not just re-defaulted: the column DEFAULT reaches new rows only, so 'Daily Summary' becomes 'Daily', 'Weekly Summary' becomes 'Weekly', and `regional_summary` is dropped; - the two `DROP CONSTRAINT` statements the generator emits for FKs its own `DROP TABLE … CASCADE` has already taken are removed, as `20261019_182311_import_plugin.ts` removed them. Verified up → down → up against a throwaway Postgres with each of those rows already present, the migration applied as its own batch. Measured, not reasoned about: the bare cast was reproduced failing first. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
`atlas-overview.int.spec.ts` reads one loader through all three roles with `overrideAccess: false`, so a case that passes is one the reader's own access admits. `digests.int.spec.ts` replaces `registration-digests` for `SendDigests`. Two defects the specs found, both fixed here: - **A manager holding two roles lost one role's watermarks.** The run sends their emails in a loop over one loaded document, and the second role merged into the document's stale column — writing its own marks over the first's, so the first role's whole window would have been re-sent. `advanceWatermarks` now returns the column and the loop keeps its copy in step. - **Reopening a refused proposal became admin-only.** The spam branch was answering ahead of the reviewer path for every intake; a reviewer's own false-positive recovery on a proposal is theirs and stays theirs, and only confirming a refusal — and releasing one on an intake nobody reviews — is the admin's. Also restores two files the wholesale checkout from PR #1052's branch reverted: `ScreenSubmissions.ts` lost #1060's blocked-sender check and `projects.ts` lost #1068's role rename, because that branch predates both. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
`docs/rules/admin-ui.md`'s dashboard section described two homes and a "Needs attention" row that is gone. It now says which home each role gets and why the widest wins, where every word about an open item lives, why a `'use client'` component must deep-import `atlasOverview/filters`, and where a tile's change line comes from — a stage count from the daily snapshot, a sign-up count from two dated queries, and neither as "+0" when nothing can say. Also: `src/AGENTS.md` for the new lib folder and why `managerRoles` is shared; `docs/rules/email.md` for `DigestEmail`, the four new `EmailLayout` exports and the preview script; `tests/COVERAGE.md` for both new specs. One spec changed with it: a new-event proposal's delivery now defers at a digest pace, so `atlas-submission-routing` asserts both arms — routing is settled before the pace is read, because escalating a muted manager's proposal to somebody else is not what muting asks for. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
…ot rewind Two acceptance criteria that only a query-backed read and a refused field satisfy, each written against the way it would otherwise fail quietly. A join carries at most its own limit, so a home reading "which events" off `req.user.managedEvents` shows a manager with thirteen programs ten of them and calls that their list. The case creates thirteen and asserts both the count and the page. A manager who could rewind their own watermarks would re-send themselves every open item the window covers. Payload strips a field its `access.update` refuses rather than erroring, so the PATCH succeeds and the assertion is the unchanged column, not a 403. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
…ng the map Three things the review pass found, each a defect this branch introduced. **A button only an admin may press was offered to every manager.** The spam buttons were declared `ungatedStages`, which outranked the `onlyWhen` gate unconditionally — so a region manager opening a refused *contact* row addressed to them (which `managerSubmissionScope` admits) saw "Confirm spam" and "Not spam", both of which `reviewMove` answers with "Only an admin can settle a spam refusal." It also left `REVIEW_STAGES.spam` permanently shadowed, so the Reopen a reviewer is entitled to was unreachable and read as live coupling. `onlyWhen` + `stages` + `ungatedStages` are replaced by one ordered `rules` list, first match wins, whose `when` can name a form field **or** the viewer's admin type. A slot serving several kinds of document decides over (kind, viewer, stage), and precedence between those is what a reader most needs to see; it also gives the privileged-move gate one spelling on both sides of the wire. `spamActionFor` now takes `reviewable` rather than the intake, so the reviewability rule is read once instead of twice with opposite polarity. **The region table was read three or four times per page.** Every loader in `atlasOverview` is its own entry point, and each opened with a full scan of a table holding a node per country, region, area, city and venue, with a breadcrumbs join — `memoizeOnRequest` collapses that to one, and the open proposals read with it. `managersInSubtree` walked the whole node table per emitted row; it is one accumulating pass now, the same shape as `rollUpRegionMetrics`. The regions overview read every event on the atlas whatever the scope, and `loadRefusals` had no bound at all on a table that keeps 90 days of refused sign-ups. `subtreeOf` no longer wraps `resolveOwnedRegionIds`, which already returns the subtree, and `toNode` calls `breadcrumbAncestorIds` instead of re-inlining it without its dedupe. `RegionNode.parentId` and the refusal path's fabricated empty dataset are gone; `AtlasRegionData` is a union, so a refusal carries nothing to render by mistake. **The one claim that was simply false:** `filters.ts` said `status.ts` reaches `@/lib/env/server` through `eventDetails`. Walking the real graph with the bundle-safety spec's own resolver, `status.ts` reaches six files and no server-only module; the barrel reaches sixty-seven and is the whole hazard. The docblock, `docs/rules/admin-ui.md` and the barrel now say that instead, and the barrel carries only the names a consumer takes off it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
The rest of the review pass. Nothing here changes what a reader sees, with one exception noted below. **Facts that were written twice.** The refused-sign-up count had its window in two constants, its query in two places and its sentence in two more — one of which hard-coded the 7 the other read from a constant, so moving the window would have left the home and the email disagreeing in words while agreeing in data. It is one `refusedAtTheForm` now, returning the finished line. `due.ts` takes its three paces from `SUMMARY_FREQUENCIES` rather than restating them, so a fourth cadence added to a preference row is a type error here instead of a manager silently never mailed. `changeLabel` lives beside the window it measures. Both new collections take `adminOnlyAccess` from the module whose stated job is owning that predicate, where one had spelled the body out by hand. The two query-side overdue stage sets are one constant — and the status table's Overdue is deliberately *not* merged into it, because that one also carries `reminded`: a reminded listing is still healthy and still nobody else's to join, so the difference is the point and the comment says so. **Dead ends.** `stageRank` and the nine `rank:` entries feeding it lost their only caller when the old manager home went, and the docstring still described that home's ordering. `OpenItemsResult.open` was never read. `RegionNode.parentId` was only ever written. Four exports had no importer. `methodRequired` tested a blank-pace state the flattened preferences cannot produce. `OpenItemsList` now derives its own `open`, where three views computed the same expression and each carried an arm that cannot fire. `buildDigest` implements the "a failing section is counted and skipped" rule once instead of three times. `failed` is what rides out in the task output, so a fourth section catching an error without counting it would report the job green while the email was short a section. **The exception: a lone `SectionTabs` rendered nothing.** The component refused fewer than two tabs, so the program home's Open-items tab — and with it the count, or the tick that stands in for zero — was never drawn, which the ticket asks for explicitly. A single tab renders now. Not done, and deliberately: `status.ts`'s ten status literals each spell `rank`, `filter` and `counts` inline, and those three are functions of the key (bar `overdue`'s two ranks). Collapsing them into one table beside the keys is a real simplification and `open-item-status.spec.ts` pins every value, so it is safe — but it rewrites the most-read part of the feature, and it is better reviewed on its own than inside this diff. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
`adminOnly.ts` exports a field-level lock and a condition but had no collection-level `Access`, so a collection declaring its own admin-only block spelled `isAdminManager`'s body by hand — the shape #630 records as having silently refused a role that should have been admitted. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
`getAtlasRegionData` answers a union now, so every read of the home's data was an error under `typecheck:tests` — which `pnpm typecheck` does not cover, since the root tsconfig excludes `tests`. The lean gate caught it. The narrowing lives in the describe block's `load` helper rather than at each read; the refusal keeps its own case, which calls the loader directly and asserts the whole shape. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
A collection in no project reads as *shared* for visibility (`docs/rules/access.md`), so every manager saw a sidebar entry whose `access` can only answer 403 on open — the kind of decorative control the access layer avoids elsewhere. ⚠ The function form, not `true`: `hidden: true` unregisters the routes too, and the admin home's own View link points at this collection, so `true` would 404 the one reader it exists for. `payload-jobs` is the precedent. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTrJHBHrgoxUxPjKL
|
🚅 Deployed to the SahajCloud-pr-1083 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
1 question for the reviewer, one per thread.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
🤖 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
#1070 names nearly every file here by path, so this 113-file diff is the ticket's size, not the PR's. The contract holds: confirmed_spam is additive and no endpoint moves. What a second reading costs is shape: three copies of one region-tree rollup remain, two surfaces of one page disagree about what a "program" is, and the preference vocabulary is bare string end to end, which is what lets a key be restated twice more and a wrong cadence fail silently. On your own question: digestWatermarks as bare json is what #1070 specified, so leave it.
Findings
- should-fix —
statistics.ts:218: Total programs countsfinishedevents; the Programs column beside it does not. - should-fix —
due.ts:29: a docblock promising a type error that cannot happen; a new cadence would mail nobody. - should-fix —
regions.ts:78: the third copy of one tree rollup. - consider —
snapshots.ts:9: a file for one line written elsewhere already. - consider —
filters.ts:8: one hazard explained at length three times.
What was checked
Read whole on the branch: all ten atlasOverview/ modules, all four Digests/ modules, WorkflowButtons/stages.ts, the migration, and the statuses.ts / active.ts / access/ diffs.
Ladder, named: rollUpRegionCounts and buildRegionTree (sidebarModel.ts:234,263) against the new walkers; NOTIFICATION_TYPES against DIGEST_KEYS.
Clean: the program scope suppresses its snapshot comparison rather than mismatching it (statistics.ts:210); advance is pushed inside each section, so a throw re-sends; scopeRegionIds cannot widen past resolveOwnedRegionIds; down releases confirmed_spam before both enum rebuilds. One gap: up destroys regional_summary, down does not restore it.
Preview /admin and ?region=1 answer 200; unseeded, so read as code.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`up` subtracted `regional_summary` outright, so a rollback left the key missing and a manager who had muted regional summaries came back on the default. The two rows offer the same ['Monthly', 'Never'] pair, so the value carries into `statistics` — the row #1070 gave that content to — and `down` puts it back under its old key. Measuring the round trip against a throwaway Postgres also showed `down` writing `"event_registration": null` on every manager without that row, and planting `regional_summary` on one who never had it: `jsonb_build_object` on an absent key writes a literal null. Both branches are conditional now, and `jsonb_strip_nulls` wraps the statement as it already wrapped `up`'s. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXqfxsuuwdsr1T23Qz
Total programs counted every event in scope, finished listings included, while the Programs column beside it counted only the ones that are not — so an admin read one total in the tile and a different sum down the Countries table for the same scope. #1070 defines Programs as the latter. `isProgramStage` is the one definition now, in `status.ts` beside the rest of what a reader is told, and the snapshot comparison takes the same subset or a listing finishing reads as a program disappearing. The sign-up totals still count every event, as the Sign-ups column does, but the per-event map is narrowed to programs: both its readers divide by a count of programs, and a finished listing in it could put "Programs with a sign-up" above the total above it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXqfxsuuwdsr1T23Qz
`due.ts`'s docblock promised that a cadence added to `SUMMARY_FREQUENCIES` would be a type error here. It was not: `isDue` took a `string` and answered `false` for anything it did not name, so a fourth cadence would have left every manager who picked it unmailed with nothing failing — the exact failure the comment claimed to prevent. The switch is exhaustive over the union now and carries no `default`, so adding one fails `tsc` in `isDue` and `periodMs` both. Measured by adding a fourth. The preference keys were bare `string` end to end, which is what let `DIGEST_KEYS` restate seven of them where a typo resolves to `Never` and sends nothing. `NOTIFICATION_KEYS` is the vocabulary, `NotificationType['key']` and every reader take it, and a misspelling is TS2820. It is declared rather than derived — derived, `key` would be `string` again — so a unit case pins it against the rows in both directions. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXqfxsuuwdsr1T23Qz
The same walk — item into its own region, then up the ancestor chain, gated on the scope — existed three times: the sidebar's published/total pair, the overviews' six counters, and the overviews' manager sets. Each differed only in what it added per item, which is the part that is genuinely each caller's. `rollUpRegionTree` takes the chain, the scope and an accumulator factory, and every caller instantiates it. No extra walk: the item set and each chain still come from the caller. The manager roll-up keeps the one real difference and now says so — it filters the nodes rather than letting the scope refuse them, because an out-of-scope region's own managers must not reach an in-scope ancestor's count. The new spec pins what the three share and none of them stated, including that `empty` is a factory: one shared accumulator makes every region report the whole scope's total, and was watched failing six cases across two specs. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXqfxsuuwdsr1T23Qz
A module whose ten lines were seven of docblock and one of `toISOString().slice(0, 10)`. Two callers is a reason not to inline it twice, not a reason for its own file — `statistics.ts` reads the key back, so it is where the spelling belongs, and the nightly task imports it from there. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXqfxsuuwdsr1T23Qz
The story ran at full length in four places — filters.ts, the barrel, this rule file and src/AGENTS.md — about 25 lines re-narrating one import chain. src/AGENTS.md already declares itself its one home, so the three others carry the rule and a pointer, with the ⚠ markers kept. The measured walk moves to that home, since it is the evidence a reader deciding whether to deep-import actually wants. Also lists the new `regionTree/` folder in the src/ layout. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXqfxsuuwdsr1T23Qz
Start time, the cadence in as few words as reads, and the city the event meets in (a venue's city, else its address's), on the dashboard and in the digest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolves the Registrations view onto FilterTabs and QueryPager, keeping #1092's hidden empty filters and accepted-only CSV; FilterTabs renders no tab row when it is given none. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@sydevs-bot review |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
Since the first review the branch changed shape twice over, and the handoff did not keep up. The snapshot collection became payload.kv, registration-refusals became a count over spam submissions, and rollUpRegionTree — the shared walker this thread settled on — was deleted. All three read as simplifications. None is declared, and two are described the old way in the body.
The walker needs a decision, not an edit: regions.ts walks the subtree itself again, beside sidebarModel.ts:234, which is what the ruling settled against. Scope is otherwise the ticket's: #1070 names these files by path. The contract holds — confirmed_spam is additive and no endpoint moves.
Findings
- blocker —
regions.ts:106: the shared roll-up this thread approved was deleted after approval. - should-fix —
statistics.ts:28: the body's Contract, Migration, file tree and flow describe an abandoned design. - consider —
statistics.ts:270: the Registrations tile always draws a change line; step 6 says none does.
What was checked
Read whole on the branch, against #1070 §3, §5, §6: the seven atlasOverview/ modules, the three Digests/ modules, RecordAtlasSnapshot.ts, StatTiles.tsx, the migration.
Ladder: rollUpRegionCounts / buildRegionTree (sidebarModel.ts:234,263) against regions.ts:99-118; payload_kv is already in 20260606_050852_initial_schema, so no config change was owed.
Clean: the migration round-trips — slug rows deleted and confirmed_spam released before each enum rebuild, both preference branches conditional under jsonb_strip_nulls; 38-day pruning covers the compare plus SNAPSHOT_TOLERANCE_DAYS; countByRegion counts the set the live tiles do.
Anomaly: an anchor on mergeRepeatRegistration.ts was refused — it is main's (#1092), not this PR's. Previews not opened.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
Three critic threads answered, no code pushed. The branch was already level with
⚠ The four Mailpit previews predate Test results now attribute the last gate to 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`EMAIL_STRING_DEFAULTS` spans two groups of the atlas translations global: `emails`, and the twelve `recurrence_*` keys an email's schedule reads from `event.recurrence`. The translations seed filled the `emails` group from the whole table, so every run sent those twelve as additional properties. Each leaf group declares `additionalProperties: false`, so Payload refused the write with `The following field is invalid: Emails > Emails` — naming no key, and naming a group the data was right about. `EMAILS_GROUP_DEFAULTS` is the subset the group itself declares, and the seed fills blanks from that. The recurrence copy already reaches `event.recurrence` from each locale's own seed file, so nothing else changes. `tests/unit/atlas-translations-schema.spec.ts` now pins that export against the schema rather than re-spelling the prefix filter. Watched it fail with the filter removed, then pass with it back. Fixes: seeds/tests/atlas-translations-import.test.ts and tests/int/wm-web-translations-seed.int.spec.ts, the two red files on 3a31e39. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVAL2jVJbjdYCDQsZY
`20261106_094841_clients_one_site.json` was generated before #1083 merged in, and it is the newest snapshot, so the next `migrate:create` diffed against a schema without #1083's columns and enums and re-emitted all of them — the duplicate-DDL crash-loop `src/migrations/AGENTS.md` describes. Every statement the probe emitted already ships in `20261105_201411_atlas_digests_and_homes`. This migration has run nowhere (the PR preview was deleted), so its snapshot is replaced with the probe's, generated on the merged tree, rather than stacking an empty migration. A second probe writes no files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Change outline
Files — where an open item's meaning now lives
One folder answers "what is open, for whom", and four surfaces read it instead of each deciding for themselves. No barrel: every module is imported by its own path, so a client view cannot pull the server graph in behind one.
The region tree stays
@/lib/atlas/regionTree.getRegionTreenow also selectslevelandmanagers, soscope.tsandregions.tsread the memoized tree rather than loading one of their own.Contract — what a consumer or an operator can observe
No collection is added. A snapshot is a
payload.kvrow and a refused sign-up is aspamsubmission already stored, so the migration creates no table.Flow — one run, one email per manager per role
sendDigests (07:00 UTC, nightly queue) src/jobs/Digests/SendDigests.ts for each active manager (paginated) managerRoles(manager) # program | region | admin, off the joins for each role + buildDigest(manager, role, runStart) src/jobs/Digests/buildDigest.ts + PACES[frequency].due(runStart) # one schedule, three paces, off one 07:00 run + windowStart(mark, frequency, runStart) # the watermark, trusted inside two periods + section('statistics' | 'open items' | 'registrations') # each counted, skipped on failure + nothing due → no email at all + sendDigest(…) # false → continue, so nothing counts as delivered + payload.db.updateOne({ digestWatermarks }) # bookkeeping on someone else's row, hooks skipped + manager.digestWatermarks = next # kept in step on the loaded documentThe watermark assignment is load-bearing: the loop sends a manager's roles against one loaded document, so a second role that merged into the stale column overwrote the first role's marks and would have re-sent its whole window.
PACESis keyed bySummaryFrequencyandbuildDigestnames its keys asNotificationKey, so a fourth cadence or a misspelled row is atscfailure rather than a manager nobody mails.recordAtlasSnapshotrides the same hourly tick an hour earlier, so the statistics an email quotes are the ones the home shows.Behaviour — who sees which open item
Components — the admin button declaration
A slot serving four intakes and two kinds of viewer decided over (kind, viewer, stage) through two maps and a gate, with the precedence rule living only in a comment.
Preview
?region=withSetStepNavbreadcrumbs; outside your own subtree it refuses before it reads anythingrecordAtlasSnapshotandsendDigestsby handSign in with
PREVIEW_ADMIN_EMAILat/admin/login. Data: not seeded yet — a Railway preview forks configuration, not volume data, so the homes open empty until the atlas seed runs. Step 1 of Manual verification is that seed; no later run is promised to do it, so this line stays as a disclosure.Email previews
⚠ These four predate the email rewrite and are no longer what a run produces.
7fd282dgenerated the plain-text part and split out the shared itinerary and answer components,c7893e0realigned registrations and localized a registrant's schedule,5aa84d0put open items back in two columns, and7013079reheaded them "Need your attention". Read them for the shape of a digest, not for its wording. They expire 2026-11-12.Contract impact
user-submissions.statusgainsconfirmed_spam, andmanagersgains the generatedDigestWatermarkstype, sosrc/payload-types.tschanges. After this merges, sydevs/WeMeditateWeb and sydevs/SahajAtlasWeb re-sync withpnpm types:cms. No endpoint, response shape or embed contract changes, and the widget's own write path (POST /api/user-submissionswithtype: registration) is untouched.Migration
src/migrations/20261105_201411_atlas_digests_and_homes.tsconfirmed_spamto the submission-status enum; rebuilds bothtask_slugenums to dropsendRegistrationDigestsand addsendDigests/recordAtlasSnapshot; rewritesmanagers.notification_preferencesin place; addsmanagers.digest_watermarks; dropsmanagers.last_registration_digest_sent_at.downreturnsconfirmed_spamrows tospamand the renamed paces to their old spellings before it shrinks either enum, and deletes job rows naming the slugs it removes — a surviving row makes the rebuild's final cast throw, which on a deploy is a boot crash-loop rather than a failed statement.regional_summarycarries intostatisticsand back out again, so the round trip is lossless rather than approximately so (e1249a6).Hand-edited in four places, each documented in the file's own docblock. Verified
up → down → upagainst a throwaway Postgres with a row of every affected kind already present, the migration applied as its own batch; the bare enum cast was reproduced failing first, so the guard is measured rather than argued.Test results
5ec6920, themainsync —.claude/skills/pr-prep/check.sh(lint,format:check,typecheck,typecheck:tests,test:unit), plusatlas-manager,atlas-overview,digestsandatlas-report-issue-form: 52 passed.3a31e39.Manual verification
The homes read live data, and a fresh preview has none — so seed first:
pnpm tsx scripts/redeem-signin-link.ts '<link>' --seed atlasagainst the preview, with a link requested asPREVIEW_ADMIN_EMAIL./adminopens on Open items. Verify, Review and Continue editing each open an edit view that already exists — confirm none 404s and none acts on open.?region=<id>for a region outside your subtree shows the refusal.spamsign-ups and the items reaching no region manager; the Countries overview drills into a country. Settingconfirmed_spam, or releasing one topending, removes it from the list.recordAtlasSnapshot, thensendDigests. Mailpit should show one email per role, summary line first, each ending in "Open your dashboard".Notes for reviewer
The reviewer has pushed 22 commits onto this branch (
f9fdc38…3a31e39), reshaping it twice over. Four of them build what the earlier rounds had dismissed, so those dismissals are gone from this body rather than restated:f9fdc38gavedigestWatermarksajsonFieldschema, soDigestWatermarksis generated rather than hand-written. That settles the "worth a second opinion" this body used to carry.d304220collapsed the ten status literals intoSTATUS_TABLE.86ce445gave the four task handlers onerunClock.adabf6amade an implicit read follow project membership, so a project-less collection fails closed —tests/unit/implicit-read-fails-closed.spec.tspins it.The region-tree ruling is superseded by the reviewer's own commit.
0f6d7d4builtrollUpRegionTreeand the thread approved it;19cb9a9then deleted it, put the sidebar back onmain's loop and inlined the overview roll-up. Two walks remain, not three —rollUpRegionManagersis gone andgetRegionManagersserves managers — and the two differ in input:rollUpRegionCountsis pure over pre-shapedSidebarCountEventInput, whileregions.tsreads event documents againsttree.chainByIdand the scope set for six counters plus the dated sign-up pair.Deliberate deviations from the ticket:
src/emails/EmailLayout.tsxas specified, besideSectionHeadingandBrandButton— not into a new module.buildRegionTreestays sidebar-only, by the reviewer's decision: both overviews render flat rows, not a nested tree.Still dismissed, with reasons:
event in (every id)from the admin scope's sign-up query. Not behaviour-preserving:findexcludes trashed events, so the id list is not every event, and dropping the term would newly count sign-ups on trashed ones.reminded, while a reminded listing is still healthy and still not a region manager's to join.OVERDUE_QUERY_STAGEScovers the two that do match, and says so.EventVerificationNotice.tsx. They are not the same function: that one is a nullable display formatter with a NaN guard, and it sits in a'use client'component that must not reachatlasOverviewat all. The key lives instatistics.ts, which reads it back.A
/security-reviewover the branch found nothing exploitable. It traced everyoverrideAccess: trueread inatlasOverviewto a bound the reader cannot influence, confirmed?region=cannot widen pastresolveOwnedRegionIds, and confirmed there is no path toconfirmed_spamexcept fromspamby an admin. One thing it raised turned out to be a false positive: it readUsers/endpoints/block.ts'spending → spamsweep as somethingguardStatusTransitionwould now refuse —block-user.int.spec.tspasses and the rows do move. That review predatesadabf6a, which is the one commit since to touch asecurityReview.triggerPatternpath.Detail
The migration's four hand edits, in
upanddownboth: job rows naming a removed slug are deleted above eachtask_slugrebuild;confirmed_spamrows go back tospamabove the status rebuild; preferences are rewritten rather than re-defaulted, because a column DEFAULT reaches new rows only; and the twoDROP CONSTRAINTstatements the generator emits for foreign keys its ownDROP TABLE … CASCADEhas already taken are removed, as20261019_182311_import_plugin.tsremoved them.The preference rewrite round-trips, and did not.
upsubtractedregional_summaryoutright, so a rollback left the key missing and a manager who had muted regional summaries came back on the default. Both rows offer the same['Monthly', 'Never']pair, so the value carries intostatistics— the row #1070 gave that content to — anddownputs it back. Re-measuring the cycle against a throwaway Postgres also caughtdownwriting"event_registration": nullon every manager without that row, and plantingregional_summaryon one who never had it:jsonb_build_objecton an absent key writes a literal null. Both branches are conditional now, under thejsonb_strip_nullsthat already wrappedup.Why snapshots are
payload.kvand not a collection.5f425c9moved them.payload_kvis already in20260606_050852_initial_schema, so the store owed no schema change; one row per UTC day isset, never appended, so a retry after a crash cannot leave a day half counted; andRecordAtlasSnapshotprunes pastSNAPSHOT_RETENTION_DAYS(38 — the 30-day comparison, plusSNAPSHOT_TOLERANCE_DAYS, plus a day of slack) with a string comparison, because the keys sort as their dates do. The same commit dropped theregistration-refusalscollection: a refused sign-up is already auser-submissionsrow atstatus: spam, sorefusals.tscounts those instead of storing a second copy.Nothing is left from the closed PR #1052 (
claude/feat-259-refused-signup-digest). The branch took itsregistration-refusalscollection andrecordRefusedRegistrationwholesale;5f425c9deleted both, because a refused sign-up is already aspamsubmission. ⚠ That checkout silently reverted two later changes —ScreenSubmissions.tslost #1060's blocked-sender check andprojects.tslost #1068's role rename, because #1052 predates both. Existing integration specs caught each; both are restored in302c9c9.Why the homes read with
overrideAccess: falseand the job withtrue. A page shows exactly what the reader's own access admits, so a scoping bug surfaces as a missing row rather than as a leak. The job has an explicit scope and no user at all, so there is no access to defer to —scopeRegionIdsis what bounds it, andloadRegionOverviewtakes nooverrideAccessprecisely because it cannot honour one: a row's counts are a roll-up over a subtree, where a reader's own grants would undercount a region rather than refuse it.Performance, measured against the shape rather than a stopwatch. Every loader in
atlasOverviewwas its own entry point, so a region home opened with four full scans of a table holding a node per country, region, area, city and venue, each with a breadcrumbs join; the digest paid two per manager per role. The region tree and the open-proposals read are memoized per request, the regions overview's event and sign-up reads are narrowed to the scope, and the refusal count is acount, not afind.One acceptance criterion was silently unmet until the review pass.
SectionTabsrefused to render fewer than two tabs, so the program home's Open-items tab — and with it the count, or the tick that stands in for zero — was never drawn. A lone tab renders now.Closes #1070