Skip to content

refactor(db): move event query store ownership - #6788

Closed
TheSentinel454 wants to merge 1 commit into
codex/issue-13-reminder-storefrom
codex/issue-2-event-query-store
Closed

refactor(db): move event query store ownership#6788
TheSentinel454 wants to merge 1 commit into
codex/issue-13-reminder-storefrom
codex/issue-2-event-query-store

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Current reconstructed head

Exact base: codex/issue-13-reminder-store at 9ca2f893f7c23d972cb90c163672b2e5bbbf5e1b
Exact head: codex/issue-2-event-query-store at 02d75823c301f935d767d15d7c70b031c7a0d35f

This current head removes crates/buzz-db/tests/store_ownership.rs; no replacement path-sensitive ownership test is introduced. Apart from removing that complete test-file diff, the production patch is byte-for-byte identical to the previously reviewed slice. This remains part of tracker #2 and the #17/#19 acceptance work.

Independent exact-head review from a separate clean Blox workstation found no issues. Current-head evidence passed formatting, strict buzz-db clippy, 111 non-PostgreSQL library tests with 200 PostgreSQL tests ignored, the observability source test, relay consumer compilation, exact ownership/unique-span review checks, and 12 event PostgreSQL tests on native PostgreSQL where applicable.

Why

Advance tracker #2 past its five minimum domain slices by making event.rs own the event/query Db facade alongside its records, query builder, SQL, and focused tests. This child stacks on the reminder extraction in #6787 and preserves the runtime/store boundary established by #6660 and #6668.

What

  • Move event insertion, direct/routed query and count, huddle-link lookup, replaceable/event lookup, event soft-deletion, channel last-message, batch hydration, threaded insertion, and discovery-event deletion Db methods/spans into event.rs
  • Move coordinate_delete_spares_head_newer_than_the_deletion beside the coordinate-deletion implementation
  • Preserve every public Db method signature, SQL statement/bind order, mention-index behavior, routing predicate/fallback behavior, and span name
  • Keep ReadSession, route_read, route proofs/predicates, pool/session infrastructure, mention materialization, and cross-cutting routing tests in lib.rs
  • Keep insert_event_with_serving_write_guard with the cross-domain deletion invariant for its later dedicated slice

Stack

Non-goals

  • No SQL, schema, query-shape, routing, retry, timeout, lock, transaction, or client-visible behavior changes
  • No movement or redesign of replica routing infrastructure, route proofs, ReadSession, or cross-cutting routing tests
  • No movement of thread, reaction, feed, deletion-admission, or mention-index ownership in this slice
  • No store traits, domain-handle redesign, broad PgExecutor migration, raw pool accessor, new crate, or directory-wide reorganization
  • No changes to, retargeting of, or merge action on parent PRs or PR Add database pressure observability #6700

Risk Assessment

Moderate review surface, low semantic risk. The diff moves 19 existing Db methods and one focused test without changing their bodies beyond module qualification and use of event.rs's existing test helper name. The routed methods continue calling the same crate-root private routing infrastructure.

Blox Verification

Author workstation: buzz-tornquist-issue-2-store-stack (2046520), exact head a8a0975585d691fff554cae16ee3b1fc811b8366.

  • cargo fmt --all --check — passed
  • cargo clippy -p buzz-db -p buzz-relay --all-targets -- -D warnings — passed
  • Native PostgreSQL event::tests:: ignored suite — 12 passed, including the moved coordinate-deletion test
  • Native PostgreSQL routed-query checks — 5 passed: routed query gate/coverage, bounded count, tenant confinement, head-fetch budget routing, and one-snapshot request routing
  • cargo test -p buzz-relay --lib -- --test-threads=1 — 909 passed, 48 ignored
  • git diff --check and commit-time formatting, sadscan, attribution, and sign-off hooks — passed

Independent exact-head review: buzz-tornquist-pr-6788-review (2050005) checked clean detached head a8a0975585d691fff554cae16ee3b1fc811b8366 over exact merge-base 52b7bb6cba2a0d09877cc8a1b3a561eb537256da. No critical, important, or minor findings. The relay suite passed 908 tests with one known unrelated mesh-demo 504 timing failure; that exact test passed immediately in isolation. Strict rustdoc produced the same 11 pre-existing warnings on parent and head, with no new warning.

Generated with Codex

Superseded pre-comment restack verification

PR #6700 merged before publication completed. This layer was restacked onto current main through the exact parent named above; the final cumulative tip is 2ddcc8a. Cumulative author gates passed: formatting and diff checks; buzz-db and buzz-relay all-target clippy with -D warnings; DB lib 111 passed / 200 ignored; ownership 22/22; observability 1/1; the full isolated PostgreSQL domain matrix; and relay lib 910 passed / 49 ignored.

  • Workstation: buzz-tornquist-pr-6788-final-review (2057616), fresh shallow checkout
  • Base: 35f3b66eae412d4aeea1500c9022681966b14a5f
  • Head: ff7f57fafe20354b1608683edb056f3f6486fdb6
  • Findings: none

Reviewed event/query Db wrappers and focused event tests moving into event.rs. Writer/replica routing still calls the same private runtime routing infrastructure in lib.rs; route predicates, read sessions, query/count SQL, event insertion/materialization, deletion behavior, and public signatures are preserved.

Verification: format and diff checks passed; buzz-db --all-targets clippy passed with -D warnings; DB lib tests passed (111 passed, 200 PostgreSQL tests ignored); ownership (6/6) and observability (1/1) guards passed; all 12 event PostgreSQL tests passed on native PostgreSQL 17 with migrations 1-32 successful; relay lib test target compiled successfully. Final worktree was detached at the exact head and clean.

Complete evidence archive SHA-256: d1d33ccf366ff680d0b747449cfa08b49ee9bea8180a28d00fd7dffb667f43f1.

Comment-addressed restack

Review follow-up on #6777 removed only the low-value replaceable ownership source test. This PR was restacked onto its rewritten parent; its production patch is unchanged.

  • Exact base: 888627a3d41b72c904d1546fe62492f01bdfdd3e
  • Exact head: ce2d9b3d8f599cf1c0dfe4abb8f2a8c116a0d329
  • Final cumulative tip: 6fa2f104d42c6ba85bdf62e7ccb74ceaf4a84f67
  • Per-layer patch-ID and tree audits confirm this PR’s production diff is unchanged from its pre-comment head.
  • Cumulative Blox gate: formatting and diff checks; strict buzz-db/buzz-relay Clippy; DB lib 111 passed / 200 ignored; ownership 21/21; observability 1/1; every moved PostgreSQL test; relay lib 910 passed / 49 ignored.
  • Independent re-review at this exact head: no findings; fresh exact-parent/head Blox review passed fmt/diff, strict Clippy, DB lib 111 passed / 200 ignored, current ownership/observability guards, 12 event PostgreSQL tests, and relay compilation.

@TheSentinel454
TheSentinel454 force-pushed the codex/issue-2-event-query-store branch from a8a0975 to ff7f57f Compare August 25, 2026 20:06
@TheSentinel454
TheSentinel454 force-pushed the codex/issue-2-event-query-store branch from ff7f57f to ce2d9b3 Compare August 25, 2026 20:59
@TheSentinel454 TheSentinel454 changed the title db: move event query store ownership refactor(db): move event query store ownership Aug 26, 2026
@TheSentinel454
TheSentinel454 force-pushed the codex/issue-2-event-query-store branch from ce2d9b3 to 7e1746c Compare August 26, 2026 14:33
@TheSentinel454
TheSentinel454 force-pushed the codex/issue-2-event-query-store branch from 7e1746c to 02d7582 Compare August 26, 2026 15:53
@TheSentinel454
TheSentinel454 force-pushed the codex/issue-2-event-query-store branch from 02d7582 to 6347722 Compare August 27, 2026 20:07
Signed-off-by: OpenAI Codex <codex@openai.com>
@TheSentinel454

Copy link
Copy Markdown
Contributor Author

🤖 Superseded by #6987, which consolidates the remaining issue #2 store-extraction stack onto merged #6782. #6987 is an open draft at the independently reviewed exact head, and all exact-head CI checks are green. This PR remains available for review history; please continue review on #6987.

TheSentinel454 added a commit that referenced this pull request Aug 28, 2026
## Summary

Finish the remaining database-store extraction tracked by
[TheSentinel454#2](TheSentinel454#2)
in one reviewable PR.

This consolidates the previously stacked domain slices after #6782
merged. It preserves the runtime/store boundary established by #6660,
#6668, #6700, and #6782 while separating database runtime infrastructure
from domain-owned persistence:

- `runtime/` owns pool construction and sizing, writer/reader routing,
read sessions and route proofs, transaction infrastructure,
observability primitives, replica fencing, health support, migrations,
and cross-cutting runtime tests.
- `store/` owns domain records, SQL, row parsing, locks and invariants,
`Db` domain methods, focused tests, and logical-operation datastore
spans.
- `lib.rs` remains a 57-line compatibility facade that preserves
existing crate-root paths and `Db` method signatures through re-exports.

Domain coverage includes API tokens, authentication allowlists,
reminders, event queries, threads, reactions, feeds, users and DMs,
push, workflows/runs/approvals, relay membership and invites, product
feedback, moderation/admin moderation, relay admin actions/operators,
git repositories, archived identities, usage, partition maintenance,
deletion, channel membership inherited from merged #6782, and the final
runtime/store layout.

The branch has been rebased onto current `main`. Database changes that
landed there were incorporated rather than overwritten:
`relay_admin_actions.rs` and `relay_operators.rs` now live under
`store/`, their 27 public `Db` wrappers and existing behavior remain
intact, and every wrapper has exactly one fixed-name datastore span.
Concurrent changes to migration, moderation, admin moderation, and error
handling are also retained.

### Exact base and head

- Base: `main` at `ed11c8d8bf0a17402be5cf243724f89471530d2f`
- Head: `codex/issue-2-store-extraction` at
`be24430472d1a87ac5c0d6026c620cd6caea3537`

### Related issue

- Structural tracker:
[TheSentinel454#2](TheSentinel454#2)
- Domain trackers:
[#6](TheSentinel454#6),
[#7](TheSentinel454#7),
[#12](TheSentinel454#12),
[#13](TheSentinel454#13)
- Acceptance trackers:
[#17](TheSentinel454#17),
[#19](TheSentinel454#19)

This supersedes #6783, #6784, #6787, #6788, #6789, #6792, #6820, #6794,
#6796, #6797, #6798, #6799, #6804, #6805, #6806, #6808, #6809, #6811,
#6812, #6813, #6814, #6815, and #6890. Their discussions remain
available for review history.

### #17 / #19 acceptance

- Preserves the metric names, fixed labels, transaction/lock timing
boundaries, and privacy/cardinality constraints introduced by #6700.
- Keeps exactly one datastore span per public logical operation,
including the 27 relay-admin wrappers added on `main`.
- Removes `store_ownership.rs`; physical ownership and focused source
guards now enforce the boundary directly.
- Leaves no `impl Db`, domain SQL, focused domain test group, or
datastore span in `lib.rs`.
- Preserves existing public paths such as `buzz_db::channel`,
`buzz_db::event`, and `buzz_db::workflow` through crate-root re-exports
while keeping internal `runtime` and `store` namespaces private.

### Non-goals

- No SQL, schema, locking, transaction, retry, timeout, or
client-visible behavior changes.
- No generic store traits, domain handles, broad `PgExecutor` migration,
new store crate, raw pool accessor, or broader directory reorganization.
- No tracker issues are closed by this PR.

### Risk

The cumulative diff is large but structural. Risk is primarily
module-path, ownership, or conflict-resolution drift. It is mitigated by
preserving public re-exports, comparing the newly moved `main`
implementations to their upstream source, source guards, touched-crate
compilation, PostgreSQL-backed test coverage, and an independent
exact-head review on a separate clean Blox workstation.

### Testing

Author workstation `buzz-tornquist-pr-6987-rebase`, rebased branch
ending at exact head `be24430472d1a87ac5c0d6026c620cd6caea3537`:

- `cargo fmt --all --check`
- `cargo clippy -p buzz-db -p buzz-relay --all-targets -- -D warnings`
- `cargo test -p buzz-db --lib` — 113 passed, 240 PostgreSQL tests
intentionally ignored
- `cargo test -p buzz-db --test observability_source` — 2 passed
- PostgreSQL-backed `buzz-db` coverage under native PostgreSQL — 235
passed in the shared serial run; the five shared-state/config-sensitive
cases passed as isolated reruns against fresh schemas, including the two
owner-limit tests with their fixture's
`BUZZ_MAX_COMMUNITIES_PER_OWNER=3`
- `cargo test -p buzz-relay --lib -- --test-threads=1` under native
PostgreSQL/Redis — 991 passed; the three current-month
partition-sensitive identity-archive cases passed after provisioning the
August 2026 test partition; 87 infrastructure-marked tests remained
ignored
- Source/diff guards — relay-admin implementation bodies match current
`main`; all 27 public wrapper signatures are retained; exactly one
datastore span wraps each wrapper; `lib.rs` has zero `impl Db` blocks
and zero datastore spans; no duplicate top-level relay-admin modules or
`store_ownership.rs`; `error.rs` matches current `main`

Independent clean review workstation `buzz-tornquist-pr-6987-review`,
detached at exact head `be24430472d1a87ac5c0d6026c620cd6caea3537`:

- `cargo fmt --all --check`
- `cargo clippy -p buzz-db -p buzz-relay --all-targets -- -D warnings`
- `cargo test -p buzz-db --lib` — 113 passed, 240 ignored
- `cargo test -p buzz-db --test observability_source` — 2 passed
- Exact-head ownership/re-export/instrumentation audit — no remaining
actionable findings

---------

Signed-off-by: OpenAI Codex <codex@openai.com>
Signed-off-by: tornquist <tornquist@squareup.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants