Skip to content

fix(api): harden presence + reported read paths and trust share formatting - #84

Open
Ayush7614 wants to merge 2 commits into
Twigpine:mainfrom
Ayush7614:fix/presence-reported-trust-robustness
Open

Ayush7614 wants to merge 2 commits into
Twigpine:mainfrom
Ayush7614:fix/presence-reported-trust-robustness

Conversation

@Ayush7614

@Ayush7614 Ayush7614 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What / why

Three real, verified gaps — the leftovers after PR #83 hardened the meta/holder/count paths. Each is the outlier against its siblings:

  1. Presence GET+POST HTML-500 on DB failure — app/src/app/api/presence/route.ts had zero error handling. readPulse/recordBeacon (presence.ts) throw on a configured-DB outage (maybeDb() null is safe, outage throws; memo.ts rethrows). Every sibling read route (feed/list/live/search/candles/holders/me/posts) wraps in try/catch → JSON 502 + no-store. The site-wide pulse (LivePulse.tsx, beacon every 30s) went silently stale on HTML 500s.
  2. Reported-queue GET missing try/catch + a two-stage client break — app/src/app/api/posts/reported/route.ts threw instead of JSON-erroring, and AdminQueue.tsx called await res.json() before checking res.ok with no try/catch (invoked as void load()). So a DB blip became an unhandled promise rejection instead of the graceful error row a JSON error takes.
  3. fmtShare painted NaN%/Infinity% — holders.ts: NaN <= 0 and NaN < 1 are both false, so NaN fell through to "NaN%"; Infinity → "Infinity%". Rendered in the trust-critical panel (HoldersPanel, TokenProof, trustNotes) where users judge rug risk. Every sibling guards (math.ts fmtCompact/fmtEth, market-format.ts marketUsd, chart-terminal.ts, and fix(api): harden launch read paths — meta error shape, bounded holder swaps, finite count formatting #83's marketCount).

Fix

  • Presence GET + both POST branches: try/catch → JSON 502 + no-store + server log. Rate-limit bucket and prune logic untouched.
  • Reported GET: keeps the current admin-session check (requireAdmin), then try/catch → JSON 502 + private, no-store. AdminQueue.load(): defensive JSON parse (non-JSON → moderation queue returned <status>), friendlyError surfacing, setPosts(null) on failure — no more unhandled rejections.
  • fmtShare: !Number.isFinite → "—", matching siblings.

Uniqueness check (no open/merged/closed duplicate)

Verification (all true, nothing faked)

  • Repro: node -e confirms old fmtShare(NaN) → "NaN%", Infinity → "Infinity%"; new → "—" (test added).
  • New/extend tests: holders.test.ts non-finite fmtShare cases, new presence.test.ts (bot allow-list, 64-hex visitor-hash uniqueness/stability).
  • npm test: 1371 pass / 0 fail / 11 skipped.
  • npm run typecheck: clean. eslint on all touched files: clean. npm run build: pass.
  • Rebased onto upstream/main@1e006c3; the conflict in the reported route / AdminQueue was resolved keeping the new requireAdmin + useAdminAccount auth. Head 2c54f91, CI green.

Summary by CodeRabbit

  • Bug Fixes
    • Admin reported-posts and presence requests now return clear error responses when data cannot be loaded or recorded.
    • Reported-posts and presence errors are handled without disrupting the rest of the app.
    • Invalid holder-share values now display as an em dash instead of a misleading number.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The reported-post and presence routes now handle database failures with no-store 502 responses. The moderation queue uses a shared response reader. Holder-share formatting now displays an em dash for non-finite values.

Changes: API error handling and queue loading

Layer / File(s) Summary
Reported-post route errors and test setup
app/src/app/api/posts/reported/route.ts, app/src/app/api/posts/reported/route.test.ts, app/src/lib/db-mock.ts
The route logs lookup failures and returns a private, no-store 502 response. The mock and tests cover database errors, admin-session gating, and successful retrieval.
Presence route errors and tests
app/src/app/api/presence/route.ts, app/src/app/api/presence/route.test.ts, app/src/lib/launchpad/presence.test.ts
GET and POST return no-store 502 responses for pulse-read or beacon-write failures. Tests also cover successful responses, bot detection, and visitor hashes.
Reported queue reader and component integration
app/src/lib/launchpad/adminQueue.ts, app/src/lib/launchpad/adminQueue.test.ts, app/src/components/launchpad/AdminQueue.tsx
The shared reader handles successful responses, server errors, invalid JSON, and fetch failures. AdminQueue uses its result to set the displayed error and posts.

Holder share formatting

Layer / File(s) Summary
Non-finite share formatting
app/src/lib/launchpad/holders.ts, app/src/lib/launchpad/holders.test.ts
fmtShare returns an em dash for non-finite values. Tests cover NaN and positive and negative infinity.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: kevincodex1, vasanthdev2004

Merge Risk: Minimal · up to ef1d4

This change makes presence and moderation-queue failures return handled errors and keeps non-finite holder shares from displaying as NaN or Infinity. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main areas of the change: hardening presence and reported-post read paths with error handling, and the trust-share formatting fix. The changeset adds JSON 502 error handling to…
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.
Full details: Title check

Explanation

The title names the two main areas of the change: hardening presence and reported-post read paths with error handling, and the trust-share formatting fix. The changeset adds JSON 502 error handling to the presence and reported routes, adds a readReportedQueue client helper, and makes fmtShare return an em dash for non-finite values. The title is conventional-commit style and is specific enough to scan history. It omits the client-side AdminQueue change and the tests, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

Note

This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d4defda-c42d-4b21-9b73-8ba29be30d62
Commits

Reviewing files that changed from the base of the PR and between 9c0f099 and ef1d4d7.

Files selected for processing: 11

  • app/src/app/api/posts/reported/route.test.ts
  • app/src/app/api/posts/reported/route.ts
  • app/src/app/api/presence/route.test.ts
  • app/src/app/api/presence/route.ts
  • app/src/components/launchpad/AdminQueue.tsx
  • app/src/lib/db-mock.ts
  • app/src/lib/launchpad/adminQueue.test.ts
  • app/src/lib/launchpad/adminQueue.ts
  • app/src/lib/launchpad/holders.test.ts
  • app/src/lib/launchpad/holders.ts
  • app/src/lib/launchpad/presence.test.ts

Limit details: You’ve used the included review currently available.

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These fixes still address gaps on main. Please sync the branch first: the reported-post route and AdminQueue now use authenticated admin sessions. Keep requireAdmin, useAdminAccount, the private/no-store response policy and the endpoint without ?wallet= while adding the error handling.

Please also add focused tests for the database failure and non-JSON/network-error paths, then rerun CI on the updated head. The current helper tests don't exercise those failures, and the older green checks don't cover the new auth integration.

@Ayush7614
Ayush7614 force-pushed the fix/presence-reported-trust-robustness branch from d8cd2ed to 2c54f91 Compare October 20, 2026 09:54
@Ayush7614

Ayush7614 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @Vasanthdev2004

Rebased onto current upstream/main (1e006c3), which had moved the moderation queue to admin sessions (requireAdmin + useAdminAccount). The rebase conflict is resolved by keeping that auth and layering the error handling on top:

  • GET /api/posts/reported keeps requireAdmin, wraps listReported() in try/catch → JSON 502 + private, no-store.
  • AdminQueue.load() no longer sends the removed ?wallet= param; it parses JSON defensively, shows friendlyError, and clears the list instead of throwing an unhandled rejection.
  • Presence and fmtShare changes applied unchanged.

New head 2c54f91; CI green (app lint/typecheck/tests/build, contracts, guard, deps). Local verification: 1371 pass / 0 fail / 11 skipped, typecheck + eslint clean, production build passes.

…tting

Presence GET/POST were the last JSON read routes without try/catch:
a DB outage turned the site-wide pulse/beacon into HTML 500s
instead of the JSON 502 contract every sibling keeps. Both verbs
now return JSON 502 + no-store with a server log, keeping the
per-IP beacon bucket untouched.

GET /api/posts/reported had the same hole, with a two-stage break:
AdminQueue called res.json() before checking res.ok with no
try/catch (via void load()), so an HTML 500 became an unhandled
rejection instead of the graceful error row. Route now returns
JSON 502; the queue parses defensively and surfaces friendlyError.

fmtShare was the last trust formatter missing the finite guard its
siblings have: NaN painted as 'NaN%' and Infinity as 'Infinity%'
in the holder/trust panel where users judge rug risk. Now '—'.

Tests: fmtShare non-finite, presence bot/hash helpers (new file).
Verified: npm test 1047 pass / 0 fail, typecheck + eslint clean.
@Ayush7614
Ayush7614 force-pushed the fix/presence-reported-trust-robustness branch from 2c54f91 to ef1d4d7 Compare November 30, 2026 12:52
@Ayush7614

Copy link
Copy Markdown
Contributor Author

@Vasanthdev2004 Synced the branch onto current main and resolved the presence-route conflict, keeping the hardened clientIp(req) bucket and adding the try/catch around the bot-pulse read. requireAdmin, useAdminAccount, the private/no-store policy and the endpoint without ?wallet= are all intact. Added focused route tests for presence DB outage (GET and both POST branches), reported-queue DB outage behind the admin session gate, and a pure readReportedQueue helper test for 502 JSON, non-JSON bodies and network failures. Full tests, lint, typecheck, build, pr-guard and CodeRabbit all pass on the new head. Ready for your re-review.

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