Repository navigation
fix(summaries): pod-less post summaries come from feed posts only; analytics is admin-only - #2324
Conversation
…alytics is admin-only - summarizePosts reads feed posts (podId null), the set summarizeAllPosts already reads, and stamps its summaries metadata.source 'feed-posts' (services/summaryScope.ts); the empty-hour summary is stamped too. - The summaries visibility filter, and GET /api/summaries/latest, serve a pod-less summary only when it carries that stamp; daily digests stay owner-only and pod summaries stay canViewPod-gated. - The /api/analytics router (six instance-wide aggregate routes, no client callers) is admin-only, behind an IP limiter in the moltbot router's order; the rate-limit guard baseline drops its six entries. - scripts/purge-unstamped-post-summaries.ts removes stored unstamped pod-less 'posts' summaries whose window holds a pod post (dry run by default, before/after counts). Tests: summarizePosts with LEGACY_SUMMARIZER_ENABLED=1, the filter and /latest, analytics as admin and non-admin, and the purge script's survivors. Each change was mutation-checked. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MCgCsf3UJRCPRbnNKxsECe
… the feed stamp GET /api/summaries/latest now serves a pod-less summary only when it is a stamped feed-posts summary, so the fixture's 'Community Posts Overview' is stamped, and the latest chats summary is asserted to be one of the caller's pods' rather than the pod-less 'Overall Chat Activity'. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MCgCsf3UJRCPRbnNKxsECe
lilyshen0722
left a comment
There was a problem hiding this comment.
Security gate — #2324 at b7691063
Base main, merge-base b57966d2 = origin/main (base unmoved), 11 files. CI green at this SHA: 15 success, and the four cancelled entries each have a success of the same name. The five touched suites 42/42, the route rate-limit guard 16/16, tsc --noEmit -p tsconfig.typescheck.json 0 errors, eslint 0 errors.
The property I checked. A stored summary with no podId is served only when it is the caller's own daily digest, or a posts summary stamped metadata.source: 'feed-posts'; pod-scoped summaries stay membership-gated; the analytics router requires an instance administrator; and the purge script is dry by default and targets only unstamped pod-less posts summaries whose window contains a pod post.
The filter's three branches
filterSummariesToViewable dispatches on the summary's own shape, in order: a podId goes to the membership set; a daily-digest must carry the caller's metadata.userId; everything else now goes to isFeedOnlySummary. Branch 3's predicate re-checks !podId and type === 'posts' as well as the stamp, so a pod-less chats summary reaching that branch resolves false rather than relying on the caller having filtered by type first. Reverting the branch to return true reddens three arms across two suites.
/latest's fallback
This was the one I most wanted to measure, because the fallback's result is assigned straight to the response without passing the filter. It is sound: summarizeAllPosts queries Post.find({ podId: null }) — the same feed-only set the stamp certifies — and its own comment states that constraint. That query predates this PR, so the filter and the fallback now agree by construction rather than by coincidence. Two further details: the fallback returns a plain object rather than a stored Summary, so there is nothing for the stamp to mark; and its five-minute process cache holds feed-only content, so sharing it across callers carries nothing caller-specific.
The analytics router order
router.use(analyticsAdminLimit, auth, adminAuth) sits above all six route definitions and each route's own auth is removed, so the three run in that order for every one of them. The limiter-before-adminAuth ordering has a stated reason — adminAuth reads the caller's User row per request — and adminAuth fails closed in all three directions (401 without req.user, 401 on a missing row, 403 on a non-admin, 500 on a throw). The routes still read req.user?.id, which auth populates. The module's CJS-compat export means require yields the function itself, which is what router.use needs. Dropping adminAuth reddens five arms.
The rate-limit baseline is the other half: the six routes/analytics.ts … [unlimited] entries are removed from routeRateLimitGuard.baseline.json, so the guard now requires those routes to be limited rather than tolerating them — the guard passes 16/16 at this head.
I also censused callers of /api/analytics across frontend/src, cli/src, docs and e2e at this ref: none.
The purge script's predicate and its survivors
PODLESS_POSTS covers both podId: null and a missing podId, and the unstamped filter uses $ne, which matches a missing metadata.source too — so neither shape slips the net. Per summary, a window with at least one podId: { $ne: null } post makes it a target; a summary with no window is treated as a target, which is the fail-closed direction and is what the comment says. deleteMany re-applies the whole predicate alongside the id list, so a row that acquires the stamp between the find and the delete is spared. The apply path re-counts and prints before - after === deleted.
Survivors are unstamped pod-less posts summaries whose window held no pod post. The script's reason for leaving them — that non-digest summaries age out within 24 hours — checks out: garbageCollectForDigest deletes createdAt older than 24 h with type !== 'daily-digest', and it is called from the scheduler and three summaries routes.
Mutations
Seven, each applied alone; all four touched files restored byte-identical to HEAD afterwards.
| mutation | result |
|---|---|
filter branch 3 back to return true |
3 red |
/latest serves the stored summary unfiltered |
1 red |
analytics loses adminAuth |
5 red |
summarizePosts drops its podId: null |
2 red |
| the feed stamp is not written | 1 red |
| the purge target set stops excluding stamped rows | 1 red |
| a window-less summary is no longer a target | survives |
One note (not blocking)
The purge script's fail-closed choice is unasserted. Flipping the no-window case from "target" to "not a target" keeps every suite green, so the one judgement the script's comment calls out explicitly is the one no arm pins. It is low-stakes — the read path withholds an unstamped pod-less summary whether or not the script removes it, so the script is hygiene rather than the control, and the 24-hour collector reaches the same rows — but an unpinned fail-closed decision is the kind a later edit inverts quietly. One arm with a timeRange-less fixture would close it.
Written by Vera, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015
GATE: PASS
Pod-less
postssummaries are now built from feed posts only, and only those are served. The/api/analyticsrouter becomes admin-only.Changes
summarizePostsreads feed posts (podId: null), the same setsummarizeAllPostsalready reads. It stamps its summariesmetadata.source: 'feed-posts'(services/summaryScope.ts), and the empty-hour summary is stamped too. The scheduler runs it only withLEGACY_SUMMARIZER_ENABLED=1. The new test sets that flag and calls it directly.filterSummariesToViewable(summaries.ts) serves a pod-less summary only when it carries that stamp.GET /api/summaries/latestnow runs its posts summary through the same filter, falling back tosummarizeAllPostsas before. Daily digests stay owner-only, and pod summaries staycanViewPod-gated./api/analyticscovers six instance-wide aggregate routes: keywords, topics, activity, users, trending, summary. They have no callers in the frontend, cli, commonly-mcp, scripts, workers, or the openclaw extension at its pin. The router is nowplatformIpRateLimit→auth→adminAuth, the orderroutes/providers/moltbot.tsuses. The rate-limit guard baseline drops their six "unlimited" entries.scripts/purge-unstamped-post-summaries.tsremoves stored pod-lesspostssummaries without the stamp whose time window holds a pod post. It dry-runs by default, and--applyre-counts afterwards (before − after = deleted).Stored pod-less
postssummaries matching the purge:postssummaries in total, 0 targets;--applyrun ondf8c219f, 2026-10-18 20:29Z, printedpodless=0 unstamped=0 targets=0, thendeleted=0 after=0 check=ok.Tests
summarizerService.feedPosts, run withLEGACY_SUMMARIZER_ENABLED=1:isFeedOnlySummarycases;summaries.visibility, updated:chatssummaries are dropped, and stamped ones are kept;/latestserves a stamped summary, and falls back on an unstamped one;analytics.adminOnly: non-admins get 403 and no read on all six routes; admins get through;__tests__/service/summaries.test.js, updated: its pod-less posts fixture carries the stamp, and/latest's chats summary is now one of the caller's pods' summaries rather than the pod-less overview;purgeUnstampedPostSummaries: only the target is deleted, every neighbouring class survives, and it's idempotent.Six mutations each fail at least one test: reading all posts, passing every pod-less summary, an unfiltered
/latest, droppingadminAuth, an unstamped empty summary, and purging every unstamped summary.tsc:checkand eslint on the changed.tsare clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01MCgCsf3UJRCPRbnNKxsECe