fix: casino 0-balance — persistent guest room for live-roster Credits#73
Merged
Conversation
… roster The guest runtime created a fresh `room` every callback but built the game's Handler + stored Services only ONCE at OnStart, binding svc.Credits to the start callback's room. creditsSvc resolves a player's host index against that room's ctx.members — empty for a solo game (the player joins after start) — so every Balance/Wager/Settle was denied at the guest facade (ErrCreditsDenied) and never reached the host: casino games showed a 0 balance and refused bets. Use a single persistent `theRoom`, refreshed in place each callback, so the game's once-built Services always resolve against the current ctx. No behavior change for non-casino games (the room reuse is transparent; ctx is the same data, just not reallocated). The kittest/native/memsvc doubles resolve credits by account id rather than roster index, which is why unit tests and `shellcade-kit check` conformance missed this — it only manifests on the real wasm ABI path. Follow-up: add a casino wasm-fixture host test that Start()s empty then Join()s and asserts a guest credits call reaches the host service. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W7oJQSTva5xgbAZomdV5Jj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
Every casino game (blackjack/pokies/scratchies/roulette) shows a 0 balance and refuses all bets in production, despite the platform reserving credits correctly.
Root cause
The guest runtime (
internal/game/run.go) builds a freshroomevery callback, but creates the game'sHandler— and its storedServices(includingcreditsSvc) — only once atOnStart, bound to the start callback's room.creditsSvcresolves a player's host-side index by scanning that room'sctx.members, which is empty for a solo game (the player joins afterOnStart). SocreditsSvc.index(p) → -1and everyBalance/Wager/Settleis denied at the guest facade (ErrCreditsDenied) — it never even reaches the hostcreditsCall.The
kittest/native/memsvcdoubles resolve credits by account id, not roster index, so unit tests andshellcade-kit checkconformance all passed — the bug only manifests on the real wasm ABI path.Fix
Use a single persistent
theRoom, refreshed in place each callback (itsctxis reassigned indecodeCall), so the game's once-builtServicesalways resolve against the live roster. Theroomstruct is just{ctx, rng}with no per-callback state, and its own comment says it's "refreshed per callback" — this makes that true. No behavior change for non-casino games.Verification
Reproduced and fixed locally end-to-end (dev server + sideloaded casino blackjack, driven via tmux):
Balance→ErrCreditsDeniedat the facade, HUD showscredits 0, bets refused.creditsCallreached (idx=0 rosterLen=1),Balance→1015, HUD shows$1015; placing a bet deals cards and debits to$990.go build ./...(native +GOOS=wasip1) andgo test ./...green.Follow-ups
Startempty →Join→ assert a guest credits call reaches the host service) so this can't regress — the current doubles can't catch it.🤖 Generated with Claude Code