Skip to content

feat(cli): Add an anonymous Snake leaderboard - #1437

Open
sergical wants to merge 7 commits into
feat/cli-init-snakefrom
feat/cli-games-leaderboard
Open

sergical wants to merge 7 commits into
feat/cli-init-snakefrom
feat/cli-games-leaderboard

Conversation

@sergical

@sergical sergical commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Adds sentry games leaderboard, which shows the top 10 Snake scores from the last 30 days. Stacked on #1435.

Scores (CLI)

  • A finished game sends one snake.score metric to the CLI telemetry project. Its only custom attribute is a random handle such as brave-otter-42, stored in the local metadata table.
  • The metric goes out in a new trace with the user cleared on both scopes. beforeSendMetric keeps only handle, sentry.release, sentry.environment and sentry.sdk.* for this metric.
  • Nothing is sent when telemetry is off (SENTRY_CLI_NO_TELEMETRY, DO_NOT_TRACK, or the stored preference).
  • The score is flushed as soon as it is recorded. Metrics otherwise wait up to 5 seconds in the SDK buffer, and on macOS the CLI force-exits about 100 ms after a command ends, so a player who quit right after game over lost the score.

Endpoint (new packages/games-api Worker)

  • A standalone Hono Worker, sentry-games-api, in the Cloudflare "Sentry Internal" account on https://games.sentry.new. The MCP server is not changed: the read token never shares a Worker with its OAuth secrets.
  • GET /v1/snake/leaderboard queries the tracemetrics dataset for max(value) per handle, with value:<=10000.
  • It rate-limits by hashed IP (30/min) and caches the result with the Workers Cache API for 5 minutes.
  • It checks the upstream rows against the handle format and the score bounds. Every failure returns a generic error. The token, URL and upstream text never reach the response or the logs.
  • The CLI validates each row again and drops rows that fail, so server text cannot write control sequences to the terminal.

Setup before deploy

  1. Create a token on a bot account that is only a member of the team that owns the CLI project, with the org:read scope only.
  2. From packages/games-api: pnpm run deploy, then npx wrangler secret put SENTRY_GAMES_READ_TOKEN.
  3. Optional: turn on "Prevent storing IP addresses" on the CLI project. This also affects the rest of the CLI telemetry.

Known limit: the DSN is public, so anyone can submit a score. The handle format and the 10,000 cap block only impossible values.

Breaking Changes: None

Created with Claude Code

@sergical
sergical force-pushed the feat/cli-games-leaderboard branch 2 times, most recently from f775f5e to 49149a9 Compare October 7, 2026 15:25
@sergical
sergical marked this pull request as ready for review October 8, 2026 16:45
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 8, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/games-api/src/leaderboard.ts
@linear-code

linear-code Bot commented Oct 12, 2026

Copy link
Copy Markdown

DEVEX-752

Base automatically changed from feat/cli-games to feat/cli-init-snake October 15, 2026 17:58
@github-actions github-actions Bot removed the risk: medium PR risk score: medium label Oct 15, 2026
@sergical
sergical force-pushed the feat/cli-init-snake branch from ba78133 to 2e16786 Compare October 15, 2026 18:18
@sergical
sergical force-pushed the feat/cli-games-leaderboard branch from dd48465 to e167a54 Compare October 15, 2026 18:22
@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 15, 2026 6:46pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 15, 2026
sergical and others added 6 commits October 15, 2026 14:36
A finished Snake game sends one snake.score metric tagged only with a
random player handle. It goes out in a new trace with the user cleared,
and beforeSendMetric keeps only an attribute allowlist. Nothing is sent
when telemetry is off.

The sentry-mcp Worker serves GET /api/games/snake/leaderboard. It reads
the top 10 scores of the last 30 days with a read-only token, caches the
result in KV, rate-limits by hashed IP, and returns only generic errors.
`sentry games leaderboard` validates every row again before it prints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Score reporting runs from the game timer, so a database or transport error
could crash sentry init. It now logs the error and skips the score.

Handles had only 102,400 values, so two players were likely to share one
after a few hundred players. Four-digit suffixes give about 10 million. An
old two-digit handle is replaced the next time it is read.

Co-authored-by: Claude <claude@anthropic.com>
Move the leaderboard endpoint out of the sentry-mcp Worker into a new
packages/games-api Hono Worker in the Cloudflare "Sentry Internal"
account, on games.sentry.new. The Sentry read token no longer shares a
Worker with the MCP server's OAuth secrets, and the MCP server has no
games changes. The Workers Cache API replaces the KV cache, so the new
Worker needs no account resources besides the rate limiter.

The CLI now reads https://games.sentry.new/v1/snake/leaderboard.

Co-authored-by: Claude <claude@anthropic.com>
Metrics wait up to 5s in the SDK buffer. On macOS the CLI force-exits
about 100ms after a command ends, which cuts off the exit flush, so a
player who quit right after game over lost the score.

Co-authored-by: Claude <claude@anthropic.com>
The games-api install re-resolved zod to 4.6.5 and workerd to a newer
build for unrelated packages, which broke the mcp-core typecheck. The
lockfile now adds only the games-api importer.

Also restore the MCP server config and docs to the base branch. The
pre-commit formatter had reformatted them during the earlier revert.

Co-authored-by: Claude <claude@anthropic.com>
The old branch resolved some changes in merge commits. A linear rebase
drops merge commits, so restore the games flag test, the onGameOver
doc comment, the generated games reference, and the unchanged MCP
deployment docs. Keep the lockfile change to the games-api importer
only, so that other resolutions stay the same as on the base branch.

Co-authored-by: Claude <claude@anthropic.com>
@sergical
sergical force-pushed the feat/cli-games-leaderboard branch from e167a54 to 73367ce Compare October 15, 2026 18:37

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 73367ce. Configure here.

Comment thread packages/cli/src/lib/init/ui/ink-snake.tsx
A resize can start the run over when the snake no longer fits, or end it
when no cell is left for food. Both paths ran in render, outside the
step handler that reports the score, so the leaderboard lost the run.

Co-authored-by: Claude <claude@anthropic.com>

This branch was previously deployed

1 inactive deployment
Preview — 038a46a1 Deployed Oct 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant