Guard receive-path transport rendering

Skip raw packet, decoded message, peer, and channel formatting when
transport logging is disabled. Keep message processing and wire
reads outside the guards so logging controls never affect IPC flow.

Also narrow the remaining pretty-struct TODO to require a
non-raising formatter with native-repr fallback.

(this patch was generated in some part by `opencode` using
`gpt-5.6-sol` (`openai`))
wkt/start_or_cancel_tests_474
Gud Boi 2026-08-12 13:48:40 -04:00
parent 84ec895150
commit 935c8cf656
2 changed files with 21 additions and 19 deletions

View File

@ -309,7 +309,10 @@ class MsgpackTransport(MsgTransport):
log.transport(f'received header {size}') # type: ignore log.transport(f'received header {size}') # type: ignore
msg_bytes: bytes = await self.recv_stream.receive_exactly(size) msg_bytes: bytes = await self.recv_stream.receive_exactly(size)
log.transport(f"received {msg_bytes}") # type: ignore if log.at_least_level('transport'):
log.transport( # type: ignore
f'received {msg_bytes}'
)
try: try:
# NOTE: lookup the `trio.Task.context`'s var for # NOTE: lookup the `trio.Task.context`'s var for
# the current `MsgCodec`. # the current `MsgCodec`.

View File

@ -1003,17 +1003,15 @@ async def process_messages(
task_status.started(loop_cs) task_status.started(loop_cs)
async for msg in chan: async for msg in chan:
if log.at_least_level('transport'):
log.transport( # type: ignore log.transport( # type: ignore
f'IPC msg from peer\n' f'IPC msg from peer\n'
f'<= {chan.aid.reprol()}\n\n' f'<= {chan.aid.reprol()}\n\n'
# TODO: use of the pprinting of structs is # TODO: pretty-printing structs is FRAGILE;
# FRAGILE and should prolly not be # -[ ] add a non-raising log formatter with
# # native-repr fallback before using
# avoid fmting depending on loglevel for perf? # `.msg.pretty_struct` here.
# -[ ] specifically `pretty_struct.pformat()` sub-call..?
# - how to only log-level-aware actually call this?
# -[ ] use `.msg.pretty_struct` here now instead!
# f'{pretty_struct.pformat(msg)}\n' # f'{pretty_struct.pformat(msg)}\n'
f'{msg}\n' f'{msg}\n'
) )
@ -1262,6 +1260,7 @@ async def process_messages(
log.exception(message) log.exception(message)
raise RuntimeError(message) raise RuntimeError(message)
if log.at_least_level('transport'):
log.transport( log.transport(
'Waiting on next IPC msg from\n' 'Waiting on next IPC msg from\n'
f'peer: {chan.aid.reprol()}\n' f'peer: {chan.aid.reprol()}\n'