Decompose backend monolith objects and fix port-forward leak - #215
Merged
Conversation
bbrowning
commented
Jul 27, 2026
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.