Skip to content

[architect] pkg/dashboard/contribute_ws.go god file: 7,175 lines, 140+ funcs, 8+ domains in one file (incl. 1,155-line HandleWS, 687-line selectTask) #7491

Description

@hivecommons-hive

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:

  1. WS transport/session — HandleWS (a single 1,155-line function, lines 3624–4778), sendJSON, writeProtocolPing, closeWithReason, heartbeatLoop, connectionRegistered
  2. Task-lease persistence — recordLease/renewLease/revokeLease/lookupLease, saveLeasesLocked/loadLeases, reclaimExpiredLeases
  3. Cooldown & failure bookkeeping — recordTaskFailure*, isTaskInCooldown*, bookReleaseCooldown, failureCooldown*
  4. Completed/failed task ledgers — load/save Completed/Failed tasks, markTaskCompletedVerdict*, no-work-verdict suppression, no-PR streaks
  5. Task selection — selectTask (687 lines, 6228–6914), leasedIssueKeys, resumeGateReason
  6. Task-prompt rendering — buildTaskPrompt*, taskBaseBranch, releaseLineFromTitle, sourceLabel, attributionPromptInstruction (~460 lines of pure functions)
  7. Token/credential lifecycle — mintScopedToken, maybeRefreshToken, sendTokenRefresh*, deliverTaskCredential, contributorCanPush
  8. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/architectCreated or modified by the architect agentarchitectureApproved by a Hive merger/owner for auto-merge on green CIhelp wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.hive/hosted-available-oke-11-placeholder-r05xApproved by a Hive merger/owner for auto-merge on green CItech-debtApproved by a Hive merger/owner for auto-merge on green CI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions