Skip to content

Conversation

@dsarno
Copy link
Owner

@dsarno dsarno commented Jan 1, 2026

Motivation

  • Prefer resolving sessions from PluginHub when HTTP transport is active to avoid probing stdio unnecessarily.
  • Auto-select the single connected Unity instance when no active instance is set to simplify developer experience.
  • Make auto-selection defensive to avoid transient errors clearing or flipping the active instance.
  • Improve observability and reduce noisy catching by tightening exception handling and making logging clearer.

Description

  • Added async def _maybe_autoselect_instance(self, ctx) which prefers PluginHub.get_sessions() for HTTP transport and falls back to stdio discovery only when transport != "http".
  • Limited stdio discovery to call get_unity_connection_pool().discover_all_instances(force_refresh=True) and only auto-select when exactly one instance is found, storing it via set_active_instance.
  • Refined exception handling to catch expected exception types explicitly, re-raise SystemExit/KeyboardInterrupt, and add clearer info/debug logs for probe results.
  • Added integration tests Server/tests/integration/test_instance_autoselect.py and updated Server/tests/integration/conftest.py to include src on sys.path and stub minimal starlette modules to allow isolated test runs.

Testing

  • Ran pytest tests/integration/test_instance_autoselect.py -v which executed the new tests and reported 2 passed.
  • The new tests validate PluginHub-based auto-selection and stdio fallback, and verify that PluginHub calls are not redundantly invoked.
  • Test suite uses asyncio.run(...) to execute middleware async paths and stubs transport submodules to isolate the unit under test.
  • No other automated tests were modified as part of this change.

Codex Task

…tion handling

### Motivation
- Avoid probing `stdio` when the server transport is `http` and prefer PluginHub session resolution instead.
- Prevent transient errors from clearing or flipping the active instance by making auto-selection defensive.
- Reduce noisy exception handling by catching expected errors explicitly and re-raising system-level interrupts.
- Improve observability by logging successful auto-selection at `info` and probe failures at `debug`.

### Description
- Added `async def _maybe_autoselect_instance(self, ctx)` which calls `transport.unity_transport._current_transport()` and tries PluginHub `get_sessions()` first, falling back to stdio discovery only when `transport != "http"`.
- Limited stdio discovery to `get_unity_connection_pool().discover_all_instances(force_refresh=True)` and only auto-select when exactly one instance is found, and set the session via `set_active_instance`.
- Replaced broad `except Exception:` catches with targeted exception tuples and a final handler that re-raises `SystemExit`/`KeyboardInterrupt`, and added clearer `info`/`debug` logging messages.
- Updated `_inject_unity_instance` to call `_maybe_autoselect_instance` when there is no `active_instance` and to validate PluginHub session resolution defensively.

### Testing
- No automated tests were executed as part of this rollout.
@coderabbitai
Copy link

coderabbitai bot commented Jan 1, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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 and usage tips.

@dsarno dsarno closed this Jan 1, 2026
@dsarno dsarno deleted the codex/clarify-issue-with-custom-tools-in-repo-klbeb2 branch January 2, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants