fix: align tool exit codes with response success#1824
Conversation
Make tool envelopes fail closed when Success is false or malformed, and unify Unity response Success fields.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughChangesResponse semantics and compile outcomes
CLI result and process handling
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (32)
Assets/Tests/Editor/CompileResponseFactoryTests.csAssets/Tests/Editor/CompileStatusBridgeCommandTests.csAssets/Tests/Editor/JsonRpcRequestProcessorCliVersionGateTests.csAssets/Tests/Editor/JsonRpcResponseFactoryWireShapeCharacterizationTests.csAssets/Tests/Editor/ToolExecutionSessionTests.csPackages/src/Editor/FirstPartyTools/ClearConsole/ClearConsoleResponse.csPackages/src/Editor/FirstPartyTools/Compile/CompileResponse.csPackages/src/Editor/FirstPartyTools/Compile/CompileResponseFactory.csPackages/src/Editor/FirstPartyTools/ExecuteDynamicCode/ExecuteDynamicCodeResponse.csPackages/src/Editor/FirstPartyTools/PausePoint/PausePointTools.csPackages/src/Editor/FirstPartyTools/Raycast/RaycastResponse.csPackages/src/Editor/FirstPartyTools/RecordInput/RecordInputResponse.csPackages/src/Editor/FirstPartyTools/ReplayInput/ReplayInputResponse.csPackages/src/Editor/FirstPartyTools/RunTests/RunTestsResponse.csPackages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.csPackages/src/Editor/FirstPartyTools/SimulateKeyboard/SimulateKeyboardResponse.csPackages/src/Editor/FirstPartyTools/SimulateMouseInput/SimulateMouseInputResponse.csPackages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiResponse.csPackages/src/Editor/FirstPartyTools/Watch/WatchTools.csPackages/src/Editor/Infrastructure/Api/CompileStatusBridgeCommand.csPackages/src/Editor/ToolContracts/ForceCompileUnknownResult.csPackages/src/Editor/ToolContracts/ScreenshotResponse.csPackages/src/Editor/ToolContracts/UnityCliLoopToolResponse.cscli/dispatcher/internal/dispatcher/launch_ready.gocli/dispatcher/internal/dispatcher/launch_test.gocli/project-runner/internal/projectrunner/compile_wait_test.gocli/project-runner/internal/projectrunner/run.gocli/project-runner/internal/projectrunner/tool_envelope_exit_code.gocli/project-runner/internal/projectrunner/tool_envelope_exit_code_test.gotests/contracts/compile_status_response_contract.jsontests/contracts/get_logs_response_contract.jsontests/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; |
There was a problem hiding this comment.
🗄️ 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.csRepository: 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.csRepository: 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.csRepository: 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.csRepository: 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.
Dismissed: adding an optional response field preserves the existing IPC wire contract; protocol versions remain unchanged by design.
Summary
Establishes the invariant that every Unity tool envelope with
Success:falseproduces exit code 1, whileSuccess:trueproduces exit code 0.Successparsing; malformed, missing, and non-boolean values fail closed.Successto the shared Unity response base and removes duplicate response fields.COMPILE_RESULT_UNKNOWNand a definitive-compile next action.launch -qno-process behavior as an idempotent success with a message.Verification
go test ./internal/projectrunner -count=1go test ./internal/dispatcher -count=1uloop compile: 0 errors, 0 warningsThe full EditMode suite had the eight Windows-incompatible failures already recorded in the Windows verification results; the changed contract tests passed.