Установка
SKILL.md
Adding a personhog RPC
This skill walks through adding a new RPC end-to-end: proto definition, code generation, Rust implementation, and client updates.
Before you start: eligibility check
Personhog serves person, distinct ID, group, group type mapping, cohort membership, and feature flag hash key override data. If the data being accessed doesn't live in one of these tables, this RPC doesn't belong in personhog:
| Table | Data category | Routing |
|---|---|---|
posthog_person | PersonData | Reads: replica (eventual) or leader (strong). Writes: leader |
posthog_persondistinctid | PersonData | Same as person |
posthog_group | NonPersonData | All ops: replica |
posthog_grouptypemapping | NonPersonData | All ops: replica |
posthog_cohortpeople | NonPersonData | All ops: replica |
posthog_featureflaghashkeyoverride | NonPersonData | All ops: replica |
posthog_personoverride | PersonData | Reads/writes follow person routing |
posthog_personlessdistinctid | PersonData | Same as person |
If the table is not listed above, stop — this data should not go through personhog.
Step 0: design the data access pattern
Before writing any proto, figure out the SQL query you need. Then validate it against the available indexes — see references/database-indexes.md.
Key questions:
- What table(s) does this query hit?
- Does the WHERE clause match an existing index? Every query must be an index scan, never a sequential scan.
- Is this a read or write? This determines routing (see table above).
- For reads: does the caller need strong consistency (primary pool) or is eventual (replica pool) acceptable?
- For batch lookups: is the batch within a single team or cross-team?
Step 1: define proto messages and RPC
All proto files live in proto/personhog/.
See references/proto-conventions.md for message conventions and a worked example.
Where to add what
- Message types →
proto/personhog/types/v1/<domain>.proto(person.proto, group.proto, cohort.proto, feature_flag.proto, or common.proto) - Service RPC →
proto/personhog/service/v1/service.proto(the public API clients call) - Replica RPC →
proto/personhog/replica/v1/replica.proto(the internal API the router delegates to) - Leader RPC →
proto/personhog/leader/v1/leader.proto(only if this is a person-data write routed to leader)
The service and replica protos must both declare the RPC with identical signature. The router delegates from service → replica (or leader) transparently.
Step 2: generate client stubs
Python
bin/generate_personhog_proto.sh
Then update three files:
posthog/personhog_client/proto/__init__.py— add re-exports for new request/response message typesposthog/personhog_client/client.py— add a wrapper method matching the pattern of existing methodsposthog/personhog_client/fake_client.py— implement the method for test use
Node.js
cd nodejs && pnpm run generate:personhog-proto
Then update:
nodejs/src/ingestion/personhog/client.ts— add a wrapper method matching the pattern of existing methodsnodejs/src/ingestion/personhog/client.test.ts— add a default stub toSERVICE_DEFAULTSfor the new RPC
Rust
No generation step needed — tonic regenerates on cargo build.
But you must implement the RPC (next step), or the build will fail.
Step 3: implement in Rust
The compiler guides you — once the proto is defined, cargo build errors tell you exactly which trait methods are missing.
3a. Storage layer (personhog-replica)
- Add a trait method in
rust/personhog-replica/src/storage/traits/<domain>.rs - Implement the query in
rust/personhog-replica/src/storage/postgres/<domain>.rs- Use
sqlx::query_as!orsqlx::query!macros - Add timing instrumentation via
DB_QUERY_DURATIONandDB_ROWS_RETURNEDmetrics - Use
self.replica_poolfor reads,self.primary_poolfor writes - Return early for empty batch inputs
- Use
- Add storage tests in
rust/personhog-replica/tests/storage_tests.rs
3b. Service layer (personhog-replica)
- Add the RPC handler in
rust/personhog-replica/src/service/mod.rs- Extract fields from the proto request
- Call the storage trait method
- Convert storage results to proto responses
- Map storage errors to tonic
Statuscodes
- Add service tests in
rust/personhog-replica/tests/service_tests.rs
3c. Router wiring (personhog-router)
- Add the method to
rust/personhog-router/src/router/mod.rs- Use the
route_requestfunction (imported fromrouting.rs) with the correctDataCategoryandOperationType - Call the replica (or leader) backend
- Use the
call_backend!macro for instrumentation
- Use the
- Add the service impl to
rust/personhog-router/src/service/mod.rs- Invoke the
route_request!macro (defined at the top of this file) to delegate to the router
- Invoke the
- Add to the backend trait in
rust/personhog-router/src/backend/mod.rsand implement inreplica.rs - Add router tests in
rust/personhog-router/tests/
Use rstest parameterized tests where multiple variations of the same behavior are being tested.
Step 4: verify
cargo build -p personhog-proto
cargo build -p personhog-replica
cargo build -p personhog-router
cargo test -p personhog-replica
cargo test -p personhog-router
Checklist
- <!-- -->Query uses an existing index (no seq scans)
- <!-- -->Proto messages added to
types/v1/<domain>.proto - <!-- -->RPC added to both
service.protoandreplica.proto(andleader.protoif needed) - <!-- -->Python stubs generated,
proto/__init__.pyupdated,client.pymethod added,fake_client.pyupdated - <!-- -->Node.js stubs generated,
client.test.tsSERVICE_DEFAULTS updated - <!-- -->Rust storage trait + postgres impl + service handler + router wiring all implemented
- <!-- -->Tests added at storage, service, and router layers
-
cargo buildandcargo testpass for all three crates
Вставить в README
Ссылка на карточку для вашего README — без картинок и счётчиков.
[DarkPlay: adding-personhog-rpc](https://darkplay.ru/ai/skills/posthog-posthog-adding-personhog-rpc)
Описание
Руководство по добавлению нового RPC в personhog-replica и personhog-router. Охватывает проверки eligibility, определение proto, генерацию кода для клиентов на Python и Node.js, реализацию на Rust (storage trait, запросы к postgres, обработчик сервиса, подключение в router) и валидацию совместимости индексов. Используй при добавлении нового gRPC-эндпоинта в personhog, переносе запроса Django ORM в personhog или расширении pers...
Из того же репозитория
Похожие скиллы и другие разделы каталога
Самые востребованные скиллов раздела по установкам и звёздам.
find-skillsvercel-labs · Помогает находить и устанавливать навыки агентов по запросам вроде «как сделать X»…
grill-memattpocock · Настойчивое интервью для доработки плана или дизайна.
hyperframesheygen-com · Обязательная точка входа для любых задач по видео, анимации и motion-графике в…
hyperframes-cliheygen-com · Цикл разработки HyperFrames CLI: init, add, render, preview, publish и другие команды.
agent-browservercel-labs · CLI для автоматизации браузера для ИИ-агентов: навигация по страницам, заполнение форм…
media-useheygen-com · Agent Media OS: единый навык для медиа в HyperFrames — BGM, SFX, изображения, голос, LUT.
hyperframes-registryheygen-com · Установка и подключение блоков реестра в композиции HyperFrames через add и catalog.
grill-with-docsmattpocock · Настойчивое интервью для доработки плана или дизайна, попутно создающее документацию (ADR…
improve-codebase-architecturemattpocock · Поиск в кодовой базе возможностей для углубления, визуальный HTML-отчёт о них и детальный…
tddmattpocock · Разработка через тестирование (TDD): red-green-refactor и интеграционные тесты.Соседние разделы каталога: возможно, нужный инструмент живёт там.
amazon-location-serviceanthropics · Помогает разработчикам добавлять карты, поиск мест, геокодирование, маршрутизацию и…
deepevalanthropics · Навыки для добавления в AI-приложения оценок DeepEval, трассировки, датасетов, отчётов…
Pr Test Analyzeranthropics · Ревью pull request на качество и полноту тестового покрытия.
deepevalconfident-ai · Навыки для добавления в ИИ-приложения оценок DeepEval, трассировки, датасетов, отчётов…
amazon-location-serviceanthropics · Помогает разработчикам добавлять карты, поиск мест, геокодирование и маршрутизацию через…
billing-planeanthropics · Плагин BillingPlane для Stripe: помогает Claude избегать типичных ошибок биллинга на…
dependency-evaluatoranthropics · Оценка npm и Python пакетов перед добавлением: метаданные, безопасность, сложность и…
grillanthropics · Шесть агентов параллельно проверяют код и сводят находки в отчёт с оценкой серьёзности.
review-modeanthropics · Review Mode приносит структурированное ревью кода на основе аннотаций: просмот�…
sports-edge-estimatoranthropics · Оценка спортивных вероятностей на основе рейтингов ELO для баскетбола, футбола, хоккея.Лучшие ИИ-инструменты для программирования
Подборка нейросетей и ИИ-ассистентов для разработки и автоматизации кода. Сервисы, которые ускоряют написание, ревью и отладку, экономят часы рутины и снижают порог входа в сложные
GenAPIGenapi
Notepad++ AINotepad-plus-plus
Creatium MaxCremax
Emacs AIGnu
KiteKite
Amazon Q DeveloperAmazonЛучшие ИИ-инструменты для генерации видео
Подборка нейросетей для генерации и монтажа видео. Инструменты, которые превращают текст в готовые ролики, экономят часы на съемках и постпродакшне. Подходит для SMM-специалистов,
VEED.IOVeed
MootionMootion
Sora (OpenAI)OpenAI
viralpulse.appViralpulse
Viral Maker AIViral-makerЛучшие ИИ-инструменты для генерации текста и копирайтинга
Подборка нейросетей для генерации текстов и копирайтинга. Сервисы, которые помогают создавать статьи, посты и рекламные объявления с нуля или по черновику, экономя часы рутинной ра
NeuroscribeNeuroscribe
GoGPTGogpt
НейроТекстерNeuro-texter
ChatGPTOpenAI
Cosmo ScribeCosmoscribe
Memo HelperCopilot33
LibraChatLibrachat