Skip to content

chore: Simplify JSON-RPC execution wiring#1555

Merged
hatayama merged 4 commits into
v3-betafrom
codex/pr6a-json-rpc-entry-router
Jul 6, 2026
Merged

chore: Simplify JSON-RPC execution wiring#1555
hatayama merged 4 commits into
v3-betafrom
codex/pr6a-json-rpc-entry-router

Conversation

@hatayama

@hatayama hatayama commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Route runtime JSON-RPC execution through injected instance services instead of static Application registrar calls.
  • Keep the existing static JsonRpcProcessor compatibility entrypoint for tests and callers that have not moved to DI yet.

User Impact

  • No user-facing behavior changes are intended.
  • The wire format is unchanged, so the IPC protocol version is not bumped. If the IPC reminder appears in CI, it should be treated as a review prompt only.

Changes

  • Added an instance JsonRpcRequestProcessor and UnityCliLoopExecutionRouter.
  • Injected the request processor into the bridge server and the tool registrar into server startup/recovery warmup paths.
  • Removed the obsolete UnityApiHandler static entrypoint and the Application registrar pass-throughs made unreachable by the injected production path.
  • Preserved ApplicationRegistrar.Service/RegisterService and custom registration wrappers for the existing test seam and compatibility surface.

Verification

  • dist/darwin-arm64/uloop compile --project-path <PROJECT_ROOT>: 0 errors / 0 warnings.
  • Related EditMode subset: 159/159 passed for JsonRpcProcessorCliVersionGateTests|JsonRpcHeartbeatTests|UnityCliLoopToolRegistryTests|UnityCliLoopServerControllerStartupLockTests|UnityCliLoopServerStartupProtectionTests|UnityCliLoopBridgeServerShutdownTests|OnionAssemblyDependencyTests|StaticFacadeStateGuardTests.
  • Full EditMode suite was run once: 1558 passed, 5 failed, 7 skipped. The 5 failures are pre-existing on origin/v3-beta and outside this diff:
    • InputVisualizationCanvasPrefabTests.RuntimeSources_WhenScanned_AreEditorOnly: Packages/src/Runtime/PausePoints/AssemblyInfo.cs is already not wrapped in #if UNITY_EDITOR on the base branch.
    • 4 UnityCliLoopSettingsWindowCliActionTests cases: the checked-in pin requires minimumDispatcherVersion 3.0.1-beta.6, while these expectations still treat 3.0.0 as the satisfied boundary.
  • Added follow-up notes for both pre-existing full-suite failures in the Obsidian planning note.

Review in cubic

hatayama added 3 commits July 6, 2026 21:54
Introduce JsonRpcRequestProcessor and UnityCliLoopExecutionRouter so JSON-RPC execution can be injected without changing the existing static entrypoints yet. The compatibility wrappers read ApplicationRegistrar.Service at call time to preserve the current test swap seam.
Pass the tool registrar into the server factory, bridge server, and server controller so runtime dispatch no longer reaches ApplicationRegistrar or JsonRpcProcessor static entrypoints from production paths.
Retarget the remaining execution-router tests to the injected router and drop the Application registrar pass-throughs made unreachable by the new production path. Keep the Service swap seam and custom registration wrappers for compatibility.
@coderabbitai

coderabbitai Bot commented Jul 6, 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: 18 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: 7a018795-3fa4-4950-9dd8-ad255e0e76f7

📥 Commits

Reviewing files that changed from the base of the PR and between cb12f38 and ff90639.

⛔ Files ignored due to path filters (1)
  • Assets/Tests/Editor/UnityCliLoopToolRegistrarTestFactory.cs.meta is excluded by none and included by none
📒 Files selected for processing (6)
  • Assets/Tests/Editor/UnityCliLoopServerControllerStartupLockTests.cs
  • Assets/Tests/Editor/UnityCliLoopServerStartupProtectionTests.cs
  • Assets/Tests/Editor/UnityCliLoopToolRegistrarTestFactory.cs
  • Assets/Tests/Editor/UnityCliLoopToolRegistryTests.cs
  • Packages/src/Editor/Infrastructure/Api/JsonRpcProcessor.cs
  • Packages/src/Editor/Infrastructure/Api/UnityCliLoopExecutionRouter.cs
📝 Walkthrough

Walkthrough

This PR replaces static ApplicationRegistrar access with an injected UnityCliLoopToolRegistrarService across bridge commands, execution routing, server controller, and bridge server factory. JsonRpcProcessor is split into a thin wrapper delegating to a new JsonRpcRequestProcessor, which now owns full JSON-RPC parsing, error mapping, and response models. Tests are updated accordingly.

Changes

Tool registrar service injection and JSON-RPC processor split

Layer / File(s) Summary
Remove static registry accessor
Packages/src/Editor/Application/UnityCliLoopToolRegistrar.cs
GetRegistry() is removed; only TryGetRegistry() remains, delegating to Service.
Service-aware bridge commands
Packages/src/Editor/Infrastructure/Api/GetToolDetailsBridgeCommand.cs, InternalBridgeCommandRouter.cs
Execute methods now accept UnityCliLoopToolRegistrarService to fetch the registry and dispatch commands instead of a static alias.
Instance-based execution router
Packages/src/Editor/Infrastructure/Api/UnityCliLoopExecutionRouter.cs
Static UnityApiHandler is replaced by an internal UnityCliLoopExecutionRouter class holding an injected registrar service, exposing ExecuteAsync.
Split JsonRpcProcessor into JsonRpcRequestProcessor
Packages/src/Editor/Infrastructure/Api/JsonRpcProcessor.cs, JsonRpcRequestProcessor.cs
JsonRpcProcessor becomes a compatibility wrapper delegating to new JsonRpcRequestProcessor, which implements parsing, protocol-mismatch handling, timing, error conversion, and defines JSON-RPC DTO types.
Wire registrar service into controller and server
Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerController.cs, UnityCliLoopBridgeServer.cs, Packages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.cs
Controller service and bridge server factory accept the registrar service and JsonRpcRequestProcessor; composition root wires them through constructors.
Update tests for registrar service and execution router
Assets/Tests/Editor/UnityCliLoopServerControllerStartupLockTests.cs, UnityCliLoopServerStartupProtectionTests.cs, UnityCliLoopToolRegistryTests.cs
Tests add CreateToolRegistrarService()/CreateExecutionRouter() helpers and use them instead of static ApplicationRegistrar/UnityApiHandler calls.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant UnityCliLoopExecutionRouter
  participant InternalBridgeCommandRouter
  participant UnityCliLoopToolRegistrarService
  participant JsonRpcRequestProcessor

  Caller->>JsonRpcRequestProcessor: ProcessRequestWithEarlyResponseAsync(request)
  JsonRpcRequestProcessor->>UnityCliLoopExecutionRouter: ExecuteAsync(commandName, paramsToken, ct)
  alt internal command
    UnityCliLoopExecutionRouter->>InternalBridgeCommandRouter: Execute(commandName, paramsToken, toolRegistrarService)
    InternalBridgeCommandRouter->>UnityCliLoopToolRegistrarService: GetRegistry()
  else tool command
    UnityCliLoopExecutionRouter->>UnityCliLoopToolRegistrarService: ExecuteToolAsync(commandName, paramsToken, ct)
  end
  UnityCliLoopToolRegistrarService-->>UnityCliLoopExecutionRouter: UnityCliLoopToolResponse
  UnityCliLoopExecutionRouter-->>JsonRpcRequestProcessor: response
  JsonRpcRequestProcessor-->>Caller: JSON-RPC response frame
Loading

Possibly related PRs

  • hatayama/unity-cli-loop#1524: Also rewires UnityCliLoopToolRegistrarService into the controller/router and updates test factories to build the service, directly aligning with this PR's changes.
  • hatayama/unity-cli-loop#1528: Test helpers in this PR construct UnityCliLoopToolExecutionService with NoOpEditorRuntimeStatePort, wiring it into UnityCliLoopToolRegistrarService similarly across the same test files.
  • hatayama/unity-cli-loop#1079: Changes tool execution routing through UnityCliLoopToolRegistrar.ExecuteToolAsync, touching the same tool-execution/control-flow path this PR modifies.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: simplifying JSON-RPC execution wiring.
Description check ✅ Passed The description matches the code changes, covering injected JSON-RPC routing, compatibility, and verification notes.
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 codex/pr6a-json-rpc-entry-router

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.

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

