Skip to content

feat(mcp): add input recording and deterministic replay tools (#467) - #710

Merged
houko merged 3 commits into
mainfrom
feat/mcp-record-replay-467
Nov 24, 2026
Merged

houko merged 3 commits into
mainfrom
feat/mcp-record-replay-467

Conversation

@houko

@houko houko commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements MCP input recording and deterministic replay tools in packages/game/mcp so coding agents can start and stop recordings and replay stored or inline YAML recordings back to the exact same game state.

  • Adds ReplayController and ReplayConfig (packages/game/mcp/replay.go) implementing replay.ActionSource so games wire live play, recording (replay.Recorder), and deterministic playback (replay.Player) through one update loop.
  • Registers six strictly-decoded game_replay_* tools via Bridge.Tools():
    • game_replay_status
    • game_replay_record_start
    • game_replay_record_stop
    • game_replay_play (by stored name or inline yaml, with ResetFunc(seed) and run_to_end, steps, or frame-by-frame playback)
    • game_replay_stop
    • game_replay_list
  • Record and play share one reset (re-seed Config.Random/RandomStreams/SetSeed, then ResetFunc(seed)), on by default for both whenever there is something to reset. Playback refuses a recording made at a rate other than the game's fixed rate, advances the Bridge's loop with Loop.StepNow (so game_loop_status stays in sync) unless StepFunc is set, and is capped at MaxLoopSteps per call. A trailing playback step releases actions held at the end of the recording before live input resumes.
  • save_path writes go through os.Root (no symlink escapes), and an existing file or stored name is refused unless overwrite: true.
  • Keeps packages/game/mcp/mcp.go changes minimal (Config.Replay field + b.replayTools() append) so parallel MCP PRs rebase cleanly.
  • Updates docs/en/mcp.md and docs/zh/mcp.md, adds changelog fragment changelog.d/mcp-record-replay.md, and records architectural decisions in .agents/notes/implemented/feature/2026-11-24-mcp-record-and-replay.md.

Verification

After rebasing onto main and the review fixes: gofmt -l empty, go tool nsgo test ./mcp (29 passed), go tool nsgo check -target linux,web ./mcp, full go tool nsgo test . in packages/game (3426 passed), go run ./tools/changelog check.

Before the rebase:

  • git ls-files -z -- '*.go' | xargs -0 -r gofmt -l (empty)
  • (cd packages/game && env -u GOROOT go run ./cmd/gameschema -check)
  • (cd packages/game && env -u GOROOT go tool nsgo check -target macos,windows,linux,android,web)
  • (cd packages/game && env -u GOROOT go tool nsgo test ./mcp) (13 passed)
  • (cd packages/game && env -u GOROOT go tool nsgo test ./replay) (17 passed)
  • (cd packages/game && env -u GOROOT go tool nsgo test -run TestStabilityTable .) (1 passed)
  • env -u GOROOT go run ./tools/changelog check
  • bun run verify-notes

Closes #467

@github-actions github-actions Bot added enhancement New feature or request size/XL documentation Improvements or additions to documentation area/agents conflict Conflicts with the target branch; resolve before merging and removed size/XL labels Nov 24, 2026
…d seed

Synchronous playback now advances the Bridge's loop (Config.Loop/LoopFunc) with Loop.StepNow instead of calling the raw Update callback, so game_loop_status counts the replayed steps and game time; ReplayConfig.Loop is gone and StepFunc stays as an explicit override.

game_replay_play refuses a recording whose rate differs from the game's fixed rate (the loop's StepRate, else ReplayConfig.StepRate, else 60), and record_start no longer takes step_rate: recordings are always made at that rate.

Record and play share one reset that defaults to true whenever there is something to reset: the Bridge's seed targets (Config.Random, RandomStreams, SetSeed, as game_loop_seed uses) are re-seeded and then ResetFunc runs. A recording started mid-game with default arguments now replays to the same state.

steps is capped at MaxLoopSteps in schema and handler, and run_to_end is refused for recordings longer than MaxLoopSteps.

ReplayConfig.Source is required (the Recorder fallback left live play without input), it keeps being stepped during playback, and a trailing playback step releases actions held at the end of the recording before live input resumes.

save_path writes go through os.Root, so symlinks cannot leave SaveDir, and an existing file or stored name is refused unless overwrite: true. metadata is documented as in-memory only.
@houko
houko force-pushed the feat/mcp-record-replay-467 branch from a54f86f to 253d854 Compare November 24, 2026 19:23
@github-actions github-actions Bot added size/XL and removed conflict Conflicts with the target branch; resolve before merging labels Nov 24, 2026
@houko
houko merged commit 140f4f5 into main Nov 24, 2026
20 of 35 checks passed
@houko
houko deleted the feat/mcp-record-replay-467 branch November 24, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agents documentation Improvements or additions to documentation enhancement New feature or request size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: record and replay

1 participant