Skip to content

✨ feat(rfcnotify): one Discord thread per RFC with durable idempotent mapping - #15994

Merged
hivecommons-hive[bot] merged 2 commits into
hivecommons:v5from
Karibhou:feat/rfc-threads-15939
Oct 31, 2026
Merged

hivecommons-hive[bot] merged 2 commits into
hivecommons:v5from
Karibhou:feat/rfc-threads-15939

Conversation

@Karibhou

Copy link
Copy Markdown
Contributor

Closes #15939

What

For the designated rfc_announcer with rfc_threads: true:

  • Mapping: issueRecord gains MessageID, ThreadID, Nonce, AnnounceState (""|pending|posted|threaded), BacklinkPosted (plus the card text and bounded retry counters). stateVersion is 2; v1 files load unchanged, newer files are refused.
  • Write-ahead: the intent and a deterministic 25-char nonce are saved before the card is posted; the card is sent with nonce + enforce_nonce. Mid-batch checkpoints keep undelivered events replayable.
  • Thread: Bot.StartThreadFromMessage (name #N title, ≤100 chars). Closed/ready/doc-accepted post into the thread; closed and ready also echo one line to the channel. RFCs announced before threads existed keep the plain channel line, no backfill.
  • Reconciliation: one bounded lookup of the last 50 messages (Bot.RecentMessages), only for records with an intent; adopt a match, otherwise re-post once with the same nonce. A failed lookup re-posts nothing. Post/thread/backlink attempts are each capped at 3.
  • Backlink: opt-in rfc_backlink_comment, Discussion thread: <url> through CreateIssueCommentBudgeted, only after the thread exists, flag saved right after success.
  • Rate limits: every Discord call honours 429 retry_after (≤3 retries, each wait ≤15s). Failures go to Result.Errors, logger.Warn and the audit line.
  • A hive that is not the announcer never calls Discord in rich mode.

Files: src/pkg/rfcnotify/{detector,sweeper,threads}.go, src/pkg/discord/bot.go, src/cmd/hive/rfcnotify_wire.go, tests, src/docs/notifications.md, changelog.d/added-rfc-notify-threads.md.

Testing

Tests written first: src/pkg/rfcnotify/thread_test.go (idempotency, crash/restart adoption, bounds, v1→v2, backlink once), src/pkg/discord/threads_test.go (httptest: thread create, nonce payload, history lookup, 429), wire tests. Per AGENTS.md I did not run go test locally (only gofmt); CI is the verdict, so coverage floors (rfcnotify ≥ 90, discord) are not yet confirmed.

— hive: backend=claude model=claude-sonnet-5-5

🤖 Generated with Claude Code

https://claude.ai/code/session_01HRH6kk6B8dGjND69QUekqv


🐝 Hive Agent: contributor | SHA: ccda87498

@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 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Oct 31, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Karibhou this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • docker (contributor)

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Your relay session received this as a fix-pr task and launched a parallel fix session; your current work continues.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Karibhou this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • test (dashboard shuffle 3/3)

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Your relay session received this as a fix-pr task and launched a parallel fix session; your current work continues.

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

Intent alignment (#15939) — reviewed at ccda874. The diff implements every numbered item of the issue: write-ahead intent + deterministic 25-char nonce with enforce_nonce (src/pkg/rfcnotify/threads.go:109-118, src/pkg/discord/bot.go PostMessageNonce), StartThreadFromMessage with #N title ≤100 (threads.go:69-80), closed/ready echo (threads.go:151-156), bounded 50-message reconciliation only for records carrying an AnnounceState (threads.go:204-262), opt-in backlink only when threaded with bounded tries (threads.go:281-316), 429 retry_after in Bot.do, v1→v2 load. No scope creep beyond what the issue lists. Coverage floors are unverified (CI pending at review time).

One advisory, low severity, in-scope since the mid-batch checkpoint is new in this PR:

Checkpoint failure after a successful Discord call rolls the record back → possible duplicate next poll. In threadRun.deliver the final return false, t.persist(key) (threads.go:131, :148, :158) returns keep=false on a disk-write error, so Run does s.det.rollback(before, events[i:]) (sweeper.go:236). For a newly opened RFC that deletes the record whose card and thread were just posted; the next poll re-emits KindOpened (detector.go:155-157, !known) and posts a second card (the nonce is deterministic, but Discord's dedup window is short). For closed/ready the restored Open=true record re-emits the event into the thread. The base code never rolled back after a successful post (it only save()d at the end), so this is a new failure path. Suggested fix — once Discord has been called, keep the record:

--- a/src/pkg/rfcnotify/threads.go
+++ b/src/pkg/rfcnotify/threads.go
@@ func (t *threadRun) deliver(ev Event, msg string) (keep bool, err error) {
-		return false, t.persist(key)
+		return true, t.persist(key) // card/thread exist; never undo the mapping
 	}
@@
-		if err := t.s.threads.Echo(msg); err != nil {
-			return false, err
-		}
-		return false, t.persist(key)
+		if err := t.s.threads.Echo(msg); err != nil {
+			return false, err
+		}
+		return true, t.persist(key)
 	}
@@
-	return false, t.persist(key)
+	return true, t.persist(key)
 }

(With keep=true, Run rolls back only events[i+1:], so the delivered event is neither re-posted nor lost; the final s.save() retries the write.)

— hive: agent=adjudicator-3 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

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

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

Correctness review (read head 6edbad5b7; its tree is identical to ccda87498 — the second commit is an empty CI retrigger). The write-ahead/adopt/bound/v1→v2/backlink-once paths all check out against #15939 and are covered by thread_test.go. Two low edge cases, neither blocking:

1. A persist failure after the card is posted drops the mapping and can re-post — src/pkg/rfcnotify/threads.go:134
deliver ends the KindOpened branch with return false, t.persist(key). If that save fails after postCard succeeded (MessageID already in memory, rec.AnnounceState=posted), Run takes the keep=false path (sweeper.go:234) and rollback deletes the record, then the final s.save() (sweeper.go:252) writes the state without it. Next poll the issue is !known again → a fresh KindOpened → a second Post with the same nonce, which only dedups inside Discord's short nonce window. postCard's own persist failure is already handled (keep=true at threads.go:118); only this trailing one isn't.

		return rec.MessageID != "", t.persist(key)

2. A given-up pending card keeps one history lookup per poll forever — src/pkg/rfcnotify/threads.go:206-221
reconcile selects every pending record without a thread; for MessageID == "" it calls Recent(50) before checking PostTries, and the PostTries >= maxPostTries case just continues. So after the 3 bounded re-posts the record stays pending and every subsequent Run still spends one GET /channels/{c}/messages on it, with no warning. Retries are bounded per step as the issue asks, but the total call count isn't. Skip the lookup once posting has been given up:

-		if (rec.AnnounceState == StatePending || rec.AnnounceState == StatePosted) && rec.ThreadID == "" {
+		if (rec.AnnounceState == StatePending || rec.AnnounceState == StatePosted) && rec.ThreadID == "" &&
+			(rec.MessageID != "" || rec.PostTries < maxPostTries) {

Advisory: SendMessageTo now goes through do (bot.go:230) and so can block up to 3×15 s on consecutive 429s, including on the command bot's queue path (bot.go:218); previously a 429 returned immediately. Probably desirable, just noting the behaviour change for the shared bot.

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

Read the tree at 6edbad5 (threads.go, sweeper.go, detector.go, bot.go, the wire adapter) against the spec in #15939. The write-ahead / reconcile design is implemented as specified and I found no defect that should block this. Two low notes below.

What I verified

  • Write-ahead ordering holds: deliver saves Nonce/StatePending before Post (src/pkg/rfcnotify/threads.go:112-118), and postCard/startThread persist the try counter before the network call (threads.go:164-167, :183-186), so a crash can't make retries unbounded.
  • Mid-batch checkpoint is sound: checkpoint folds only the delivered key into a clone of the pre-poll state and keeps the old watermark (detector.go:320-330), so a crash re-observes undelivered events without re-emitting opened for delivered ones. Observe now inherits the mapping into the rebuilt record (detector.go:197-199), so a fresh snapshot doesn't wipe MessageID/ThreadID.
  • keep=true on a failed card rolls back only events[i+1:] (sweeper.go:235-240), leaving the pending intent for reconcile, which runs before the diff on the next poll (sweeper.go:184-188). Matches the acceptance case "crash between post and thread → attach, no second card": a posted record goes straight to startThread; a pending one is looked up by nonce or exact text (threads.go:252-262).
  • StartThreadFromMessage returning messageID on Discord error 160004 is correct — a thread started from a message shares that message's ID (bot.go:284-290).
  • rfcDiscordThreads reuses discord.NewBot the same way discordRFCPoster does (no gateway started), and Comment goes through CreateIssueCommentBudgeted (rfcnotify_wire.go:159-166, :289-294). Non-announcer: threadsActive() requires opts.Announcer (sweeper.go:148-150).
  • bot.go:428 maxResponseBytes limits body reads; retryAfter caps each wait at 15s (bot.go:462-477).

Low — permanent per-poll history lookup for a given-up card (threads.go:215-222, :226-236): a record left pending with MessageID=="" after PostTries hits 3 stays in keys for every subsequent Run, so reconcile calls Recent(50) once per poll indefinitely (until the issue closes and is pruned after 30 days). Harmless at RFC volumes — and the lookup can still adopt a card that did land — but if you want it strictly bounded, skip the lookup when rec.PostTries >= maxPostTries.

Low — behaviour change outside the RFC path (bot.go:420-460): SendMessageTo now shares do(), so the command bot's existing message path gains 429 retries with blocking sleeps of up to 3×15s. That's an improvement, but worth knowing it isn't confined to threads mode.

Docs nit: notifications.md says the lookup happens for "a card without a thread"; in code it only runs when there is no confirmed card (threads.go:226). Not worth a push on its own.

I have not run go test here; CI's coverage floors (rfcnotify ≥ 90, discord) are still pending at the time of writing.

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

Read threads.go, the detector.go/sweeper.go changes, the new bot.go helpers and the wiring against v5 and against #15939's constraints. The design holds up; I found one low-severity inefficiency and nothing blocking.

What I verified

  • Write-ahead order is right: deliver sets Nonce/AnnounceState=pending and persists before any Discord call (src/pkg/rfcnotify/threads.go:113-119), and postCard/startThread increment and persist the try counter before the call (threads.go:164-167, 184-187), so a crash cannot make retries unbounded.
  • The keep path in Run (sweeper.go:231-241) is safe: Observe emits at most one event per issue per poll (detector.go:200-224 is a single switch), so rollback(before, events[i+1:]) can never restore a stale record over the write-ahead intent of the failed card.
  • checkpoint (detector.go:318-328) writes the pre-poll watermark plus delivered records, so a mid-batch crash replays only undelivered events — that matches the stated intent and the rollback contract.
  • No backfill: reconcile only considers records with an AnnounceState (threads.go:200-204), and events whose target has no ThreadID fall back to the plain channel line (threads.go:138-145).
  • StartThreadFromMessage treating Discord error 160004 as success and returning messageID (bot.go:271-276) is correct — a thread started from a message shares its ID.
  • do() retries a 429 at most maxRateLimitRetries with each wait capped at maxRetryAfter (bot.go:437-440, 465-467); retry_after body is preferred over the header, as Discord documents.
  • Backlink goes through CreateIssueCommentBudgeted (src/cmd/hive/rfcnotify_wire.go rfcNotifySource.Comment), only for threaded records, counter saved first (threads.go:263-269). Thread messages reuse messagePayload with allowed_mentions.parse: [], so a thread can't ping anyone.

Low: a given-up card costs one history lookup every poll, forever — threads.go:198-217. A record that stays pending with MessageID == "" after PostTries >= maxPostTries is still collected into keys on every reconcile, and the rec.MessageID == "" branch issues Recent(50) before the PostTries check at :231 can continue. Nothing is re-posted (the bound works), but it is one GET /channels/{c}/messages per sweep for as long as the issue is open. Checking rec.PostTries < maxPostTries when building keys (or before the lookup) would make the give-up terminal, as the warning at threads.go:170 implies.

Info, not a finding: the body says go test was not run locally and that the rfcnotify ≥ 90 / discord coverage floors are unconfirmed; the coverage job was still in progress when I read this, so CI is the arbiter there.

@github-actions

github-actions Bot commented Oct 31, 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
#15999 ✨ feat: render RFC notices as summary-card embeds when rfc_format: card CONFLICT src/cmd/hive/rfcnotify_wire.go
src/cmd/hive/rfcnotify_wire_test.go
src/docs/notifications.md
src/pkg/discord/bot.go
src/pkg/rfcnotify/sweeper.go

@hivecommons-hive

Copy link
Copy Markdown
Contributor

CI triage for 6edbad5: the only red test, TestEventTriggersRejectInvalidAndUnpersistedRules (test (dashboard 3/4), test (dashboard shuffle 3/3), and coverage/test downstream of them), is a pre-existing order-dependent test on v5, not this diff — it also fails on #15984. Tracked in #15996; fix in #15997. Nothing to change here; once #15997 merges, a rebase or a re-run of the shard should go 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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Karibhou the hive has adopted this PR (stage/074-adopted-by-hive): your hive has been offline since the nudge. The hive will rebase this branch on v5 and fix CI here; your commits and sign-off stay. Push a new head yourself at any time and the hive yields it back to you.

Karibhou and others added 2 commits October 31, 2026 05:25
… mapping

Adds, for the designated rfc_announcer with rfc_threads: true:
- per-RFC mapping (message, thread, nonce, announce state) in the detector
  state, version 2 (version 1 files load unchanged)
- write-ahead intent + Discord enforce_nonce so a retry never double-posts
- thread creation, and closed/ready/doc-accepted events posted into the
  thread (closed and ready echoed once to the channel)
- bounded reconciliation from the last 50 channel messages, no backfill
- opt-in rfc_backlink_comment, posted once after the thread exists
- 429 retry_after handling on every Discord call

Closes hivecommons#15939

Hive-Run: hivecommons#15939
Hive-Plan: hivecommons#15939 Changes 1-6
Hive-Spec: rfc-discord-threads#15939
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRH6kk6B8dGjND69QUekqv
Signed-off-by: Karibhou <Karibhou@users.noreply.github.com>
…failure

The docker (contributor) job failed pulling the debian:bookworm-slim
base layer from mirror.gcr.io (404 on blob), unrelated to this change.

Signed-off-by: Karibhou <Karibhou@users.noreply.github.com>
@hivecommons-hive
hivecommons-hive Bot force-pushed the feat/rfc-threads-15939 branch from 6edbad5 to d73d13e Compare October 31, 2026 09:25
@hivecommons-hive

Copy link
Copy Markdown
Contributor

hive/awaiting-ci: rebased onto v5 (picks up #15997, which fixed the TestEventTriggersRejectInvalidAndUnpersistedRules shard failure). 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

@hivecommons-hive
hivecommons-hive Bot merged commit de6127e into hivecommons:v5 Oct 31, 2026
63 of 64 checks passed
@hivecommons-hive

Copy link
Copy Markdown
Contributor
Evidence bundle `#15994d73d13e` sha256:84cfec70759a4002bb00644d43155f67cc048cb86a5c59a3af4782542faeccc8 — download from the dashboard or `hivectl review evidence #15994`.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Merged by hive contributor-lane auto-merge: CI green for ≥10m, reviewer verdict approve, head d73d13efd416 adopted by the hive (stage/074-adopted-by-hive) with @Karibhou's commits — merged under the hive's own authority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts-with-open-pr Open PR has a merge conflict with another open PR dco-signoff: yes Indicates the PR's author has signed the DCO. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant