Skip to content

Admin social load-time instrumentation#111

Merged
therealityreport merged 4 commits into
mainfrom
codex/admin-load-time-app-20260618
Jun 18, 2026
Merged

Admin social load-time instrumentation#111
therealityreport merged 4 commits into
mainfrom
codex/admin-load-time-app-20260618

Conversation

@therealityreport

@therealityreport therealityreport commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Persist local admin load-time samples for the social landing/profile surfaces and API snapshot reads.
  • Add Server-Timing/x-trr timing headers on critical admin social routes.
  • Defer non-essential social profile reads until after first paint while keeping snapshot as the first-paint profile request.
  • Show a stale-progress badge on the social landing page when backend progress data is stale or unavailable.

Notes

  • apps/web/src/lib/admin/api-references/generated/inventory.ts was regenerated because pnpm -C apps/web run validate:quick requires the generated admin API inventory to match the current scanner output.

Validation

  • pnpm -C apps/web exec vitest run -c vitest.config.mts tests/social-landing-repository.test.ts tests/social-account-profile-snapshot-route.test.ts tests/social-account-profile-page.runtime.test.tsx tests/social-account-summary-route.test.ts
  • pnpm -C apps/web run validate:quick
  • pnpm -C apps/web run typecheck
  • git diff --check

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a social progress freshness/status badge to the admin social dashboard.
  • Improvements

    • Expanded admin telemetry with more consistent request timing and clearer cache-status reporting across social landing and profile APIs.
    • Improved landing and profile load signals to more accurately distinguish fresh vs. stale data.
    • Refined secondary-read gating for better responsiveness under load.
    • Polished admin flows including Instagram restart and cookie health preflight.
  • Tests

    • Reduced runtime test flakiness by waiting for UI updates more reliably.

Copilot AI review requested due to automatic review settings June 18, 2026 22:13
@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
trr-app Ready Ready Preview, Comment Jun 18, 2026 11:29pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ecb5fae4-d85c-4fa8-ac07-acebf3d8c493

📥 Commits

Reviewing files that changed from the base of the PR and between 46f5740 and 756b366.

📒 Files selected for processing (1)
  • apps/web/tests/social-account-profile-page.runtime.test.tsx

📝 Walkthrough

Walkthrough

Adds end-to-end admin observability: a new attachAdminRouteTiming server helper attaches Server-Timing and x-trr-admin-*-ms headers to all admin API responses; social landing repository propagates a SocialLandingProgressStatus (source, staleness, cache status) through to the payload; client-side recordAdminLoadSample persists timing metrics to localStorage; and the social landing page and profile page surface progress freshness badges and record navigation load samples. SocialAccountProfilePage also tightens secondary-reads gating, improves guarded comments-run restart, and refactors live-profile-total coordination with a request nonce.

Changes

Admin Route Timing, Progress Status, and Load Sample Telemetry

Layer / File(s) Summary
Data contracts: progress status, timing collector, load sample types
apps/web/src/lib/admin/social-landing.ts, apps/web/src/lib/server/admin/social-landing-repository.ts, apps/web/src/lib/admin/admin-load-samples.ts
Adds SocialLandingProgressStatus type and extends SocialLandingPayload; introduces SocialLandingTimingCollector, SocialProgressSummaryResult, and timing fields on SocialProgressRollupPayload; defines AdminLoadSampleSurface and AdminLoadSample types with localStorage capability detection.
Server route timing helper and profile route factory wrapper
apps/web/src/lib/server/admin/admin-route-timing.ts, apps/web/src/lib/server/trr-api/social-profile-route-factory.ts
New attachAdminRouteTiming computes elapsed durations, appends Server-Timing entries, and sets x-trr-admin-route-ms headers; socialProfileTimedJsonResponse centralizes timed JSON responses for hit/miss/stale/error cache paths.
Social landing repository: timing collection and progress status derivation
apps/web/src/lib/server/admin/social-landing-repository.ts
safeLoadBackendSocialProgressRollup now accepts timingCollector, parses backend timing fields, derives cache_status/stale/generated_at, and returns a structured { status } object; getSocialLandingPayloadResult accepts timingCollector and includes social_progress_status in the final payload.
Landing API route GET/POST timing instrumentation
apps/web/src/app/api/admin/social/landing/route.ts
Both GET and POST handlers create a per-request timingCollector, pass it to getSocialLandingPayloadResult, and wrap all response branches (cache hit, stale, uncacheable, success, error) with attachAdminRouteTiming.
TRR-API route timing instrumentation
apps/web/src/app/api/admin/trr-api/social/ingest/queue-status/route.ts, apps/web/src/app/api/admin/trr-api/social/profiles/.../catalog/posts/route.ts, apps/web/src/app/api/admin/trr-api/social/profiles/.../snapshot/route.ts
Adds routeStartedAt and attachAdminRouteTiming wrapping to queue-status, catalog/posts, and snapshot GET handlers for both success and error paths.
Client-side admin load sample persistence
apps/web/src/lib/admin/admin-load-samples.ts
Implements recordAdminLoadSample (normalizes duration, groups by surface, caps at 50 entries per surface, persists to localStorage) and getAdminLoadSampleSurfaceForPath for path-to-surface mapping.
Admin social landing page: telemetry, coercion, and progress status badge
apps/web/src/app/admin/social/page.tsx
Adds coerceSocialProgressStatus and progressStale option to coerceLandingPayload; loadLandingData reads x-trr-cache and calls recordAdminLoadSample; new SocialProgressStatusBadge component rendered in the page header; one-time navigation load sample recorded via useEffect.
SocialAccountProfilePage: telemetry, secondary reads gating, live profile nonce, and comments restart
apps/web/src/components/admin/SocialAccountProfilePage.tsx, apps/web/tests/social-account-profile-page.runtime.test.tsx
Records recordAdminLoadSample for profile navigation and snapshot fetches; adds liveProfileTotalRequestNonce to coordinate live-profile-total refresh; tightens secondary-reads gate opening logic and propagates constraints through hashtag/collaborators/posts/catalog effects; adds fetchActiveCommentsRunProgressNow to backfill date window before guarded comments-run restart; raises cookie preflight budget threshold; updates catalog action to increment nonce; wraps UI assertions in waitFor to reduce flakiness.

Sequence Diagram(s)

sequenceDiagram
  participant Browser as Admin Browser
  participant LandingRoute as /api/admin/social/landing GET
  participant Repository as getSocialLandingPayloadResult
  participant Backend as Backend Social Progress API
  participant Attach as attachAdminRouteTiming
  participant Storage as localStorage

  Browser->>LandingRoute: GET /api/admin/social/landing
  LandingRoute->>LandingRoute: create timingCollector, record routeStartedAt
  LandingRoute->>Repository: getSocialLandingPayloadResult(ctx, timingCollector)
  Repository->>Backend: fetch social progress rollup
  Backend-->>Repository: payload { timing, stale, cache_status }
  Repository->>Repository: normalize timing → timingCollector.recordBackendMs()
  Repository-->>LandingRoute: { payload: { social_progress_status }, cacheable }
  LandingRoute->>Attach: attachAdminRouteTiming(response, { cacheStatus, backendMs, databaseMs })
  Attach->>Attach: append Server-Timing header
  Attach->>Attach: set x-trr-admin-route-ms
  Attach-->>Browser: NextResponse with timing headers + social_progress_status
  Browser->>Browser: recordAdminLoadSample(duration, x-trr-cache)
  Browser->>Storage: write sample to localStorage
  Browser->>Browser: render SocialProgressStatusBadge(social_progress_status)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~70 minutes

Possibly Related PRs

  • therealityreport/trr-app#107: Both PRs modify the same /api/admin/social/landing route handlers (GET/POST) in apps/web/src/app/api/admin/social/landing/route.ts—main PR adds request timing via attachAdminRouteTiming, while the related PR changes cached rebuild error handling and syncPersonExternalIds to include adminContext.
  • therealityreport/trr-app#109: Overlaps directly with the main PR's social landing progress/status pipeline changes—especially in apps/web/src/lib/server/admin/social-landing-repository.ts (backend rollup-based social progress, shared-source fallback status/timing, and enriched payload status fields).

Poem

🐇 Tick-tock, the rabbit checks the clock,
Each response now wears a timing badge,
Server-Timing headers on every block,
Progress status fresh from cache to page.
Secondary reads now flow with grace,
localStorage holds our samples in place,
No more guessing — just pure insight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Admin social load-time instrumentation' directly and clearly summarizes the main change: introducing load-time instrumentation for admin social features across multiple routes and pages.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/admin-load-time-app-20260618

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds end-to-end load-time instrumentation for the admin social landing + social profile surfaces, combining server-side Server-Timing / x-trr-* timing headers with client-side persistence of local load samples, and adds UI signaling when progress data is stale.

Changes:

  • Introduces attachAdminRouteTiming() to standardize Server-Timing and timing headers on admin API routes and TRR social proxy routes.
  • Persists local (per-browser) admin load samples for social landing/profile navigation + snapshot API calls.
  • Extends social landing payload with progress freshness metadata and renders a stale/live progress badge; defers some secondary reads post-first-paint.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
apps/web/src/lib/server/trr-api/social-profile-route-factory.ts Wraps admin social proxy JSON responses with standardized timing instrumentation.
apps/web/src/lib/server/admin/social-landing-repository.ts Adds progress status + timing fields for landing progress rollups and exposes timing collection hooks.
apps/web/src/lib/server/admin/admin-route-timing.ts New helper to attach Server-Timing + x-trr-admin-* headers to admin responses.
apps/web/src/lib/admin/social-landing.ts Adds SocialLandingProgressStatus type to represent progress freshness/staleness.
apps/web/src/lib/admin/api-references/generated/inventory.ts Regenerated admin API inventory to match scanner output.
apps/web/src/lib/admin/admin-load-samples.ts New client utility to record/read admin load samples in localStorage.
apps/web/src/components/admin/SocialAccountProfilePage.tsx Records load samples, adjusts secondary-read gating, and defers non-essential reads until after first paint.
apps/web/src/app/api/admin/trr-api/social/profiles/[platform]/[handle]/snapshot/route.ts Attaches admin route timing to the social profile snapshot API route.
apps/web/src/app/api/admin/trr-api/social/profiles/[platform]/[handle]/catalog/posts/route.ts Attaches admin route timing to the catalog posts API route.
apps/web/src/app/api/admin/trr-api/social/ingest/queue-status/route.ts Attaches admin route timing to the ingest queue status API route.
apps/web/src/app/api/admin/social/landing/route.ts Adds timing collection + attaches admin route timing headers to landing GET/POST responses.
apps/web/src/app/admin/social/page.tsx Records landing load samples and renders a progress stale/live badge on the admin social landing page.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +368 to +378
const routeStartedAt = performance.now();
let backendMs = 0;
let databaseMs = 0;
const timingCollector = {
recordBackendMs(durationMs: number) {
backendMs += durationMs;
},
recordDbMs(durationMs: number) {
databaseMs += durationMs;
},
};
Comment on lines +506 to +516
const routeStartedAt = performance.now();
let backendMs = 0;
let databaseMs = 0;
const timingCollector = {
recordBackendMs(durationMs: number) {
backendMs += durationMs;
},
recordDbMs(durationMs: number) {
databaseMs += durationMs;
},
};
Comment on lines 4163 to +4167
platform !== "instagram" ||
summaryLoading ||
!summary
!summary ||
!secondaryReadsGateOpen ||
secondaryReadBudgetSlot < 2
Comment on lines 4247 to 4250
platform,
pauseSecondaryReadsForPressure,
secondaryReadBudgetSlot,
secondaryReadsGateOpen,
summary,
Comment on lines +24 to +28
return attachAdminRouteTiming(NextResponse.json(data), {
routeFamily: "admin-social-profile",
routeName: "GET /api/admin/trr-api/social/ingest/queue-status",
cacheStatus: "miss",
startedAt: routeStartedAt,

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
apps/web/src/lib/server/trr-api/social-profile-route-factory.ts (1)

253-258: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use the handler start time for cached profile responses.

The cache helpers start timing after admin auth and param resolution, while the non-cache/error paths use routeStartedAt from Line 329. Cache-hit/stale timings will underreport the same route. Pass routeStartedAt into both cache helpers instead of creating a new timestamp inside them.

Suggested shape
 const respondWithRouteResponseCache = async (
   input: SocialProfileProxyRouteInput,
   config: SocialProfileProxyRouteConfig,
   cache: RouteResponseCacheConfig,
+  startedAt: number,
 ): Promise<NextResponse> => {
-  const startedAt = performance.now();

 const respondWithAdminSnapshotCache = async (
   input: SocialProfileProxyRouteInput,
   config: SocialProfileProxyRouteConfig,
   cache: AdminSnapshotCacheConfig,
+  startedAt: number,
 ): Promise<NextResponse> => {
-  const startedAt = performance.now();

       if (config.cache?.kind === "route-response") {
-        return await respondWithRouteResponseCache(input, config, config.cache);
+        return await respondWithRouteResponseCache(input, config, config.cache, routeStartedAt);
       }
       if (config.cache?.kind === "admin-snapshot") {
-        return await respondWithAdminSnapshotCache(input, config, config.cache);
+        return await respondWithAdminSnapshotCache(input, config, config.cache, routeStartedAt);
       }

Also applies to: 304-309, 342-347

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/lib/server/trr-api/social-profile-route-factory.ts` around lines
253 - 258, The cache helpers respondWithRouteResponseCache and other
cache-related functions are creating their own timestamp via performance.now()
instead of using the routeStartedAt value established earlier in the request
lifecycle, causing inconsistent timing measurements across cached and non-cached
response paths. Remove the startedAt timestamp creation from inside these cache
helper functions and instead add routeStartedAt as a parameter to both
respondWithRouteResponseCache and the other cache helpers mentioned in the
related lines. Update all references to startedAt within these functions to use
the passed-in routeStartedAt parameter instead, ensuring consistent timing
measurement across all response paths.
apps/web/src/app/api/admin/social/landing/route.ts (1)

528-538: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Wrap POST early returns with route timing too.

These validation/not-found branches still return raw NextResponse.json, so 400/404 POST responses miss the new Server-Timing and x-trr-admin-route-ms headers. Use a small local helper to keep these branches consistent with the success/error paths.

Suggested helper shape
 export async function POST(request: NextRequest) {
   const routeStartedAt = performance.now();
   let backendMs = 0;
   let databaseMs = 0;
   const timingCollector = {
     recordBackendMs(durationMs: number) {
       backendMs += durationMs;
     },
     recordDbMs(durationMs: number) {
       databaseMs += durationMs;
     },
   };
+  const timedJson = (
+    body: Record<string, unknown>,
+    init: ResponseInit,
+    cacheStatus = "error",
+  ) =>
+    attachAdminRouteTiming(NextResponse.json(body, init), {
+      routeFamily: "admin-social-landing",
+      routeName: "POST /api/admin/social/landing",
+      cacheStatus,
+      startedAt: routeStartedAt,
+      backendMs,
+      databaseMs,
+    });
   try {

Then replace early returns like:

-      return NextResponse.json({ error: "target_type is required" }, { status: 400 });
+      return timedJson({ error: "target_type is required" }, { status: 400 });

Also applies to: 542-543, 567-568, 633-634

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/app/api/admin/social/landing/route.ts` around lines 528 - 538,
The early return statements that validate parameters (checking
isLandingTargetType, targetId, isLandingPlatform, platform, and rawValue) are
returning NextResponse.json() directly without the Server-Timing and
x-trr-admin-route-ms headers that are applied elsewhere in the route. Create a
small local helper function in the POST handler that wraps the error response
creation and includes the necessary timing headers, then replace all early
validation return statements (including the ones at 542-543, 567-568, and
633-634) to use this helper function instead of calling NextResponse.json()
directly to ensure consistency across all response paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/app/admin/social/page.tsx`:
- Line 1045: The condition in the coerceLandingPayload function call that sets
progressStale only checks for the exact string "stale" using cacheStatus ===
"stale", but this misses other stale cache-status variants like
"uncacheable-stale". Update the condition to handle all stale cache-status
variants, such as by checking if cacheStatus includes the substring "stale" or
by explicitly checking for all known stale variant values, so that the
progressStale flag correctly identifies all cases where the data is stale.

In `@apps/web/src/components/admin/SocialAccountProfilePage.tsx`:
- Around line 4165-4168: The effect has overly broad dependencies on the full
`summary` object and `catalogActionMessage`, causing unnecessary re-runs for
unrelated updates, and it lacks a check for `secondaryReadsPressurePause` to
honor secondary-read pressure. Refactor the dependency array to depend only on
the specific properties of `summary` that are actually used in the effect logic
rather than the entire object, add a check for `!secondaryReadsPressurePause` to
the condition alongside the existing checks for `secondaryReadsGateOpen` and
`secondaryReadBudgetSlot`, and apply these same changes to the duplicate effect
pattern mentioned in the also-applies-to range.
- Around line 4324-4332: Multiple tab data fetch effects in
SocialAccountProfilePage.tsx are initiating requests while the summary is still
null and the first snapshot request is in flight, causing unnecessary
competition for resources. Apply the same `!hasSummary` guard condition
(matching the pattern shown in the provided diff with `summaryUninitialized`) to
the catalog fetch effect, hashtag fetch effect, hashtag timeline fetch effect,
and collaborators/tag fetch effects at the locations noted (around lines
4375-4384, 4448-4455, 4512-4521, 4620-4628). This ensures these secondary
requests are only initiated after the summary snapshot has been successfully
fetched, keeping the critical first-paint data fetch as the priority.
- Around line 8512-8520: The condition checking activeCommentsRunDateWindow
currently uses AND logic (!dateStart && !dateEnd) which only refreshes progress
when both boundaries are missing. Change this to OR logic (!dateStart ||
!dateEnd) so that the fetch of activeCommentsRunProgressNow and subsequent
readCommentsRunDateWindow call occurs whenever either dateStart or dateEnd is
missing, ensuring both boundaries are properly backfilled from the fresh
progress response.
- Around line 3325-3336: The useEffect hook that calls recordAdminLoadSample can
execute before the summary state is properly reset when platform or handle
changes, causing it to record navigation samples for the new route using the old
route's summary data. Add an additional condition to verify that the loaded
summary data's platform and handle match the current route parameters (the
platform and handle variables in the dependency array) before proceeding with
the recordAdminLoadSample call. This ensures that we only record a sample when
the summary state corresponds to the current route, not stale data from the
previous route.

In `@apps/web/src/lib/admin/admin-load-samples.ts`:
- Around line 91-93: The regex pattern in the conditional check is missing
support for admin-prefixed routes. Update the pattern to match both
`/social/{platform}/{handle}` and `/admin/social/{platform}/{handle}` paths by
making the `/admin` portion optional in the regex. This will ensure that when
callers provide admin-prefixed social profile paths, the function returns
"admin-social-profile" instead of null.

In `@apps/web/src/lib/server/admin/social-landing-repository.ts`:
- Around line 890-900: When the backend social progress rollup fails in the
catch block, the code returns a status with source set to "fallback" even though
it never actually executes the local SQL fallback (since adminContext returns
early later). This misleads the landing badge into displaying "local fallback"
when the backend is unavailable and no fallback has been attempted. Either move
the local SQL fallback logic before this early return so it executes on backend
failure, or change the status source to a distinct value like "unavailable" or
"degraded" to accurately reflect the degraded state without claiming a fallback
was used. Apply the same fix to the related error handling blocks at lines
922-923 and 2794-2799 for consistency.

---

Outside diff comments:
In `@apps/web/src/app/api/admin/social/landing/route.ts`:
- Around line 528-538: The early return statements that validate parameters
(checking isLandingTargetType, targetId, isLandingPlatform, platform, and
rawValue) are returning NextResponse.json() directly without the Server-Timing
and x-trr-admin-route-ms headers that are applied elsewhere in the route. Create
a small local helper function in the POST handler that wraps the error response
creation and includes the necessary timing headers, then replace all early
validation return statements (including the ones at 542-543, 567-568, and
633-634) to use this helper function instead of calling NextResponse.json()
directly to ensure consistency across all response paths.

In `@apps/web/src/lib/server/trr-api/social-profile-route-factory.ts`:
- Around line 253-258: The cache helpers respondWithRouteResponseCache and other
cache-related functions are creating their own timestamp via performance.now()
instead of using the routeStartedAt value established earlier in the request
lifecycle, causing inconsistent timing measurements across cached and non-cached
response paths. Remove the startedAt timestamp creation from inside these cache
helper functions and instead add routeStartedAt as a parameter to both
respondWithRouteResponseCache and the other cache helpers mentioned in the
related lines. Update all references to startedAt within these functions to use
the passed-in routeStartedAt parameter instead, ensuring consistent timing
measurement across all response paths.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fd470d66-1339-4b35-a369-d090777e332c

📥 Commits

Reviewing files that changed from the base of the PR and between e0a9725 and 550a2eb.

⛔ Files ignored due to path filters (1)
  • apps/web/src/lib/admin/api-references/generated/inventory.ts is excluded by !**/generated/**
📒 Files selected for processing (11)
  • apps/web/src/app/admin/social/page.tsx
  • apps/web/src/app/api/admin/social/landing/route.ts
  • apps/web/src/app/api/admin/trr-api/social/ingest/queue-status/route.ts
  • apps/web/src/app/api/admin/trr-api/social/profiles/[platform]/[handle]/catalog/posts/route.ts
  • apps/web/src/app/api/admin/trr-api/social/profiles/[platform]/[handle]/snapshot/route.ts
  • apps/web/src/components/admin/SocialAccountProfilePage.tsx
  • apps/web/src/lib/admin/admin-load-samples.ts
  • apps/web/src/lib/admin/social-landing.ts
  • apps/web/src/lib/server/admin/admin-route-timing.ts
  • apps/web/src/lib/server/admin/social-landing-repository.ts
  • apps/web/src/lib/server/trr-api/social-profile-route-factory.ts

Comment thread apps/web/src/app/admin/social/page.tsx Outdated
Comment thread apps/web/src/components/admin/SocialAccountProfilePage.tsx Outdated
Comment thread apps/web/src/components/admin/SocialAccountProfilePage.tsx Outdated
Comment thread apps/web/src/components/admin/SocialAccountProfilePage.tsx
Comment thread apps/web/src/components/admin/SocialAccountProfilePage.tsx
Comment thread apps/web/src/lib/admin/admin-load-samples.ts Outdated
Comment thread apps/web/src/lib/server/admin/social-landing-repository.ts
@github-actions

Copy link
Copy Markdown
Contributor

Codex Exhaustive Code Review

Findings

  • Medium SocialAccountProfilePage.tsx: the PR removes the pauseSecondaryReadsForPressure(...) call from the live-profile-total secondary read failure path. That request still goes through the backend and can return the same saturation/pressure errors the rest of this page is designed to detect. Now those errors are swallowed as “best effort,” so the page keeps firing other optional reads during backend pressure instead of opening secondaryReadsPressurePause. Practical impact: under DB pool/session saturation, an admin profile page can continue optional load and make the pressure worse. Small fix: restore pauseSecondaryReadsForPressure(error, "Failed to load social account live profile total") in this catch block and put the callback back in the effect dependency list.

Validation

I reviewed only the specified diff range and surrounding code. I attempted the focused Vitest run:

pnpm -C apps/web exec vitest run -c vitest.config.mts tests/social-landing-route-cache.test.ts tests/social-landing-repository.test.ts tests/social-account-profile-read-routes.test.ts tests/social-account-profile-snapshot-route.test.ts tests/social-account-profile-page.runtime.test.tsx

It could not run in this sandbox because pnpm is not installed (pnpm: command not found). git diff --find-renames --check ... passed with no whitespace errors.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/components/admin/SocialAccountProfilePage.tsx (1)

3320-3346: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use route-matched summary state before unlocking profile reads.

On a platform/handle change, these effects still see the previous route’s summary, hasSummary, gate, and budget values until the reset effect’s state updates commit. That can start new-route tab/secondary requests before the new snapshot first-paint request finishes. Derive a route-scoped summary readiness flag and use it for these guards, including the review-queue path.

Proposed direction
   const shouldShowCatalogRunProgressCard = selectedTab !== "comments";
   const hasSummary = summary !== null;
+  const summaryMatchesCurrentRoute =
+    summary?.platform === platform &&
+    normalizeComparable(String(summary?.account_handle || "").replace(/^@+/, "")) ===
+      normalizeComparable(handle.replace(/^@+/, ""));
+  const hasCurrentSummary = hasSummary && summaryMatchesCurrentRoute;
   useEffect(() => {
     profileLoadStartedAtRef.current = nowMs();
     profileNavigationSampleRecordedRef.current = false;
   }, [handle, platform]);
   useEffect(() => {
     if (profileNavigationSampleRecordedRef.current) return;
-    if (!hasSummary && !summaryUninitialized) return;
-    if (
-      hasSummary &&
-      (summary?.platform !== platform ||
-        String(summary?.account_handle || "")
-          .trim()
-          .replace(/^@+/, "")
-          .toLowerCase() !== handle.trim().replace(/^@+/, "").toLowerCase())
-    ) {
-      return;
-    }
+    if (!hasCurrentSummary) return;
     profileNavigationSampleRecordedRef.current = true;
   const selectedTabPrimaryReadPending =
-    hasSummary &&
+    hasCurrentSummary &&
     !summaryUninitialized &&
   const shouldDeferSecondaryCatalogReads =
-    !hasSummary || summaryLoading || selectedTabPrimaryReadActive || selectedTabPrimaryReadPending || shouldPauseSecondaryReads;
+    !hasCurrentSummary || summaryLoading || selectedTabPrimaryReadActive || selectedTabPrimaryReadPending || shouldPauseSecondaryReads;

Apply the same !hasCurrentSummary replacement to the live-total, posts, catalog posts, hashtags, timeline, collaborators, review-queue, and cookie-health guards in this range.

Also applies to: 3426-3446, 4168-4178, 4344-4351, 4397-4405, 4468-4478, 4537-4547, 4588-4598, 4647-4654, 7507-7526

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/components/admin/SocialAccountProfilePage.tsx` around lines 3320
- 3346, The useEffect blocks in SocialAccountProfilePage are using stale summary
data from previous routes because hasSummary is checked before verifying the
summary matches the current platform and handle. Create a new derived state
variable (e.g., hasCurrentSummary) that checks both that summary is not null AND
that the summary's platform and account_handle match the current route's
platform and handle parameters. Then replace all instances of hasSummary with
this new hasCurrentSummary flag in the guard conditions throughout all the
useEffect dependency arrays and conditional checks at lines 3320-3346 and the
other ranges (3426-3446, 4168-4178, 4344-4351, 4397-4405, 4468-4478, 4537-4547,
4588-4598, 4647-4654, 7507-7526) to prevent mismatched route reads.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/components/admin/SocialAccountProfilePage.tsx`:
- Around line 4241-4250: Replace the three-part condition checking
isBackendSaturationError, isBackendPressureCode, and hasBackendSaturationText
with a single call to isBackendPressureError(requestError) in the if statement
before pauseSecondaryReadsForPressure is called. This will use the shared
pressure detector which has broader coverage than the current narrower checks,
preventing timeout and upstream-status-only failures from skipping the pressure
pause logic.

---

Outside diff comments:
In `@apps/web/src/components/admin/SocialAccountProfilePage.tsx`:
- Around line 3320-3346: The useEffect blocks in SocialAccountProfilePage are
using stale summary data from previous routes because hasSummary is checked
before verifying the summary matches the current platform and handle. Create a
new derived state variable (e.g., hasCurrentSummary) that checks both that
summary is not null AND that the summary's platform and account_handle match the
current route's platform and handle parameters. Then replace all instances of
hasSummary with this new hasCurrentSummary flag in the guard conditions
throughout all the useEffect dependency arrays and conditional checks at lines
3320-3346 and the other ranges (3426-3446, 4168-4178, 4344-4351, 4397-4405,
4468-4478, 4537-4547, 4588-4598, 4647-4654, 7507-7526) to prevent mismatched
route reads.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e4ee500-0177-48cf-a637-60163a890f4f

📥 Commits

Reviewing files that changed from the base of the PR and between 550a2eb and e819edf.

📒 Files selected for processing (7)
  • apps/web/src/app/admin/social/page.tsx
  • apps/web/src/app/api/admin/social/landing/route.ts
  • apps/web/src/components/admin/SocialAccountProfilePage.tsx
  • apps/web/src/lib/admin/admin-load-samples.ts
  • apps/web/src/lib/admin/social-landing.ts
  • apps/web/src/lib/server/admin/social-landing-repository.ts
  • apps/web/src/lib/server/trr-api/social-profile-route-factory.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • apps/web/src/lib/admin/social-landing.ts
  • apps/web/src/app/admin/social/page.tsx
  • apps/web/src/lib/admin/admin-load-samples.ts
  • apps/web/src/app/api/admin/social/landing/route.ts
  • apps/web/src/lib/server/admin/social-landing-repository.ts
  • apps/web/src/lib/server/trr-api/social-profile-route-factory.ts

Comment thread apps/web/src/components/admin/SocialAccountProfilePage.tsx
@therealityreport therealityreport merged commit e5bc156 into main Jun 18, 2026
4 checks passed
@therealityreport therealityreport deleted the codex/admin-load-time-app-20260618 branch June 18, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants