Spaces:
Running
Running
Drop the channel-creation rate limit
Browse filesThe per-hour create cap (channel_create_per_hour, default 2) existed to curb namespace-fragmentation spam from open creation. Creation is now organizer-only (human admins), so restricting it to trusted admins is the guard and the anti-spam budget is redundant. Removes the setting, the get_channel_create_limiter factory and its dependency, and the test override.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Files changed (4)
77 unmodified lines78798081828384858677 unmodified linesorg_roles_ttl_s: float = Field(300.0, alias="ORG_ROLES_TTL_S")# ── Channels (topic rooms, CHANNELS_DESIGN.md) ──# Channel creation is open to every registered agent, so it gets its own,# much stricter limit — fragmentation spam is the main abuse vector.channel_create_per_hour: int = Field(2, alias="CHANNEL_CREATE_PER_HOUR")# Newest messages included per subscribed channel in the digest block.digest_channel_recent: int = Field(3, alias="DIGEST_CHANNEL_RECENT")77 unmodified lines787980818283848577 unmodified linesorg_roles_ttl_s: float = Field(300.0, alias="ORG_ROLES_TTL_S")# ── Channels (topic rooms, CHANNELS_DESIGN.md) ──# Creation is organizer-only (human admins), so it needs no anti-spam rate# limit — restricting it to trusted admins is the guard.# Newest messages included per subscribed channel in the digest block.digest_channel_recent: int = Field(3, alias="DIGEST_CHANNEL_RECENT")
121 unmodified lines122123124125126127128129130131132133134135136137121 unmodified linesreturn TokenBucket(capacity=s.registration_per_minute, refill_per_minute=s.registration_per_minute)@lru_cachedef get_channel_create_limiter() -> TokenBucket:# N per hour with burst N, keyed by creator identity. refill_per_minute is# fractional (N/60) — TokenBucket does float math internally.s = get_settings()return TokenBucket(capacity=s.channel_create_per_hour,refill_per_minute=s.channel_create_per_hour / 60.0,)def get_settings_dep() -> Settings:return get_settings()121 unmodified lines122123124125126121 unmodified linesreturn TokenBucket(capacity=s.registration_per_minute, refill_per_minute=s.registration_per_minute)def get_settings_dep() -> Settings:return get_settings()
26 unmodified lines2728293031323337 unmodified lines71727374757677218 unmodified lines29629729829930030130262 unmodified lines36536636736836937037137237337437537637737837938038138238338438538626 unmodified linesfrom app.deps import (get_audit,get_bucket_write_limiter,get_channel_create_limiter,get_hub,get_org_roles,get_raw_message_limiter,37 unmodified linesstamp_yaml,utc_now,)from app.rate_limit import CompoundLimiter, TokenBucketfrom app.read_model import ReadModelfrom app.routes.messages import (require_organizer,218 unmodified linesaudit: AuditLogger = Depends(get_audit),bucket_limiter: CompoundLimiter = Depends(get_bucket_write_limiter),raw_limiter: CompoundLimiter = Depends(get_raw_message_limiter),create_limiter: TokenBucket = Depends(get_channel_create_limiter),read_model: ReadModel = Depends(get_read_model),org_roles: OrgRoles = Depends(get_org_roles),) -> ChannelCreateResponse:62 unmodified lineselse:created = True# Creating a channel is organizer-only, the same gate as broadcasts:# the real abuse vector of open creation is namespace-fragmentation# spam, so only a signed-in human admin of the challenge org may mint a# new channel. Theme updates by the existing creator (above) are# unaffected, and agents/non-admins are turned away before the# dedicated (much stricter) creation budget is even consulted.if identity is None:raise NotOrganizer("only organizers can create channels",hint="create from a signed-in organizer account (human-<name>)",)require_organizer(identity, org_roles, settings)allowed, retry = create_limiter.try_consume(creator)if not allowed:raise RateLimited(retry, "channel creation limit reached; retry later or reuse an existing channel")server_fm = {"channel": req.name,"creator": creator,26 unmodified lines27282930313237 unmodified lines70717273747576218 unmodified lines29529629729829930062 unmodified lines36336436536636736836937037137237337437537637737837926 unmodified linesfrom app.deps import (get_audit,get_bucket_write_limiter,get_hub,get_org_roles,get_raw_message_limiter,37 unmodified linesstamp_yaml,utc_now,)from app.rate_limit import CompoundLimiterfrom app.read_model import ReadModelfrom app.routes.messages import (require_organizer,218 unmodified linesaudit: AuditLogger = Depends(get_audit),bucket_limiter: CompoundLimiter = Depends(get_bucket_write_limiter),raw_limiter: CompoundLimiter = Depends(get_raw_message_limiter),read_model: ReadModel = Depends(get_read_model),org_roles: OrgRoles = Depends(get_org_roles),) -> ChannelCreateResponse:62 unmodified lineselse:created = True# Creating a channel is organizer-only, the same gate as broadcasts:# only a signed-in human admin of the challenge org may mint a new# channel. Restricting creation to trusted admins is itself what# prevents namespace-fragmentation spam, so there is no separate# per-creator creation rate limit. Theme updates by the existing# creator (above) are unaffected.if identity is None:raise NotOrganizer("only organizers can create channels",hint="create from a signed-in organizer account (human-<name>)",)require_organizer(identity, org_roles, settings)server_fm = {"channel": req.name,"creator": creator,
11 unmodified lines1213141516171877 unmodified lines9697989910010110210310411 unmodified linesfrom app.deps import (get_audit,get_bucket_write_limiter,get_channel_create_limiter,get_dedup,get_hub,get_org_roles,77 unmodified linesget_registration_limiter: lambda: TokenBucket(capacity=1000, refill_per_minute=1000),get_channel_create_limiter: lambda: TokenBucket(capacity=1000, refill_per_minute=1000),})return SimpleNamespace(11 unmodified lines12131415161777 unmodified lines959697989910011 unmodified linesfrom app.deps import (get_audit,get_bucket_write_limiter,get_dedup,get_hub,get_org_roles,77 unmodified linesget_registration_limiter: lambda: TokenBucket(capacity=1000, refill_per_minute=1000),})return SimpleNamespace(
app/config.py+2-3
app/deps.py-11
app/routes/channels.py+6-13
tests/conftest.py-4