Skip to content

Refactor: Split forwardproxy/server.go into six files by job - #1690

Merged
huang195 merged 2 commits into
rossoctl:mainfrom
huang195:refactor/split-forwardproxy-server-1584
Nov 7, 2026
Merged

huang195 merged 2 commits into
rossoctl:mainfrom
huang195:refactor/split-forwardproxy-server-1584

Conversation

@huang195

@huang195 huang195 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of #1584. This PR moves code only. It changes no signature and no statement.

core/listener/forwardproxy/server.go had 3834 lines and six jobs. Each declaration moves, with its doc comment, to a new file in the same package:

File Job
tunnel.go CONNECT handling, the pre-dial and its memo, tunnelLog
bridging.go The TLS bridge path, its CA and handshake helpers
upgrade.go WebSocket upgrades: decline, splice, relay
identity.go Session identity and attribution
record.go Session rows for requests, responses and refusals
stream.go The SSE relay and the buffered fallback

server.go keeps the Server type, NewServer, the mTLS dialer, serveOutbound and the header helpers. The issue expected about 600 lines. The result is 1322 lines, because serveOutbound alone has 645 lines, and a pure move cannot split one function.

upgrade.go is not in the issue. The WebSocket upgrade code arrived after the audit.

Test changes

No test logic changes.

  • core/listener/parity/dispatch_audit_test.go keys each dispatch site by file name. Six keys now say stream.go in place of server.go.
  • A comment in session_identity_test.go now says identity.go.

How to review

git show --color-moved=dimmed-zebra --color-moved-ws=allow-indentation-change HEAD

The only lines that are not dimmed are the new file headers (package clause and imports), the import block of server.go, and the two test changes.

Checks

  • A script parsed the package before and after the move. It compared every top-level declaration (with its doc comment) and every free comment, as text. The two sets are equal.
  • GOWORK=off go build ./..., go vet and go test ./... pass in core.
  • golangci-lint --max-same-issues=0 --max-issues-per-linter=0 gives the same 149 findings before and after the move.

CodeQL

CodeQL reported 31 new alerts (go/clear-text-logging, go/log-injection). All of them are in files that this PR does not change: inferencerouter, sessionbudget, pipeline/context.go and the parsers. main has none of these alerts. The doc comment of hydrateSession (now in identity.go) records the same result from #1569. When a source line moves, the diff-informed analysis of CodeQL reports its old taint paths as new. The alerts on this PR are now dismissed as false positives.

Assisted-By: Claude (Anthropic AI) noreply@anthropic.com

server.go had 3834 lines and six jobs. This change moves code only.
It changes no signature and no statement. Each declaration moves with
its doc comment to a file in the same package:

- tunnel.go: CONNECT handling, the pre-dial and its memo, tunnelLog
- bridging.go: the TLS bridge path, its CA and handshake helpers
- upgrade.go: WebSocket upgrades (decline, splice, relay)
- identity.go: session identity and attribution
- record.go: session rows for requests, responses and refusals
- stream.go: the SSE relay and the buffered fallback

server.go keeps the Server type, NewServer, the mTLS dialer,
serveOutbound and the header helpers. It has 1322 lines now.
serveOutbound alone has 645 lines, and a pure move cannot split it.

Two test files change, and no test logic changes:

- dispatch_audit_test.go keys each dispatch site by file name. Six keys
  now say stream.go in place of server.go.
- A comment in session_identity_test.go now says identity.go.

Check: a script parsed the package before and after the move. It
compared every top-level declaration (with its doc comment) and every
free comment, as text. The two sets are equal. golangci-lint gives the
same 42 findings before and after the move.

Part of rossoctl#1584.

Signed-off-by: Hai Huang <huang195@gmail.com>
Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
@huang195
huang195 requested a review from a team as a code owner November 7, 2026 00:13
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 29 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 39793d8c-88de-4a3e-a476-e62d66bbb4fd
Commits

Reviewing files that changed from the base of the PR and between dc15da6 and d74b887.

Files selected for processing: 9

  • core/listener/forwardproxy/bridging.go
  • core/listener/forwardproxy/identity.go
  • core/listener/forwardproxy/record.go
  • core/listener/forwardproxy/server.go
  • core/listener/forwardproxy/session_identity_test.go
  • core/listener/forwardproxy/stream.go
  • core/listener/forwardproxy/tunnel.go
  • core/listener/forwardproxy/upgrade.go
  • core/listener/parity/dispatch_audit_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Pure move, verified independently. I parsed core/listener/forwardproxy (non-test files) at base dc15da6b and at head with go/ast: the sorted set of every top-level declaration (with its doc comment) and every free comment is byte-identical before and after. There are no init funcs or //go: directives in the package, and the package-level vars that moved (dialTCP, errIdleCut) have no cross-var initialization dependencies, so file order can't change init order. The two test edits are rename-only: the six dispatch_audit_test.go keys point at stream.go, which is where handleStreamingResponse / streamPassthrough / streamFallbackBuffered now live, and the serveOutbound keys correctly stay on server.go.

Locally: GOWORK=off go build ./..., go vet ./listener/..., and go test ./listener/forwardproxy/... ./listener/parity/... all pass at head.

Non-blocking, outside this diff: the existing line-number pointer forwardproxy/server.go:377 and :880 in core/session/intern.go was already stale on base, so the move doesn't affect it. A follow-up could swap it for function names (serveOutbound, the response-phase snapshot) so the next split doesn't strand it again.

Author: @huang195 (MEMBER, maintainer)
Areas reviewed: Go (forwardproxy package split, parity audit test)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing, except the CodeQL summary check. Its 31 annotations are all in core/plugins/* and core/pipeline/context.go, files this PR doesn't touch. They look like the "change too large" re-attribution the check itself warns about, not new findings. agentop and macOS peerproc jobs were still pending when I checked.

Only stream.go uses the idle read cutoff. The code was in tunnel.go,
and its time limit was in server.go. This change moves both into
stream.go:

- idleReadCloser, idleReader and errIdleCut, from tunnel.go
- streamReadIdleTimeout, from server.go

It moves code only, with each doc comment. It changes no statement.

Part of rossoctl#1584.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Re-review at d74b887d. My earlier approval covered fe20e431. The only new commit, d74b887d, moves streamReadIdleTimeout (from server.go) and idleReadCloser / idleReader / errIdleCut (from tunnel.go) into stream.go, each with its doc comment, and updates the import blocks (sync/atomic dropped from tunnel.go; sync, sync/atomic, time added to stream.go). The move fits: the two idleReader call sites and the errIdleCut match in classifyBrokenStream are all in stream.go, and the only other user is truncated_stream_test.go, which is in the same package.

I re-ran the same go/ast check against base dc15da6b: the sorted set of top-level declarations (with doc comments) and free comments in the package's non-test files is byte-identical at base, at fe20e431 and at d74b887d. errIdleCut is a plain errors.New var with no init dependencies, so moving it to another file can't change init order. No test files changed in this commit, and the dispatch_audit_test.go keys from the first commit still match.

Locally at head: GOWORK=off go build ./..., go vet ./listener/... and gofmt -l are clean, and go test -count=1 ./listener/forwardproxy/... ./listener/parity/... ./session/... passes.

The earlier review had no findings to address. Its one non-blocking note (the stale server.go:377 and :880 pointer in core/session/intern.go) is outside this diff and still applies as an optional follow-up.

Author: @huang195 (MEMBER, maintainer)
Areas reviewed: Go (forwardproxy package split, parity audit test)
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: all checks passing (CodeRabbit and Spellcheck skipped)

@huang195
huang195 merged commit 2fa0eb1 into rossoctl:main Nov 7, 2026
42 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 7, 2026
@huang195
huang195 deleted the refactor/split-forwardproxy-server-1584 branch November 7, 2026 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants