Skip to content

Refactor duplicated helper logic for session logging, rate-limit parsing, and routed server setup#8762

Draft
lpcox with Copilot wants to merge 4 commits into
mainfrom
copilot/refactor-semantic-function-clustering
Draft

Refactor duplicated helper logic for session logging, rate-limit parsing, and routed server setup#8762
lpcox with Copilot wants to merge 4 commits into
mainfrom
copilot/refactor-semantic-function-clustering

Conversation

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This change addresses several small but recurring organization issues surfaced by the semantic clustering analysis: duplicated session-ID logging logic, split GitHub rate-limit parsing, a trivial logger alias, a misplaced tool-classification helper, and HTTP server factory functions split across files. The intent is to reduce duplication and make these helpers easier to find and evolve without changing behavior.

  • Session ID log formatting

    • Added util.FormatSessionIDForLog as the shared log-safe session ID formatter.
    • Updated server and launcher logging paths to use the same truncation behavior, so launcher logs no longer emit full session IDs while server logs keep existing semantics.
  • GitHub rate-limit parsing

    • Moved reset-time parsing into internal/githubhttp/rate_limit.go.
    • Kept both parsing concerns together:
      • ParseRateLimitResetHeader for X-RateLimit-Reset
      • ParseRateLimitResetFromText for MCP/tool error text such as rate reset in 42s
    • Updated server-side circuit-breaker logic and tests to consume the shared parser.
  • Helper placement and indirection cleanup

    • Removed the trivial truncateSanitized wrapper and used util.Truncate directly at call sites.
    • Moved IsSingularReadTool from internal/difc to internal/mcp, which better matches its role as a tool-naming heuristic rather than DIFC logic.
    • Relocated CreateHTTPServerForRoutedMode into internal/server/http_server.go so HTTP server factory functions live together.
  • Targeted test updates

    • Moved and preserved edge-case coverage for IsSingularReadTool under internal/mcp.
    • Updated session logging and rate-limit parsing tests to follow the shared helpers and preserve previous behavioral coverage.

Example of the new shared session-ID formatting path:

func FormatSessionIDForLog(sessionID string) string {
	const sessionIDLogMaxLen = 8
	if sessionID == "" {
		return "(none)"
	}
	return Truncate(sessionID, sessionIDLogMaxLen)
}

Copilot AI changed the title [WIP] Refactor code organization in semantic function clustering analysis Refactor duplicated helper logic for session logging, rate-limit parsing, and routed server setup Jul 6, 2026
Copilot finished work on behalf of lpcox July 6, 2026 03:47
Copilot AI requested a review from lpcox July 6, 2026 03:47
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] Semantic Function Clustering Analysis: Code Organization Opportunities

2 participants