487-501: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consolidate the duplicated CreateToolRegistrarService() test helper.

This helper (real ToolSettingsRepository, EmptyInternalToolNameProvider, UnityCliLoopToolExecutionService(NoOpEditorRuntimeStatePort), and a toolDiscovery func) is now copy-pasted verbatim in UnityCliLoopServerControllerStartupLockTests.cs and UnityCliLoopServerStartupProtectionTests.cs, differing only in the discovery delegate. Extracting a single shared test factory (with an optional discovery-func parameter, mirroring the existing CreateControllerService(...) optional-param pattern) would prevent the three copies drifting when UnityCliLoopToolRegistrarService's constructor changes.

♻️ Example consolidation (shared test-support type)
internal static class ToolRegistrarServiceTestFactory
{
    internal static UnityCliLoopToolRegistrarService Create(
        Func<IReadOnlyList<IUnityCliLoopTool>> toolDiscovery = null)
    {
        IToolSettingsPort toolSettingsPort = new ToolSettingsRepository();
        return new UnityCliLoopToolRegistrarService(
            new EmptyInternalToolNameProvider(),
            toolSettingsPort,
            new UnityCliLoopToolExecutionService(new NoOpEditorRuntimeStatePort()),
            toolDiscovery ?? (() => Array.Empty<IUnityCliLoopTool>()));
    }
}
🤖 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/UnityCliLoopToolRegistryTests.cs` around lines 487 - 501,
The duplicated CreateToolRegistrarService test helper should be consolidated
into a shared test factory so the three copies do not drift. Extract the common
UnityCliLoopToolRegistrarService setup (ToolSettingsRepository,
EmptyInternalToolNameProvider, UnityCliLoopToolExecutionService with
NoOpEditorRuntimeStatePort) into a single helper, and make the toolDiscovery
delegate optional so UnityCliLoopServerControllerStartupLockTests and
UnityCliLoopServerStartupProtectionTests can reuse it while preserving their
differing discovery behavior.
🤖 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/UnityCliLoopToolRegistryTests.cs`:
- Around line 487-501: The duplicated CreateToolRegistrarService test helper
should be consolidated into a shared test factory so the three copies do not
drift. Extract the common UnityCliLoopToolRegistrarService setup
(ToolSettingsRepository, EmptyInternalToolNameProvider,
UnityCliLoopToolExecutionService with NoOpEditorRuntimeStatePort) into a single
helper, and make the toolDiscovery delegate optional so
UnityCliLoopServerControllerStartupLockTests and
UnityCliLoopServerStartupProtectionTests can reuse it while preserving their
differing discovery behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e676a3f4-bb44-400f-b30f-55ecf680f6c6

📥 Commits

Reviewing files that changed from the base of the PR and between 017e1ad and cb12f38.

⛔ Files ignored due to path filters (3)
  • Packages/src/Editor/Infrastructure/Api/JsonRpcProcessor.cs.meta is excluded by none and included by none
  • Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs.meta is excluded by none and included by none
  • Packages/src/Editor/Infrastructure/Api/UnityCliLoopExecutionRouter.cs.meta is excluded by none and included by none
📒 Files selected for processing (12)
  • Assets/Tests/Editor/UnityCliLoopServerControllerStartupLockTests.cs
  • Assets/Tests/Editor/UnityCliLoopServerStartupProtectionTests.cs
  • Assets/Tests/Editor/UnityCliLoopToolRegistryTests.cs
  • Packages/src/Editor/Application/UnityCliLoopToolRegistrar.cs
  • Packages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.cs
  • Packages/src/Editor/Infrastructure/Api/GetToolDetailsBridgeCommand.cs
  • Packages/src/Editor/Infrastructure/Api/InternalBridgeCommandRouter.cs
  • Packages/src/Editor/Infrastructure/Api/JsonRpcProcessor.cs
  • Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs
  • Packages/src/Editor/Infrastructure/Api/UnityCliLoopExecutionRouter.cs
  • Packages/src/Editor/Infrastructure/Server/UnityCliLoopServerController.cs
  • Packages/src/Editor/Infrastructure/UnityCliLoopBridgeServer.cs
💤 Files with no reviewable changes (1)
  • Packages/src/Editor/Application/UnityCliLoopToolRegistrar.cs

Share the registrar test factory used by execution-router tests and clean up the wrapper/comment nits found in review.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="Packages/src/Editor/Infrastructure/Api/JsonRpcProcessor.cs">

<violation number="1" location="Packages/src/Editor/Infrastructure/Api/JsonRpcProcessor.cs:42">
P3: The compatibility wrapper's CreateProcessor() constructs a new JsonRpcRequestProcessor (and underlying UnityCliLoopExecutionRouter) on every call. If ProcessRequest or ProcessRequestWithEarlyResponseAsync is called multiple times — which happens on every JSON-RPC request — this allocates a new processor, router, and references every time. Since the underlying toolRegistrarService (ApplicationRegistrar.Service) is effectively a singleton after initialization, consider caching the processor instance (or at least the executionRouter) to avoid per-request allocation pressure on the hot IPC path.</violation>

<violation number="2" location="Packages/src/Editor/Infrastructure/Api/JsonRpcProcessor.cs:44">
P2: The static JSON-RPC compatibility entrypoint can now throw before producing a JSON-RPC response when the application registrar has not been registered yet. Because CreateProcessor reads ApplicationRegistrar.Service before request parsing/error handling, callers not yet migrated to DI lose the previous parse/protocol error behavior; consider deferring service lookup until actual command execution or providing a registered fallback for this path.</violation>
</file>

<file name="Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs">

<violation number="1" location="Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs:163">
P2: Optional capability flags should be tolerant to malformed or future values, but direct `Value<bool>()` conversion can hard-fail request parsing. Checking `JTokenType.Boolean` before reading and defaulting to false would keep this negotiation path robust.</violation>

<violation number="2" location="Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs:207">
P3: HandleFocusWindowNotification() is an empty method with only a comment saying it's intentionally empty because focus-window is handled at the OS level by the CLI. Since the switch case for `focus-window` already calls this method, and the method does nothing, consider either removing the switch case entirely (focus-window notification would fall through to the default case and be silently ignored) or inline the explanation as a comment on the case itself. An empty method with only one call site is unnecessary indirection.</violation>

<violation number="3" location="Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs:460">
P2: If result serialization fails, this path still returns a JSON-RPC success response, so callers can interpret a failed execution as a completed request. Using a normal JSON-RPC error response here would preserve consistent failure handling.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

this.jsonrpc = jsonRpc;
this.id = id;
this.error = error;
UnityCliLoopToolRegistrarService toolRegistrarService = ApplicationRegistrar.Service;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The static JSON-RPC compatibility entrypoint can now throw before producing a JSON-RPC response when the application registrar has not been registered yet. Because CreateProcessor reads ApplicationRegistrar.Service before request parsing/error handling, callers not yet migrated to DI lose the previous parse/protocol error behavior; consider deferring service lookup until actual command execution or providing a registered fallback for this path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Packages/src/Editor/Infrastructure/Api/JsonRpcProcessor.cs, line 45:

<comment>The static JSON-RPC compatibility entrypoint can now throw before producing a JSON-RPC response when the application registrar has not been registered yet. Because CreateProcessor reads ApplicationRegistrar.Service before request parsing/error handling, callers not yet migrated to DI lose the previous parse/protocol error behavior; consider deferring service lookup until actual command execution or providing a registered fallback for this path.</comment>

<file context>
@@ -1,706 +1,50 @@
-            this.jsonrpc = jsonRpc;
-            this.id = id;
-            this.error = error;
+            UnityCliLoopToolRegistrarService toolRegistrarService = ApplicationRegistrar.Service;
+            UnityCliLoopExecutionRouter executionRouter = new(toolRegistrarService);
+            return new JsonRpcRequestProcessor(executionRouter);
</file context>

return false;
}

return metadata["acceptsDispatchAck"]?.Value<bool>() ?? false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Optional capability flags should be tolerant to malformed or future values, but direct Value<bool>() conversion can hard-fail request parsing. Checking JTokenType.Boolean before reading and defaulting to false would keep this negotiation path robust.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs, line 163:

<comment>Optional capability flags should be tolerant to malformed or future values, but direct `Value<bool>()` conversion can hard-fail request parsing. Checking `JTokenType.Boolean` before reading and defaulting to false would keep this negotiation path robust.</comment>

<file context>
@@ -0,0 +1,715 @@
+                return false;
+            }
+
+            return metadata["acceptsDispatchAck"]?.Value<bool>() ?? false;
+        }
+
</file context>

);
return JsonConvert.SerializeObject(response, Formatting.None, ResponseSerializerSettings);
}
catch (Exception)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: If result serialization fails, this path still returns a JSON-RPC success response, so callers can interpret a failed execution as a completed request. Using a normal JSON-RPC error response here would preserve consistent failure handling.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs, line 460:

<comment>If result serialization fails, this path still returns a JSON-RPC success response, so callers can interpret a failed execution as a completed request. Using a normal JSON-RPC error response here would preserve consistent failure handling.</comment>

<file context>
@@ -0,0 +1,715 @@
+                );
+                return JsonConvert.SerializeObject(response, Formatting.None, ResponseSerializerSettings);
+            }
+            catch (Exception)
+            {
+                // Return safe fallback response for any serialization errors
</file context>

/// Note: focus-window is handled at OS level by the CLI using native process control.
/// This notification handler remains for protocol compatibility but does nothing.
/// </summary>
private static void HandleFocusWindowNotification()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: HandleFocusWindowNotification() is an empty method with only a comment saying it's intentionally empty because focus-window is handled at the OS level by the CLI. Since the switch case for focus-window already calls this method, and the method does nothing, consider either removing the switch case entirely (focus-window notification would fall through to the default case and be silently ignored) or inline the explanation as a comment on the case itself. An empty method with only one call site is unnecessary indirection.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Packages/src/Editor/Infrastructure/Api/JsonRpcRequestProcessor.cs, line 207:

<comment>HandleFocusWindowNotification() is an empty method with only a comment saying it's intentionally empty because focus-window is handled at the OS level by the CLI. Since the switch case for `focus-window` already calls this method, and the method does nothing, consider either removing the switch case entirely (focus-window notification would fall through to the default case and be silently ignored) or inline the explanation as a comment on the case itself. An empty method with only one call site is unnecessary indirection.</comment>

<file context>
@@ -0,0 +1,715 @@
+        /// Note: focus-window is handled at OS level by the CLI using native process control.
+        /// This notification handler remains for protocol compatibility but does nothing.
+        /// </summary>
+        private static void HandleFocusWindowNotification()
+        {
+            // Intentionally empty because focus-window is handled by the CLI at OS level.
</file context>

public JsonRpcError error { get; }

public JsonRpcErrorResponse(string jsonRpc, object id, JsonRpcError error)
private static JsonRpcRequestProcessor CreateProcessor()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The compatibility wrapper's CreateProcessor() constructs a new JsonRpcRequestProcessor (and underlying UnityCliLoopExecutionRouter) on every call. If ProcessRequest or ProcessRequestWithEarlyResponseAsync is called multiple times — which happens on every JSON-RPC request — this allocates a new processor, router, and references every time. Since the underlying toolRegistrarService (ApplicationRegistrar.Service) is effectively a singleton after initialization, consider caching the processor instance (or at least the executionRouter) to avoid per-request allocation pressure on the hot IPC path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Packages/src/Editor/Infrastructure/Api/JsonRpcProcessor.cs, line 43:

<comment>The compatibility wrapper's CreateProcessor() constructs a new JsonRpcRequestProcessor (and underlying UnityCliLoopExecutionRouter) on every call. If ProcessRequest or ProcessRequestWithEarlyResponseAsync is called multiple times — which happens on every JSON-RPC request — this allocates a new processor, router, and references every time. Since the underlying toolRegistrarService (ApplicationRegistrar.Service) is effectively a singleton after initialization, consider caching the processor instance (or at least the executionRouter) to avoid per-request allocation pressure on the hot IPC path.</comment>

<file context>
@@ -1,706 +1,50 @@
-        public JsonRpcError error { get; }
-        
-        public JsonRpcErrorResponse(string jsonRpc, object id, JsonRpcError error)
+        private static JsonRpcRequestProcessor CreateProcessor()
         {
-            this.jsonrpc = jsonRpc;
</file context>

@hatayama
hatayama merged commit dd973d1 into v3-beta Jul 6, 2026
10 checks passed
@hatayama
hatayama deleted the codex/pr6a-json-rpc-entry-router branch July 6, 2026 13:20
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