Skip to content

fix(native): route resolve all decisions - #7215

Merged
matthewevans merged 1 commit into
mainfrom
ship/fixnative-route-resolve-all-decisions
Aug 10, 2026
Merged

fix(native): route resolve all decisions#7215
matthewevans merged 1 commit into
mainfrom
ship/fixnative-route-resolve-all-decisions

Conversation

@matthewevans

@matthewevans matthewevans commented Aug 10, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added a Resolve All action for supported games, allowing multiple AI-controlled decisions to be processed automatically.
    • Added support for Resolve All in native and WebSocket gameplay.
    • Displays progress and final resolution results while updating the game state for players and spectators.
    • Supports native AI opponents with the appropriate difficulty settings.
  • Bug Fixes

    • Resolve All requests now report server errors and connection interruptions instead of remaining pending.

@matthewevans
matthewevans enabled auto-merge August 10, 2026 18:38
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This change adds native Resolve All protocol support. The server resolves batches of AI-controlled turns, publishes compact state updates, and returns progress acknowledgements. The WebSocket adapter tracks pending requests and failures. The board supports Resolve All for native-AI games.

Changes

Resolve All protocol and wire contract

Layer / File(s) Summary
Protocol and wire contract
crates/server-core/src/protocol.rs, crates/server-core/src/client_message_wire_guard.rs, crates/lobby-broker/src/protocol.rs, scripts/check-protocol-version.mjs
Adds ClientMessage::ResolveAll and ServerMessage::ResolveAllResult. Updates wire tests, guards, and protocol version checks to version 28.

Server batch resolution

Layer / File(s) Summary
Session batch resolution
crates/server-core/src/session.rs
Adds SessionManager::resolve_all_for_player, resolution limits, typed summaries, validation, AI decision execution, and revisioned results.
Server Resolve All orchestration
crates/phase-server/src/main.rs
Dispatches Resolve All requests, builds compact state updates, persists or finalizes sessions, broadcasts updates, and sends requester-scoped acknowledgements.

Client integration

Layer / File(s) Summary
WebSocket and board integration
client/src/adapter/ws-adapter.ts, client/src/adapter/__tests__/ws-adapter.test.ts, client/src/components/board/ActionButton.tsx, client/src/components/board/__tests__/ActionButton.test.tsx, client/src/game/dispatch.ts
Adds pending Resolve All request handling and failure paths in WebSocketAdapter. Includes native-AI seats in board dispatch. Adds adapter and UI tests and updates transport comments.

Estimated code review effort: 5 (Critical) | ~90 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Player
  participant ActionButton
  participant WebSocketAdapter
  participant phase_server as phase-server
  participant SessionManager
  participant Players
  Player->>ActionButton: Click Resolve All
  ActionButton->>WebSocketAdapter: resolveAll(requester, aiSeats, maxResolutions)
  WebSocketAdapter->>phase_server: ClientMessage.ResolveAll
  phase_server->>SessionManager: resolve_all_for_player
  SessionManager-->>phase_server: Resolution summary and state result
  phase_server-->>Players: Compact state update
  phase_server-->>WebSocketAdapter: ResolveAllResult
  WebSocketAdapter-->>ActionButton: BatchResolveResult
Loading

Possibly related PRs

  • phase-rs/phase#6305: Adds the native-AI WebSocket transport and game-mode support used by this Resolve All integration.
  • phase-rs/phase#6675: Modifies related WebSocket rejection and reconnect handling.
  • phase-rs/phase#6829: Introduces proposal-bound AI decisions used by batch resolution validation.

Suggested labels: bug

Suggested reviewers: claytonlin1110, lgray, parthmishra

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: routing Resolve All decisions through the native implementation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ship/fixnative-route-resolve-all-decisions

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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
client/src/components/board/ActionButton.tsx (1)

429-435: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Move native AI seat authority out of ActionButton.

These lines derive native AI player IDs and difficulties from local state and preferences. The native ResolveAll frame does not send this data, and WebSocketAdapter.resolveAll ignores it. A nonempty fabricated list only enables the batch path.

Expose an engine-owned Resolve All capability or typed resolution scope. Use that capability for native sessions. Keep AI-seat data only where the local worker requires it.

As per path instructions, client/src/ must not infer GAME data; expose it from the engine instead.

🤖 Prompt for 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.

In `@client/src/components/board/ActionButton.tsx` around lines 429 - 435, Update
the Resolve All logic in ActionButton so native-ai sessions use an engine-owned
Resolve All capability or typed resolution scope instead of deriving player IDs
and difficulties from gs and aiSeats. Keep the fabricated AI-seat list only for
local worker AI sessions, and ensure client/src does not infer game data for
native sessions.

Source: Path instructions

🤖 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 `@client/src/adapter/ws-adapter.ts`:
- Around line 1482-1484: Update the Resolve All failure handling in
client/src/adapter/ws-adapter.ts at lines 1482-1484 and 1723-1726 so
ActionRejected and Error responses are correlated by request_id before rejecting
pendingResolveAll; ignore uncorrelated failures from earlier requests, and add
coverage for an earlier rejected request followed by Resolve All.

In `@crates/phase-server/src/main.rs`:
- Around line 498-502: Update the Resolve All broadcast builder and
handle_resolve_all flow so batch.log_entries are not discarded. Publish a
payload-bounded tail of the engine-authored entries, or a single summary entry
identifying the number resolved, while preserving guard_state_snapshot_broadcast
limits and acknowledgement progress metadata.
- Around line 4350-4373: Extend the terminal-game teardown in the batch-ending
path after state.remove_game to remove the game_code entries from connections
and game_spectators, matching the cleanup performed by
ClientMessage::AbandonGame. Verify whether started games retain a lobby
registration; if they do, thread the lobby handle into handle_resolve_all and
unregister the game there as well, otherwise leave lobby handling unchanged.

---

Outside diff comments:
In `@client/src/components/board/ActionButton.tsx`:
- Around line 429-435: Update the Resolve All logic in ActionButton so native-ai
sessions use an engine-owned Resolve All capability or typed resolution scope
instead of deriving player IDs and difficulties from gs and aiSeats. Keep the
fabricated AI-seat list only for local worker AI sessions, and ensure client/src
does not infer game data for native sessions.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6ed18cb8-96c1-4712-8dd2-ad737508499c

📥 Commits

Reviewing files that changed from the base of the PR and between 7f86377 and 5ca528a.

📒 Files selected for processing (11)
  • client/src/adapter/__tests__/ws-adapter.test.ts
  • client/src/adapter/ws-adapter.ts
  • client/src/components/board/ActionButton.tsx
  • client/src/components/board/__tests__/ActionButton.test.tsx
  • client/src/game/dispatch.ts
  • crates/lobby-broker/src/protocol.rs
  • crates/phase-server/src/main.rs
  • crates/server-core/src/client_message_wire_guard.rs
  • crates/server-core/src/protocol.rs
  • crates/server-core/src/session.rs
  • scripts/check-protocol-version.mjs

Comment on lines +1482 to +1484
} else if (this.pendingResolveAll) {
this.pendingResolveAll.reject(actionRejectionError(data.reason));
this.pendingResolveAll = null;

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.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Correlate Resolve All failures with request_id.

ActionRejected and Error carry no request ID. A rejection from an earlier fire-and-forget request can arrive after resolveAll() installs pendingResolveAll. The adapter then rejects Resolve All even though the server still processes it.

Add a correlated Resolve All failure response. Reject only when its request_id matches the pending request. Add coverage for an earlier rejected request followed by Resolve All.

  • client/src/adapter/ws-adapter.ts#L1482-L1484: do not assign an uncorrelated ActionRejected to pendingResolveAll.
  • client/src/adapter/ws-adapter.ts#L1723-L1726: do not assign an uncorrelated Error to pendingResolveAll.
📍 Affects 1 file
  • client/src/adapter/ws-adapter.ts#L1482-L1484 (this comment)
  • client/src/adapter/ws-adapter.ts#L1723-L1726
🤖 Prompt for 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.

In `@client/src/adapter/ws-adapter.ts` around lines 1482 - 1484, Update the
Resolve All failure handling in client/src/adapter/ws-adapter.ts at lines
1482-1484 and 1723-1726 so ActionRejected and Error responses are correlated by
request_id before rejecting pendingResolveAll; ignore uncorrelated failures from
earlier requests, and add coverage for an earlier rejected request followed by
Resolve All.

Comment on lines +498 to +502
/// Resolve All can collect thousands of engine events. They are needed for
/// authoritative transition bookkeeping, but replaying them in one wire frame
/// defeats the batch path and breaches the snapshot payload guard. Publish the
/// final, fully-derived state only; the requester acknowledgement carries
/// progress metadata separately.

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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Resolve All discards the batch's game-log entries entirely.

The builder sets log_entries: Vec::new() for every recipient, and handle_resolve_all binds the session's log entries to _logs at Line 4269. The engine produces batch.log_entries for every resolved stack item, and SessionManager::resolve_all_for_player returns them, but no wire frame carries them.

The consequence is a permanent hole in user-visible game history: after one Resolve All, no player and no spectator ever sees what resolved. Log entries are not part of the GameState snapshot on this path, so a reconnect does not recover them either.

The doc comment justifies dropping events to respect guard_state_snapshot_broadcast. That argument bounds the payload; it does not require zero log entries. Consider publishing a bounded tail of batch.log_entries, or one engine-authored summary entry naming the count resolved, so the log stays continuous.

Also applies to: 540-540

🤖 Prompt for 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.

In `@crates/phase-server/src/main.rs` around lines 498 - 502, Update the Resolve
All broadcast builder and handle_resolve_all flow so batch.log_entries are not
discarded. Publish a payload-bounded tail of the engine-authored entries, or a
single summary entry identifying the number resolved, while preserving
guard_state_snapshot_broadcast limits and acknowledgement progress metadata.

Comment on lines +4350 to +4373
if !terminal_deliveries.is_empty() {
let conns = connections.lock().await;
if let Some(players) = conns.get(&game_code) {
for (player, delivery) in &terminal_deliveries {
if *player == requester {
let _ = tx.send(ServerMessage::TerminalResult {
delivery: Some(delivery.clone()),
});
} else if let Some(sender) = players.get(player) {
let _ = sender.send(ServerMessage::TerminalResult {
delivery: Some(delivery.clone()),
});
}
}
}
drop(conns);
report_draft_game_over(
draft_state,
connections,
&game_code,
game_over_winner.flatten(),
)
.await;
state.lock().await.remove_game(&game_code);

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

The terminal path removes the session but leaves connections, game_spectators, and the lobby entry behind.

When the batch ends the game, this block sends TerminalResult and calls state.lock().await.remove_game(&game_code). It never removes the connections entry for game_code, never removes the game_spectators entry, and never unregisters the lobby entry.

Compare ClientMessage::AbandonGame at Lines 6281-6283, which performs all three cleanups after remove_game.

The spectator entry is the clearest leak. Lines 4340-4346 only remove the game_spectators key when the sender list becomes empty. Any live spectator keeps a map entry that points at a game code with no session, and nothing on this path reclaims it.

🧹 Proposed teardown to match the abandon path
         drop(conns);
         report_draft_game_over(
             draft_state,
             connections,
             &game_code,
             game_over_winner.flatten(),
         )
         .await;
         state.lock().await.remove_game(&game_code);
+        connections.lock().await.remove(&game_code);
+        game_spectators.lock().await.remove(&game_code);
     }
 }

Note that lobby.unregister_game also runs on the abandon path. handle_resolve_all does not receive the lobby handle, so confirm whether a started game still holds a lobby entry at this point before adding that call.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !terminal_deliveries.is_empty() {
let conns = connections.lock().await;
if let Some(players) = conns.get(&game_code) {
for (player, delivery) in &terminal_deliveries {
if *player == requester {
let _ = tx.send(ServerMessage::TerminalResult {
delivery: Some(delivery.clone()),
});
} else if let Some(sender) = players.get(player) {
let _ = sender.send(ServerMessage::TerminalResult {
delivery: Some(delivery.clone()),
});
}
}
}
drop(conns);
report_draft_game_over(
draft_state,
connections,
&game_code,
game_over_winner.flatten(),
)
.await;
state.lock().await.remove_game(&game_code);
if !terminal_deliveries.is_empty() {
let conns = connections.lock().await;
if let Some(players) = conns.get(&game_code) {
for (player, delivery) in &terminal_deliveries {
if *player == requester {
let _ = tx.send(ServerMessage::TerminalResult {
delivery: Some(delivery.clone()),
});
} else if let Some(sender) = players.get(player) {
let _ = sender.send(ServerMessage::TerminalResult {
delivery: Some(delivery.clone()),
});
}
}
}
drop(conns);
report_draft_game_over(
draft_state,
connections,
&game_code,
game_over_winner.flatten(),
)
.await;
state.lock().await.remove_game(&game_code);
connections.lock().await.remove(&game_code);
game_spectators.lock().await.remove(&game_code);
🤖 Prompt for 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.

In `@crates/phase-server/src/main.rs` around lines 4350 - 4373, Extend the
terminal-game teardown in the batch-ending path after state.remove_game to
remove the game_code entries from connections and game_spectators, matching the
cleanup performed by ClientMessage::AbandonGame. Verify whether started games
retain a lobby registration; if they do, thread the lobby handle into
handle_resolve_all and unregister the game there as well, otherwise leave lobby
handling unchanged.

@matthewevans
matthewevans added this pull request to the merge queue Aug 10, 2026
Merged via the queue into main with commit 15017c3 Aug 10, 2026
15 checks passed
@matthewevans
matthewevans deleted the ship/fixnative-route-resolve-all-decisions branch August 10, 2026 19:11
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