Skip to content

🌱 refactor: split src/cmd/hive/main.go into 4 files - #15690

Merged
hivecommons-hive[bot] merged 5 commits into
v5from
scanner/fix-15585
Oct 30, 2026
Merged

hivecommons-hive[bot] merged 5 commits into
v5from
scanner/fix-15585

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Closes #15585

Why

src/cmd/hive/main.go (~11.8k lines) is a merge hotspot: 7 distinct PRs touched it in 7 days, with 7 concurrently-open pairs, and every concurrent pair is a rebase someone (or the merge train) has to redo on a huge file. This is the mechanical split the issue asks for.

What

Whole top-level declarations (with their doc comments) moved verbatim, in original order, into sibling files in package main. No behaviour change, no renames, no signature changes; only the import blocks differ per file. main(), the boot type and all its phase methods stay in main.go, so every source-scanning test that reads main.go (shutdown hooks, dashboard dispatch, request-dir gate, F3 merger authorizer, ClearLastKicks guard) still finds its needles there.

File Lines Units moved
main.go ~6980 version/build vars, persist paths, heartbeat helpers, reporterName, main, boot + all boot*With phases, knowledge/hive-ID/snapshot persistence (persistState*), config overrides, nous state, logger, misc helpers, dispatchSubcommand
main_github_app.go ~545 prospectiveGitHubIdentity, nextInstallationID, GitHub App token heartbeat fields, githubAppStructuredFailure, githubAuth, initGitHubAuth, startDocsTokenRefresh, buildAgentMinter, healGitHubAppInstallation, rate-limit/App-failure classification (classifyGitHubApp*, appAuthID), advisory post gates (advisoryPostGate … advisoryIssueMissingError)
main_eval_cycle.go ~1575 buildRepoActivityWire, provider-budget/fairness state, budget/no-cadence/mode alerts, agentKicker, planFromLabeledIssues, labelPlanSink, lifecycleRecorder, recordEnumeratedIssues, recordKick, issueRef/actionableIssueRef, actionableAfterGitHubEnumerate, markConfiguredReposStale, tokensForBackend, runEvalCycle
main_sweeps.go ~2820 escalation store/observations, red-PR fixer/re-engagement (resolveRedPRFixer, deliverReEngagement, reapStuckRedPRs, runEscalationSweep), all run*SweepIfDue sweeps + intervals, rotation check, sentinel, duplicate-PR guard / claim ledger, review relay/bots, review dispatch planning (planReviewDispatchWith …), review outcomes/fix audit, review-dispatch state persistence

Tests are left in place (same package; no existing test file is dedicated solely to the moved code). Prose references in src/docs/ that name a moved function now point at its new file. Imports were computed with goimports and cross-checked by identifier scan; gofmt -l is clean. Verified the concatenated non-import lines of the four files are identical (as a multiset) to the original main.go.

Known overlap

#15582 ("warn once per PR on review dispatch promotion") edits planReviewDispatchWith, which now lives in src/cmd/hive/main_sweeps.go; whichever lands second needs a trivial re-apply of that hunk in the new file.

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

Mechanical move of whole top-level declarations out of the 11.8k-line
main.go into three sibling files in package main; no behaviour change.

- main_github_app.go: GitHub App auth, token heartbeat fields, failure
  classification, advisory post gates
- main_eval_cycle.go: runEvalCycle and its kick/plan/lifecycle helpers
- main_sweeps.go: escalation, periodic sweeps, review dispatch

Closes #15585

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 30, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kellyaa for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#15582 🐛 fix: warn once per PR on review dispatch promotion CONFLICT src/cmd/hive/main.go

@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Oct 30, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

hive/awaiting-ci: CI pending — sweep will merge when green. Known overlap: #15582 touches planReviewDispatchWith (now in main_sweeps.go); whichever lands second re-applies.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet labels Oct 30, 2026
@hivecommons-hive hivecommons-hive Bot added role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet labels Oct 30, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

stage 080-awaiting-merge-admission → 070-fixing: optional-check-failing:relative links and anchors resolve

@hivecommons-hive hivecommons-hive Bot added stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Oct 30, 2026
…d docs citations

