refactor(proxy): split large functions and modularize proxy.py (#6) - #7
Merged
Merged
Conversation
Decompose the 8 monolithic functions into named, searchable helpers and reorganize proxy.py (721->95 lines) into three modules: - proxy.py - slim entry point (lifecycle, route registration) - proxy_config.py - model metadata, preset generation, CLI config - proxy_request_handlers.py - HTTP handlers, streaming, retry/recovery Functions split: proxy_request, _do_forward (-> _retry_with_recovery, _stream_response), recover_worker (5 helpers), embed_forward, build_config, _load_locked (-> _poll_until_loaded), _transform_event, _readany_once; plus shared router-HTTP helpers (_auth_headers/_post_json/_get_json) and a CLAUDE.md module map. Behaviour-preserving: AST-verified pure move for all unchanged symbols, 9/9 rescue unit tests pass, and live chat/embed smoke tests green (model loads on GPU0, ~37 tok/s). Refs #6 Co-Authored-By: Claude Opus 4.8 <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.
Summary
Refactor for issue #6: decompose the 8 monolithic functions into named, searchable helpers and split the 721-line
proxy.pyinto a slim entry point plus two focused modules. No behaviour changes — pure structural reorganization for code-search clarity.Module split
proxy.py(721 -> 95 lines) — entry point: app lifecycle, route registrationproxy_config.py(new) — model metadata, preset generation, CLI configproxy_request_handlers.py(new) — HTTP handlers, streaming, retry/recoveryFunctions split
proxy_request,_do_forward(->_retry_with_recovery,_stream_response),recover_worker(5 helpers),embed_forward,build_config,_load_locked(->_poll_until_loaded),_transform_event,_readany_once, plus shared router-HTTP helpers (_auth_headers/_post_json/_get_json) and a CLAUDE.md module map.Verification
/v1/models,/chat/props, streaming chat completion (model load + SSE +[DONE]), chat-trace capture, and embeddings all green; model loads on GPU0 at ~37 tok/s.Two behaviour-preserving bugs were caught during review/smoke-testing and fixed in this branch (a dropped
mark_worker_suspect()on mid-stream disconnect, and anasync/awaitmismatch in the new router-HTTP helpers).Closes #6
🤖 Generated with Claude Code