Skip to content

chore: reduce complexity of three C901-flagged functions - #92081

Draft
posthog[bot] wants to merge 1 commit into
masterfrom
posthog-self-driving/refactorpython-reduce-three-production-2b7397
Draft

chore: reduce complexity of three C901-flagged functions#92081
posthog[bot] wants to merge 1 commit into
masterfrom
posthog-self-driving/refactorpython-reduce-three-production-2b7397

Conversation

@posthog

@posthog posthog Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Problem

  • Three production functions exceed Ruff's C901 complexity limit (10), so each mixes several concerns in one body and reads as a single dense branch tree. This raises regression risk on person-property reconstruction, review progress, and warehouse ingestion paths.
  • build_person_properties_at_time scored 17, resolution_states scored 12, and get_rows scored 11.

Changes

No behavior changes — each function keeps its query bounds, retry behavior, and resolution semantics. The split is mechanical helper extraction.

  • build_person_properties_at_time: input validation, ClickHouse query construction, and property reconstruction now live in focused helpers. A shared JSON parser removes the two duplicated $set / $set_once try/except blocks.
  • resolution_states: run loading, liveness filtering (supersession and completion), and verdict aggregation are separate helpers; the top-level function reads as three steps plus the final state build.
  • get_rows: the retrying POST builder, scroll-page extraction with float coercion, and best-effort scroll cleanup are separate helpers; the walk loop stays in get_rows.

How did you test this code?

  • ruff check --select C901 reports no violations on the three files; full ruff check and ruff format --check pass.
  • Ran the covering unit tests locally: 20 person point-in-time tests and 33 Elasticsearch tests pass.
  • Review Hog progress tests need Postgres, which was not available in this environment; CI covers them. No manual UI testing was done — the change is a behavior-preserving refactor.

Automatic notifications

  • Publish to changelog?

Docs update

None — no user-facing behavior, API, or config change.

🤖 Agent context

Autonomy: Fully autonomous

  • Authored by an agent (Claude Code). Skills invoked: /writing-code-comments, /writing-pr-descriptions.
  • Scope was a lint-driven cleanup: reduce cyclomatic complexity on three flagged functions without changing behavior. Helpers were chosen to match the concern boundaries the functions already implied (validate / build query / reconstruct; load / filter / aggregate; request / page / cleanup).
  • The nested resolution_states closure _latest_after was promoted to a module-level _latest_created_at helper so the liveness filter could move out cleanly; same query and behavior.

Created with PostHog Desktop from this inbox report.

Extract helpers to bring three functions under Ruff's C901 limit of 10,
preserving query bounds, retry behavior, and resolution semantics.

- build_person_properties_at_time: split input validation, query
  construction, and property reconstruction into helpers.
- resolution_states: separate run loading, liveness filtering, and
  verdict aggregation.
- get_rows: isolate the retrying request builder, page extraction, and
  scroll cleanup.

Generated-By: PostHog Desktop
Task-Id: 14988e0a-3dae-4762-aeba-ca4db6b456ef
@posthog

posthog Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

🦔 PostHog Review reviewed this pull request

Nothing worth raising this time, so here's a calming picture instead:

A panda relaxing and waving

@trunk-io

trunk-io Bot commented Sep 1, 2026

Copy link
Copy Markdown

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@posthog posthog Bot added the skip-agent-review Save $$$, skip auto agent reviews (Greptile) — use for trivial or chore PRs label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

⚠️ Trunk lane — backend Python lane

This PR is assigned to the backend Python lane. It runs backend Python tests and may merge in parallel with PRs in other lanes.

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

Approved.

Verified line-by-line: each of the three refactors extracts existing logic into helpers with identical control flow, no behavior change, and none of the touched code enters risky territory (no schema/API/auth/billing/dependency/CI changes).

Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 263L, 3F substantive — within ceiling
tier T1-agent / T1c-medium (263L, 3F, two-areas, chore)
stamphog 2.0.0b4 .stamphog/policy.yml @ f82e49c · reviewed head f82e49c

@trunk-io

trunk-io Bot commented Sep 1, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-agent-review Save $$$, skip auto agent reviews (Greptile) — use for trivial or chore PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants