8000 fix(groups): hold a group's slug to one rule whenever it is set by mwoods79 · Pull Request #742 · huddlz-hq/huddlz · GitHub
[go: up one dir, main page]

Skip to content

fix(groups): hold a group's slug to one rule whenever it is set - #742

Merged
mwoods79 merged 10 commits into
mainfrom
t3/validate-group-slug
Dec 1, 2026
Merged

mwoods79 merged 10 commits into
mainfrom
t3/validate-group-slug

Conversation

@mwoods79
@mwoods79 mwoods79 commented Nov 30, 2026 •
Copy link
Copy Markdown
Contributor

Summary

Group addresses accept 1–255 lowercase ASCII letters, digits and hyphens. The address new is reserved for group creation. An address supplied on create or update is validated as entered, including surrounding whitespace. Owners can still edit other details on a legacy group without supplying its address.

The migration repairs invalid addresses in creation order, using the group ID to resolve collisions. During a rolling deploy, a unique boot or daily job picks up invalid addresses written by older servers.

Evidence

  • Before: On a local PostgreSQL 16 database with 30,000 invalid group addresses and no competing writer, the original migration exhausted its 15-second transaction deadline. All 30,000 rows retained their old addresses and the migration version was absent.
  • After: On the same fixture, Ecto reported 0.6 seconds for the migration. All 30,000 rows had their expected addresses and the migration version was recorded.
  • JSON:API coverage verifies that a description-only edit succeeds on a legacy group. Explicitly resubmitting its invalid address returns a slug validation error and preserves the previously saved description.
  • Separate-connection tests exercise a competing writer and verify that persistent contention exhausts the job with a recorded reason. Duplicate schedules reuse the unfinished job. Successful repair tests use a connection-local copy of the group table and its indexes.

Merge Danger

Door: one-way. The migration rewrites invalid addresses in place. Rolling back does not restore their old links.

Blast Radius: Addresses

  • Existing valid group links keep working. Groups with repaired addresses need new links. Names that cannot produce an address require an explicit valid slug or a different name.
  • The repair asks for an exclusive table lock while holding no group row locks. Ordinary reads continue. Writers may wait during lock acquisition (up to 500 ms per attempt) and while the repair runs. The repair transaction has a two-minute deadline and holds the occupied addresses and pending replacements in memory.
  • On a busy table, the migration retries. The job can snooze four times for one minute each, then sustained contention consumes its five ordinary attempts. Once that job finishes or is discarded, a future schedule can enqueue another repair.
  • Ash enforces the rule across interfaces. The migration calls the shared repair module, which must remain available to fresh installations after the temporary schedule is retired.

A slug was checked only when a group's details were edited. One given
when a group was created could hold any characters at any length, and
nothing limited the length on an edit either. The same rule now applies
whenever a slug is set: lowercase letters, digits and hyphens, at most
255 characters. A slug derived from the name always satisfies it, and a
name with nothing a slug can be made from is refused. A migration
rewrites existing slugs that break the rule.
…a rolling deploy

The repair gave up after two candidates, could overwrite an owner's edit
or lose a candidate to one made while it ran, could hand a group the
address of the page that creates groups, and ran only once, before
servers of the previous release had stopped writing unchecked slugs. It
now keeps looking until a slug is free, makes writers wait while it
runs, never gives out "new", and runs again each day from a job. A slug
is also judged exactly as given: it is no longer trimmed first, and
"new" is refused.
…he table

The repair locked the whole table while it worked. An owner editing their
group reads the row with a lock and then writes; holding the table between
those two steps set the repair and the edit against each other, and held
up writes to every other group meanwhile. Each group is now settled by a
single statement that replaces the slug only while it is still the broken
one that was read and only with a slug nobody has. The migration runs it
outside a transaction, so no row stays locked while the next is handled.
… a contested slug

The repair locked a group and then waited for its new slug while someone
creating a group held that slug uncommitted, and they in turn could be
waiting on a third transaction that wanted the locked group. The repair
now locks the group with nothing else held, and cuts the wait for the
slug short: it lets the group go and tries the next candidate. Its tests
read who is waiting for whom from the database before going on.
…ding nothing

Settling each group under its own row lock still left the repair holding
that row while it waited for a slug another writer was claiming, a wait
that could close a cycle. The repair now asks for the whole table before
it touches anything and works only once it has it: at that point nobody
else holds a row or an unfinished claim, so it never waits again. If the
table is not free within half a second the attempt is dropped and tried
again later, so writers are never held up for long. The caller's own lock
wait is put back as it was found.
@mwoods79
mwoods79 merged commit 1e6cf94 into main Dec 1, 2026
5 checks passed
@mwoods79
mwoods79 deleted the t3/validate-group-slug branch December 1, 2026 20:43
mwoods79 added a commit that referenced this pull request Dec 1, 2026
…n-escaping

* origin/main:
  fix(groups): hold a group's slug to one rule whenever it is set (#742)
  fix(huddl): copy only huddlz the actor can organize (#723)
  fix(auth): have open pages follow a change of access (#735)
  fix(groups): authorize membership changes against their roster (#739)
  fix(auth): bind administrator viewing credentials to the browser session (#736)
mwoods79 added a commit that referenced this pull request Dec 1, 2026
* origin/main:
  fix(notifications): notify only people who can open the huddl (#731)
  fix(groups): hold a group's slug to one rule whenever it is set (#742)
  fix(huddl): copy only huddlz the actor can organize (#723)
mwoods79 added a commit that referenced this pull request Dec 1, 2026
* origin/main:
  fix(auth): revoke reset links when the email address changes (#732)
  fix(notifications): notify only people who can open the huddl (#731)
  fix(groups): hold a group's slug to one rule whenever it is set (#742)
  fix(huddl): copy only huddlz the actor can organize (#723)
mwoods79 added a commit that referenced this pull request Dec 1, 2026
* origin/main:
  fix(auth): revoke reset links when the email address changes (#732)
  fix(notifications): notify only people who can open the huddl (#731)
  fix(groups): hold a group's slug to one rule whenever it is set (#742)
  fix(huddl): copy only huddlz the actor can organize (#723)
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.

1 participant

0