Skip to content

Index game turn actions, pin game actions near the database, and report slow actions - #124

Open
ejsmith wants to merge 3 commits into
mainfrom
reduce-action-latency
Open

ejsmith wants to merge 3 commits into
mainfrom
reduce-action-latency

Conversation

@ejsmith

@ejsmith ejsmith commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Why

Players keep seeing "Server is taking longer than usual…". This PR fixes the cheap causes and adds the telemetry needed to diagnose the rest.

Changes

  • Index: adds turn_actions (game_id, action_type, created_at). Five per-game reads (turn history, Punch history, taunt checks, final-game stats) previously scanned every game's actions. schema.sql matches the migration.
  • Region: game-action now runs in us-east-1. The database is in us-east-2, which can't be forced, and us-east-1 is the closest region that can. Local backends are unaffected. The function's CORS allow-list now includes x-region.
  • Server telemetry: Server-Timing and the slow game-action log now include commit, complete, and worker boot time. First requests after the function was idle are also logged, as cold game-action, when they are fast. Responses now expose the timing headers so web clients can read them.
  • Client telemetry: when a player action takes as long as the banner delay (3s), the app sends an Exceptionless SlowGameAction warning (one stack per action type) containing:
    • each attempt's duration and status (network when the function never answered)
    • the serving region and server timing breakdown
    • total server time vs. time outside the server
    • connection type

Deploy status

The migration and both game-action deploys are already live on the hosted project, so this is safe to merge.

Validation

  • npm run typecheck, npm run typecheck:edge, npm run lint
  • npm run test (221 pass, including new slowActionReport tests), npm run test:edge (44 pass)
  • Checked against the hosted function: the CORS preflight allows x-region, and responses expose server-timing and x-sb-edge-region.

🤖 Generated with Claude Code

… cold starts

- Add a (game_id, action_type, created_at) index on turn_actions so per-game
  history, Punch, taunt, and stats reads stop scanning every game's actions.
- Run game-action in us-east-1, the forceable region closest to the us-east-2
  database, and allow the x-region CORS header it needs.
- Report worker boot time, commit, and completion in Server-Timing and the
  slow game-action log, and log cold starts even when they are fast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-23T21:53:45.759643Z d73fc67 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04db1bccf4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +132 to +133
const timer = new ActionTimer(pendingBootMs);
pendingBootMs = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve cold-start timing across CORS preflight requests

When a fresh worker first receives a browser's CORS preflight, this clears pendingBootMs before the OPTIONS branch returns without calling timer.toHeaders() or timer.logIfSlow(). The boot measurement is therefore discarded, and subsequent POST requests handled by that worker are reported as warm. This loses the new cold-start diagnostics for precisely that browser request sequence. Preserve the pending measurement until a POST consumes it, or explicitly record it on the preflight response.

Useful? React with 👍 / 👎.

When a player action takes as long as the server-slowness banner delay,
submit a SlowGameAction warning with each attempt's duration, status,
serving region, and Server-Timing breakdown, plus the connection type.
Expose the timing headers to web clients so browser reports match native.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ejsmith ejsmith changed the title Index game turn actions, pin game actions near the database, and time cold starts Index game turn actions, pin game actions near the database, and report slow actions Oct 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant