Skip to content

chore(personhog): extract persons module and router client to common - #73254

Merged
jose-sequeira merged 3 commits into
masterfrom
jose-sequeira/personhog-common-persons-client
Jul 24, 2026
Merged

chore(personhog): extract persons module and router client to common#73254
jose-sequeira merged 3 commits into
masterfrom
jose-sequeira/personhog-common-persons-client

Conversation

@jose-sequeira

Copy link
Copy Markdown
Contributor

Problem

The personhog services are growing: replica reads person rows, the upcoming identity service creates them, and the lifecycle-manager from the identity saga RFC will follow. Each Rust service so far declared its own copy of the person row type, the storage error enum, the deterministic uuidv5 scheme, and the router-calling conventions (the x-team-id/x-person-id leader-routing headers). Three copies of the same wire contract is how services drift apart.

Changes

  • New personhog_common::persons module: the Person storage row type, StorageError/StorageResult (with the sqlx::Error conversion), the PERSON_UUIDV5_NAMESPACE + person_uuid() helper, and the storage-to-proto Person conversion.
  • New personhog_common::client module: RouterClient, a thin wrapper over the generated PersonHogServiceClient that owns the leader-routing contract internally. Leader-bound calls (update_person_properties, strong get_person) get the routing headers stamped from the request's own ids, so callers can't forget them. Eventual reads carry no headers, as before.
  • personhog-replica now re-exports the shared types from its existing module paths, so its call sites are unchanged. Its local From<sqlx::Error> impl, uuidv5 constant, and proto conversion are deleted in favor of the shared ones (the orphan rule enforces the single copy once the type lives in common).

No behavior change and no wire change: the headers and types are today's contract, relocated.

How did you test this code?

Automated only, run by the agent in this branch's worktree:

  • cargo test -p personhog-common (54 tests) and cargo test -p personhog-replica (333 tests across suites, against the local posthog_persons database)
  • cargo build, cargo clippy --all-targets -- -D warnings, cargo shear, cargo fmt --check on both crates

The re-export approach means replica's storage/service code compiles unchanged, which is itself the regression check for the type move.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Authored with Claude Code while building the personhog-identity service (follow-up PR, stacked on this). The identity work surfaced the duplication: identity needed the same Person type, error taxonomy, uuid scheme, and router headers that replica and the test harness had each declared locally. José directed the extraction: pool construction was already shared via common-database, so only the domain primitives and the client contract moved. A broader "move header constants only" variant was considered and rejected in favor of a full RouterClient so the routing contract is owned by one type rather than re-implemented per caller. Skill used: /adding-personhog-rpc (for the surrounding identity work).

@jose-sequeira jose-sequeira self-assigned this Jul 23, 2026
@jose-sequeira
jose-sequeira requested a review from a team July 23, 2026 14:40
@jose-sequeira
jose-sequeira marked this pull request as ready for review July 23, 2026 14:40
Replica, identity, and future personhog services each declared their own
person row type, storage error enum, uuidv5 namespace, and router-calling
conventions. Move them to personhog-common so services cannot drift:

- persons: Person, StorageError/StorageResult, person_uuid(), proto
  conversion
- client: RouterClient wrapping the generated PersonHogServiceClient,
  owning the leader-routing header contract (x-team-id/x-person-id,
  x-read-consistency) internally

personhog-replica now re-exports the shared types; no behavior change.
@jose-sequeira
jose-sequeira force-pushed the jose-sequeira/personhog-common-persons-client branch from f42d65a to 6937430 Compare July 23, 2026 14:42
@greptile-apps

greptile-apps Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
rust/personhog-common/src/client.rs:84-91
**Routing branches lack regression tests**

This shared client is now the single owner of routing metadata, but its distinct branches lack focused tests verifying that strong reads and writes receive the required headers while eventual and unspecified reads do not. A later metadata change can silently violate the router contract without a focused test detecting it.

Reviews (1): Last reviewed commit: "chore(personhog): extract persons module..." | Re-trigger Greptile

Comment thread rust/personhog-common/src/client.rs Outdated
Comment thread rust/personhog-common/src/persons.rs Outdated

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

one nit, not a blocker

…nches

Review feedback: StorageError classification moves from persons.rs to its
own storage_error module, and the RouterClient's request builders gain
parameterized tests pinning the header contract per routing branch —
leader-bound calls (writes, strong reads) carry the routing headers,
replica-bound reads carry none.
@posthog-bot-comment-resolver

posthog-bot-comment-resolver Bot commented Jul 23, 2026

Copy link
Copy Markdown

🔀 Tried to auto-resolve conflicts with master but this one needs a human.

I won't retry until the branch or master moves.

@jose-sequeira
jose-sequeira enabled auto-merge (squash) July 24, 2026 06:52
@jose-sequeira
jose-sequeira merged commit badb247 into master Jul 24, 2026
232 of 234 checks passed
@jose-sequeira
jose-sequeira deleted the jose-sequeira/personhog-common-persons-client branch July 24, 2026 07:08
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-24 07:36 UTC Run
prod-us ✅ Deployed 2026-07-24 07:49 UTC Run
prod-eu ✅ Deployed 2026-07-24 07:53 UTC Run

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