Architecture Finding
Type: tech-debt
Affected area: src/pkg/dashboard/contribute_ws.go
contribute_ws.go has grown to 7,175 lines and ~140 functions — the second-largest file in pkg/dashboard after the api_contribute.go split (#7435). It mixes at least eight separable domains in one compilation unit:
- WS transport/session — HandleWS (a single 1,155-line function, lines 3624–4778), sendJSON, writeProtocolPing, closeWithReason, heartbeatLoop, connectionRegistered
- Task-lease persistence — recordLease/renewLease/revokeLease/lookupLease, saveLeasesLocked/loadLeases, reclaimExpiredLeases
- Cooldown & failure bookkeeping — recordTaskFailure*, isTaskInCooldown*, bookReleaseCooldown, failureCooldown*
- Completed/failed task ledgers — load/save Completed/Failed tasks, markTaskCompletedVerdict*, no-work-verdict suppression, no-PR streaks
- Task selection — selectTask (687 lines, 6228–6914), leasedIssueKeys, resumeGateReason
- Task-prompt rendering — buildTaskPrompt*, taskBaseBranch, releaseLineFromTitle, sourceLabel, attributionPromptInstruction (~460 lines of pure functions)
- Token/credential lifecycle — mintScopedToken, maybeRefreshToken, sendTokenRefresh*, deliverTaskCredential, contributorCanPush
- Fleet/ops snapshots — FleetSnapshot, LiveStates, RoleBreakdown, ActiveConnections, CooldownCounts
Impact
Every fix in one domain (e.g., the #7457 identity work, token-refresh changes, lease semantics) rebases against unrelated churn in the same file; reviewers must load a 7k-line context to review a 30-line diff; test-to-code navigation is already split across 20+ contribute_*_test.go files while the code under test sits in one blob. HandleWS at 1,155 lines and selectTask at 687 lines are beyond safe-review size on their own.
Recommendation
Split by domain, verbatim moves, no behavior change — same recipe as the api_contribute.go split (#7435):
- contribute_task_prompt.go (pure prompt rendering — stage 1, PR incoming)
- contribute_leases.go (lease persistence + reclaim)
- contribute_cooldowns.go (cooldown/failure bookkeeping)
- contribute_ledgers.go (completed/failed/no-work/streak persistence)
- contribute_select.go (selectTask + gating helpers)
- contribute_tokens.go (mint/refresh/deliver credential paths)
- Longer term: decompose HandleWS into named phase helpers.
Filed by architect agent (ACMM L5 — hold-gated mode)
🐝 Hive Agent: architect | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown
— hive: agent=architect backend=copilot model=claude-opus-4-6
Architecture Finding
Type: tech-debt
Affected area: src/pkg/dashboard/contribute_ws.go
contribute_ws.go has grown to 7,175 lines and ~140 functions — the second-largest file in pkg/dashboard after the api_contribute.go split (#7435). It mixes at least eight separable domains in one compilation unit:
Impact
Every fix in one domain (e.g., the #7457 identity work, token-refresh changes, lease semantics) rebases against unrelated churn in the same file; reviewers must load a 7k-line context to review a 30-line diff; test-to-code navigation is already split across 20+ contribute_*_test.go files while the code under test sits in one blob. HandleWS at 1,155 lines and selectTask at 687 lines are beyond safe-review size on their own.
Recommendation
Split by domain, verbatim moves, no behavior change — same recipe as the api_contribute.go split (#7435):
Filed by architect agent (ACMM L5 — hold-gated mode)
🐝 Hive Agent:
architect| Instance:hosted-available-oke-11-placeholder-r05x| SHA:unknown— hive: agent=architect backend=copilot model=claude-opus-4-6