AI-Assisted Coding Lab · Roll Out Feature Flags by Percentage

45:00left of 45:00

Roll Out Feature Flags by Percentage

Product ramps features through flags, and the API runs as many processes that restart on every deploy. The README has the rules and what goes wrong in production when assignment drifts. Build flags.py with the assistant, and judge each suggestion by how it behaves across the whole fleet.

flags.py1 of 3

Files

flags.py

Python · Editable
from dataclasses import dataclass, field
BUCKETS = 10_000
@dataclass
class Flag:
name: str
percent: float = 0.0 # share of users, 0 to 100
allow: set = field(default_factory=set) # user ids always on
deny: set = field(default_factory=set) # user ids always off
killed: bool = False
def __post_init__(self):
pass
def bucket(flag_name, user_id):
"""A number from 0 to BUCKETS - 1, the same for a flag and user on every host and every deploy."""
raise NotImplementedError
def in_rollout(flag, user_id):
"""True when the user's bucket falls inside the flag's percentage."""
raise NotImplementedError
def is_enabled(flag, user_id):
return in_rollout(flag, user_id)

Test Output

No runs yet.

Assistant

Scripted
  1. Send the first prompt to start.

Next Prompt

Write bucket. Each flag should pick its own users.