Skip to content

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

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

Ayush7614 wants to merge 1 commit 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.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 81a5521e-dfe1-4583-b2e6-16a8cf9a8e7b
📥 Commits

Reviewing files that changed from the base of the PR and between 1e006c3 and 2c54f91.

📒 Files selected for processing: 6
  • app/src/app/api/posts/reported/route.ts
  • app/src/app/api/presence/route.ts
  • app/src/components/launchpad/AdminQueue.tsx
  • app/src/lib/launchpad/holders.test.ts
  • app/src/lib/launchpad/holders.ts
  • app/src/lib/launchpad/presence.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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.

…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 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.

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