Restore IPC transport style conventions

Bring the transport helpers back in line with project style:

- restore single-quote strings and docstrings;
- drop the oversized helper divider and simplify comments;
- keep guarded `match` dispatch so a missing `socket.AF_UNIX`
  remains safe when `HAS_UDS` is false.

Also, format the `HAS_UDS` conjunction with the project's
multiline branch convention.

Review: PR #475 (goodboy)
https://github.com/goodboy/tractor/pull/475

Prompt-IO: ai/prompt-io/opencode/20260817T231825Z_359fe75c_prompt_io.md

(this patch was generated in some part by `opencode` using `gpt-5.6-sol` (`openai`))
wkt/macos_ci_reruns
Gud Boi 2026-08-17 19:37:44 -04:00
parent 359fe75ced
commit 93322405a1
4 changed files with 125 additions and 34 deletions

View File

@ -0,0 +1,39 @@
---
model: openai/gpt-5.6-sol
service: opencode
session: pr475-review-fixes-20260817
timestamp: 2026-08-17T23:18:25Z
git_ref: 359fe75c
scope: code
substantive: true
raw_file: 20260817T231825Z_359fe75c_prompt_io.raw.md
---
## Prompt
Continue the `/code-review-changes` pass for PR #475 in its isolated
worktree. Address the seven accepted manual-review findings in
`tractor/ipc/_types.py` and `tractor/ipc/_uds.py`, preserve the existing
Windows capability behavior, verify the result, and prepare the work for
human-controlled commit and review-reply steps. Do not publish replies,
stage, commit, or push without the required explicit authorization.
## Response summary
Restored project quote, docstring, multiline-expression, and
`match/case` conventions while retaining the Windows-safe UDS guard.
Removed unnecessary structural and comment churn, then verified the
focused transport, discovery, and lazy-import paths plus the missing
`AF_UNIX` behavior.
## Files changed
- `tractor/ipc/_types.py` - restore project style and guarded
socket-family dispatch.
- `tractor/ipc/_uds.py` - format the UDS capability gate
consistently.
## Human edits
None - the generated patch remains uncommitted and awaits human
review.

View File

@ -0,0 +1,45 @@
---
model: openai/gpt-5.6-sol
service: opencode
timestamp: 2026-08-17T23:18:25Z
git_ref: 359fe75c
diff_cmd: git diff HEAD~1..HEAD
---
Applied the seven accepted manual-review fixes for PR #475 while
preserving the Windows transport capability behavior.
> `git diff HEAD~1..HEAD -- tractor/ipc/_types.py`
The generated changes restore the project's single-quote docstring and
string conventions, remove the unnecessary helper divider, simplify the
transport-registry comments, and restore `match/case` socket-family
dispatch. The UDS case retains a `HAS_UDS` guard that short-circuits
before `socket.AF_UNIX` is evaluated on unsupported hosts. Nearby error
messages are wrapped without changing their content.
> `git diff HEAD~1..HEAD -- tractor/ipc/_uds.py`
The generated change reformats the `HAS_UDS` conjunction according to
the project's multiline boolean-expression convention and simplifies
the adjacent capability comment.
Verification:
`/home/goodboy/repos/tractor/py313/bin/pytest -q tests/test_lazy_imports.py tests/discovery tests/ipc/test_server.py`
Result: `66 passed, 2 xpassed in 60.62s`.
`ruff check --no-cache --output-format=json tractor/ipc/_types.py tractor/ipc/_uds.py`
Result: no findings.
`git diff --check`
Result: no whitespace errors.
An explicit missing-`AF_UNIX` probe set `HAS_UDS = False`, removed the
socket constant, and exercised an unsupported socket family. It raised
the expected `NotImplementedError` instead of `AttributeError`.
No review replies, commits, or pushes were published.

View File

@ -36,16 +36,14 @@ from tractor.ipc._uds import (
HAS_UDS, HAS_UDS,
) )
# the UDS backend is importable everywhere but only *usable* where # the UDS backend is importable everywhere but only *usable* when
# `trio` reports `has_unix` (i.e. POSIX). On Windows / no-`AF_UNIX` # `HAS_UDS` is `True`; otherwise the runtime registers TCP only.
# hosts `HAS_UDS` is `False` and the runtime registers TCP only.
Address = TCPAddress|UDSAddress Address = TCPAddress|UDSAddress
# the available msg-transport backends on this host: TCP always, # the available msg-transport backends on this host: TCP always,
# UDS only where usable (`HAS_UDS`). The lookup maps below are all # UDS only where usable (`HAS_UDS`). The lookup maps below derive
# DERIVED from this single list via each backend's ClassVars # from this single list via each backend's `codec_key` and
# (`codec_key`, `address_type`) — register a backend here and every # `address_type`: register a backend here and every map picks it up.
# map picks it up; no per-map `if HAS_UDS` to keep in sync.
_msg_transports: list[Type[MsgTransport]] = [ _msg_transports: list[Type[MsgTransport]] = [
MsgpackTCPStream, MsgpackTCPStream,
] ]
@ -65,55 +63,63 @@ _addr_to_transport: dict[Type[Address], Type[MsgTransport]] = {
} }
# ------------------------------------------------------------
# Helpers
# ------------------------------------------------------------
def transport_from_addr( def transport_from_addr(
addr: Address, addr: Address,
codec_key: str = "msgpack", codec_key: str = 'msgpack',
) -> Type[MsgTransport]: ) -> Type[MsgTransport]:
""" '''
Given a destination address and a desired codec, find the Given a destination address and a desired codec, find the
corresponding `MsgTransport` type. corresponding `MsgTransport` type.
"""
'''
try: try:
return _addr_to_transport[type(addr)] # type: ignore[call-arg] addr_type = type(addr)
return _addr_to_transport[addr_type]
except KeyError: except KeyError:
raise NotImplementedError( raise NotImplementedError(
f"No known transport for address {repr(addr)}" f'No known transport for address '
f'{addr!r}'
) )
def transport_from_stream( def transport_from_stream(
stream: trio.abc.Stream, stream: trio.abc.Stream,
codec_key: str = "msgpack", codec_key: str = 'msgpack',
) -> Type[MsgTransport]: ) -> Type[MsgTransport]:
""" '''
Given an arbitrary `trio.abc.Stream` and a desired codec, Given an arbitrary `trio.abc.Stream` and a desired codec,
find the corresponding `MsgTransport` type. find the corresponding `MsgTransport` type.
"""
transport = None '''
transport: str|None = None
if isinstance(stream, trio.SocketStream): if isinstance(stream, trio.SocketStream):
sock: socket.socket = stream.socket sock: socket.socket = stream.socket
fam = sock.family match sock.family:
case socket.AF_INET | socket.AF_INET6:
transport = 'tcp'
if fam in (socket.AF_INET, getattr(socket, "AF_INET6", None)): # `HAS_UDS` short-circuits before `socket.AF_UNIX` on
transport = "tcp" # hosts where that constant is absent.
case fam if (
HAS_UDS
and
fam == socket.AF_UNIX
):
transport = 'uds'
# only consider `AF_UNIX` when the UDS backend is active; case fam:
# `HAS_UDS` short-circuits before `socket.AF_UNIX` so this raise NotImplementedError(
# stays safe on hosts where that constant is absent. f'Unsupported socket family: {fam}'
if transport is None and HAS_UDS and fam == socket.AF_UNIX: # type: ignore[attr-defined] )
transport = "uds"
if transport is None:
raise NotImplementedError(f"Unsupported socket family: {fam}")
if not transport: if not transport:
raise NotImplementedError( raise NotImplementedError(
f"Could not figure out transport type for stream type {type(stream)}" f'Could not figure out transport type for stream type '
f'{type(stream)}'
) )
key = (codec_key, transport) key = (codec_key, transport)
return _key_to_transport[key] return _key_to_transport[key]

View File

@ -114,12 +114,13 @@ _SUN_PATH_LIMIT: int = (
) )
# single source of truth for "is the UDS backend usable on this # single source of truth for whether the UDS backend is usable on this
# host?" Windows can expose `AF_UNIX`, but this backend remains # host. Windows can expose `AF_UNIX`, but this backend remains
# POSIX-only until its credential and lifecycle paths are supported. # POSIX-only until its credential and lifecycle paths are supported.
HAS_UDS: bool = ( HAS_UDS: bool = (
sys.platform != 'win32' sys.platform != 'win32'
and has_unix and
has_unix
) )