Skip to content

Simplify transport module and remove unnecessary complexity#278

Merged
Mng-dev-ai merged 3 commits intomainfrom
refactor/transports-simplification
Feb 24, 2026
Merged

Simplify transport module and remove unnecessary complexity#278
Mng-dev-ai merged 3 commits intomainfrom
refactor/transports-simplification

Conversation

@Mng-dev-ai
Copy link
Owner

Summary

  • Removes 87 lines of unnecessary complexity from the transport module (90 added, 177 removed)
  • Eliminates dead code, redundant abstractions, and single-use wrappers across base.py, docker.py, and host.py
  • Centralizes shared logic (TERM env var, module-level logging) and simplifies expressions throughout

Changes

Removed abstractions:

  • _get_logger abstract method → module-level logger in each file
  • _ensure_input_open → inlined into write()
  • _preexec_drop_privileges wrapper → direct partial(self._set_process_ids, ...)
  • _write_stream_eof → merged into _send_eof

Simplified logic:

  • _parse_json_buffer whitespace handling (4 lines → 1 line)
  • first_brace_positions list comprehension (9 lines) → compiled JSON_START_RE regex (4 lines)
  • servers_for_cli for-loop → dict comprehension, removed dead if servers_for_cli: guard
  • _send_eof null checks (3 early returns → 1 short-circuit chain)
  • _kill_exec_process Running + Pid checks combined into short-circuit
  • Env setup: os.environ.copy() + update() + assignments → single dict literal with ** unpacking
  • TERM env var centralized in _prepare_environment (was duplicated in both subclasses)

Removed dead code:

  • isinstance(chunk, str) check (queue only contains str and sentinel)
  • seen set in _resolve_run_user (duplicate lookup is harmless)
  • Redundant if servers_for_cli: guard (always true for non-empty dict)
  • Dead or env.get("USER", "user") fallback (_prepare_environment guarantees non-empty)

Narrowed exception handling:

  • end_input: except Exceptionexcept (OSError, CLIConnectionError)
  • _send_eof in docker: except Exceptionexcept OSError
  • Removed redundant double exception wrapping in docker connect

Test plan

  • Verify Docker transport connects and streams CLI output correctly
  • Verify Host transport connects and streams CLI output correctly
  • Verify EOF handling works for both transports
  • Verify process cleanup on close for both transports

- Remove _get_logger abstract method, use module-level logger in each file
- Inline single-use methods (_ensure_input_open, _preexec_drop_privileges, _write_stream_eof)
- Narrow broad except clauses to specific exception types
- Remove redundant exception wrapping in docker connect
- Remove explanatory comments from _parse_cli_output
- Simplify _parse_json_buffer whitespace handling
- Replace first_brace_positions logic with compiled regex
- Centralize TERM env var in _prepare_environment
- Remove dead code (isinstance check, redundant guards, seen set)
- Inline single-use variables throughout
- Use dict unpacking and short-circuit patterns for cleaner expressions
- Sync frontend/backend-sidecar transport files
@Mng-dev-ai Mng-dev-ai force-pushed the refactor/transports-simplification branch from 5b1d18e to a0b3cd9 Compare February 24, 2026 08:05
@Mng-dev-ai Mng-dev-ai merged commit ad0856d into main Feb 24, 2026
1 of 2 checks passed
Mng-dev-ai added a commit that referenced this pull request Feb 24, 2026
…ation

Simplify transport module and remove unnecessary complexity
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