Skip to content

fix(online): follow up on the merged online pull requests - #2486

Open
houko wants to merge 8 commits into
mainfrom
fix/followup-online-2
Open

houko wants to merge 8 commits into
mainfrom
fix/followup-online-2

Conversation

@houko

@houko houko commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Follow-up review of the online-2 bucket of the merge/2387 train, checked against current main.

Reviewed pull requests

#2263 docs: add runnable package examples

Landed intact. Its claim on #1559 is not met: internal/repocheck/examples_test.go checks a hard-coded list of 25 packages instead of every library package, so a new package without examples still passes (pkg/online/economy, for one, has none). Not changed here.

#2239 feat(compliance): add mainland China policy checks

Already folded into pkg/online/antiaddiction by #2473. Left over: the "Current status (planned)" box in docs/{en,zh}/shipping-china.md still said NSGo Game has no play-time or spending checks, while the same page documents them. This PR marks the status partial and links to the checks.

#2241 feat(economy): add idempotent wallet core

  • Spend negated its amount and only refused zero, so Spend("coins", -1000, k) minted 1000 coins and skipped the cap; a negative Grant drained a balance past zero. Amounts must now be positive (ErrInvalidAmount).
  • A key used again for a different currency, amount or operation returned the first change's result as if it were the same request (ErrDuplicateKey was declared but never returned). Each key now records its request, and a mismatch is ErrDuplicateKey.
  • A replayed Exchange returned the target currency's current balance, not the first result. Both results are stored now. An exchange into the same currency is refused.
  • A grant could overflow int64. It is ErrCapExceeded now.
  • Error values got doc comments. The Economy paragraph feat(economy): add idempotent wallet core #2241 added to liveops.md (en and zh) was dropped by a later merge, so it is back.

#2094 feat(online): add Epic Online Services boundary

A first draft of the same issue as the Platform API that #2473 restored. Nothing from #2094 should come back: its eos.Service docs describe an API that no longer exists. This PR only adds doc comments to the package's error values.

#2067 feat(gameserver): add expiring seat reservations / #2214 feat(gameserver): sign reservations and track servers

#2214 contains all of #2067. Both landed in code. Problems:

  • Rooms.Claim deleted the reservation, released the room lock and then joined. A concurrent Join could take the freed seat, and the claimant got ErrRoomFull with its reservation gone. A handler refusal or a busy server also lost the reservation, and JoinAttempt never saw the account. join now takes explicit account, meta, claim parameters instead of the ...any the merge left. It checks and consumes the reservation under the same lock that admits the peer, leaves the claimed seat out of the capacity count, and passes res.Account to the handler. A missing or expired reservation is refused before the handler is called.
  • feat(gameserver): sign reservations and track servers #2214's docs section and its version of the note were overwritten. Both are restored and describe the claim behaviour.

#2068 feat(gameserver): add match lifecycle handlers

#2072 feat(gameserver): add matchmaking ticket queries

  • Each candidate's query was checked only against the room's oldest ticket, so two candidates that refuse each other could share a room, although the docs promise symmetric matching. Must and MustNot are now checked between every pair in the room. The rating window still counts from the oldest ticket, as documented.
  • Candidates are taken in Should-score order, but the pass that removes chosen tickets assumes ascending indexes. A reordered candidate stayed in the list and could be put in a second room in the same Match call. The chosen indexes are now sorted before removal.
  • The docs section was sitting under Player tokens. It is moved under Matchmaking.

#2086 feat(gameserver): add idempotent result commits / #2087 feat(gameserver): add idempotent match result commits

Two attempts at #1678. The merge kept #2086's ResultsBackend code but left #2087's docs, note and changelog fragment, which describe MatchResults/MemoryResultCommitter, an API that does not exist. #2086's own docs section was dropped. This PR deletes #2087's leftovers (docs/{en,zh}/server-results.md, its note and its fragment) and restores #2086's section. Bugs in ResultsBackend.Commit:

  • equalResult compared only the number of grants, so a retry with different amounts was accepted as an identical no-op. It now compares grant by grant against a copy of the committed result.
  • A committed record kept the version the caller sent, so every later writer holding that version passed the optimistic check. A commit now stores the record at Version+1, and a record that does not exist yet is version 0.
  • A board's first score below zero was dropped. It is kept now.
  • ErrResultConflict got a doc comment.

#2209 feat(netplay): add broadcast groups

Landed intact, and no defects found. #1697 is still open, and the WebSocket and UDP SendMany fast paths are not implemented yet.

#2212 feat(gameserver): add bounded match mailbox

The code and tests landed, but the "Match mailbox and one-writer state" section was dropped from gameserver.md (en and zh). It is restored, together with the "Live inspection and pprof" section that the same merges dropped.

Issues closed without meeting their acceptance

Verification

  • go tool nsgo test ./pkg/online/gameserver/... ./pkg/online/economy/... ./pkg/online/eos/... ./internal/repocheck/... on the remote build host: pass. New tests cover claim versus concurrent joins, a claim refused by the handler, Signal versus SetHandler, a stale record version and a changed payload in results, negative scores, pairwise query refusal, Should reordering, negative and overflowing wallet amounts, key reuse, and Exchange replay.
  • go tool nsgo check ./pkg/online/...: pass.
  • bun run verify-notes, go run ./changelog check (tools module): pass.

Screenshots: None

…nd inspector sections

The merge train dropped the Seat reservations and server directories (#2214), Idempotent match results (#2086), Match mailbox and one-writer state (#2212) and Live inspection and pprof sections from docs/en/gameserver.md and docs/zh/gameserver.md, and left the ticket properties section of #2072 under Player tokens. Restore the four sections and move the ticket section under Matchmaking.

Remove the duplicates the train left beside it: docs/{en,zh}/server.md, recreated by a later title fix after the match handler section had moved into gameserver.md, and docs/{en,zh}/server-results.md with the note and changelog fragment of #2087, which describe gameserver.MatchResults and MemoryResultCommitter, an API that #2086's ResultsBackend replaced in the same merge.
equalResult compared only the number of record, wallet and score grants, so a retry of a committed match with different amounts was reported as an identical no-op. A committed record kept the version the caller sent, so every later writer holding that version still passed the optimistic check, and a first score below zero was dropped because a missing best score read as 0.

Compare grants field by field and keep a copy of the committed result, store a committed record at its version plus one with a record that does not exist yet at version 0, and record a board's first score whatever its sign. Give ErrResultConflict a doc comment.
Rooms.Claim deleted the reservation, released the room lock and then joined, so a concurrent Join could take the freed seat and the claimant got ErrRoomFull with its reservation gone; a handler refusal or a busy server lost the reservation the same way, and JoinAttempt never saw the reservation's account. The merge of #2067 and #2068 also left join taking its account and metadata as ...any.

Give join explicit account, meta and claim parameters, check and consume the reservation under the room lock while the claimed seat is left out of the capacity count, and pass res.Account to the handler. Room.Signal read r.handler without the lock that SetHandler takes; read it under the lock. Document the LeaveReason constants.
The default rule checked each candidate's query only against the room's oldest ticket, so two candidates that refuse each other could share a room, against the documented symmetric matching. Candidates are also taken in Should-score order, while the removal pass that drops the chosen tickets from the remaining list assumes ascending indexes: a reordered candidate stayed in the list and could be placed in a second room in the same Match call.

Check a candidate's Must and MustNot terms against every ticket already in the room (the rating window is still measured from the oldest ticket, as documented), and sort the chosen indexes before the removal pass.
…e wallet

Spend negated its amount and checked only that the result was non-zero, so Spend("coins", -1000, key) added 1000 coins with no cap check, and Grant with a negative amount drained a balance past zero. A key replayed with a different currency, amount or operation returned the first change's result as if it were the same request, leaving ErrDuplicateKey unused, and a replayed Exchange returned the current balance of the target currency instead of its first result. Grants could also overflow int64.

Require positive amounts (ErrInvalidAmount), record the request under each key and answer a mismatch with ErrDuplicateKey, store both Exchange results for replay, refuse an exchange into the same currency, and treat an overflowing grant as ErrCapExceeded. Document the error values. Restore the Economy paragraph of liveops.md that #2241 added and a later merge dropped.
…S errors

shipping-china.md still said NSGo Game ships no anti-addiction play-time or spending checks, while the same page documents pkg/online/antiaddiction (folded from #2239's pkg/online/compliance). Mark the status partial and point to the checks; real-name verification, reporting, the Purchases pre-check and the advisory screen stay tracked in #1649.

Give the pkg/online/eos error values (#2094, restored by #2473) doc comments saying when each is returned.
…r sees the claim

Claim now reached JoinAttempt before join looked the reservation up, so an expired claim reported the handler's refusal instead of ErrRoomFull and the handler saw claims that could never be admitted. Check the reservation first; join still checks and consumes it under the admitting lock.
@github-actions github-actions Bot added size/L documentation Improvements or additions to documentation area/agents bug Something isn't working pkg/online labels Nov 29, 2026

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

area/agents bug Something isn't working documentation Improvements or additions to documentation pkg/online size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant