Skip to content

docs(embedding): keep reporting every load, correct the 1 h collapse - #341

Merged
sydevs-bot merged 6 commits into
mainfrom
claude/docs-160-embed-report-window
Oct 28, 2026
Merged

sydevs-bot merged 6 commits into
mainfrom
claude/docs-160-embed-report-window

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The collapse window is 6 h everywhere, and docs/rules/data-layer.md now records that reporting on every page load stays, with the revisit trigger.
  • Joined: three code comments and one more spot in mutate.ts carried the same stale hour — criterion 2 is "no file in this repo", not "these two files".
  • Joined: mutate.ts and the reportEmbed bullet named the endpoint's unpinned response fields as mount / stored; they are mounts / updated.
  • Joined: embed-announce.test.ts's fixture mocked that same impossible response shape.
  • Review: the changelog entry offered the window as a sizing number a host cannot observe. It now says what the window bounds.
  • Review: the figure was written out at 10 sites across 5 files. Four remain, each where the number is the point; the rest name SahajCloud's constant.

Change outline

Contract — docs/embedding.md § The embed report

The one host-facing number. A host sizing its traffic against the published figure was budgeting for six times the writes we make.

 Reports on every load, so "last seen" distinguishes a live embed from a removed one
-Repeat reports of an unchanged page collapse into at most one write an hour
+Repeat reports of an unchanged page collapse into at most one write in any 6 h window
 Sends origin and path only, `?p=<number>` excepted

CHANGELOG.md gains one ### Changed entry for the window. The ### Added entry for #159 carried the same figure and is corrected in place — it sits in the same [Unreleased] section, so leaving it would have the file contradict itself.

Contract — what the changelog entry claims about the window

