Skip to content

[scanner] Single authoritative hive:status writer: serialise, compare-and-retry, reconcile duplicate status comments #16263

Closed

Description

@hivecommons-hive

Problem

hive:status is the quiet-mode delivery path (#15876) and the maintainer decision on #16075 says to reuse it for issues and PRs, but first to "provide one authoritative cross-writer admission path and prevent lost sections or duplicate status creation". Today it has three races (analysed on v5 @ae1ffdf in the #16075 thread):

  1. Lost update. Client.UpsertPRStatusSection (src/pkg/github/pr_status_comment.go) lists comments to read the status body, computes next := prstatus.Upsert(prev, key, text), then calls UpsertIssueMarkerComment (src/pkg/github/gfi_forge.go), which lists again and edits to next. The second read is compared only with next, never with the first read, so a section another writer added in between is overwritten.
  2. Second writer, no shared serialisation. The automerge engine's Engine.editStatusSection (src/pkg/github/automerge/automerge_stage_labels.go) edits the same comment from its own read, and creates it from a separate call site.
  3. Duplicate create. When no status comment exists, two writers can both see "not found" and both create one (two notifying comments); later passes edit only the first match, so the second goes stale but stays visible.

Issue-side consolidation (#15966 has three writers on one lifecycle) will hit these far more often than PRs do, so this must land before any issue-side work.

Scope

  • One authoritative status-write function (e.g. a StatusWriter in src/pkg/github or src/pkg/prstatus) that every hive:status writer goes through — UpsertPRStatusSection/PostNoteOrFold/PostClaimNote and the automerge engine's editStatusSection + its create site.
  • Serialise status writes per (repo, number) within a process.
  • Compare-and-retry: immediately before EditComment, re-read the comment; if its body differs from the body the section was computed from, recompute prstatus.Upsert on the fresh body and retry (bounded attempts).
  • Post-create reconciliation: after creating a status comment, re-list; if more than one comment carries prstatus.Marker, merge their sections into the oldest and delete the newer ones (deletion only of hive-authored status comments).
  • No change to which notes are folded, to normal (non-quiet) mode, or to any hold/merge/review behaviour.

Decision taken by hive: cross-instance safety for the status card is achieved by the in-process lock + compare-and-retry + merge-into-oldest reconciliation (status edits do not notify, so a rare transient duplicate self-heals). Cross-instance admission for notifying attention events is a separate, stronger mechanism scoped in the episode child — per the decision, a non-atomic list-before-create check is not treated as attention dedupe.

Acceptance criteria

  • All in-tree hive:status writers (client + automerge engine) route through the single writer; no other code path edits/creates a prstatus.Marker comment (grep-checked in a test or lint-style unit test).
  • Unit test: two concurrent writers upserting different section keys on the same item both survive.
  • Unit test: a body changed between read and edit triggers re-read and retry, and the third-party section is preserved.
  • Unit test: two status comments present → sections merged into the oldest, newer one deleted, merged body contains every section exactly once.
  • Notification tally (notification_tally.go) still counts created/edited/suppressed correctly.
  • No new dependency.

Likely files

src/pkg/github/pr_status_comment.go, src/pkg/github/gfi_forge.go, src/pkg/github/automerge/automerge_stage_labels.go, src/pkg/prstatus/prstatus.go, tests alongside.

Evidence

RFC #16075 §1 and §2 ("one authoritative writer or atomic admission per item"); maintainer decision comment on #16075 (2026-11-02, @clubanderson); race analysis in the #16075 thread (point 1).

Part of #16075

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

Activity

  1. added
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    agent/scannerCreated or modified by the scanner agent
    on Nov 2, 2026
  2. hivecommons-hive commented on Nov 2, 2026

    @hivecommons-hive
    ContributorAuthor

    🔒 Claimed by @mrbobbytables (contributor on hive hosted-available-oke-11-placeholder-r05x). The claim lasts 30m0s without activity and renews while the work continues. Reply /unclaim to release, or /claim to take it over if you outrank the holder.

  3. 4 remaining items

  4. added
    stage/020-claimedClaimed by the scanner or a relay contributor
    and removed
    stage/010-actionableTriaged; eligible for the hive to pick up
    on Nov 2, 2026
  5. hivecommons-hive commented on Nov 2, 2026

    @hivecommons-hive
    ContributorAuthor

    🔒 Claimed by agent scanner (agent on hive hosted-available-oke-11-placeholder-r05x). The claim lasts 2h0m0s without activity and renews while the work continues. Reply /unclaim to release, or /claim to take it over if you outrank the holder.

  6. hivecommons-hive commented on Nov 2, 2026

    @hivecommons-hive
    ContributorAuthor

    🔓 Claim by agent scanner released (holding agent relaunched).

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/scannerCreated or modified by the scanner agenthelp wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions