[duplicate-code] Duplicate Code Pattern: Launcher Connection Store-and-Record Block
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Bắt đầu tại internal/launcher/launcher.go, ở ba vị trí được liệt kê trong issue: các luồng HTTP và stdio trong getOrLaunchWithConfig, cùng với GetOrLaunchForSession. So sánh các kiểm tra trạng thái đóng, nơi lưu kết nối, cách xử lý khóa và các lời gọi recordStart; issue mô tả những khác biệt cần được giữ lại. Hoàn tất khi phần xử lý lặp lại được hợp nhất và các bài kiểm thử launcher bao phủ luồng đóng và khởi chạy đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Part of duplicate code analysis: #16690
Summary
The launcher repeats the same "lock, re-check closed, store connection, unlock, record start" sequence at three call sites. Each copy must keep the same lock ordering and closed-launcher handling.
Duplication Details
Pattern: Closed-check, store, and recordStart after a launch
-
Severity: Medium
-
Occurrences: 3
-
Locations:
internal/launcher/launcher.go(lines 204-212): HTTP backend path ingetOrLaunchWithConfig. Storesl.connections[serverID].internal/launcher/launcher.go(lines 222-230): stdio backend path ingetOrLaunchWithConfig. Storesl.connections[serverID].internal/launcher/launcher.go(lines 321-330):GetOrLaunchForSession. Stores vial.sessionPool.Set(serverID, sessionID, conn).
-
Code Sample (from lines 222-230):
l.mu.Lock() if l.closed { l.mu.Unlock() conn.Close() return nil, ErrLauncherClosed } l.connections[serverID] = conn l.mu.Unlock() l.recordStart(serverID) return conn, nil
The three copies differ only in the store statement, and the session variant also logs after the store.
Impact Analysis
- Maintainability: Any change to closed-launcher semantics, such as cleanup or logging, must be made in three places.
- Bug Risk: The copies could drift. A missed
conn.Close()on the closed path would leak a backend process. - Code Bloat: About 27 duplicated lines.
Refactoring Recommendations
-
Extract a locked store helper
- Add a method such as
(l *Launcher) storeConnectionIfOpen(serverID string, conn *mcp.Connection, store func()) errorininternal/launcher/launcher.go. It takes the lock, checksl.closed, closesconnon the closed path, runsstore()under the lock, and callsrecordStartafter unlocking. - Pass
storeas a closure:l.connections[serverID] = connfor the two server paths, andl.sessionPool.Set(serverID, sessionID, conn)for the session path. - Estimated effort: low (under 1 hour). Existing launcher tests cover the closed and launch paths.
- Benefits: One place defines the shutdown race handling.
- Add a method such as
-
Keep the lock ordering explicit
- The helper must not call
recordStartwhile holdingl.mu, becauserecordStarttakes its own state lock. Preserve the current post-unlock call.
- The helper must not call
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Parent Issue
See parent analysis report: #16690
Related to #16690
Generated by Duplicate Code Detector · copilot · routed: haiku55 xhigh · ~24 AIC · ⊞ 6.7K · ◷
- expires on Nov 24, 2026, 2:34 AM UTC
- Ngôn ngữ chính
- Go
- Star
- 188
- Fork
- 60
- Merge trung bình
- 6 giờ 50 phút
- Pull request đã merge (30 ngày)
- 177
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của github/gh-aw-mcpg
-
automated documentation maintenance
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
github/gh-aw-mcpg#16717 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
refactor rust-guard
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
github/gh-aw-mcpg#16697 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
go-fan module-review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
github/gh-aw-mcpg#16659 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
automated-analysis code-quality refactoring
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
github/gh-aw-mcpg#16716 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agentic-workflows
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
github/gh-aw-mcpg#16714 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của github/gh-aw-mcpg
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
OneBusAway/maglev#2145 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
priority/medium status/ready type/chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
discobox-ai/discobox#1357 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
TestPseudoLocaleRemote fails now and then: it types the code before the laptop asks for itCó thể đã có người làm @fzn0x đã nhận hôm nay. Đang mởbug priority: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement ui/ux
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
jbigler/railswitch#243 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
go-vulnerability security-scan
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
teslashibe/agent-go#35 ·