chore(code): add per-user option to ph code usage reset#60301
Merged
adboio merged 3 commits intoMay 27, 2026
Conversation
Contributor
Prompt To Fix All With AIFix 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) |
Contributor
There was a problem hiding this 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.
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.Generated-By: PostHog Code Task-Id: 9ed9002d-cea6-4bb5-bf42-797423e55a1b
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
reset_posthog_code_usageonly work for ALL users, need the ability to do this per-userChanges
adds
--user-idargument to the commandusage:
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