Skip to content

chore(code): add per-user option to ph code usage reset#60301

Merged
adboio merged 3 commits into
masterfrom
05-27-chore_code_add_per-user_option_to_ph_code_usage_reset
May 27, 2026
Merged

chore(code): add per-user option to ph code usage reset#60301
adboio merged 3 commits into
masterfrom
05-27-chore_code_add_per-user_option_to_ph_code_usage_reset

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented May 27, 2026

Problem

reset_posthog_code_usage only work for ALL users, need the ability to do this per-user

Changes

adds --user-id argument to the command

usage:

reset-posthog-code-usage --dry-run --user-id <the-user-id>

How did you test this code?

tested against local stack

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Publish to changelog?

no

Docs update

no

🤖 Agent context

Copy link
Copy Markdown
Contributor Author

adboio commented May 27, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@adboio adboio marked this pull request as ready for review May 27, 2026 17:59
@adboio adboio requested a review from a team May 27, 2026 17:59
@assign-reviewers-posthog assign-reviewers-posthog Bot requested a review from a team May 27, 2026 18:00
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 27, 2026

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
services/llm-gateway/src/llm_gateway/cli/reset_posthog_code_usage.py:26-28
If an operator passes a `user_id` containing Redis glob characters (`*`, `?`, `[`), the exact-key and wildcard patterns generated by `_patterns_for` will silently expand beyond the intended user. For example `--user-id "1*"` would produce the match pattern `...posthog_code:1*`, which matches every user whose ID starts with `1`. A lightweight guard with an early error prevents this accidental over-deletion.

```suggestion
def _patterns_for(user_id: str | None) -> tuple[str, ...]:
    if user_id is None:
        return tuple(f"ratelimit:cost:user:{scope}:{POSTHOG_CODE_PRODUCT}:*" for scope in SCOPES)
    if any(c in user_id for c in ("*", "?", "[")):
        raise ValueError(f"user_id contains Redis glob characters: {user_id!r}")
```

Reviews (1): Last reviewed commit: "chore(code): add per-user option to ph c..." | Re-trigger Greptile

Comment on lines +26 to +28
def _patterns_for(user_id: str | None) -> tuple[str, ...]:
if user_id is None:
return tuple(f"ratelimit:cost:user:{scope}:{POSTHOG_CODE_PRODUCT}:*" for scope in SCOPES)
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.

P2 If an operator passes a user_id containing Redis glob characters (*, ?, [), the exact-key and wildcard patterns generated by _patterns_for will silently expand beyond the intended user. For example --user-id "1*" would produce the match pattern ...posthog_code:1*, which matches every user whose ID starts with 1. A lightweight guard with an early error prevents this accidental over-deletion.

Suggested change
def _patterns_for(user_id: str | None) -> tuple[str, ...]:
if user_id is None:
return tuple(f"ratelimit:cost:user:{scope}:{POSTHOG_CODE_PRODUCT}:*" for scope in SCOPES)
def _patterns_for(user_id: str | None) -> tuple[str, ...]:
if user_id is None:
return tuple(f"ratelimit:cost:user:{scope}:{POSTHOG_CODE_PRODUCT}:*" for scope in SCOPES)
if any(c in user_id for c in ("*", "?", "[")):
raise ValueError(f"user_id contains Redis glob characters: {user_id!r}")
Prompt To Fix With AI
This is a comment left during a code review.
Path: services/llm-gateway/src/llm_gateway/cli/reset_posthog_code_usage.py
Line: 26-28

Comment:
If an operator passes a `user_id` containing Redis glob characters (`*`, `?`, `[`), the exact-key and wildcard patterns generated by `_patterns_for` will silently expand beyond the intended user. For example `--user-id "1*"` would produce the match pattern `...posthog_code:1*`, which matches every user whose ID starts with `1`. A lightweight guard with an early error prevents this accidental over-deletion.

```suggestion
def _patterns_for(user_id: str | None) -> tuple[str, ...]:
    if user_id is None:
        return tuple(f"ratelimit:cost:user:{scope}:{POSTHOG_CODE_PRODUCT}:*" for scope in SCOPES)
    if any(c in user_id for c in ("*", "?", "[")):
        raise ValueError(f"user_id contains Redis glob characters: {user_id!r}")
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Member

@charlesvien charlesvien left a comment

Choose a reason for hiding this comment

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

L G T M 🍻

Generated-By: PostHog Code
Task-Id: 9ed9002d-cea6-4bb5-bf42-797423e55a1b
@adboio adboio merged commit 6a5659f into master May 27, 2026
145 checks passed
Copy link
Copy Markdown
Contributor Author

adboio commented May 27, 2026

Merge activity

@adboio adboio deleted the 05-27-chore_code_add_per-user_option_to_ph_code_usage_reset branch May 27, 2026 18:42
@deployment-status-posthog
Copy link
Copy Markdown

deployment-status-posthog Bot commented May 27, 2026

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-05-27 19:13 UTC Run
prod-us ✅ Deployed 2026-05-27 19:40 UTC Run
prod-eu ✅ Deployed 2026-05-27 19:42 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.

2 participants