Skip to content

chore: Move tool execution session state into Domain#1578

Merged
hatayama merged 2 commits into
v3-betafrom
chore/c5-2-tool-execution-session
Jul 7, 2026
Merged

chore: Move tool execution session state into Domain#1578
hatayama merged 2 commits into
v3-betafrom
chore/c5-2-tool-execution-session

Conversation

@hatayama

@hatayama hatayama commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Move the single-flight tool execution slot state into Domain.
  • Keep Application responsible for busy exception shaping and editor play-state snapshots.

User Impact

  • No user-facing behavior changes.
  • Existing server_busy, disabled, and security-blocked JSON-RPC shapes are pinned by tests.

Changes

  • Add ToolExecutionSession and ToolExecutionSessionEnterResult in Domain.
  • Replace Application-owned execution slot fields with a Domain session instance.
  • Add Domain session tests for enter, busy rejection, execute-dynamic-code sharing, and shared-entry release count.
  • Add JSON-RPC disabled/security shape tests before PR3 folds enabled/allowed gates into the session admission flow.

Verification

  • dist/darwin-arm64/uloop compile --project-path "$(git rev-parse --show-toplevel)"
  • dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type regex --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.ToolExecutionSessionTests.*"
  • dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type regex --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.UnityCliLoopToolExecutionServiceTests.*"
  • dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type regex --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.JsonRpcRequestProcessorCliVersionGateTests.*"

Review in cubic

Extract the single-flight execution slot state into a Domain session so the Application service only orchestrates tool execution and preserves busy exception shaping.
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@hatayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7b04efb5-a997-4733-a022-7d04d55ed170

📥 Commits

Reviewing files that changed from the base of the PR and between a976e3b and 70ad1cd.

📒 Files selected for processing (1)
  • Assets/Tests/Editor/JsonRpcRequestProcessorCliVersionGateTests.cs
📝 Walkthrough

Walkthrough

Introduces ToolExecutionSession, a lock-protected single-flight concurrency gate that tracks running tool name and count, supporting shared re-entrancy for the dynamic-code tool. UnityCliLoopToolExecutionService is migrated to use this session, removing prior ad-hoc lock/counter fields. Adds corresponding unit tests, plus new JsonRpcRequestProcessor tests for disabled-tool and security-blocked gate responses.

Changes

Tool Execution Concurrency Gate

Layer / File(s) Summary
ToolExecutionSession contract and single-flight logic
Packages/src/Editor/Domain/ToolExecutionSession.cs
Adds ToolExecutionSession with TryEnter/Exit methods tracking running tool name and count, allowing shared re-entrancy for the dynamic-code tool, and ToolExecutionSessionEnterResult struct representing entered/busy outcomes.
Migrate execution service to session
Packages/src/Editor/Application/UnityCliLoopToolExecutionService.cs
Removes ad-hoc lock/counter/running-tool fields and helper methods (TryEnterExecution, ExitExecution, CanShareExecutionSlot, GetRunningToolNameInsideLock), replacing them with a single _executionSession field used in ExecuteToolAsync's entry, busy-exception, and exit paths.
ToolExecutionSession unit tests
Assets/Tests/Editor/ToolExecutionSessionTests.cs
Adds tests validating first-entry acceptance, busy rejection with running tool name, shared dynamic-code re-entrancy, and slot release requiring both shared exits.
Pre-execution tool gate tests
Assets/Tests/Editor/JsonRpcRequestProcessorCliVersionGateTests.cs
Adds tests for disabled-tool internal_error and security-blocked responses, plus a CreateRegistrarServiceWithToolSettings helper, SecurityBlockedTestTool, and InMemoryToolSettingsPort test double.

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

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant UnityCliLoopToolExecutionService
  participant ToolExecutionSession

  Client->>UnityCliLoopToolExecutionService: ExecuteToolAsync(toolName)
  UnityCliLoopToolExecutionService->>ToolExecutionSession: TryEnter(toolName)
  alt entered
    ToolExecutionSession-->>UnityCliLoopToolExecutionService: entered = true
    UnityCliLoopToolExecutionService->>UnityCliLoopToolExecutionService: execute tool
    UnityCliLoopToolExecutionService->>ToolExecutionSession: Exit()
  else busy
    ToolExecutionSession-->>UnityCliLoopToolExecutionService: entered = false, runningToolName
    UnityCliLoopToolExecutionService->>UnityCliLoopToolExecutionService: CreateBusyException(runningToolName)
    UnityCliLoopToolExecutionService-->>Client: busy error
  end
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: moving tool execution session state into the Domain layer.
Description check ✅ Passed The description is clearly related to the changeset and matches the domain session refactor and added tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/c5-2-tool-execution-session

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.

Document why the JSON-RPC security shape test uses an undefined security enum value while the production enum currently only exposes None.

@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.

🧹 Nitpick comments (1)
Assets/Tests/Editor/JsonRpcRequestProcessorCliVersionGateTests.cs (1)

592-605: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicate registrar-construction wiring.

CreateRegistrarServiceWithToolSettings re-implements the same wiring as CreateRegistrarService/UnityCliLoopToolRegistrarTestFactory.Create instead of extending the shared factory to accept an optional IToolSettingsPort. Test-only duplication, low risk, but could drift if the registrar constructor signature changes again.

🤖 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 `@Assets/Tests/Editor/JsonRpcRequestProcessorCliVersionGateTests.cs` around
lines 592 - 605, The registrar setup is duplicated between
CreateRegistrarService, CreateRegistrarServiceWithToolSettings, and
UnityCliLoopToolRegistrarTestFactory.Create, so update the shared test factory
to accept an optional IToolSettingsPort and have both helpers delegate to it.
Refactor the wiring in UnityCliLoopToolRegistrarTestFactory and
CreateRegistrarServiceWithToolSettings to reuse the same construction path
instead of manually instantiating UnityCliLoopToolRegistrarService, keeping the
test helpers aligned if the registrar constructor changes again.
🤖 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.

Nitpick comments:
In `@Assets/Tests/Editor/JsonRpcRequestProcessorCliVersionGateTests.cs`:
- Around line 592-605: The registrar setup is duplicated between
CreateRegistrarService, CreateRegistrarServiceWithToolSettings, and
UnityCliLoopToolRegistrarTestFactory.Create, so update the shared test factory
to accept an optional IToolSettingsPort and have both helpers delegate to it.
Refactor the wiring in UnityCliLoopToolRegistrarTestFactory and
CreateRegistrarServiceWithToolSettings to reuse the same construction path
instead of manually instantiating UnityCliLoopToolRegistrarService, keeping the
test helpers aligned if the registrar constructor changes again.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 98d5b865-0a38-4126-a5f9-3ed2fbca66ed

📥 Commits

Reviewing files that changed from the base of the PR and between b5b7238 and a976e3b.

⛔ Files ignored due to path filters (2)
  • Assets/Tests/Editor/ToolExecutionSessionTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/Domain/ToolExecutionSession.cs.meta is excluded by none and included by none
📒 Files selected for processing (4)
  • Assets/Tests/Editor/JsonRpcRequestProcessorCliVersionGateTests.cs
  • Assets/Tests/Editor/ToolExecutionSessionTests.cs
  • Packages/src/Editor/Application/UnityCliLoopToolExecutionService.cs
  • Packages/src/Editor/Domain/ToolExecutionSession.cs

@hatayama
hatayama merged commit 0693f54 into v3-beta Jul 7, 2026
10 checks passed
@hatayama
hatayama deleted the chore/c5-2-tool-execution-session branch July 7, 2026 01:44
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