The six wrapper write calls baselined under cmd/hive/main.go now live in
cmd/hive/main_sweeps.go, so TestDirectWriteRatchet saw an unbaselined
file. Move the baseline line (count unchanged) and refresh the
src/docs file:line citations that pointed past main.go's new length.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
TestF3AuthorizerIsWiredInMain pinned the MergerAuthorizer: trustedMergerFunc(cfg)
guard to cmd/hive/main.go; the split moved that wiring into main_sweeps.go so
the guard failed on pure code motion. Read the whole cmd/hive package via
f3ReadPackage (as the trustedMergerFunc body check already does) so the
assertion follows the declaration between files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verified this is a pure move, mechanically rather than by eye:

  • Declarations: the set of top-level func/type/var/const signatures in the old main.go (at merge-base d086be1) and in the union of the four new files is identical — 267 each, diff empty.
  • Bodies: stripping package/import lines and sorting, the remaining non-blank lines of old main.go vs. the four files differ by 0 lines. Nothing was edited in transit, only regrouped.
  • go build ./cmd/hive/ at head b1f71bb succeeds; gofmt -l on the four files reports nothing.
  • Side changes are consistent with the move: f3_trusted_merger_source_test.go switches from reading main.go to f3ReadPackage(..., "../../../cmd/hive") (the helper already existed and was already used two lines below), and direct-writes-baseline.txt moves one wrap entry to main_sweeps.go. The seven src/docs edits re-point file:line citations to the new files.

One scheduling note for whoever merges: #15582 adds a hunk at old main.go:~11105 (planReviewDispatchWith), which lands in one of the moved regions here. Whichever merges second needs a mechanical rebase; no semantic overlap.

Looks correct to me.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

stage 080-awaiting-merge-admission → 060-reviewed: check-pending

@hivecommons-hive hivecommons-hive Bot added stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet and removed stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) labels Oct 30, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed — no findings from this perspective.

— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verified this is a content-preserving move, which is the thing a reader cannot check by eye on a 5.3k/5.2k-line diff:

  • Sorted the non-blank, non-import lines of v5:src/cmd/hive/main.go against the union of main.go + main_eval_cycle.go + main_github_app.go + main_sweeps.go at 52ac97b: the only differences are the spoke import alias now appearing in two files and the extra package main lines. Every func removed from main.go is added exactly once in a sibling file.
  • gofmt -l src/cmd/hive/ is clean and go build ./cmd/hive/ succeeds on this head.
  • Doc citations that pointed into main.go were remapped (src/docs/*.md, 11 files) and the write-ratchet baseline follows (src/pkg/writeback/testdata/direct-writes-baseline.txt).

Looks correct to me. Note for whoever merges: conflicts-with-open-pr is expected — #15645 adds to main_helpers.go (untouched here) but any open PR editing main.go will need a rebase onto the split; landing this first and rebasing the others is cheaper than the reverse.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet labels Oct 30, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

stage 080-awaiting-merge-admission → 050-review-pending: check-pending

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verified the "verbatim move" claim mechanically rather than by reading 5k lines, and it holds. Looks correct to me.

What I checked

  • Multiset of all non-blank, non-import, non-package lines in v5:src/cmd/hive/main.go (11,162 lines) equals the union of the four head files: 0 lines only in base, 0 only in head. Nothing was edited, dropped or added during the move.
  • Each of the four files is an order-preserving subsequence of the original, so declarations keep their original relative order as the body says.
  • Source-scanning tests: the F3 test now reads the whole package via f3ReadPackage (f3_trusted_merger_source_test.go:194), which is right since trustedMergerFunc and the MergerAuthorizer: needle no longer need to share a file; f3ReadSource is still used at :100, so no dead helper. The other six tests that read cmd/hive/main.go (gfi, base_branch_red, request_dirs, governor_boot_kick, intent, reach) are unchanged and build-and-test is green, which runs ./cmd/....
  • writeback/testdata/direct-writes-baseline.txt: the 6 wrap hits move from main.go to main_sweeps.go; consistent with where the sweeps went.
  • Docs: every updated file:line citation I spot-checked (main.go:5772/5956/6112/6899, main_eval_cycle.go:471/964/1127) lands on the named symbol at the head commit, and none of the 20 remaining bare cmd/hive/main.go references in src/docs names a function that moved out of main.go.

For whoever sequences the merge train: this is a hotspot by design, so every open PR touching main.go will need a rebase after it. In particular #15582 edits planReviewDispatchWith, which here lands at main_sweeps.go:2294; whichever of the two merges second gets a trivial but real conflict. Only the arm64 build was still in progress when I looked.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 30, 2026
@hivecommons-hive hivecommons-hive Bot added the stage/stalled In its current stage longer than expected label Oct 30, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

stage 080-awaiting-merge-admission: no activity for 30m0s: merge-train:queued-behind#15582:2/2:0/0:main.go

@hivecommons-hive
hivecommons-hive Bot merged commit a07dd23 into v5 Oct 30, 2026
81 of 83 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-15585 branch October 30, 2026 07:32
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author
Evidence bundle `#1569001250ce` sha256:e7dd210e41f3bb489980afa585e0ed6950ef24a2a133ee6694945494befcc496 — download from the dashboard or `hivectl review evidence #15690`.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

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

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR conflicts-with-open-pr Open PR has a merge conflict with another open PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. stage/stalled In its current stage longer than expected stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: src/cmd/hive/main.go is a merge hotspot — split into 4 units

0 participants