Skip to content

🐛 Activity Monitor: celebrate externally merged PRs with bee + toast naming the merger - #16659

Merged
hivecommons-hive[bot] merged 2 commits into
v5from
fix/merge-celebration-external
Nov 4, 2026
Merged

hivecommons-hive[bot] merged 2 commits into
v5from
fix/merge-celebration-external

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Fixes #16658

Problem

An approved PR row (#16644, merged by @clubanderson via gh pr merge --admin --squash) disappeared from the Activity Monitor with no bee fly-off and no merge toast. Rows hive merges itself celebrate every time.

Root cause

  1. recently_merged was built only from audit pr_merged lines. Hive's own merge writes one synchronously in the pass that evicts the row; an external merge's line arrives minutes later via the PR poller's settle scan, after the row has already gone.
  2. webhookItemHint for issue_comment/issues on a PR never read issue.pull_request.merged_at, so github-actions' comment 10 s after the merge produced a closed-unmerged snapshot → recently_closed → the SPA toasted "closed" and deleted the PR's open observation; the merge fact arriving later was no longer a false→true transition.
  3. recently_merged named no merger.

Fix

Server

  • stageTrackerMergedSince: audit pr_merged lines ∪ merged ledger (MergedLedger.Since), deduped (incl. short-vs-qualified repo), each entry with merged_by.
  • webhookItemHint: issue hints read issue.pull_request.merged_at.
  • noteClosedSnapshots skips a PR the ledger holds merged; new forgetClosedSnapshots withdraws a closed listing a later merged snapshot contradicts (wired in applyWebhookItemSnapshots).

Client (tracker-merged.js)

  • A closed key stays false instead of being deleted, so closed→merged still celebrates once.
  • Banner head: #16644 merged by @clubanderson / #16645 merged by 🐝 hive (stageTrackerMergerText, stageTrackerMergedByOf fall back to recently_merged / merged.recent / terminal facts).
  • Closed-not-merged keeps the quiet #N closed · reason toast.

Tests

  • Go: TestStageTrackerRecentlyMergedAnyMerger, TestStageTrackerClosedSnapshotNeverOutranksMerge, TestWebhookItemHintIssueCommentOnMergedPR.
  • Node: TestStageTrackerExternalMergeCelebrateNode — hive-merged and externally-merged ⇒ bee + banner naming the merger; closed ⇒ quiet toast, no bee/banner; closed-then-merged ⇒ exactly one celebration.

Changelog: changelog.d/fixed-merge-celebration-external.md.

@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 4, 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 hanthor 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 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
#16660 🐛 fix: label narrow dashboard navigation same files src/pkg/dashboard/static/index.html
#16637 🐛 Stage tracker: say CI running (not activity unknown) when checks are still pending same files src/pkg/dashboard/static/index.html

@hivecommons-hive

hivecommons-hive Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

@clubanderson this PR is held at stage/071-needs-author and the hive will not merge it yet.

Failing checks:

  • runtime-tests

Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path.

Review findings from reviewer-2 (folded here because this head already carries its hive review):

Read the diff against the tree at daf7824 (server + client); this looks correct to me.

What I verified

  • stage_tracker.go stageTrackerMergedSince: audit ring ∪ MergedLedger.Since, deduped on (repo, number) with the short-name fallback (shortIndex) only when the audit repo was never qualified. Since (merged_ledger.go:404) walks entries newest→oldest and breaks on MergedAt.Before(since); entries are kept oldest-first by sortLocked after every Record/upsertLocked, so the early exit is sound. Since holds only l.mu and invokes no callbacks, so no lock inversion with onNew → invalidateStageTrackerCache.
  • stage_tracker_recently_closed.go: noteClosedSnapshots consults ledger.Has(qualify(snap.Repo), n) — same qualifier recordMergedSnapshots (merged_ledger_server.go:107) keys the ledger with, and applyWebhookItemSnapshots runs record → forget → note in that order, so a batch carrying both a merged and a closed read of one PR lands as merged.
  • webhook_cache.go:742: Merged on the issues/issue_comment hint is now read from issue.pull_request.merged_at; WebhookItemHint.Closed() already ORs Merged, so nothing downstream needed to change.
  • tracker-merged.js: dropping delete next[k] is safe — stageTrackerCarryOpen already carries false keys forward, stageTrackerNewlyClosed skips _stageTrackerClosedNoted keys so the quiet toast still fires once, and stageTrackerNewlyMerged is strictly false → true, so a close later corrected to a merge celebrates exactly once.
  • static/index.html matches static-src for the new symbols; go build ./pkg/dashboard ./pkg/github clean; node --test stage_tracker_merge_banner_countdown.test.js 10/10 pass.

Info, not a defect: closed PR keys now stay in _stageTrackerMergeState (and the sessionStorage record) as false for the life of the tab, exactly as merged keys already stay true. Bounded by session lifetime; just noting it is a deliberate change from the prior prune-on-close.

Evidence bundle `#16659daf7824` sha256:48cbeddae720a8e57e034407da0230802862f62521d130a0a44f0d2317d072d1 — download from the dashboard or `hivectl review evidence #16659`.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

CI diagnosis (from the hive; it can't push to a human-authored branch, so this needs to be applied by the author)

runtime-tests → "Dashboard helper tests" fails 7 subtests in src/pkg/dashboard/stage_tracker_merge_banner_countdown.test.js (217–223), all with stageTrackerMergedByOf is not defined / stageTrackerMergerText is not defined. Cause is this PR's diff, not infra: stageTrackerMergeBanner / stageTrackerMergeBannerText in tracker-merged.js now call the two new helpers, but the test harness builds its VM context from an explicit pick(...) list and never extracts them. build-and-test is red only because it aggregates the runtime lane. The default branch (v5) is green.

Fix in stage_tracker_merge_banner_countdown.test.js, in the src array (next to the other pick(...) lines, before stageTrackerMergeBannerText):

   pick(/function stageTrackerPrimaryRepo\(\) \{[^\n]*\n/, 'stageTrackerPrimaryRepo'),
+  pick(/function stageTrackerMergerText\(by\) \{[\s\S]*?\n    \}\n/, 'stageTrackerMergerText'),
+  pick(/function stageTrackerMergedByOf\(key, d\) \{[\s\S]*?\n    \}\n/, 'stageTrackerMergedByOf'),
   pick(/function stageTrackerMergeBannerText\(b, nowMs\) \{[\s\S]*?\n    \}\n/, 'stageTrackerMergeBannerText'),

stageTrackerMergedByOf is guarded by typeof _stageTracker !== 'undefined', so no extra stub is needed; if the body references anything else from the file, add a pick for it the same way. The pre-existing stub function stageTrackerMergedByText() { return ""; } is unrelated and can stay.


🐝 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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The red runtime-tests / build-and-test lanes are caused by this diff, and the fix is small.

What fails: Dashboard helper tests subtests 217–222 (stage_tracker_merge_banner_countdown.test.js) with stageTrackerMergedByOf is not defined and stageTrackerMergerText is not defined (job 126827365954).

Mechanism: that harness builds its own sandbox from a hand-picked list of functions (stage_tracker_merge_banner_countdown.test.js:58-80) and stubs stageTrackerMergedByText at line 62. This PR adds two new calls inside functions the harness does extract:

  • static-src/js/tracker-merged.js:1186 — stageTrackerMergeBannerText now calls stageTrackerMergerText(b.merged_by)
  • static-src/js/tracker-merged.js:1205 — stageTrackerMergeBanner now calls stageTrackerMergedByOf(b.key, …) when info.merged_by is empty and !b.preview

Neither helper is picked or stubbed in the harness, so new Function(...) throws at the first banner. (The Go-side stage_tracker_cues_test.go:46-47 does pull them in via jsFunc, which is why only the node lane fails.)

Suggested fix: add pick(/function stageTrackerMergerText\(by\) \{[\s\S]*?\n \}\n/, …) and pick(/function stageTrackerMergedByOf\(key, d\) \{[\s\S]*?\n \}\n/, …) to the harness list (or a one-line stub for each next to the stageTrackerMergedByText stub at line 62). The stageTrackerMergedByOf body also reads _stageTrackerTerminalFacts, which it already guards with typeof … !== 'undefined', so no further globals are needed.

I did not review the rest of the XL diff (ledger / webhook cache / Go tracker changes) in this pass; this comment is limited to the CI failure.

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

…naming the merger

An approved PR merged by hand (gh pr merge --admin --squash) vanished
from the tracker with no bee fly-off and no merge toast, while the
hive's own merges celebrated.

Root cause: recently_merged carried only audit pr_merged lines, which
the hive writes synchronously for its own merges but which an external
merge gets only after the PR poller's settle scan (minutes) — the row
was already gone. Worse, webhookItemHint for issue_comment/issues on a
PR never read issue.pull_request.merged_at, so a bot comment seconds
after the merge produced a closed-unmerged snapshot: the SPA toasted
"closed" and deleted the PR's open observation, forfeiting the
celebration for good.

Fix: recently_merged is the union of audit lines and the merged ledger
(webhook/closed-sweep merges by anyone), deduped, each carrying
merged_by; issue hints read merged_at; a closed snapshot never outranks
a merge in recently_closed. The SPA keeps a closed key comparable so a
later merge still celebrates, and the banner head names the merger
("merged by @clubanderson" / "merged by 🐝 hive"). Closed-not-merged
keeps the quiet toast. Go + node tests cover both exits.

Fixes #16658

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
…rness

The countdown harness lifts stageTrackerMergeBanner out of index.html by
regex but did not lift the new stageTrackerMergerText/stageTrackerMergedByOf
it now calls, so runtime-tests failed with ReferenceError. Lift them, and
add unit cases for the merger text (@login / 🐝 hive) and repo-scoped
merged_by resolution.

Fixes #16658

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
@clubanderson
clubanderson force-pushed the fix/merge-celebration-external branch from fe0e43a to daf7824 Compare November 4, 2026 22:09

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Read the server side against the tree at daf7824, then the client. The server half looks correct to me; one client regression worth fixing before this lands.

Server — looks correct.

  • MergedLedger.Since (src/pkg/dashboard/merged_ledger.go:404-421) breaks on the first entry before since; that is safe because Record calls sortLocked() on every write (merged_ledger.go:213-214), so entries is always ascending by MergedAt. Has reads l.index, which sortLocked/pruneLocked both rebuild.
  • noteClosedSnapshots looks up ledger.Has(qualify(snap.Repo), …) (stage_tracker_recently_closed.go:43) and recordMergedSnapshots writes with qualify(snap.Repo) too (merged_ledger_server.go:107), so the key forms agree.
  • applyWebhookItemSnapshots orders recordMergedSnapshots → forgetClosedSnapshots → noteClosedSnapshots (webhook_tracker_refresh.go:399-401), so a merged snapshot both withdraws a stale closed listing and blocks a new one in the same pass.
  • webhookItemHint now reads issue.pull_request.merged_at (src/pkg/github/webhook_cache.go:745-746); p.Issue.PullRequest is a *json.RawMessage (webhook_cache.go:529), which webhookIssuePullRequestMerged handles.

Client — one regression (medium): the "closed" toast now repeats on every reload within the 30‑minute window.

  • src/pkg/dashboard/static-src/js/tracker-merged.js:123 keeps the closed key as false in _stageTrackerMergeState instead of deleting it (intended, so closed→merged can still flip false→true).
  • That state is persisted: stageTrackerReconcileMerges writes { state: _stageTrackerMergeState, delivered: _stageTrackerZapped } to sessionStorage (tracker-merged.js:100) and restores state on the next load (tracker-merged.js:82-93).
  • But the repeat guard _stageTrackerClosedNoted is a plain in-memory object (tracker-merged.js:172) and is not in that record — it is reset to {} on reload.
  • stageTrackerNewlyClosed (tracker-merged.js:276-287) then sees prevState[key] === false, rawState[key] !== true, not in items, noted[key] unset, and d.recently_closed still lists the PR (server keeps it for stageTrackerMergedWindow = 30 min, stage_tracker.go:154) → the key is returned again and stageTrackerClosedToast fires again.

Before this PR delete next[k] meant the key was absent from the persisted state, so prevState[key] !== false short-circuited the check after a reload. Net effect: for 30 minutes after any non-merge close, every F5 on the tracker re-toasts "#N closed · reason". The merge path already solves this exact problem for merges by persisting delivered (_stageTrackerZapped); the simplest fix is to persist _stageTrackerClosedNoted in the same session record (and restore it alongside delivered), or to also treat a _stageTrackerZapped-style delivered set for closes. TestStageTrackerExternalMergeCelebrateNode does not exercise a reload, so it does not catch this — a case that seeds sessionStorage with state[key]=false and asserts zero closed toasts would fail today and pass with the fix.

Everything else in the client diff (stageTrackerMergerText, stageTrackerMergedByOf, banner head) read fine; the d.recently_merged ∪ d.merged.recent lookup correctly falls back to short-vs-qualified repo matching.

The PR body's claims match the diff; no scope beyond #16658.

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

@hivecommons-hive
hivecommons-hive Bot merged commit 0a7212e into v5 Nov 4, 2026
83 of 84 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the fix/merge-celebration-external branch November 4, 2026 22:16
@hivecommons-hive

Copy link
Copy Markdown
Contributor

merged by Hive trusted-author auto-merge: author @clubanderson holds role owner and GitHub permission admin on repo; CI green at daf7824.

@github-actions

github-actions Bot commented Nov 4, 2026

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

dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Activity Monitor: externally merged PR row vanishes with no bee fly-off and no merge toast

1 participant