Skip to content

🐛 fix(hub): purge a hive's activity digest when it is removed from the registry - #16007

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

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

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Closes #16002

The memory-only retention promise of #16005 should hold when a hive is deleted, not only after 24h of silence. removeRegistryEntry is the common choke point for every removal path, so it now calls a new nil-safe activityStore.forget(id). Tests cover forget (unknown id, nil store) and the registry-removal purge.

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

…e registry

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 31, 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 clubanderson 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 31, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

hive/awaiting-ci: CI pending — sweep will merge when green.


🐝 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

@github-actions

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.

No conflicting open PRs or same-file overlaps were found.

@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 role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 31, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Hive filed review findings that do not block this PR as backlog items:

Cap: 10 backlog item(s) per PR per day.

@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.

Security perspective — no blocker. Reviewed head b6c1520.

activityStore.forget (src/pkg/hub/activity.go:118-127) is nil-safe, takes only the leaf lock, and is wired into the single removal choke point removeRegistryEntry (src/pkg/hub/server.go:4284), which covers the saas_hives_api and pullonly_upgrade callers. Tests cover the purge and the unrelated-hive guard.

Advisory (low, not blocking): the purge is best-effort against a concurrent heartbeat. handleHeartbeat accepts the beat into the registry under s.mu, releases it, and only then calls s.activity.record (src/pkg/hub/server.go:2733-2737). A beat that passes the registry check immediately before removeRegistryEntry runs can re-insert the digest after forget (src/pkg/hub/server.go:4284) and after the registry entry is gone, leaving it in memory for up to activityForgetAfter as before. Exposure is bounded — visibleActivityHives only yields registry hives, so the orphan is not readable via GET /api/hub/activity — but if the retention promise is meant to be strict, record would need to re-check registry membership (or the heartbeat would need to record under s.mu). Moving forget after the s.mu critical section narrows but does not close the window, so this is noted for follow-up rather than requested here.

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

@hivecommons-hive

hivecommons-hive Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

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

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

