Repository navigation
✨ feat(hub): carry bounded activity events through the heartbeat and hub ring - #16049
Conversation
…hub ring Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. hive/awaiting-ci: pushed f0a524d — 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. Review findings from Correctness review (read at head Low — spoke clock step-back across a restart silently loses events. Verified: ring is only touched under Review findings from CI is red for a real reason in this PR's own test, and it is deterministic — it failed identically on all three reruns of
This is a test bug, not a production bug: real Everything else I read checks out against the tree:
Once the test input is fixed this should be mergeable; I have no other findings. Review findings from Read the tree at Why CI is red —
What I verified as correct
Body/code mismatch (wording only) The PR body says the hub ring "holds the last 1,000 events per hive"; the code and changelog say fleet-wide ( Related: #16044 moves the |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of No conflicting open PRs or same-file overlaps were found. |
The coverage gate failed with hubactivity at 76.3% (floor 90%) because events.go landed without tests. Cover NormalizeEvent (bounding, UTC normalization, every rejection branch), SanitizeEvents (dedupe by Seq, ordering, MaxEvents cap with oldest-dropped disclosure, input not modified) and ClampCount. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Security perspective (reviewed at head 53d57884; the dispatched head 9da07a3e had already been superseded).
No in-scope blocker. Event ingest sits behind the same per-hive bearer as the digest (pkg/hub/activity_update.go:62-73, pkg/hub/server.go:2737), hubactivity.Sanitize builds a fresh digest so raw spoke events never reach the stored block (pkg/hubactivity/hubactivity.go:164-189), and eventsSnapshot(ids) is only called with the ids visibleActivityHives already authorized (pkg/hub/activity.go:371-377, pkg/hub/activity_events.go:120-137). Two low notes:
-
Private events outlive a
share_privateopt-out (low, in-scope).observeLockedskips private items only at creation time (pkg/hub/spoke/activity_publisher.go:265,:283); events already buffered whileshare_privatewas on stay inp.eventsand are resent on every build (:177) until an ack covers them (:228). Against a pre-#15964 hub that never acks, they are re-sent indefinitely after the operator turned sharing off. Suggested fix: inbuild, when!opts.SharePrivate, drop buffered events withPrivatebefore cloning them intod.Events.TestActivityEventsExcludePrivateItemsUnlessShared(activity_events_test.go:166) only covers a fixed setting, not the toggle. -
One spoke can evict the whole fleet's events (low, out-of-scope — the fleet-wide 1,000 ring is what #15964 specifies). The ring is shared across hives and trimmed oldest-first (
pkg/hub/activity_events.go:23,:79-80); a single authenticated spoke sending 200 fresh-seq events per 15 s update empties everyone else's events in ~5 updates. Items have no equivalent shared resource (per-hive 250 ceiling). A per-hive fair-share cap inside the ring would close this; backlog material, not a blocker here.
Minor: the PR body says the hub ring holds "the last 1,000 events per hive"; the code and the changelog fragment say fleet-wide (activity_events.go:21-23). The code matches the issue; the body wording is off.
— hive: agent=adjudicator-4 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Root cause: the test feeds One-line fix matching the test's intent (tokens are case-insensitive on the wire): // pkg/hubactivity/events.go, NormalizeEvent
out.Type = oneOf(strings.ToLower(cleanToken(e.Type)), allowedEventTypes)
...
out.Kind = oneOf(strings.ToLower(cleanToken(e.Kind)), allowedKinds)If uppercase tokens are instead meant to be rejected, change the test fixture to The other red checks on this head ( — quality agent (did not push: 🐝 Hive Agent: — hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
…e validation Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Correctness delta re-review (53d5788 → f0a524d; read src/pkg/hubactivity/events.go, src/pkg/hub/activity_events.go, src/pkg/hub/spoke/activity_publisher.go, src/pkg/hub/activity_events_test.go at head).
- Fixed:
NormalizeEventnow case-foldsType/Kind(events.go:69,74), soTestNormalizeEvent_BoundsAndValidates(events_test.go:13-27," STAGE\t"/"PR"→stage/pr) passes. - Still present (in-scope, low): hub
events_droppeddouble-counts a spoke's cumulative disclosure. The spoke'seventsDroppedis cumulative until an ack coverssentMaxSeq(activity_publisher.go:178-183, 232-236), so a resend after a lost ack carries the same drops again. The hub adds it to its running total whenever the batch has any fresh event (activity_events.go:66-78), contradicting its own comment at:49-51("…or its drops counted twice").TestActivityEventRing_DedupAndAcknow bakes this in: the spoke drops 3 events, resends withEventsDropped = 3plus one new event, and the test asserts 6 (activity_events_test.go:137-156). Fix: track the spoke's last disclosed count per hive and add only the increase over it (or reset the hub's per-hive count to the disclosed value), and flip the test expectation to 3. - docs-currency note (old-hub re-send behaviour,
activity_publisher.go:365) is outside this perspective and the delta does not touch that file.
— hive: agent=adjudicator-4 backend=copilot model=claude-fable-5.1 copilot=1.0.88
The spoke's events_dropped is cumulative until an ack covers its latest build, so a batch resent after a lost ack restates the drops the hub already counted. The ring now records the count each counted batch claimed per hive and, when the batch holds an already-acknowledged event (proof the spoke never saw the ack), adds only the increase over it; a batch of only new events marks a spoke that trimmed and reset, so its disclosure counts in full. The dedup test now asserts 3 drops for 3 real drops across the resend, and covers a grown resend and a post-ack batch. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Correctness delta re-review (read f0a524d…e3dbf24: src/pkg/hub/activity_events.go, activity_events_test.go, plus the spoke publisher and hubactivity at head).
Still present — src/pkg/hubactivity/events_test.go:18-19,33 makes test (rest 2/4) red at this head. The delta did not touch this file. TestNormalizeEvent_BoundsAndValidates feeds From: "Needs Review!" / Stage: "Actionable" and asserts got.From != "" / got.Stage != "", but NormalizeEvent routes both through slug() (events.go:76-77), which is a validator: it returns the input only when it matches slugPattern = ^[a-z0-9][a-z0-9_.-]{0,63}$ (hubactivity.go:52, :298-304) and "" otherwise. Reproduced against the head package: ok=true type="stage" kind="pr" from="" stage="". The f0a524d fix (lower-casing Type/Kind) addressed the :25 failure, not this one. Fix in the test: use slug-shaped inputs ("needs-review", "actionable"), or assert the empty-on-non-slug behaviour explicitly. Production callers already pass slugs.
Delta — restated drop accounting (activity_events.go:72-94) is correct for the case it tests; one bounded gap. restated is inferred from a duplicate Seq (:74-79), which matches the spoke's semantics: eventsDropped is cumulative and only reset when an ack covers sentMaxSeq (spoke/activity_publisher.go:228-236). If an ack is lost and the spoke then buffers more than MaxEvents (200) new events before its next accepted beat, the resend contains no previously-seen Seq (the old ones were trimmed at :309-311), so restated stays false and the still-cumulative disclosure is added in full — over-counting the earlier batch's drops once. Disclosure-only, bounded by one batch's count, and undetectable from the hub side without more wire state, so advisory; worth a comment at :74 and a test if you want the limit on record.
Previous intent-alignment note (PR body "1,000 events per hive" vs fleet-wide ring at activity_events.go:21-23) is unchanged; not re-filed here.
— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88
slug() only accepts lowercase [a-z0-9][a-z0-9_.-]* so "Needs Review!" and "Actionable" correctly normalize to ""; the test asserted the opposite. Exercise trimming with padded valid slugs and assert that invalid slugs blank the field without dropping the event. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
…turnover A resend whose earlier events were already trimmed for room carries no repeated Seq, so the hub cannot tell the spoke's cumulative disclosure restates drops already counted and adds them once more. Document the limit at the detection site and pin the bounded over-count in a test. Hive-Fix-Attempt: 2/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Closes #15964
Part of #15861 (RFC by @hanthor; follows #15951 and #15963)
Why
The hub Activity Monitor from #15951/#15963 shows where each item is now, but nothing about how it got there. RFC #15861 §A/§B asks the hub board to animate stage hops and show merge toasts like the spoke Activity Monitor does. It also requires that this stays bounded, disclosed, memory-only and polled by ETag (no SSE), and that a viewer never learns about items they are not authorized to see. Without events in the activity block, the hub can only diff whole digests. Diffing whole digests loses merges, because a merged PR just disappears from the item list, and it misses any hop that happens between two polls.
What shipped (in this PR)
pkg/hubactivity): theactivityblock has newevents(opened/stage/merged, each with a monotonicseq) andevents_droppedfields. Events are excluded from the content etag, and an unchanged marker can carry them, so the existing etag handshake is unchanged.recently_mergedlist. The first snapshot only sets the baseline. It buffers up to 200 events, drops the oldest first and reports the count inevents_dropped. Events are trimmed only when a response's newactivity_events_ackcovers them. Private-repo items produce no events unlessshare_privateis on.heartbeat_omitalso applies to events.GET /api/hub/activityreturnsevents[]only for hives the viewer is authorized for, and copies them out per hive before aggregation. Events are part of the response body, so new events change the ETag./api/hub/activityafter one heartbeat.hub-server.md,telemetry.md) and a changelog fragment.Status
The PR is open and CI has not finished. Nothing is deployed or activated. Hubs and spokes only exchange events once both run this code. Older hubs ignore
events, and older spokes never send them. Against an older hub, a spoke's buffer stays capped at 200 because it never receives an ack.Overlap with #16044
#16044 moves the
s.activity.record/forgetcall sites inserver.goand adds a test at the end ofactivity_test.go. This PR leaves those lines alone. The changes are limited to the store internals inactivity.go, one addedresp.ActivityEventsAckline nearresp.ActivityETag, and new files. Event purging is insideactivityStore.forget, so it follows wherever #16044 moves the call.— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 requested_by=@hanthor