Skip to content

Decompose backend monolith objects and fix port-forward leak - #215

Merged
bbrowning merged 4 commits into
mainfrom
tech-debt-cleanup
Jul 27, 2026
Merged

Decompose backend monolith objects and fix port-forward leak#215
bbrowning merged 4 commits into
mainfrom
tech-debt-cleanup

Conversation

@bbrowning

Copy link
Copy Markdown
Owner
  • Decompose PodmanBackend and PodmanProxyManager into focused modules (session_setup, ca_cert, proxy_credentials), reducing the largest class from ~550 lines to under 200
  • Decompose backends/shared.py monolith into cohesive modules (proxy_config, session_env, labels, naming, ssh)
  • Fix port-forward process leak in start_session — orphaned port-forward processes were left running on session failure
  • Fix minor review findings: stale import placement, unused parameter, duplicate import

bbrowning and others added 4 commits July 23, 2026 17:08
Both classes exceeded coding standards (400-line file limit, 50-line
method limit, 20-method class limit). Extract collaborating classes
while preserving the public API (Backend protocol, __init__.py exports).

PodmanBackend: 729 lines / 38 methods → 402 lines / 20 public methods
PodmanProxyManager: 641 lines → 400 lines

New files:
- session_setup.py: SessionSetup class (credential injection, config
  sync, port URLs, container startup orchestration)
- ca_cert.py: CACertDistributor (CA cert distribution logic)
- proxy_credentials.py: ProxyCredentialManager (secret management)

Key changes:
- Moved session validation helpers to helpers.py as free functions
- Deleted dead _recreate_proxy method (-58 lines)
- Decomposed create_session from 143 lines to ~37 lines
- Inlined _start_port_forward into its 2 callers
- Updated KNOWN_ISSUES.md REFACTOR-003 to reflect resolved items

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…import

- Move TYPE_CHECKING block to end of imports in backend.py
- Remove unused vname parameter from setup_proxy_for_session
- Remove duplicate SessionSetup import in test helper

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
start_session started port forwarding but didn't wrap attach_container
in try/finally, so port-forward processes leaked if attach raised.
Extract _attach_with_port_forward to share the lifecycle with
connect_session, which already had the correct cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Split the 378-line dumping ground into five focused modules:
- labels.py: container label constants
- naming.py: resource naming and backend type helpers
- proxy_config.py: proxy/CA configuration, ProxyCredentials, credentials
- session_env.py: path encoding, session env building, sandbox config
- ssh.py: SSH backend construction

All 42+ import sites migrated to the new module paths. The old
shared.py is removed entirely (no re-export shim needed since all
consumers were updated in this change).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bbrowning
bbrowning merged commit dfceaf5 into main Jul 27, 2026
5 checks passed
@bbrowning
bbrowning deleted the tech-debt-cleanup branch July 27, 2026 20:19
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