Skip to content

feat(search): remove a deleted community's messages from OpenSearch - #9999

Merged
salman1993 merged 11 commits into
mainfrom
smohammed/opensearch-community-purge
Dec 1, 2026
Merged

salman1993 merged 11 commits into
mainfrom
smohammed/opensearch-community-purge

Conversation

@salman1993

@salman1993 salman1993 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Deleting a community now removes its messages from the OpenSearch index. Before this PR they stayed there, and that was the main reason real data was kept off OpenSearch behind BUZZ_OPENSEARCH_PREVIEW.

The relay indexes chat messages into OpenSearch beside Postgres. Community deletion (buzz-admin deletions run) walks a request through fixed stages: it fences the community, purges Postgres, purges Redis, then verifies that nothing is left. It never touched OpenSearch, so a deleted community's text stayed in the index for good. Search never showed it, because every hit is re-read from Postgres, but the words stayed on disk.

This PR adds OpenSearch to the purge and to the final verification:

  • Before fencing (Approved): the executor checks that it can reach OpenSearch. If Postgres shows an index is maintained but BUZZ_OPENSEARCH_URL is unset, the deletion stops and retries rather than skipping the index.
  • Purge (PostgresPurged): the executor pages through the community's documents with _search and search_after, 500 at a time. It deletes each page with a versioned _bulk request, taking versions from the same search_index_version sequence the indexer uses. It does not use _delete_by_query, which OpenSearch Serverless does not offer.
  • Verification (CachePurged): the executor waits a lease-heartbeated 90-second settle window (covering BULK_TIMEOUT = 60 s plus margin and Serverless write-to-searchable lag), refreshes on clusters that support _refresh, and runs a second purge pass before counting. If that pass deletes any stragglers, the stage fails transiently and retries so zero only counts after a full quiet window.

Other changes:

  • The relay and the deletion executor share OpenSearchConfig::parse_parts and OpenSearchConfig::with_aws_sigv4 (with OpenSearchConfig::from_env used by buzz-deletion).
  • The Helm operatorJobs.deletionDrain CronJob wires the five optional BUZZ_OPENSEARCH_* Secret keys (BUZZ_OPENSEARCH_URL, BUZZ_OPENSEARCH_USERNAME, BUZZ_OPENSEARCH_PASSWORD, BUZZ_OPENSEARCH_AWS_SIGV4_SERVICE, BUZZ_OPENSEARCH_AWS_REGION) via optional: true secretKeyRef.
  • The deployment and deletion docs cover passing OpenSearch settings to buzz-admin deletions, pausing indexing vs. permanently decommissioning OpenSearch, and the residual late-write retention gap.
  • BUZZ_OPENSEARCH_PREVIEW stays required. Its error text and doc now name the gaps that remain: late writes and Postgres failover.

Risk: OpenSearch is not deployed anywhere yet and stays behind the preview flag, so this affects no live search. A deployment that never ran the indexer skips the OpenSearch steps. Before turning OpenSearch on anywhere: the deletion executor needs the same OpenSearch settings (and IAM identity when using SigV4) and mapping version as the relays, and each deletion takes at least 90 s longer (plus 30 s + 90 s per straggler retry, well inside the CronJob's 3600 s deadline). Rollback is the older executor, which leaves docs in the index as before.

Related issue

N/A. No existing issue or PR found.

Testing

Ran locally on 5cba5c7d02 against Postgres, Redis, and OpenSearch 2.19:

  • ./scripts/postgres-test-run.sh -p buzz-deletion -j 4 -E 'test(community_purge_deletes) | test(execute_stage_wires_opensearch)': 2 of 2 passed.
    • community_purge_deletes_and_verifies_opensearch_documents: verifies fail-closed when BUZZ_OPENSEARCH_URL is unset, purges target while keeping bystander intact, plants a late straggler and verifies retryable error + cleanup + clean second pass.
    • execute_stage_wires_opensearch_preflight_purge_and_verification: exercises execute_stage end-to-end across Approved (unreachable OpenSearch fails closed and leaves community unfenced), PostgresPurged (purges target docs and records deleted_search_documents: 2), and CachePurged (verifies absence and records "search_index": true).
  • cargo clippy -p buzz-deletion --all-targets -- -D warnings and cargo fmt --check: passed.
  • Helm templates/deletion-drain-cronjob.yaml render check and CI lint + unittest + render matrix: passed.

Not tested:

  • Running against a real Amazon OpenSearch Serverless (aoss) collection.

…eletes

Whole-community deletion now removes the community's documents from
OpenSearch and verifies that zero documents remain before marking the
community logically verified.

- Add OpenSearchConfig::from_env / parse_env and SearchIndex helpers for
  preflight, paginated community document listing (via _search +
  search_after on event_id so the same path works on self-hosted
  OpenSearch and OpenSearch Serverless), community document counting,
  and best-effort expunge (_forcemerge?only_expunge_deletes=true on
  non-Serverless clusters, skipped on Serverless).
- Expose search_index_maintained and next_search_index_version on
  DeletionStore so community deletion fails closed when Postgres has a
  maintained search index and BUZZ_OPENSEARCH_URL is unset, and tags
  purge bulk deletes with monotonic external versions.
- Wire preflight (before fencing), paginated bulk delete (during
  PostgresPurged), and absence verification with warning logs, metrics,
  and straggler cleanup (during CachePurged) into buzz-deletion.
- Request expunge_deletes after an indexer drain removes documents on
  non-Serverless clusters.
- Keep BUZZ_OPENSEARCH_PREVIEW required for now.

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
…trics

Address review feedback on OpenSearch community purge:

- On OpenSearch Serverless (no _refresh), wait a 60s settle window and
  re-purge before accepting a zero document count, waiting another 60s
  if stragglers were purged so late in-flight writes cannot slip past
  verification.
- Remove expunge_deletes (_forcemerge?only_expunge_deletes=true) from
  the indexer drain loop and community purge to avoid stalling large
  self-hosted/managed clusters.
- Deduplicate OpenSearch environment parsing by sharing
  OpenSearchConfig::parse_parts and with_aws_sigv4 between buzz-relay
  and buzz-search.
- Drop unexported buzz_search_community_purge_* counters from
  buzz-deletion and rely on warning logs and request errors.
- Align BUZZ_OPENSEARCH_PREVIEW error text and deployment docs with the
  remaining known gaps (late writes and Postgres failover).

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
@salman1993 salman1993 changed the title feat(search): purge deleted communities from OpenSearch and expunge deletes feat(search): purge deleted communities from OpenSearch Nov 27, 2026
…erification

- Increase SERVERLESS_VERIFICATION_SETTLE_DELAY from 60s to 90s to cover
  a 60s lost-lease bulk request plus Serverless write-to-searchable lag,
  and update the comment and docs to match.
- Return a retryable error when Serverless verification purges stragglers
  instead of nesting a second wait/purge pass.
- Remove the timing-based test assertion and test-only is_serverless seam.
- Call OpenSearchConfig::with_aws_sigv4 directly in buzz-relay/src/config.rs.

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
Resolve conflicts in crates/buzz-relay/src/config.rs and
docs/opensearch-search-deployment.md with #9863 and #9996, and update
a_failed_later_request_keeps_the_items_already_applied to match
SearchError::Timeout introduced by #9863.

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
Signed-off-by: Salman Mohammed <smohammed@squareup.com>
@salman1993
salman1993 marked this pull request as ready for review November 30, 2026 19:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 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-11-30T19:43:23.031169Z 8d9ca46 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.

@salman1993
salman1993 deployed to codex-review November 30, 2026 19:41 — with GitHub Actions Active

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d9ca4624a

ℹ️ 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".

Comment thread crates/buzz-deletion/src/lib.rs Resolved
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 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: 712e890f76b2932cecf1cfc003b00eac7e1bd79e...c4ebe5da840cb2b38ce6de465a16794aab7497d0
  • 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 identified in the authorized PR range.

Findings

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

Notes

  • Review used read-only inspection of the diff, surrounding source, callers, tests, and history. Builds and tests were not executed, as requested.

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

… late writes

Address automated code and security review findings:
- Pass optional `BUZZ_OPENSEARCH_*` Secret keys (`BUZZ_OPENSEARCH_URL`,
  `BUZZ_OPENSEARCH_USERNAME`, `BUZZ_OPENSEARCH_PASSWORD`,
  `BUZZ_OPENSEARCH_AWS_SIGV4_SERVICE`, `BUZZ_OPENSEARCH_AWS_REGION`) into
  the `operatorJobs.deletionDrain` CronJob so Helm deployments with
  OpenSearch indexing enabled can satisfy the fail-closed deletion gate.
- Apply a lease-heartbeated settle window (60s on self-hosted/managed
  clusters, 90s on Serverless) plus post-settle re-purge before accepting
  a zero document count during community purge verification, covering
  timed-out or lost-lease indexer bulk writes still in flight.

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 30, 2026
@salman1993 salman1993 changed the title feat(search): purge deleted communities from OpenSearch feat(search): remove a deleted community's messages from OpenSearch Nov 30, 2026
Check `outcome.rejected` alongside `outcome.failed` in `purge_search_index`
so refused deletes cannot advance past `PostgresPurged` as if deleted.
When #9998 changes `BulkOutcome.rejected` from `usize` to `Vec<[u8; 32]>`,
this check also turns into a compile-time guard whichever PR lands first.

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
…ion gap

Raise the non-Serverless community purge verification settle delay from
60s to 90s (matching Serverless) so there is explicit margin beyond
`BULK_TIMEOUT` (60s), and document the residual retention gap in
`docs/opensearch-search-deployment.md` for bulk requests applied by
OpenSearch after the settle window expires.

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
@salman1993
salman1993 deployed to codex-review November 30, 2026 20:39 — with GitHub Actions Active
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 30, 2026
- Update `community_purge_deletes_and_verifies_opensearch_documents` to
  assert `"1 late search documents"` now that `verify_search_index_absence`
  re-purges stragglers on all clusters after the settle window.
- Replace the `#[cfg(test)]` `search_verification_settle_delay_override`
  field on `Services` with a plain `settle_delay: Duration` field and drop
  the redundant `is_zero()` guard.

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
@salman1993
salman1993 deployed to codex-review November 30, 2026 20:59 — with GitHub Actions Active
@github-actions github-actions Bot added codex-security-review-current The posted Codex security review matches its recorded range. and removed codex-security-review-current The posted Codex security review matches its recorded range. labels Nov 30, 2026
…f-switch

- Add `execute_stage_wires_opensearch_preflight_purge_and_verification`
  exercising `Approved` preflight fail-closed (community stays unfenced on
  unreachable OpenSearch), `PostgresPurged` purging indexed docs and
  recording `deleted_search_documents`, and `CachePurged` verifying absence
  and recording `"search_index": true`.
- Clarify pausing vs. permanent OpenSearch decommissioning in
  `docs/opensearch-search-deployment.md` so operators know how to keep
  community deletion unblocked.

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 30, 2026
@salman1993
salman1993 deployed to codex-review November 30, 2026 22:05 — with GitHub Actions Active
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 30, 2026
Resolve the conflict in `docs/opensearch-search-deployment.md` and
update `purge_search_index` in `crates/buzz-deletion/src/lib.rs` to
handle `BulkOutcome.rejected: Vec<[u8; 32]>` introduced by #9998.

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 30, 2026
@salman1993
salman1993 deployed to codex-review November 30, 2026 23:03 — with GitHub Actions Active
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 30, 2026
@salman1993
salman1993 merged commit bf56d89 into main Dec 1, 2026
163 of 166 checks passed
@salman1993
salman1993 deleted the smohammed/opensearch-community-purge branch December 1, 2026 17:07
arthurgarzajr added a commit that referenced this pull request Dec 1, 2026
* origin/main: (26 commits)
  feat(search): people-only search filter, and the agent owner on each indexed message (#10021)
  fix(search): drop the community label from indexer metrics (#10019)
  relay: advertise the build's source SHA in NIP-11 (#9827)
  feat(mobile): record a push baseline when Android enrolls (#10038)
  Show deletion evidence to the requester (#10076)
  Give single photos the stack card style in mobile chat (#10071)
  fix(search): do not return expired AWS credentials after a failed reload (#10042)
  feat(mobile): unify the Android conversation composer (#10015)
  feat(mobile): check the relay key on Android push channel titles (#10037)
  chore(devex): streamline local OpenSearch and Postgres test workflows (#10034)
  feat(mobile): record messages the app shows so Android wakes skip them (#10039)
  feat(search): remove a deleted community's messages from OpenSearch (#9999)
  Preview user deletion from the original saved inventory (#10028)
  Add queued follow-ups to the mobile Solo composer (#10018)
  feat(mobile): browse and stage GIFs from the iOS composer (#10017)
  Wait for active uploads before purging user media (#9946)
  feat(search): park outbox rows OpenSearch rejects and split HTTP 413 bulk requests (#9998)
  fix(mobile): align icon badge with Activity (#9835)
  feat(mobile): show profile avatars in mention chips (#9868)
  feat(acp): stop one thread with cancel_thread_turn (#10002)
  ...

Co-authored-by: Arthur Garza <arthur.garzajr@gmail.com>
Signed-off-by: Arthur Garza <arthur.garzajr@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	mobile/ios/Runner/HomeScreenShortcuts.swift
#	mobile/ios/RunnerTests/HomeScreenShortcutsTests.swift
mcdickenson added a commit to mcdickenson/buzz that referenced this pull request Dec 1, 2026
…bhooks-1031-883db6fa

* origin/main:
  feat(search): people-only search filter, and the agent owner on each indexed message (block#10021)
  fix(search): drop the community label from indexer metrics (block#10019)
  relay: advertise the build's source SHA in NIP-11 (block#9827)
  feat(mobile): record a push baseline when Android enrolls (block#10038)
  Show deletion evidence to the requester (block#10076)
  Give single photos the stack card style in mobile chat (block#10071)
  fix(search): do not return expired AWS credentials after a failed reload (block#10042)
  feat(mobile): unify the Android conversation composer (block#10015)
  feat(mobile): check the relay key on Android push channel titles (block#10037)
  chore(devex): streamline local OpenSearch and Postgres test workflows (block#10034)
  feat(mobile): record messages the app shows so Android wakes skip them (block#10039)
  feat(search): remove a deleted community's messages from OpenSearch (block#9999)
  Preview user deletion from the original saved inventory (block#10028)
  Add queued follow-ups to the mobile Solo composer (block#10018)

Signed-off-by: Matt Dickenson <mdickenson@squareup.com>

This branch was successfully deployed

1 active deployment
codex-review — c4ebe5da Deployed Nov 30, 2026 by salman1993 via Run Codex Security Review #18856
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.

2 participants