Skip to content

Batch move_warship intents to stay under MAX_INTENT_SIZE - #4735

Open
bighurdan-cell wants to merge 5 commits into
openfrontio:mainfrom
bighurdan-cell:fix/move-warship-intent-batching
Open

Batch move_warship intents to stay under MAX_INTENT_SIZE#4735
bighurdan-cell wants to merge 5 commits into
openfrontio:mainfrom
bighurdan-cell:fix/move-warship-intent-batching

Conversation

@bighurdan-cell

Copy link
Copy Markdown

Resolves #4718

Supersedes #4732, which I opened before reading the contribution rules properly and which was auto-closed for having no approved issue. Same branch, plus the schema bound and the missing translation entry that #4718 also asks for.

Description:

move_warship sends every selected unit id in one intent, and past ~274-320 ships (id-width dependent) the frame exceeds MAX_INTENT_SIZE, so ClientMsgRateLimiter kicks the player.

As proposed in the issue: batches the order in onMoveWarshipEvent into intents that each fit under the cap, kept maximal so realistic orders stay well inside the 10/s intent budget (1 intent below ~274 ships, 4 at 1,000). Also bounds unitIds at .max(1000) in the schema. Above the 964 ids a single conforming batch can physically hold, and adds the missing kick_reason.too_much_data entry to en.json so the modal shows text instead of the raw key. MAX_INTENT_SIZE moved to Schemas.ts so client and server share it.

MoveWarshipExecution applies each unit id independently and dedupes, so N intents are equivalent to one.

Hurdan

Hurdan1 added 2 commits July 26, 2026 12:48
Large fleet selections produced a single move_warship intent frame larger than the server's 2000-byte cap, which kicks the client. Split fleet orders client-side into batches that each fit in one intent, and share the MAX_INTENT_SIZE constant between client and server.
The issue lists bounding the array as an alternative to batching; 1000 sits above the 964 ids a single batch can physically hold. The kick reason had no en.json entry, so players saw the raw translation key.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f15b0a69-1fa0-48a1-82d0-20e2cb6e1dd7

📥 Commits

Reviewing files that changed from the base of the PR and between 72c74d4 and 7768d8a.

📒 Files selected for processing (1)
  • src/client/Transport.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/client/Transport.ts

Walkthrough

Large warship selections are split into size-bounded intents and sent through a paced queue for remote games. The shared intent-size limit is used by batching and server rate limiting, with tests covering batching, serialization, schema validation, and pacing. The oversized-data kick reason now has an English translation.

Changes

Warship intent batching

Layer / File(s) Summary
Batching contract and validation
src/core/Schemas.ts, tests/MoveWarshipIntentBatching.test.ts
Warship unit IDs are limited to 1000 entries, and batchMoveWarshipUnitIds creates batches within the shared 2000-byte intent limit. Tests cover empty, small, size-bounded, and schema-valid batches.
Transport batching and pacing
src/client/PacedSender.ts, src/client/Transport.ts, tests/client/PacedSender.test.ts
Transport queues one move_warship intent per batch, uses no delay for local games and fixed spacing for remote games, retries unsent callbacks, gates remote sends until joined, and clears queued batches when leaving. Tests cover ordering, timing, retry behavior, and clearing.
Shared limit and kick translation
src/server/ClientMsgRateLimiter.ts, resources/lang/en.json
The rate limiter imports the shared intent-size constant, and English includes the too_much_data kick-reason translation.

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

Possibly related issues

  • Issue #4718 — Describes large warship fleets exceeding the 2000-byte intent limit and being kicked for too_much_data.
  • Issue #4734 — Covers the same client-side move_warship batching objective.

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant ClientTransport
  participant BatchingHelper
  participant PacedSender
  participant ServerRateLimiter
  ClientTransport->>BatchingHelper: split selected unit IDs for destination tile
  BatchingHelper-->>ClientTransport: return size-bounded batches
  ClientTransport->>PacedSender: queue each move_warship intent
  PacedSender->>ServerRateLimiter: send batches at the configured interval
  ServerRateLimiter-->>PacedSender: accept or kick oversized intents
Loading

Poem

Warships sail in batches bright,
Each message fits the limit right.
The queue keeps time, the fleet moves on,
The oversized kick is gone.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: batching move_warship intents under the size limit.
Description check ✅ Passed The description matches the code changes and the linked fleet-kick fix.
Linked Issues check ✅ Passed The PR satisfies #4718 by batching oversized move_warship intents, bounding unitIds, and adding the missing translation.
Out of Scope Changes check ✅ Passed The added pacing and reconnect gating support the batching fix and do not look unrelated to the issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

Actionable comments posted: 1

🤖 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 `@src/client/Transport.ts`:
- Around line 653-659: Update the warship move handling around
batchMoveWarshipUnitIds and sendIntent to rate-limit batches to the server’s
INTENTS_PER_SECOND allowance. Queue excess move_warship intents so they are sent
at the permitted interval, preserving each batch exactly once and preventing
dropped batches from being re-sent as duplicates.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 962e6577-a53d-4014-a4ff-9441c0896e9a

📥 Commits

Reviewing files that changed from the base of the PR and between edbeb69 and 0f4ffab.

📒 Files selected for processing (5)
  • resources/lang/en.json
  • src/client/Transport.ts
  • src/core/Schemas.ts
  • src/server/ClientMsgRateLimiter.ts
  • tests/MoveWarshipIntentBatching.test.ts

Comment thread src/client/Transport.ts
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management Jul 26, 2026

@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: 0f4ffabe70

ℹ️ 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 thread src/client/Transport.ts
Batches were emitted in one synchronous burst, so an order producing more than ten batches exceeded the server's per-second intent budget and the excess was silently dropped. Send the first batch immediately and the rest at 150ms spacing. Singleplayer uses no spacing since LocalServer has no rate limiter.

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

Actionable comments posted: 1

🤖 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 `@src/client/Transport.ts`:
- Around line 665-672: The warship batch callback queued in the loop around
batchMoveWarshipUnitIds must survive reconnects when the socket is unavailable.
Update the PacedSender/sendIntent flow to avoid removing the callback until
sendIntent succeeds, or requeue failed sends at the front, preserving batch
order and retrying the same unitIds after reconnection.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a4b62c20-8910-4ee6-8a4b-b23f6f408deb

📥 Commits

Reviewing files that changed from the base of the PR and between 0f4ffab and 4b82404.

📒 Files selected for processing (3)
  • src/client/PacedSender.ts
  • src/client/Transport.ts
  • tests/client/PacedSender.test.ts

Comment thread src/client/Transport.ts

@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: 4b824042b6

ℹ️ 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 thread src/client/Transport.ts
PacedSender dequeued before sending, so a batch whose send landed while the socket was reconnecting was lost permanently. sendIntent now reports whether the message went out, and the batch stays at the front of the queue until it does.
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 26, 2026

@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: 72c74d4b95

ℹ️ 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 thread src/client/Transport.ts Outdated
An open socket does not mean the server has processed our join or rejoin. Worker.ts handles messages asynchronously and discards anything other than join/rejoin until that completes, so a paced batch sent right after reconnect could be dropped while sendIntent reported success. Track whether the server has replied on this connection and gate intent sends on it.
@iiamlewis iiamlewis added the approved Approved for a PR, if you assigned to the issue. label Jul 26, 2026
@iiamlewis iiamlewis added this to the v33 milestone Jul 26, 2026
@iiamlewis iiamlewis added the Bugfix Fixes a bug label Jul 26, 2026
Comment thread src/core/Schemas.ts
// Client messages larger than this get the client kicked by ClientMsgRateLimiter.
export const MAX_INTENT_SIZE = 2000;

export function batchMoveWarshipUnitIds(

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.

this funciton shouldn't be in Schemas.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Approved for a PR, if you assigned to the issue. Bugfix Fixes a bug

Projects

Status: Development

Development

Successfully merging this pull request may close these issues.

Moving a large warship fleet kicks you for too_much_data

5 participants