Skip to content

refactor(proxy): split large functions and modularize proxy.py (#6) - #7

Merged
Hrt-Htk merged 1 commit into
mainfrom
refactor/issue6-split-large-functions
Jun 15, 2026
Merged

refactor(proxy): split large functions and modularize proxy.py (#6)#7
Hrt-Htk merged 1 commit into
mainfrom
refactor/issue6-split-large-functions

Conversation

@Hrt-Htk

@Hrt-Htk Hrt-Htk commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

Refactor for issue #6: decompose the 8 monolithic functions into named, searchable helpers and split the 721-line proxy.py into 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 registration
  • proxy_config.py (new) — model metadata, preset generation, CLI config
  • proxy_request_handlers.py (new) — 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.

Verification

  • AST-verified pure move: every symbol carried into the new modules is byte-identical except the 3 intentionally edited.
  • Unit tests: 9/9 tool-call rescue tests pass.
  • Live smoke test (production stack restarted onto this code): health, /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 an async/await mismatch in the new router-HTTP helpers).

Closes #6

🤖 Generated with Claude Code

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>
@Hrt-Htk
Hrt-Htk merged commit 26b5c45 into main Jun 15, 2026
1 check passed
@Hrt-Htk
Hrt-Htk deleted the refactor/issue6-split-large-functions branch June 15, 2026 11: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.

refactor: simplify large functions & improve code-search clarity (follow-up to #2)

1 participant