A host cannot observe the collapse window. Every page load still posts one report and the response is 200 either way, so the window bounds writes on our side alone. The first wording offered 6 h as "the figure to size against if you were budgeting for our traffic", which reads as fewer requests.

 A repeat embed report turns into at most one write in any 6 h window. ([#160])
 The widget still reports on every page load, and an unchanged report inside
 that window is answered without a write. This guide and the embedding guide
-had both published the window as one hour; six is the figure to size against
-if you were budgeting for our traffic.
+had both published the window as one hour. It bounds writes on our side, not
+requests from your page — those are still one per load.
 Nothing in your snippet, your CSP or what the widget sends changes.

Contract — the endpoint's response, as our docs and comments describe it

Not a change to what we send or parse. EmbedReportResponseSchema still pins { ok: true } alone, deliberately. What changed is that the two keys we describe-but-never-read are now the keys SahajCloud actually returns.

 ClientEmbedReportResponse   SahajCloud src/collections/Clients/endpoints/report.ts
   ok: true                  # the whole receipt our schema checks
-  mount                     # the key it filed under
-  stored: false             # when it suppressed an unchanged report
+  mounts: number            # distinct mounts stored for this service after the merge
+  updated: boolean          # false when the report repeated a recent identical observation

The "harmless CMS rename" that data-layer.md bullet warns about as hypothetical had already happened. That is the argument for not pinning the fields, intact — it just needed the real names.

Behaviour — the decision recorded, not changed

docs/rules/data-layer.md's reportEmbed entry gains the cadence decision, each reason pinned to the SahajCloud file that shows it rather than to a line number that rots across repos.

 reportEmbed → POST /api/clients/report
   send once per page from lib/embed-announce.ts, never through React Query
+  reporting on every page load STAYS, because the server path is cheap three ways:
+    clients is excluded from the usage plugin      → nothing meters the route
+    req.user is the full client doc                → a repeat answers updated: false, no query, no write
+    an unchanged report collapses within 6 h       → SahajCloud's EMBED_REPORT_REFRESH_MS
+  revisit only if Railway CPU on /clients/report becomes noticeable
   keep the response schema at { ok: true } only

One figure, one place

Correcting 1 h → 6 h left ten prose copies of one SahajCloud constant with nothing checking agreement — and all eight earlier copies had been wrong from the day EMBED_REPORT_REFRESH_MS landed. Five of the six internal sites carried the duration without an argument, so they drop it and keep the reason:

 mutate.ts   `updated: false` when it suppressed an unchanged report
-              within the 6 h window
 mutate.ts   a retry would be a second write of a record the server already
-              collapses within 6 h
 data-layer  a retry would replay a write the server already collapses
-              within 6 h
 announce:38 the endpoint would suppress the repeat
-              for 6 h anyway
 announce:102 the server suppresses an unchanged report
-              for 6 h (SahajCloud's EMBED_REPORT_REFRESH_MS), so the real cost
-              is at most one write per mount per 6 h
+              for the length of SahajCloud's EMBED_REPORT_REFRESH_MS, so the
+              real cost is at most one write per mount per window

Four copies remain, each where the figure is the point: docs/embedding.md:314, the two host-facing CHANGELOG.md entries, and the cadence decision in data-layer.md:302, which already names the constant beside it. No gate can check agreement from this repo — the unit lane is node-only and cannot reach SahajCloud — so one number in one place is the whole fix, not a step toward one.

Files — the one spec touched

 src/lib/embed-announce.test.ts
   'treats a suppressed duplicate as a successful send'
-    mock { ok: true, mount: 'x', stored: false }    # a response the endpoint cannot send
+    mock { ok: true, mounts: 1, updated: false }

No product code changed. comment-fingerprint.mjs --base origin/main reports src/config/api/mutate.ts and src/lib/embed-announce.ts codeHash identical, no comment moved, every protected marker preserved. The cadence, IDLE_DEADLINE_MS and the module-scope reported flag are untouched.

Preview

Nothing to preview. The diff is Markdown and comments, and no deployed page renders docs/, CHANGELOG.md or a JSDoc block. No branch alias is read for that reason, rather than being pending.

Test results

  • Base merged: origin/main (6f91dd3) merged in clean, no conflict. It carried fix(deps): bump zod to 4.6.7 and @hookform/resolvers to 5.9.2 #339's zod bump and new mutate.test.ts cases, so the gate below tests the merged result.
  • Lean gate: ✓ .claude/skills/pr-prep/check.sh — lint, typecheck, test:run (154 files, 1815 tests)
  • Security review: ✓ re-run on this push. src/config/api/mutate.ts matches securityReview.triggerPattern on path, and the branch diff is now entirely Markdown, comments and one test fixture — no new code path, data flow or sink. No findings.
  • Build: N/A — CI runs build + pnpm size

Manual verification

  1. Confirm 6 h is the figure you want published to hosts. EMBED_REPORT_REFRESH_MS is SahajCloud's, so our guide tracks their constant and cannot enforce it.
  2. Read the ### Changed changelog entry's register. It tells a host the number they were given was wrong, which is a judgement about how much to say.

Contract impact

docs/embedding.md is the host-facing contract, so it changes here with CHANGELOG.md as the rule requires. Nothing a consumer reads programmatically changed — no attribute, origin, CSP entry, URL shape or response field we parse — so WeMeditateWeb/lib/atlas-embed.ts and the WordPress plugin's templates need no edit. Neither repo is in this session's checkout; neither encodes the collapse window, which only the server applies.

Notes for reviewer

  • Scope is wider than the ticket's original checklist, which said the diff should list exactly three files. Criterion 2 is the reason: "no file in this repo describes the server collapsing an unchanged report hourly" cannot be met by the two doc spots alone. Each extra file is comment- or test-only and has its own commit. That checklist item is now a comment-fingerprint.mjs assertion instead of a file list, and criterion 5 reads "no product code changes" rather than "no source file changes" — the old wording a reviewer could only tick by ignoring the diff.
  • docs(embedding): keep reporting every load, correct the 1 h collapse #160's acceptance criteria carry three review lines (2026-10-28), one per adopted review point: the single-source rule, what the changelog entry must say the window bounds, and the comment-only carve-out.
  • The ticket's own verification greps would have missed the mutate.ts defect. an hour|hourly|by the hour does not match "within the hour". grep -ni hour is what found it, and the checklist now uses the wider pattern.
  • grep -n 'an hour' has no hit left anywhere in CHANGELOG.md. An earlier draft of this body claimed one at line 49; the string there is "one hour", inside the correction saying what the guides had published, and that pattern never matched it.
  • The fixture correction adds no coverage, and I am not claiming it does. The old fixture passed too, because the schema pins ok alone — which is the property that test covers. What changes is that the fixture is now a response the endpoint could send.
  • /code-review high ran on the first push; no toolkit plugin is installed here. comment-lint.mjs reports no banned comment added. No review finding was dismissed.
Detail

Why file paths and not line numbers. The ticket asked for the three reasons "each checkable at a line" and cited report.ts:26, :118, :154. The always-loaded docs/rules/code-comments.md forbids pointing at a moving target, and a line number in a sibling repo is the clearest case of one. The entry names the file plus the symbol or path to look for (embedMergeSql, the no-op path, EMBED_REPORT_REFRESH_MS), which survives their next refactor. Verified at src/collections/Clients/endpoints/report.ts (the embedMergeSql comment, the req.user read, the updated: changed body) and src/lib/clients/embedMetadata.ts:84.

Why the constant and not the number, given the constant was renamed once. EMBED_REPORT_MIN_WRITE_INTERVAL_MS → EMBED_REPORT_REFRESH_MS is exactly the drift code-comments.md warns about, so a name is not a free anchor. It wins here on the asymmetry: a renamed constant fails loudly — grep returns nothing and the reader goes looking — while a stale number reads as true and stayed wrong for months at eight sites. Where the duration carried no argument at all, neither anchor is needed and the number simply goes.

mergeMount does not exist. The breadcrumb I first wrote named it; grep -rn mergeMount over SahajCloud has zero hits. The helper is embedMergeSql.

Whether this is a correction or a behaviour change. git log -L over SahajCloud's EMBED_REPORT_REFRESH_MS shows the line was 6 * 60 * 60 * 1000 from the day it was introduced, so one hour was never right. That is why the changelog entry frames it as a published number being wrong rather than as the window moving. SahajCloud is a shallow clone here (50 commits), so this rests on the review pass's git log -L read over the range available, not on full history.

EMBED_REPORT_MIN_WRITE_INTERVAL_MS appears nowhere, per the ticket's ⚠. EMBED_REPORT_REFRESH_MS is named as SahajCloud's at both sites that name it.

One cosmetic reflow. The corrected ### Added line ran to 97 characters where its neighbours wrap near 88, and Prettier's proseWrap is preserve, so nothing would reflow it.

Closes #160


Generated by Claude Code

Two guides published one hour. `EMBED_REPORT_REFRESH_MS` is `6 * 60 * 60 *
1000` (SahajCloud `src/lib/clients/embedMetadata.ts`), so a host sizing its
traffic against the published figure was budgeting for six times the writes
our server actually makes.

The `reportEmbed` entry in `docs/rules/data-layer.md` now also records the
decision that reporting on every page load stays, with the three reasons the
cadence is cheap, each pinned to the SahajCloud file that shows it: the route
is unmetered, a repeat costs no extra read, and an unchanged report collapses
inside the window. The revisit trigger is named in the same place — Railway
CPU spent on `POST /api/clients/report` — so the next reader finds the
decision where they would look for the cadence, not in a closed thread.

The changelog entry is not a documentation entry, which that file's own rule
excludes. The number was published to hosts and was wrong, so the correction
is host-observable. The `### Added` entry for #159 carried the same stale
figure and is corrected in place: it sits in the same `[Unreleased]` section,
and leaving it would have the file contradict itself.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYiUPhrVmQrbkoG99p
The same stale figure the guides carried. `mutate.ts` and both
`embed-announce.ts` blocks told the next reader the server suppresses an
unchanged report for an hour, and one of them derived a cost from it — "at
most one write per mount per hour", wrong by six.

`EMBED_REPORT_REFRESH_MS` is named where that derivation sits, as SahajCloud's,
since the constant is theirs and a reader could take it for ours.

Comment-only: `comment-fingerprint.mjs --base origin/main` reports both files
codeHash identical, no comment moved.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYiUPhrVmQrbkoG99p
Three corrections from the branch review, each checked against SahajCloud.

`mutate.ts` had a second stale window 13 lines above the one already fixed —
"suppressed an unchanged report within the hour". The ticket's verification
greps (`an hour|hourly|by the hour`) do not match "within the hour", so a
wider `grep -ni hour` is what found it.

Both that comment and the `reportEmbed` bullet named the endpoint's two
unpinned response fields as `mount` and `stored: false`. `ClientEmbedReportResponse`
is `{ ok: true; mounts: number; updated: boolean }`
(`src/collections/Clients/endpoints/report.ts`). The "harmless CMS rename"
that bullet warns about as hypothetical had already happened, which is the
argument for not pinning them, intact.

`embed-announce.test.ts`'s fixture carried the same two wrong keys, so it
mocked a response the endpoint cannot send. It now mocks the real shape and
tests the same property — a suppressed duplicate resolves rather than throwing.
Coverage is unchanged, since the schema pins `ok` alone and tolerated either
shape; what changes is that the fixture is now true about the endpoint.

The unmetered-route breadcrumb pointed at `mergeMount`, which exists nowhere
in SahajCloud. The helper is `embedMergeSql`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYiUPhrVmQrbkoG99p
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: da75f85
Status: ✅  Deploy successful!
Preview URL: https://dd21d0b2.sahajatlas.pages.dev
Branch Preview URL: https://claude-docs-160-embed-report.sahajatlas.pages.dev

View logs

@sydevs-bot

sydevs-bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 16:49Z address-review · attempt 1 · session · done
  • 16:49Z address-review · attempt 1 · session
  • 16:42Z review-pr · attempt 1 · session · done
  • 16:42Z review-pr · attempt 1 · session

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

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 28, 2026
@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Oct 28, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
sahajatlas-design da75f85 Oct 28 2026, 04:58 PM

@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 PR is the size of its problem. The ticket asked for three doc edits and the diff is six files, because criterion 2 is "no file in this repo", not "these two files" — the extra three are comment- or test-only, one commit each, joined rather than smuggled. The facts hold upstream: EMBED_REPORT_REFRESH_MS is 6 * 60 * 60 * 1000, ClientEmbedReportResponse is { ok, mounts, updated }, and the collapse really is per mount on an identical observation. No programmatic contract moved, and the window is server-side only, so neither in-tree consumer owes an edit.

What is left is register, where this repo's contract lives. One new sentence hands a host a sizing number that bounds nothing they can observe, and the correction leaves ten prose copies of one upstream constant standing.

⚠ Criterion 5 reads "No source file changes", and three changed. Disclosed in the body, but it wants a rewrite rather than a silent tick.

Findings

  • should-fix CHANGELOG.md:50 — the sizing claim measures a host against our write window.
  • consider docs/rules/data-layer.md:303 — ten copies of a figure SahajCloud owns, nothing checking agreement.

What was checked

  • SahajCloud read directly: report.ts (embedMergeSql's docblock, the req.user no-op path, updated: changed) and mergeEmbedReport's sameObservation && isRecentlySeen guard.
  • Org-wide code search for clients/report and the hour wording beyond these two repos: zero hits, so no WeMeditateWeb or WordPress edit is owed.
  • Criteria 2 and 3 re-run on the branch: the only one hour left is CHANGELOG.md:49, inside the correction; no EMBED_REPORT_MIN_WRITE_INTERVAL_MS.
  • One ## [Unreleased] heading and no duplicate [#160], so the in-place ### Added fix rewrites nothing shipped.
  • Preview: nothing to open; the diff renders on no deployed page.

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


Generated by Claude Code

Comment thread CHANGELOG.md Resolved
Comment thread docs/rules/data-layer.md 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 Oct 28, 2026
The entry offered 6 h as "the figure to size against if you were budgeting
for our traffic". A host cannot observe it: every page load still posts one
report and the response is 200 either way, so the window bounds writes on
our side alone. As written it read as fewer requests.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjW5B1nNDxUFBZrA9Wp
Ten prose copies of one SahajCloud constant, with nothing checking
agreement: eight of them said one hour, wrong from the day
EMBED_REPORT_REFRESH_MS landed, and only a human reading caught it.

At five of the six internal sites the duration carried no argument. A
retry is pointless because the server collapses the repeat, whatever the
window; a re-mount has nothing new to tell it either. Those drop the
number and keep the reason. The one place the length is load-bearing
names the constant instead, so a reader greps rather than trusts.

Four copies remain, each where the figure is the point: the two host-facing
changelog entries, the published figure in docs/embedding.md, and the
cadence decision in data-layer.md, which already names the constant beside
it. No gate can check agreement from here — the unit lane is node-only and
cannot reach SahajCloud — so one number in one place is the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjW5B1nNDxUFBZrA9Wp
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Both critic threads adopted and resolved. Pushed da75f85.

should-fix — the sizing claim → 0bf550d. The changelog entry now says the 6 h window bounds writes on our side, not requests from the host's page, which are still one per load.

consider — ten copies of one constant → da75f85, 10 down to 4. Five internal sites carried the number without an argument and drop it; the one where the length is load-bearing names EMBED_REPORT_REFRESH_MS. Kept where the figure is the point: docs/embedding.md, the two changelog entries, the decision in data-layer.md. No gate can check agreement from here — the unit lane cannot reach SahajCloud.

origin/main merged in clean. Lean gate green (154 files, 1815 tests). Security review re-run: no findings.

#160 gained three review lines. Two criteria could only be ticked by ignoring the diff — "no source file changes", and a three-file list.

🤖 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 Oct 28, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 28, 2026 17:03
@sydevs-bot
sydevs-bot requested a review from Ardnived October 28, 2026 17:03
@sydevs-bot
sydevs-bot enabled auto-merge October 28, 2026 17:03
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Oct 28, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Oct 28, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit 6d8b437 Oct 28, 2026
52 of 54 checks passed
@sydevs-bot
sydevs-bot deleted the claude/docs-160-embed-report-window branch October 28, 2026 17:35
@sydevs-bot sydevs-bot moved this from Pending to Done in SYDevelopers Technical Roadmap Oct 28, 2026
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.

docs(embedding): keep reporting every load, correct the 1 h collapse

3 participants