Skip to content

perf(relay): republish only the discovery events a channel lacks - #10084

Open
brow wants to merge 2 commits into
mainfrom
discovery-repair-missing-only
Open

brow wants to merge 2 commits into
mainfrom
discovery-repair-missing-only

Conversation

@brow

@brow brow commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #9805. Its repair republishes all three relay-signed discovery events (kinds 39000, 39001, 39002) whenever any one is missing. Mobile reads the kind:39000 created_at as a chat's creation time, so a repaired chat with its metadata still in place jumped to the top of a list sorted by Recent, without a new message.

Now both repair paths (the DM reopen and the startup sweep) publish only the kinds the channel lacks:

  • The missing-discovery reads return the missing kinds (ascending) instead of a yes/no, using the same per-kind probes on idx_events_addressable.
  • emit_group_discovery_kinds emits a given subset of the three events. emit_group_discovery_events calls it with all three, so every other caller is unchanged. A kind outside the three is an error.

This covers only the repair path. Mobile still sorts by the kind:39000 event's created_at rather than its created_at tag (NIP-CL), so a metadata edit or membership change, or a repair where 39000 itself is missing, still moves a chat in Recent; reading the tag is a separate mobile change.

Validation

Regressions

  • Database: each read still probes the three kinds per channel on idx_events_addressable, as before (see Query plan); a healthy reopen is still one indexed read and no writes. The sweep's per-channel probe now aggregates the missing kinds instead of stopping at the first, which costs nothing extra for healthy channels and at most two more index probes for a broken one; over a 366-day window the sweep reads about 3 to 7% more buffers than the parent, depending on how many channels lack all three kinds.
  • Freshness: a channel change republishes all three events, so a live event usually reflects the channel as of its last change. Two cases now keep a stale live event that Republish channel discovery events a failed emission left missing #9805 would have rewritten alongside a missing one, until the next change: a later change that also failed partway, and an ephemeral channel's ttl_deadline tag, which messages extend without republishing 39000. The second needs only one failed emission, but it is the same stale deadline every healthy ephemeral channel already shows after a message; the relay still archives on the real deadline.
  • Query plan: each kind is probed with a scalar subquery tested IS NULL rather than NOT EXISTS, which PostgreSQL 17 can turn into an anti join that walks the channel's whole history; the scalar form keeps one idx_events_addressable probe per kind under custom and generic plans.
  • Bootstrap reconcile: the dev/CI bootstrap reconcile (BUZZ_RECONCILE_CHANNELS, reconcile_channel_events) shares republish_missing_discovery, so it also republishes only missing kinds now.
  • Other callers of emit_group_discovery_events (creation, metadata edits, membership changes, operator reconcile) still publish all three.

Rollout

No flag: the change only narrows which events a repair writes, with no schema or data change.

  • Staging: delete one DM's live kind:39002, reopen the DM, and check for the repair log line with kinds=[39002] and that the DM's kind:39000 and kind:39001 event ids are unchanged.
  • Production: watch buzz_channel_discovery_republished_total{path} and buzz_channel_discovery_repair_failures_total against the Republish channel discovery events a failed emission left missing #9805 baseline, and the channel_missing_discovery span latency on DM reopen.
  • Mixed versions: pods still on the old build keep republishing all three kinds until they're replaced, which is harmless.
  • Rollback: revert; nothing written needs cleanup.

The discovery repair rewrote all three relay-signed events (39000, 39001,
39002) when any was missing. Clients read kind:39000's created_at as a
chat's creation time, so a repaired chat jumped to the top of a list
sorted by recency without a new message. The repair now reads which kinds
are missing and publishes only those.

Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
Signed-off-by: Tom Brow <tomb@block.xyz>
@brow

brow commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T01:14:27.298265Z 870da18 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 9860ac732f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

PostgreSQL 17 can pull the lateral aggregate's NOT EXISTS up into an anti
join that walks the channel's history on the channel/time index. A scalar
subquery tested IS NULL keeps one idx_events_addressable probe per kind
under custom and generic plans.

Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
Signed-off-by: Tom Brow <tomb@block.xyz>
@brow
brow marked this pull request as ready for review December 2, 2026 01:13
@brow
brow deployed to codex-review December 2, 2026 01:13 — with GitHub Actions Active
@brow
brow enabled auto-merge (squash) December 2, 2026 01:13
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

🔐 Codex Security Review

Note: This is an automated, security-focused review generated by Codex.
Use it as a supplement to human review; false positives are possible.

Scope

  • Exact PR diff: 8c2530f1f7ade7b0c957622c01e800c82687e74d...870da183738507e366c572601d4374757b7db646
  • Model: gpt-6.1-sol

💡 Click "edited" above to see earlier reviews for this PR.


Review Summary

Overall Risk: NONE

No concrete security, correctness, or reliability findings in the authorized PR range.

Findings

No concrete security, correctness, or reliability findings were identified.

Notes

  • Review used read-only source inspection. Builds, tests, and runtime query plans were not executed.

Generated by Codex Security Review |
Requested by: @brow |
Workflow run

This branch was successfully deployed

1 active deployment
codex-review — 870da183 Deployed Dec 2, 2026 by brow via Run Codex Security Review #19129
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-security-review-current The posted Codex security review matches its recorded range.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant