Skip to content

refactor(db): move API token store ownership - #6783

Closed
TheSentinel454 wants to merge 1 commit into
mainfrom
codex/issue-12-api-token-store
Closed

refactor(db): move API token store ownership#6783
TheSentinel454 wants to merge 1 commit into
mainfrom
codex/issue-12-api-token-store

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Current reconstructed head

Exact base: codex/issue-7-channel-membership-store at 8ad0782ee311f5f51b714494ce750c5937f127cc
Exact head: codex/issue-12-api-token-store at efd769903a0aab75961453ab247bef923f64ac38

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 2 API-token PostgreSQL tests on native PostgreSQL where applicable.

Why

Complete the API-token half of tracker #2 and domain issue #12 while keeping Db as the stable public facade. This child stacks on the channel/membership extraction in #6782.

What

  • Move ApiTokenRecord, TokenSummary, parse_api_token_row, every API-token Db method, inline SQL, focused tests, and datastore spans into api_token.rs
  • Preserve every public Db signature and crate-root record export
  • Preserve validation, JSON parsing, community scoping, token limits, revocation behavior, and the existing update_token_last_used alias-to-touch_api_token single-span behavior

Stack

Non-goals

  • No SQL, schema, validation, retry, timeout, transaction, or client-visible behavior changes
  • No consolidation of authentication allowlisting with API tokens or NIP-43 relay membership
  • 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

Low. This is a direct ownership move. The usage-update alias deliberately retains only the touch_api_token span to avoid nesting.

Blox Verification

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

  • cargo fmt --all --check — passed
  • cargo clippy -p buzz-db -p buzz-relay --all-targets -- -D warnings — passed
  • Native PostgreSQL: cargo test -p buzz-db api_token::tests:: -- --ignored --test-threads=1 — 2 passed
  • Relay public-path/all-target compilation is covered by the relay clippy invocation
  • Commit-time formatting, sadscan, attribution, and sign-off hooks — passed

Independent exact-head review: buzz-tornquist-pr-6783-review (2048930) found no critical, important, or minor issues. The reviewer confirmed unchanged SQL/binds/validation/scoping and exactly one span per logical operation, including no alias span for update_token_last_used.

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-6783-final-review (2057621), fresh shallow checkout
  • Base: fa09b6c81c4db3b3e1940a2117a97ab2186e49f7
  • Head: e69f4e7180eae47d96c56012f9cbea966da584e2
  • Findings: none

Reviewed API-token records, row parsing, SQL, Db wrappers, tests, and spans as a single move to api_token.rs. Community scoping, JSON/UUID validation errors, token limits, revocation behavior, and method signatures are unchanged. Crate-root type re-exports preserve established consumers. The uninstrumented alias continues to reuse touch_api_token so one logical operation produces one span.

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 (3/3) and observability (1/1) guards passed; both API-token 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: a05380cbf4f9b1671bee1bdffe78ebae390c792b87e497233310e35d1f193fa8.

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: 25138bfd6588e046170dbdbc4ed953bdc3cf7ed1
  • Exact head: 7798ea83fe393cdc457577bb09a4fd7546b9722b
  • 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, 2 API-token PostgreSQL tests, and relay compilation.

@TheSentinel454
TheSentinel454 force-pushed the codex/issue-12-api-token-store branch from 23aac4c to 677b81e Compare August 25, 2026 16:20
@TheSentinel454
TheSentinel454 force-pushed the codex/issue-12-api-token-store branch from 677b81e to e69f4e7 Compare August 25, 2026 20:06
@TheSentinel454
TheSentinel454 force-pushed the codex/issue-12-api-token-store branch from e69f4e7 to 7798ea8 Compare August 25, 2026 20:59
@TheSentinel454 TheSentinel454 changed the title db: move API token store ownership refactor(db): move API token store ownership Aug 26, 2026
@TheSentinel454
TheSentinel454 force-pushed the codex/issue-12-api-token-store branch 2 times, most recently from 6f3dbb6 to efd7699 Compare August 26, 2026 15:53
@TheSentinel454
TheSentinel454 marked this pull request as ready for review August 27, 2026 14:05
@TheSentinel454
TheSentinel454 requested a review from a team as a code owner August 27, 2026 14:05

@wpfleger96 wpfleger96 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Combined review from three independent passes (two source reviews + one E2E test run at exact head efd7699): no findings.

  • Pure ownership move: all API-token Db wrappers relocated into api_token.rs with signatures, SQL, bind order, revocation filters, the 10-active-token limit, and all span names byte-preserved (one body differs only by rustfmt line folding).
  • pub use api_token::{ApiTokenRecord, TokenSummary} keeps the established root paths compiling; update_token_last_used correctly remains uninstrumented, delegating to instrumented touch_api_token (still one span, not two).
  • The sadscan suppression on the moved test-only TEST_DB_URL matches the existing precedent in lib.rs.
  • E2E: api_token::tests:: Postgres group 2/2 on a fresh fully-migrated database; cargo check -p buzz-relay passes.

stack merge was automatically disabled August 27, 2026 19:59

Pull Request is not mergeable

stack merge was automatically disabled August 27, 2026 20:00

Pull Request is not mergeable

stack merge was automatically disabled August 27, 2026 20:03

Pull Request is not mergeable

@TheSentinel454
TheSentinel454 force-pushed the codex/issue-12-api-token-store branch from efd7699 to 1db6384 Compare August 27, 2026 20:07
Base automatically changed from codex/issue-7-channel-membership-store to main August 28, 2026 14:55
Signed-off-by: OpenAI Codex <codex@openai.com>
@TheSentinel454
TheSentinel454 force-pushed the codex/issue-12-api-token-store branch from 1db6384 to b00f8e2 Compare August 28, 2026 14:55
@github-actions

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is e76c81968b65b0755b83efdd59dc3375c59ddf40...b00f8e291ef4b1997a4824373a614423d8960047.
A new review must complete for this exact range. When manual authorization
is required, a Block organization member must comment exactly
@buzz-security-review b00f8e291ef4b1997a4824373a614423d8960047 to authorize a new review.
Any previous review applies only to its recorded range.

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

3 participants