Skip to main content

resolve_slug_collision

Function resolve_slug_collision 

Source
pub(super) fn resolve_slug_collision(
    conn: &Connection,
    base: &str,
) -> Result<String>
Expand description

The first of base, base-2, base-3, … that no db_agents row holds.

Shared by agent_def_insert_local_only and instance_create so the two write paths cannot drift: db_agents.slug carries no UNIQUE constraint (deliberately — see migrations.rs), so uniqueness is only ever as good as the agreement between every path that inserts one. It held in only one of them until #3497 §4.

Callers must already hold the connection lock — the scan and the INSERT have to be one critical section, or two concurrent inserts race to the same candidate.

There is deliberately no “exclude this row id” option. It looks necessary for instance_create’s ON CONFLICT(id) DO UPDATE path — a row re-resolving its own slug would otherwise collide with itself — but that clause does not assign slug at all, so on the conflict path the computed value is discarded and an exclusion could never be observed (ReAgent P2 on #3514). On the insert path the row does not exist yet, so there is nothing to exclude either. If slug is ever added to that DO UPDATE SET, this becomes real and needs revisiting.