Repository navigation
feat(atlas): give the unowned remainder a sitemap via a canonical fallback client - #676
Conversation
|
🚅 Deployed to the SahajCloud-pr-676 environment in sahajcloud
1 service not affected by this PR
|
|
CI is green on
Step 13 is Worth knowing given the missing migration: had the smoke lane reached a preview, it would have been a preview whose database has no 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
Base updated — the head is now Flagging it because the PR body's test results name Nothing else changed, and the blocker has not moved: this still needs the migration whose command is in the PR body. Merging without it is a boot crash, not a slow degradation. 🤖 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
This is the right shape and roughly the right size — the gap is on the contract side, not the code side. The production logic is ~60 lines for a ticket whose acceptance list has six items, the sparse map the ticket warned about is genuinely kept (and pinned by a test that fails if it is materialized), and no new endpoint surface appeared. The one deliberate departure — requiring canonical.enabled, not just verified — is argued from a state production reaches on its own (VerifyEmbeds switches enabled off while buildVerificationState keeps the snapshot) and I would keep it: without it, a client the job has given up on speaks for every unclaimed page in the atlas.
What is missing is the consumer half of a contract change. /api/atlas/sitemap now answers one caller something it has never answered, and both surfaces a consumer reads — the OpenAPI description in customEndpoints.ts and AtlasSitemapResponse in responseTypes.ts — still say "every entry is a URL this client owns", still say a document nothing in its ancestry owns is omitted, and still justify having no pagination with "a client owns a subtree". The fallback client's answer is the complement of the corpus, so all three statements now have an exception nothing documents. Only the internal handler docblock was updated.
One layer does not pay rent: canonicalTargetFor's new second parameter computes exactly what its first parameter already computed, and the only caller passes undefined to the first — see the thread on line 299.
Not merging, as the body says. The missing migration for canonical_fallback_client_id is a boot crash rather than a degradation, and payload-types.ts shipping the field without it is what makes the gap invisible on a green CI run; nothing else here changes that verdict.
Findings
| Rank | Finding |
|---|---|
| should-fix | The OpenAPI description (customEndpoints.ts:588-615) and AtlasSitemapResponse (responseTypes.ts:200-203) still describe the pre-#652 contract, including the unpaginated justification that the fallback client breaks — src/endpoints/atlas/sitemap/index.ts:120 |
| should-fix | canonicalTargetFor's second parameter duplicates its first rung and is unreachable from production; the laziness requirement means the caller that holds both can never use it — src/lib/atlas/regionOwners.ts:299 |
| consider | getRegionTree is awaited for every caller though only the fallback branch reads it, and nothing is "already in flight" on the empty-answer path — src/endpoints/atlas/sitemap/index.ts:173 |
| consider | The (config as { canonicalFallbackClient?: unknown }) cast discards the generated type this PR just added — src/lib/atlas/regionOwners.ts:188 |
| consider | Client eligibility (enabled + published) is now stated in two query shapes; the set is already loaded in both call paths — src/lib/atlas/regionOwners.ts:192 |
| consider | The admin description gives the preconditions but not the consequence: setting this moves the canonical URL of most of the tree — src/globals/SahajAtlasConfig/SahajAtlasConfig.ts:72 |
| consider | The same rationale is written out in three places (JSDoc, docs/architecture.md, the field comment) — src/lib/atlas/regionOwners.ts:160 |
What was checked
Ticket vs diff. Read #652 in full (including the two settled decisions and the ⚠ sparse-map warning) before the diff. All six acceptance boxes are addressed: the field exists; the complement is published; unset/unverified reads as before (integration cases "reverts to the env-var surface…" and "ignores a client the verification job switched off…"); the map stays sparse (tests/unit/atlas-sitemap.spec.ts → resolveOwnersByRegion asserted .has(3) === false); the per-request cost is pinned by countFinds at N=1 and N=3; docs/architecture.md replaces the note rather than deleting it. The canonical.enabled clause is the only thing here the ticket did not ask for, and it is declared as such in the body.
Files read whole (branch edb0ad8, git diff origin/main...FETCH_HEAD): src/lib/atlas/regionOwners.ts, src/lib/atlas/regionTree.ts, src/lib/atlas/canonicalUrl.ts (signatures), src/lib/utilities/relationId.ts, src/endpoints/atlas/sitemap/index.ts, src/endpoints/atlas/sitemap/sitemapUrls.ts, src/globals/SahajAtlasConfig/SahajAtlasConfig.ts, plus the four spec files and the payload-types.ts hunk.
Consumer sides followed. src/endpoints/responseTypes.ts:179-213 and src/plugins/openapi/customEndpoints.ts:585-642 — the two in-tree contract statements, neither in this diff; that is finding 1. Cross-repo: SahajAtlasWordpress/includes/sitemap.php is the only consumer of this endpoint in the workspace (grep -rn "atlas/sitemap" across SahajAtlasWordpress, WeMeditateWeb, SahajAtlasWeb — one hit, plus its AGENTS.md reference). It reads loc verbatim, filters to URLs on its own host, caches for 6h and 404s an empty set, so a larger answer needs no change there — but it fetches with 'timeout' => 15, which is why the pagination sentence is worth re-justifying rather than just reworded. WeMeditateWeb does not consume the endpoint yet, so the remainder only reaches a crawler once it does.
Claims checked rather than taken. canonicalTargetFor(undefined, F) ≡ canonicalTargetFor(F) by reading both rungs (lines 307-311) — they call the identical canonicalTargetForHost. git grep -n canonicalTargetFor over FETCH_HEAD -- src returns one definition and one call, which passes undefined first. GeneratedTypes extends Config is declared at payload-types.ts:7157, so the global read is typed and the cast is optional. loadDirectOwners's where-clause compared line by line with loadCanonicalFallbackOwner's. The refactor of loadDirectOwners (extracting canonicalOwnerFrom) is behaviour-preserving: regionId == null still short-circuits before the domain check, and owners.has(regionId) still wins for the lowest id.
Things that looked like defects and are not. The complement is taken over chainById.keys(), which is every region row including unpublished ones — but ownedDocuments reads with overrideAccess: false, so access rules drop them before they can reach a sitemap. A region whose owner's host later becomes unpublishable falls into the complement and is published on the fallback host — which matches what webUrl answers for it, so the sitemap//seo byte-identity holds. The two halves of fallbackRegionIds are disjoint by construction, as its docblock claims.
Not checked. Nothing was run: no build, no test execution, no admin. CI is reported green on this head by the PR's own comment; the migration gap is not something CI can see.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
@sydevs-bot I've generated the needed migration |
…contract change Adversarial review on #676 raised seven threads; all seven are addressed. The two should-fix ones first. `canonicalTargetFor`'s second parameter was redundant on its own signature: `canonicalTargetFor(undefined, F)` and `canonicalTargetFor(F)` return the same value, and the only production caller passed `undefined` first. Worse, the parameter existed to express "an owner beats the fallback" — a precedence the one caller holding both can never ask for, because not resolving the fallback when the region is owned IS the laziness the design rests on. Dropped. The unit case asserting that precedence went with it and is replaced by an integration case at the site precedence actually lives: an owned region read with a fallback configured resolves on its owner's host AND leaves the `clients` query count at 1. Watched failing — eagerly awaiting the fallback in `getCanonicalUrlBase` gives `expected 2 to be 1`. The consumer half of the contract change was missing. `/api/atlas/sitemap` now answers one caller the complement of the ownership map, while both published surfaces — the OpenAPI description and `AtlasSitemapResponse`, which SahajAtlasWordpress reads by raw URL — still said every entry is a URL the client owns and that documents nothing owns are omitted. Both now describe the fallback client, and the "no pagination" claim is re-justified: it rested on a client owning a subtree, which this client does not, so consumers are told to size the fetch against the corpus. The five `consider` threads: the client-eligibility predicate is now one `CANONICAL_ELIGIBLE` constant rather than two query shapes that could drift; the structural cast on `canonicalFallbackClient` is gone, since the field is in `payload-types.ts` and `relationId` takes `unknown`; `getRegionTree` moved inside the branch that takes a complement, so every other client (the empty answer included) stops paying for a `regions` read it never looks at; the admin description now says what setting the field DOES, not only its preconditions; and the 18 lines of JSDoc restating `docs/architecture.md` are down to the two imperatives a reader cannot re-derive. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013zCsUruFTxhvz66CEANoAE
|
Thanks — migration confirmed, and the review's 7 threads are all addressed. This is ready for you. I ran your migration rather than reading it: fresh database, The code changed in two ways worth knowing before you read the diff. The integration lane ran locally for the first time — #679's One thing the migration run turned up, which is not this PR'sRolling the whole batch back on a fresh database fails inside the already-merged Ours had already rolled back cleanly by then, and production rolls forward, so nothing here is urgent. Filed as its own ticket rather than widened into this PR. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…lback client `GET /api/atlas/sitemap` answers the routes a *client* owns, and the We Meditate fallback is not a client — it is two env vars in `canonicalTargetFor()`. So every region no client declares, and every class inside one, was in nobody's sitemap: the larger share of a ~595-region tree against ~31 declaring clients, all of it with real, canonical, indexable URLs that `/api/atlas/seo` was happily serving metadata for. `sy-atlas-config.canonicalFallbackClient` names the client that owns that remainder. Ownership becomes total, so the endpoint needs no new surface — no `?scope=`, no second endpoint, and none of the auth question that came with one: the pages belong to somebody, and that somebody asks for its own sitemap through the call that already exists. Three decisions carry the implementation. **The map stays sparse.** The naive reading of "ownership becomes total" is an entry per unclaimed region, but `resolveOwnersByRegion`'s precedence rule is expressed by *absence* — it is what makes a nearer client's subtree drop out of an ancestor's sitemap. So the fallback is resolved where the fallback already is, in `canonicalTargetFor`, and the endpoint branches once: for the fallback client the answer is the complement of the map rather than a lookup in it. **The predicate requires `canonical.enabled`, not just a verified host.** `verified` is deliberately not cleared when verification fails — it is the last thing we observed — while the job switches `canonical.enabled` off after repeated failures. Reading `verified` alone would therefore let a client the job has just given up on keep speaking for every unclaimed page in the atlas, which is worse than the env-var surface it replaced. The fallback is an ordinary canonical owner that additionally covers the remainder. **The read is lazy.** `sy-atlas-config` backs no other read on the `webUrl` path, which resolves on the afterRead of every region and every event, so this adds queries where there were none. An owned region short-circuits before asking; an unowned one pays two, memoized on the request. Unset, or naming a client that cannot publish a canonical, everything reads exactly as it did before the field existed. Closes #652 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JUNP1PP41xg4MnRJfc47cG
…contract change Adversarial review on #676 raised seven threads; all seven are addressed. The two should-fix ones first. `canonicalTargetFor`'s second parameter was redundant on its own signature: `canonicalTargetFor(undefined, F)` and `canonicalTargetFor(F)` return the same value, and the only production caller passed `undefined` first. Worse, the parameter existed to express "an owner beats the fallback" — a precedence the one caller holding both can never ask for, because not resolving the fallback when the region is owned IS the laziness the design rests on. Dropped. The unit case asserting that precedence went with it and is replaced by an integration case at the site precedence actually lives: an owned region read with a fallback configured resolves on its owner's host AND leaves the `clients` query count at 1. Watched failing — eagerly awaiting the fallback in `getCanonicalUrlBase` gives `expected 2 to be 1`. The consumer half of the contract change was missing. `/api/atlas/sitemap` now answers one caller the complement of the ownership map, while both published surfaces — the OpenAPI description and `AtlasSitemapResponse`, which SahajAtlasWordpress reads by raw URL — still said every entry is a URL the client owns and that documents nothing owns are omitted. Both now describe the fallback client, and the "no pagination" claim is re-justified: it rested on a client owning a subtree, which this client does not, so consumers are told to size the fetch against the corpus. The five `consider` threads: the client-eligibility predicate is now one `CANONICAL_ELIGIBLE` constant rather than two query shapes that could drift; the structural cast on `canonicalFallbackClient` is gone, since the field is in `payload-types.ts` and `relationId` takes `unknown`; `getRegionTree` moved inside the branch that takes a complement, so every other client (the empty answer included) stops paying for a `regions` read it never looks at; the admin description now says what setting the field DOES, not only its preconditions; and the 18 lines of JSDoc restating `docs/architecture.md` are down to the two imperatives a reader cannot re-derive. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013zCsUruFTxhvz66CEANoAE
8dc6ddd to
8669441
Compare
…must act on Review asked for the whole `/api/atlas/sitemap` description to be reworded more concisely. It had grown to ~470 words of unbroken prose because each review round appended its own justification rather than replacing one. Every contract fact survives — the `loc`/`canonical` byte-identity, the don't-recompose warning, nearest-owner subtree semantics, empty-is-200, omitted-not-null, empty regions in and finished classes out, the fallback client, no pagination, `lastmod`, sorting, `generated`, per-client caching. What went is the *argument* for each: a consumer acts on the rule, not on why we chose it. ~200 words in four paragraphs, matching the paragraph style `/api/events/geojson` already uses in this file. `tests/unit/openapi-custom-endpoints.spec.ts` pins four phrases from this description; "Finished classes are excluded" is kept verbatim rather than loosening the assertion to match new prose — an assertion that tracks whatever the text happens to say stops being a guard. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01W3bncHkCBKywbTiJSniKh8
|
One of your three is done; the other two are questions I've answered and left open for you.
Nothing here changes behaviour — the only commit is the description reword. Lean gate green on this head: lint, typecheck, typecheck:tests, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…contract change Adversarial review on #676 raised seven threads; all seven are addressed. The two should-fix ones first. `canonicalTargetFor`'s second parameter was redundant on its own signature: `canonicalTargetFor(undefined, F)` and `canonicalTargetFor(F)` return the same value, and the only production caller passed `undefined` first. Worse, the parameter existed to express "an owner beats the fallback" — a precedence the one caller holding both can never ask for, because not resolving the fallback when the region is owned IS the laziness the design rests on. Dropped. The unit case asserting that precedence went with it and is replaced by an integration case at the site precedence actually lives: an owned region read with a fallback configured resolves on its owner's host AND leaves the `clients` query count at 1. Watched failing — eagerly awaiting the fallback in `getCanonicalUrlBase` gives `expected 2 to be 1`. The consumer half of the contract change was missing. `/api/atlas/sitemap` now answers one caller the complement of the ownership map, while both published surfaces — the OpenAPI description and `AtlasSitemapResponse`, which SahajAtlasWordpress reads by raw URL — still said every entry is a URL the client owns and that documents nothing owns are omitted. Both now describe the fallback client, and the "no pagination" claim is re-justified: it rested on a client owning a subtree, which this client does not, so consumers are told to size the fetch against the corpus. The five `consider` threads: the client-eligibility predicate is now one `CANONICAL_ELIGIBLE` constant rather than two query shapes that could drift; the structural cast on `canonicalFallbackClient` is gone, since the field is in `payload-types.ts` and `relationId` takes `unknown`; `getRegionTree` moved inside the branch that takes a complement, so every other client (the empty answer included) stops paying for a `regions` read it never looks at; the admin description now says what setting the field DOES, not only its preconditions; and the 18 lines of JSDoc restating `docs/architecture.md` are down to the two imperatives a reader cannot re-derive. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013zCsUruFTxhvz66CEANoAE
Closes #652.
Regions nobody claims now have a sitemap, and a canonical URL somebody verified. A region with no owning ancestor falls back to the We Meditate surface asserted by
WEMEDITATE_WEB_URL+WEMEDITATE_ATLAS_BASE_PATH— the one canonical target nothing checks, and one that appears in no client's sitemap because no client owns it.sy-atlas-configgains acanonicalFallbackClientrelationship; naming a client there puts the remainder through the same pipeline as every other owner, andGET /api/atlas/sitemapanswers that client the complement of the ownership map.An override, never a replacement. Unset, unpublished, not canonically enabled, or with no verified host, every caller keeps the behaviour it had before the field existed.
⏳ Two questions are back with @Ardnived
The third item from your review is done; the other two are questions I have answered rather than guessed at, and both threads are open on purpose.
a3d04c1). ResolvedReact.cacheis Server-Components-only and would silently not memoize in a Payload hook;req.contextis Payload's own documented mechanism for this, which is what the 15 lines are. No change recommendedThe one departure from the ticket, and the migration run
Requiring
canonical.enabled, not justverified.verifiedis deliberately not cleared when verification fails — it is the last thing we observed — and the job switchescanonical.enabledoff after repeated failures. Readingverifiedalone would let a client the job has just given up on keep speaking for every unclaimed page in the atlas, which is worse than the env-var surface it replaces. Both readers now apply oneCANONICAL_ELIGIBLEconstant, so a third condition cannot reach one and not the other.The migration, run from empty rather than inspected. A fresh database,
pnpm payload migrate→ 55 migrations applied,20260902_224424_add_atlas_canonical_fallback_clientin 3ms,Done.\d sy_atlas_configthen shows the column, the btree index, andFOREIGN KEY (canonical_fallback_client_id) REFERENCES clients(id) ON DELETE SET NULL— which is the right cascade: deleting the fallback client reverts the remainder to the env vars, matching the unset path rather than orphaning a reference. Reversible:migrate:downremoved the column cleanly.⚠ One thing that run turned up, and it is not this PR's. Rolling the whole batch back on a fresh database fails later, inside the already-merged
20260826_214829_add_user_messagesdown:constraint "payload_locked_documents_rels_user_messages_fk" of relation "payload_locked_documents_rels" does not exist. Ours had already rolled back by then. Filed as #682 rather than fixed here.The first review round (7 threads), all resolved
The two should-fix ones changed the code:
canonicalTargetFor's second parameter was redundant on its own signature and structurally unusable, so it is gone and precedence is asserted in the integration lane instead; and both published contract surfaces (the OpenAPI description,AtlasSitemapResponse) now describe the fallback client, with the "no pagination" claim re-justified against the corpus rather than a subtree.The new integration assertion was watched failing. Hoisting
await getCanonicalFallbackOwner(req)above the early return ingetCanonicalUrlBase— the shape the deleted parameter invited — givesAssertionError: expected 2 to be 1on the query count, then restored.Test results
a3d04c1): ✓pnpm lint, ✓pnpm typecheck, ✓pnpm typecheck:tests, ✓pnpm test:unit— 120 files / 1560 specs, all exit 0region-canonical-url,atlas-sitemap,atlas-seo— 82 specs, all green. Unchanged by the doc-only commitorigin/mainmerged in ata3d04c1's parent, so this is tested against fix(api): map a Postgres 22P02 cast failure to 400, on Payload's routes and in geojson #685'sdatabaseErrorsplugin🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01W3bncHkCBKywbTiJSniKh8