Skip to content

[scanner] Post one Discord thread per RFC with durable idempotent mapping, reconciliation and opt-in backlink #15939

Closed

Description

@hivecommons-hive

Part of #15869

Goal

Add one Discord thread per RFC in the existing text channel. A durable per-RFC mapping (message ID and thread ID) makes announcements idempotent and allows crash/retry reconciliation. Later lifecycle events post into the thread. An opt-in GitHub backlink is posted at most once, and only after the thread exists.

Applicable decision constraints

  • Keep the existing text channel and create one thread per RFC. No Forum migration.
  • One explicitly designated announcer per destination (the rfc_announcer gate from [scanner] Add opt-in rich RFC notify config, designated-announcer gate and private-repo gate #15926) with durable idempotency and reconciliation. Channel-history scanning is not an atomic distributed claim.
  • An optional history lookup may reconcile crash/retry uncertainty, but must not trigger unbounded backfill or duplicate announcements.
  • Backlinks are opt-in (rfc_backlink_comment) and posted at most once, only after the Discord thread is confirmed. No automatic comments on others' issues by default.
  • Bound retries, respect rate limits, surface failures. No historical announcement burst.

Current code (v5)

  • src/pkg/rfcnotify/detector.go: issueRecord{Open, Held, Actionable, ReadyAnnounced, LastSeen} lives in State (stateVersion = 1). Detector.Save persists it atomically to /data/rfc-notify.json. clone / rollback undo unposted events.
  • src/pkg/rfcnotify/sweeper.go: Sweeper.Run posts in order and stops the batch on the first failure.
  • src/pkg/discord/bot.go: SendMessageTo (+ SendEmbedTo from [scanner] Render RFC notices as summary-card embeds when rfc_format: card #15927). There is no thread API.
  • src/cmd/hive/rfcnotify_wire.go builds the poster. github.Client.CreateIssueComment and CreateIssueCommentBudgeted already exist.

Changes

  1. Extend issueRecord with MessageID, ThreadID, Nonce, AnnounceState ("" | pending | posted | threaded) and BacklinkPosted. Bump stateVersion to 2 and load v1 files unchanged.
  2. Write-ahead intent. Before posting an "opened" card, record AnnounceState=pending with a deterministic nonce (a hash of repo#number + "opened", ≤25 chars) and Save. Send with Discord's nonce + enforce_nonce: true, so a retry inside Discord's dedup window returns the same message. On success, store MessageID and save.
  3. Thread. Add StartThreadFromMessage(channelID, messageID, name string) (threadID string, err error) to bot.go (POST /channels/{c}/messages/{m}/threads, name #N plus the RFC title truncated to 100 chars). Store ThreadID and set the state to threaded. Later events for the RFC post into ThreadID; threads are channels, so SendMessageTo/SendEmbedTo work. Closed and ready events also echo one line to the parent channel.
  4. Reconciliation. This runs at startup, or when a record is pending/posted without a thread. Do one bounded lookup of the channel's last ≤50 messages (GET /channels/{c}/messages?limit=50, a new bot.go helper) for a message from this bot with a matching nonce or issue URL. If one is found, adopt it. If not, and the record is still pending, re-post once with the same nonce. Never scan further back, and never reconcile records created before the watermark, so there is no backfill. History lookup is only for this recovery, never a claim between hives.
  5. Backlink. When Backlink is set and the state is threaded, post Discussion thread: followed by the thread URL once with CreateIssueCommentBudgeted, then set BacklinkPosted and save. On failure the flag stays unset. Retries are bounded (e.g., 3 attempts tracked in the record), then a warning is logged.
  6. Rate limits. Every new bot call honours the 429 retry_after with a bounded retry. Failures go to Result.Errors, the existing logger.Warn, and the audit line in runRFCNotifySweep.

Decision taken by hive: idempotency uses Discord enforce_nonce plus a write-ahead record, not a hub lock. The decision designates a single announcer, so the only race left is a crash or retry inside one hive.

Files

  • src/pkg/rfcnotify/detector.go, src/pkg/rfcnotify/sweeper.go (+ new src/pkg/rfcnotify/thread_test.go)
  • src/pkg/discord/bot.go (+ httptest tests for thread create, the nonce payload, message lookup and 429 handling)
  • src/cmd/hive/rfcnotify_wire.go (thread and backlink adapters)

Acceptance

  • On the announcer with rfc_threads: true, opening an RFC posts one card and starts one thread. Closing it posts into the thread and echoes one line to the channel.
  • If the hive crashes between the post and the thread creation, the restart attaches the thread to the existing message and posts no second card.
  • A restart neither re-posts nor loses the mapping (covered by a v1 → v2 state load test).
  • The backlink is posted only when enabled, only after the thread ID is confirmed, and at most once across restarts.
  • A hive that is not the announcer never calls the Discord API in rich mode.
  • rfcnotify coverage stays ≥ 90 (the default floor) and discord meets its PKG_THRESHOLD entry. Add changelog.d/added-rfc-notify-threads.md and update the docs in src/docs/notifications.md.

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

Activity

  1. added
    kind/featureCategorizes issue or PR as related to a new feature.
    agent/scannerCreated or modified by the scanner agent
    on Oct 31, 2026
  2. added
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    on Oct 31, 2026
  3. hivecommons-hive commented on Oct 31, 2026

    @hivecommons-hive
    ContributorAuthor

    🔒 Claimed by @Karibhou (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.

  4. hivecommons-hive commented on Oct 31, 2026

    @hivecommons-hive
    ContributorAuthor

    🔓 Claim by @Karibhou released (released on disconnect).

  5. hivecommons-hive commented on Oct 31, 2026

    @hivecommons-hive
    ContributorAuthor

    🔒 Claimed by @Karibhou (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.

  6. hivecommons-hive commented on Oct 31, 2026

    @hivecommons-hive
    ContributorAuthor

    🔓 Claim by @Karibhou released (lease revoked).

  7. added 2 commits that reference this issue on Oct 31, 2026
    8586489
    de6127e
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.kind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions