Skip to content

fix: align tool exit codes with response success#1824

Merged
hatayama merged 2 commits into
v3-betafrom
fix/tool-envelope-exit-codes
Jul 17, 2026
Merged

fix: align tool exit codes with response success#1824
hatayama merged 2 commits into
v3-betafrom
fix/tool-envelope-exit-codes

Conversation

@hatayama

@hatayama hatayama commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

Establishes the invariant that every Unity tool envelope with Success:false produces exit code 1, while Success:true produces exit code 0.

  • Derives project-runner tool exit codes from strict top-level Success parsing; malformed, missing, and non-boolean values fail closed.
  • Adds Success to the shared Unity response base and removes duplicate response fields.
  • Makes forced compile result-unknown responses explicit failures with COMPILE_RESULT_UNKNOWN and a definitive-compile next action.
  • Makes rendering screenshot failures explicit and actionable; preserves launch -q no-process behavior as an idempotent success with a message.

Verification

  • go test ./internal/projectrunner -count=1
  • go test ./internal/dispatcher -count=1
  • repo-local uloop compile: 0 errors, 0 warnings
  • targeted EditMode tests: 20 passed, 0 failed

The full EditMode suite had the eight Windows-incompatible failures already recorded in the Windows verification results; the changed contract tests passed.

Review in cubic

Make tool envelopes fail closed when Success is false or malformed, and unify Unity response Success fields.
@coderabbitai

coderabbitai Bot commented Jul 17, 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dfaa65d8-e2da-481f-be27-775c6a04bed2

📥 Commits

Reviewing files that changed from the base of the PR and between 593962a and 20abddf.

📒 Files selected for processing (8)
  • Packages/src/Editor/FirstPartyTools/Compile/CompileResponseFactory.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs
  • Packages/src/Editor/Infrastructure/Api/CompileStatusBridgeCommand.cs
  • Packages/src/Editor/ToolContracts/ForceCompileUnknownResult.cs
  • cli/project-runner/internal/projectrunner/compile_wait.go
  • cli/project-runner/internal/projectrunner/compile_wait_test.go
  • cli/project-runner/internal/projectrunner/pause_point_logs.go
  • cli/project-runner/internal/projectrunner/pause_point_types.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • Packages/src/Editor/FirstPartyTools/Compile/CompileResponseFactory.cs
  • Packages/src/Editor/ToolContracts/ForceCompileUnknownResult.cs
  • Packages/src/Editor/Infrastructure/Api/CompileStatusBridgeCommand.cs
  • cli/project-runner/internal/projectrunner/compile_wait_test.go

📝 Walkthrough

Walkthrough

Changes

Response semantics and compile outcomes

Layer / File(s) Summary
Shared response contracts
Packages/src/Editor/ToolContracts/*, Packages/src/Editor/FirstPartyTools/*Response.cs, Assets/Tests/Editor/*Response*Tests.cs, tests/contracts/*, cli/project-runner/internal/projectrunner/pause_point_*.go
Success is centralized on UnityCliLoopToolResponse; tool DTOs, test doubles, pause-point responses, and response contracts now use explicit inherited or decoded fields.
Compile result normalization
Packages/src/Editor/FirstPartyTools/Compile/*, Packages/src/Editor/Infrastructure/Api/CompileStatusBridgeCommand.cs, Packages/src/Editor/ToolContracts/ForceCompileUnknownResult.cs, Assets/Tests/Editor/Compile*Tests.cs, cli/project-runner/internal/projectrunner/compile_wait*
Compile success is non-nullable, and unknown force-compile results now include explicit failure, error-code, and next-action metadata.
Screenshot failure responses
Packages/src/Editor/ToolContracts/ScreenshotResponse.cs, Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs
EditMode, missing-texture, missing-window, and timeout responses now return Success = false with retry instructions.

CLI result and process handling

Layer / File(s) Summary
Envelope-derived exit codes
cli/project-runner/internal/projectrunner/run.go, cli/project-runner/internal/projectrunner/tool_envelope_exit_code*.go
Project-runner commands derive exit codes from serialized Success values, failing closed for invalid or missing fields.
Launch no-process message
cli/dispatcher/internal/dispatcher/launch_ready.go, cli/dispatcher/internal/dispatcher/launch_test.go
The no-process message text and its test assertion now use the shared constant.

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

Sequence Diagram(s)

sequenceDiagram
  participant ProjectRunner
  participant ToolResponse
  participant ExitCodeParser
  ProjectRunner->>ToolResponse: Serialize result with Success
  ProjectRunner->>ExitCodeParser: Parse serialized envelope
  ExitCodeParser-->>ProjectRunner: Return 0 for true or 1 otherwise
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: aligning tool exit codes with the Success field.
Description check ✅ Passed The description is directly related to the changeset and accurately summarizes the exit-code and response-shape updates.
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 fix/tool-envelope-exit-codes

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[bot]
coderabbitai Bot previously requested changes Jul 17, 2026

@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 `@Packages/src/Editor/ToolContracts/UnityCliLoopToolResponse.cs`:
- Line 8: Update the CLI protocol version consistently in
cli/common/clicontract/contract.json and the corresponding version constant in
CliConstants, reflecting that UnityCliLoopToolResponse.Success is now part of
the response contract. Ensure both values are incremented together so older
Unity packages and the new CLI are not treated as compatible.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f591e3b7-c891-40a7-8e5c-6d402334378f

📥 Commits

Reviewing files that changed from the base of the PR and between e0a2878 and 593962a.

📒 Files selected for processing (32)
  • Assets/Tests/Editor/CompileResponseFactoryTests.cs
  • Assets/Tests/Editor/CompileStatusBridgeCommandTests.cs
  • Assets/Tests/Editor/JsonRpcRequestProcessorCliVersionGateTests.cs
  • Assets/Tests/Editor/JsonRpcResponseFactoryWireShapeCharacterizationTests.cs
  • Assets/Tests/Editor/ToolExecutionSessionTests.cs
  • Packages/src/Editor/FirstPartyTools/ClearConsole/ClearConsoleResponse.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileResponse.cs
  • Packages/src/Editor/FirstPartyTools/Compile/CompileResponseFactory.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/ExecuteDynamicCodeResponse.cs
  • Packages/src/Editor/FirstPartyTools/PausePoint/PausePointTools.cs
  • Packages/src/Editor/FirstPartyTools/Raycast/RaycastResponse.cs
  • Packages/src/Editor/FirstPartyTools/RecordInput/RecordInputResponse.cs
  • Packages/src/Editor/FirstPartyTools/ReplayInput/ReplayInputResponse.cs
  • Packages/src/Editor/FirstPartyTools/RunTests/RunTestsResponse.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs
  • Packages/src/Editor/FirstPartyTools/SimulateKeyboard/SimulateKeyboardResponse.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/SimulateMouseInputResponse.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiResponse.cs
  • Packages/src/Editor/FirstPartyTools/Watch/WatchTools.cs
  • Packages/src/Editor/Infrastructure/Api/CompileStatusBridgeCommand.cs
  • Packages/src/Editor/ToolContracts/ForceCompileUnknownResult.cs
  • Packages/src/Editor/ToolContracts/ScreenshotResponse.cs
  • Packages/src/Editor/ToolContracts/UnityCliLoopToolResponse.cs
  • cli/dispatcher/internal/dispatcher/launch_ready.go
  • cli/dispatcher/internal/dispatcher/launch_test.go
  • cli/project-runner/internal/projectrunner/compile_wait_test.go
  • cli/project-runner/internal/projectrunner/run.go
  • cli/project-runner/internal/projectrunner/tool_envelope_exit_code.go
  • cli/project-runner/internal/projectrunner/tool_envelope_exit_code_test.go
  • tests/contracts/compile_status_response_contract.json
  • tests/contracts/get_logs_response_contract.json
  • tests/contracts/pause_point_status_response_contract.json
💤 Files with no reviewable changes (13)
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/SimulateMouseInputResponse.cs
  • Packages/src/Editor/FirstPartyTools/ReplayInput/ReplayInputResponse.cs
  • Assets/Tests/Editor/ToolExecutionSessionTests.cs
  • Packages/src/Editor/FirstPartyTools/PausePoint/PausePointTools.cs
  • Packages/src/Editor/FirstPartyTools/RecordInput/RecordInputResponse.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/ExecuteDynamicCodeResponse.cs
  • Packages/src/Editor/FirstPartyTools/Raycast/RaycastResponse.cs
  • Assets/Tests/Editor/JsonRpcResponseFactoryWireShapeCharacterizationTests.cs
  • Packages/src/Editor/FirstPartyTools/SimulateKeyboard/SimulateKeyboardResponse.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiResponse.cs
  • Assets/Tests/Editor/JsonRpcRequestProcessorCliVersionGateTests.cs
  • Packages/src/Editor/FirstPartyTools/RunTests/RunTestsResponse.cs
  • Packages/src/Editor/FirstPartyTools/Watch/WatchTools.cs

/// </summary>
public abstract class UnityCliLoopToolResponse
{
public bool Success { get; set; } = true;

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 | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check if the protocol version was incremented in the contract and constants files.

# Check contract.json
echo "--- cli/common/clicontract/contract.json ---"
cat cli/common/clicontract/contract.json | grep -i "protocolVersion" || echo "File or field not found."

# Check CliConstants.cs
echo "--- CliConstants.cs ---"
rg -i "REQUIRED_CLI_PROTOCOL_VERSION" Packages/src/ || echo "Constant not found."

Repository: hatayama/unity-cli-loop

Length of output: 976


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- Packages/src/Editor/ToolContracts/UnityCliLoopToolResponse.cs ---"
sed -n '1,120p' Packages/src/Editor/ToolContracts/UnityCliLoopToolResponse.cs

echo
echo "--- Packages/src/Editor/Infrastructure/Api/JsonRpcResponseFactory.cs ---"
sed -n '1,220p' Packages/src/Editor/Infrastructure/Api/JsonRpcResponseFactory.cs

echo
echo "--- Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs ---"
sed -n '1,220p' Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs

Repository: hatayama/unity-cli-loop

Length of output: 17941


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- search for JsonRpcResponseSerializer and Success fields ---"
rg -n "JsonRpcResponseSerializer|Success\s*\{" Packages/src/ -g'*.cs'

echo
echo "--- Packages/src/Editor/Infrastructure/Api/JsonRpcResponseSerializer.cs ---"
sed -n '1,220p' Packages/src/Editor/Infrastructure/Api/JsonRpcResponseSerializer.cs

echo
echo "--- response model files containing JsonRpcSuccessResponse ---"
rg -n "class JsonRpcSuccessResponse|record JsonRpcSuccessResponse|JsonRpcSuccessResponse" Packages/src/Editor/Infrastructure/Api/ -g'*.cs'

Repository: hatayama/unity-cli-loop

Length of output: 3865


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- search serializer settings / strict JSON handling ---"
rg -n "MissingMemberHandling|DefaultValueHandling|NullValueHandling|Required\\.|JsonProperty\\(|JsonObject\\(|JsonExtensionData|AllowTrailingCommas|MetadataPropertyHandling" Packages/src/ -g'*.cs'

echo
echo "--- UnityCliLoopJsonResponseSerializerSettings.cs ---"
sed -n '1,240p' Packages/src/Editor/Infrastructure/Api/UnityCliLoopJsonResponseSerializerSettings.cs

echo
echo "--- JsonRpcSuccessResponse.cs ---"
sed -n '1,200p' Packages/src/Editor/Infrastructure/Api/JsonRpcSuccessResponse.cs

Repository: hatayama/unity-cli-loop

Length of output: 2669


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- search for Success deserialization on the CLI/package side ---"
rg -n "\bSuccess\b" Packages/src/ cli/ -g'*.cs' -g'*.json'

echo
echo "--- search for strict contract assertions around response payloads ---"
rg -n "fail closed|missing Success|Success value|success field|required.*Success|deserialize.*Success" Packages/src/ cli/ -g'*.cs' -g'*.json'

Repository: hatayama/unity-cli-loop

Length of output: 36984


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- locate serializer settings file ---"
fd -a "UnityCliLoopJsonResponseSerializerSettings.cs" Packages/src/ || true
fd -a "*JsonResponseSerializerSettings*.cs" Packages/src/ || true

echo
echo "--- read serializer settings candidates ---"
for f in $(fd -a "UnityCliLoopJsonResponseSerializerSettings.cs" Packages/src/; fd -a "*JsonResponseSerializerSettings*.cs" Packages/src/); do
  echo "### $f"
  sed -n '1,220p' "$f"
  echo
done

echo "--- JsonRpcSuccessResponse.cs ---"
sed -n '1,200p' Packages/src/Editor/Infrastructure/Api/JsonRpcSuccessResponse.cs

Repository: hatayama/unity-cli-loop

Length of output: 2636


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- changed files touching protocol surfaces ---"
git diff --stat -- cli/common/clicontract/contract.json Packages/src/Editor/Domain/CliConstants.cs Packages/src/Editor/ToolContracts/UnityCliLoopToolResponse.cs

echo
echo "--- contract.json diff ---"
git diff --unified=0 -- cli/common/clicontract/contract.json

echo
echo "--- CliConstants.cs diff ---"
git diff --unified=0 -- Packages/src/Editor/Domain/CliConstants.cs

echo
echo "--- UnityCliLoopToolResponse.cs diff ---"
git diff --unified=0 -- Packages/src/Editor/ToolContracts/UnityCliLoopToolResponse.cs

Repository: hatayama/unity-cli-loop

Length of output: 310


Bump the CLI protocol version. Success is now part of the response contract, so older Unity packages and the new CLI won’t interoperate unless cli/common/clicontract/contract.json and Packages/src/Editor/Domain/CliConstants.cs move together.

🤖 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 `@Packages/src/Editor/ToolContracts/UnityCliLoopToolResponse.cs` at line 8,
Update the CLI protocol version consistently in
cli/common/clicontract/contract.json and the corresponding version constant in
CliConstants, reflecting that UnityCliLoopToolResponse.Success is now part of
the response contract. Ensure both values are incremented together so older
Unity packages and the new CLI are not treated as compatible.

Source: Path instructions

Fail window screenshots explicitly and keep compile result-unknown guidance centralized.
@hatayama
hatayama dismissed coderabbitai[bot]’s stale review July 17, 2026 16:47

Dismissed: adding an optional response field preserves the existing IPC wire contract; protocol versions remain unchanged by design.

@hatayama
hatayama merged commit 1cc123b into v3-beta Jul 17, 2026
10 checks passed
@hatayama
hatayama deleted the fix/tool-envelope-exit-codes branch July 17, 2026 16:48
@github-actions github-actions Bot mentioned this pull request Jul 17, 2026
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