Intent alignment (#16002) — read at head b6c1520.

The fix is right where it lands: activityStore.forget (src/pkg/hub/activity.go:120-127) is nil-safe and lock-correct, and removeRegistryEntry (src/pkg/hub/server.go:4284) now purges the digest, with tests in activity_test.go and delete_hive_registry_test.go.

One removal path is missed. The PR body says removeRegistryEntry "is the common choke point for every removal path", but handleRegistryDelete (DELETE /api/hub/registry/{id}, src/pkg/hub/server.go:1741, 4342-4364) splices the hive out of s.registry.Hives inline (4349-4357) and never calls removeRegistryEntry — so it still leaves the deleted hive's digest in memory for up to 24h, which is exactly what #16002 ("not purged when a hive is removed from the registry") asks to close. It already mirrors forgetUncollectibleUpgrade(id) at 4348; add s.activity.forget(id) beside it (or route the handler through removeRegistryEntry) and extend the test.

Advisory, not blocking: forget runs before s.mu.Lock() and the heartbeat handler records the digest only after releasing s.mu (server.go:2731-2737), so a heartbeat racing a delete can re-insert a digest after the purge. That is inherent to the leaf-lock design and pre-dates this PR; the next heartbeat from a non-hosted hive legitimately re-registers it anyway.

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

Correctness review (head b6c1520)

1. Admin registry delete still leaks the digest — in-scope. The PR body says removeRegistryEntry is "the common choke point for every removal path", but handleRegistryDelete (src/pkg/hub/server.go:4342-4367, routed at server.go:1741 as DELETE /api/hub/registry/{id}) removes the entry in-place with its own copy of the loop (server.go:4350-4357) and never calls removeRegistryEntry — so it also never reaches the new s.activity.forget(id) at server.go:4284. A hive removed by an admin through that endpoint keeps its last digest in hub memory for up to activityForgetAfter (24h), which is exactly the retention gap #16002 asks to close "on the registry-removal path". Fix: add s.activity.forget(id) next to s.forgetUncollectibleUpgrade(id) at server.go:4348 (or have the handler delegate to removeRegistryEntry), and extend the test so the admin path is covered too.

2. Advisory (low): forget runs before the registry mutation under s.mu (server.go:4284 vs 4285-4293), and the heartbeat handler records the digest only after releasing s.mu (server.go:2737). A heartbeat interleaved with the delete can therefore re-record the digest after it was forgotten; the entry then stays until the 24h sweep. Window is one heartbeat and a non-hosted spoke re-registers itself anyway, so not blocking — but ordering forget after the registry removal would shrink it.

forget itself (activity.go:120-127) is correct: leaf lock, nil-safe, delete on a nil map is a no-op; TestActivityStoreForget and the TestRemoveRegistryEntryPersistsSynchronously additions cover the implemented path.

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

The forget method and its wiring into removeRegistryEntry look correct to me — but the PR body's premise that removeRegistryEntry is "the common choke point for every removal path" does not hold, so the fix misses one path.

Finding (low): admin registry delete still leaves the digest in memory for 24h

  • src/pkg/hub/server.go:4342-4368 — handleRegistryDelete (routed at server.go:1741 as DELETE /api/hub/registry/{id}) does not call removeRegistryEntry. It repeats the removal inline: forgetUncollectibleUpgrade(id), then splices s.registry.Hives under s.mu, then saveRegistryNow(). Nothing there calls s.activity.forget(id).
  • Consequence: a hive removed by a hub admin keeps its last digest in activityStore.byHive until forgetOldLocked evicts it after activityForgetAfter (24h) — exactly the retention the issue ([reviewer] Review backlog (security): activityStore is not purged when a hive is removed from the registry #16002) asks to close. The two SaaS paths (saas_hives_api.go:1746, :1790) are covered; this one is not.
  • Fix is one line: add s.activity.forget(id) next to the existing s.forgetUncollectibleUpgrade(id) at server.go:4348 (same leaf-lock ordering as the new call in removeRegistryEntry — it runs before s.mu.Lock()). A test asserting the purge via handleRegistryDelete would keep the two paths from drifting again; pullonly_upgrade.go:125 already documents them as a pair.

Verified otherwise:

  • activity is a value field (server.go:1002), so s.activity.forget(id) is addressable and the st == nil guard is harmless.
  • forget takes only activityStore.mu, never s.mu, honouring the leaf-lock rule at activity.go:62-63; delete on a nil byHive map is a safe no-op.
  • Tests exercise unknown id, nil store, and the unrelated-hive-survives case.

Marked as changes requested (advisory only — I have not changed any review state).

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

Read both removal paths and the heartbeat path at merge-base; this looks correct to me.

  • activityStore.forget (src/pkg/hub/activity.go:120-127) takes the store's own mu, the same lock record and forgetOldLocked use, and activity is a value field on HubServer (server.go:1002, "leaf lock"), so calling it before s.mu.Lock() at server.go:4283 and :4349 respects the existing lock order rather than nesting a new one.
  • The ordering question I checked — a heartbeat racing the delete and re-recording a digest for a hive that is about to vanish — is moot: handleHeartbeat only reaches s.activity.record (server.go:2737) after it has (re)appended the registry entry (:2730), so a digest can only exist for a hive that is currently in the registry. The 24h forgetOldLocked sweep remains the fallback for a hive that silently stops beating; this change adds the deterministic purge for the explicit removal, which is what [reviewer] Review backlog (security): activityStore is not purged when a hive is removed from the registry #16002 asks for.
  • Both callers (removeRegistryEntry and the admin handleRegistryDelete) are covered by the extended tests, each asserting the sibling hive's digest survives.

go build ./pkg/hub clean at 64a6a96; CI green on this head apart from tide. (I can't run go test on this host.)

Evidence bundle `#160079f7d994` sha256:b88969bfa2924e1629a2e4630d9d69616ccef9a63ffed609390a6783d7007297 — download from the dashboard or `hivectl review evidence #16007`.

@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 31, 2026
handleRegistryDelete duplicates removeRegistryEntry's inline splice and
missed the activity.forget(id) call, so an admin DELETE left the removed
hive's digest in memory until the 24h sweep. Call forget there as well and
cover it in TestHandleRegistryDeleteAsAdmin (#16002).

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>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Oct 31, 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.

Read against the v5 tree at head 29a2d0c. This looks correct to me.

What I verified

  • activityStore is documented and used as a leaf lock (src/pkg/hub/activity.go:66-71); forget takes only st.mu and both call sites (server.go:4284, server.go:4350) run before s.mu.Lock(), so there is no lock-order inversion. delete on a nil byHive is a no-op, so the zero-value store is fine.
  • s.activity is a value field (server.go:1002), so the st == nil guard is purely defensive; harmless and covered by TestActivityStoreForget.
  • The one registry-removal path the diff does not touch is markStaleHives (server.go:4434-4463). It evicts only after staleRemoveAge = 24h (server.go:124), and a digest's receivedAt is never newer than the hive's last heartbeat, so forgetOldLocked (activity.go:129, activityForgetAfter = 24h) has already dropped it by then. No gap there.
  • Tests: the new asserts in TestRemoveRegistryEntryPersistsSynchronously and TestHandleRegistryDeleteAsAdmin fail without the two forget calls, and each also checks an unrelated hive survives.
  • Changelog fragment name fixed-16002-… matches the guard's <category>-<slug>.md rule.

Info only, not a defect: a heartbeat that has already passed its s.mu section (server.go:2733) when the delete runs can re-record after forget. The digest is then unreachable (visibleActivityHives only yields registry hives) and still bounded by the 24h sweep, so the issue's advisory goal holds; just noting the window exists in either ordering of forget vs. the registry mutation.

Diff matches the PR body and resolves #16002 as scoped.

— hive: agent=reviewer-2 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.

Read the diff against the v5 tree, not just the patch. Looks correct to me.

  • activityStore.forget (src/pkg/hub/activity.go:120) takes only st.mu, and both call sites (server.go:4283, server.go:4349) run before s.mu.Lock(), so the "leaf lock" contract on the activity field (server.go:1002) holds. delete on a nil byHive map is a no-op, so a server that never received a digest is safe.
  • The only two places that splice registry.Hives are removeRegistryEntry and handleRegistryDelete (server.go:4289, :4355); both now purge. The only writer is the authenticated heartbeat (server.go:2737), which re-adds the registry entry first — so a deleted hive that keeps beating simply re-registers; there is no path that leaves a digest without an entry.
  • pkg/hub and its _test.go files type-check at this head.

One nit on the body, not the code: it says removeRegistryEntry is "the common choke point for every removal path", but the admin DELETE /api/hub/registry/{id} handler splices the slice itself and needed its own forget call — which the diff correctly adds. Worth a one-word edit so the next reader doesn't assume the handler delegates.

— hive: agent=reviewer-2 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.

Read at 4a92402. Looks correct to me.

  • removeRegistryEntry (src/pkg/hub/server.go:4283) and handleRegistryDelete (:4349) are the only two places that splice an entry out of s.registry.Hives in non-test code; both now call s.activity.forget(id) before taking s.mu, which respects the "leaf lock" note on the activity field (server.go:1002) — no lock nesting introduced.
  • forget (activity.go:120) deletes from byHive; delete on a nil map is a no-op, so the lazily-initialised store is safe before the first record.
  • Tests cover both removal paths plus the unrelated-hive-preserved case (delete_hive_registry_test.go:426, hub_coverage_boost_test.go:939). v2 Tests / coverage / patch-coverage are green at this head.

No findings. Not approving — that's a human's signature.

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

@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Oct 31, 2026
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) and removed stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 31, 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.

Looks correct to me. Read src/pkg/hub/activity.go and server.go at 9f7d994.

  • The registry only ever drops an entry in two places — removeRegistryEntry (server.go:4289) and handleRegistryDelete (server.go:4355) — and both now call s.activity.forget(id) right after forgetUncollectibleUpgrade. No removal path is missed.
  • forget runs before s.mu is taken, honouring the "leaf lock, never take s.mu while holding it" rule on activityStore (activity.go:62). A heartbeat racing the delete re-appends the registry entry (server.go:2730) and re-records the digest (server.go:2737), so the two stay consistent either way.
  • delete on a nil byHive map is a no-op, and activity is a value field (server.go:1002), so the nil-receiver branch is belt-and-braces rather than load-bearing; harmless.
  • Tests exercise both paths with a kept sibling hive, which is the assertion that matters.

One nit on the body only: it says removeRegistryEntry is "the common choke point for every removal path", but handleRegistryDelete has its own loop and doesn't call it. The diff already instruments both, so nothing to change in code — just noting so a future reader doesn't assume one hook is enough.

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

@hivecommons-hive
hivecommons-hive Bot merged commit 6f77067 into v5 Oct 31, 2026
76 of 77 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-16002 branch October 31, 2026 12:45
@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

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 31, 2026
hivecommons-hive Bot added a commit that referenced this pull request Oct 31, 2026
…es (#16039)

Since #16007, removing a hive from the registry purges its activity block
immediately via activityStore.forget (removeRegistryEntry and the admin
registry DELETE handler). The 24h sweep is now only a backstop for hives
that stopped reporting while still registered, so drop the "or left the
registry" wording that still framed departure as a time-based eviction.

Comment-only change; no behavior change.

Closes #16009

Hive-Run: #16009
Hive-Plan: reviewer backlog docs-currency (from review of #16007)
Hive-Spec: hub-activity#activityForgetAfter

Claude-Session: https://claude.ai/code/session_01HRH6kif1Xa5LCs6yXPcSgw

Signed-off-by: Karibhou <157208370+Karibhou@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com>
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 copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[reviewer] Review backlog (security): activityStore is not purged when a hive is removed from the registry

0 participants