You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(ra): ANS name is permanently consumed on cancel/failure — agent_registrations holds the name before an agent is ever active #88
RegistrationService.finalizeServerOrder documents that a terminal
certificate-order failure leaves the lifecycle at PENDING_VALIDATION
"so the operator can cancel and re-register without the ANS name being
burned by a FAILED agent" (internal/ra/service/lifecycle.go:702-703).
That guarantee does not hold: the ANS name is consumed the moment a row
exists in agent_registrations, and it stays consumed after cancel.
Current behavior
Re-registration is gated by preflightRegistrationConflicts, which
calls ExistsByAnsName (internal/ra/service/registration.go:579).
ExistsByAnsName is status-blind: SELECT COUNT(1) FROM agent_registrations WHERE ans_name = ?
(internal/adapter/store/sqlite/agent.go:328-335).
Cancel/revoke retires the row to REVOKED but does not remove it, so
the ans_name still matches → re-register fails with ANS_NAME_TAKEN.
Net: a name is burned by a registration that never reached ACTIVE,
which is exactly what the comment says won't happen.
Expected behavior
An ANS name should only be consumed once an agent becomes ACTIVE (i.e.
once an AGENT_REGISTERED leaf is sealed into the TL and the name is
resolvable). A registration that fails or is cancelled before activation
should free the name for re-registration by the same owner.
Root cause
In-flight registrations and committed registrations share one table
(agent_registrations) keyed on ans_name. There is no separation
between "an application in progress" and "a name that is live in the
registry," so name exclusivity is enforced from first insert rather than
from activation.
Proposed fix
Introduce a dedicated agent_application table for in-flight
registrations. A name is promoted into agent_registrations
(and thus becomes "taken") only at activation. Pre-active cancel/failure
simply drops the application row, freeing the name.
Names are never taken until an agent becomes ACTIVE.
Removes the status-blind exclusivity check as the burn point.
Scope / acceptance criteria
New agent_application table + store/port for in-flight state.
Name exclusivity (ANS_NAME_TAKEN) enforced against active
registrations only; already-ACTIVE/DEPRECATED names stay burned
(identity-confusion protection — a name with a TL leaf must never
be reused).
Cancel/failure before activation frees the name; re-registration
by the same owner succeeds.
finalizeServerOrder comment matches actual behavior.
Migration + tests; internal/domain stays at 100%, make check
passes.
Notes
Preserve the existing invariant that names which did reach ACTIVE
(TL leaf sealed, potentially resolved/cached by clients) remain
permanently burned. The security boundary is "was this name ever
ACTIVE," not "did it pass verify-acme."
I'd like to take this one. Working through the acceptance criteria I hit a fork on the first bullet, so I want your call before I open a PR.
The burn point needs a durable "was this name ever ACTIVE" marker, not a status test.REVOKED is reachable both from ACTIVE (must stay burned) and from a pre-active cancel (must free the name), so status alone cannot separate the two. I would add activated_at_ms to agent_registrations, stamped in AgentRegistration.Activate, and make that the exclusivity predicate — it reads as exactly the boundary you state in the notes.
The backfill can be exact rather than conservative. commitActivation is the only writer of the sealed AGENT_REGISTERED outbox row (internal/ra/service/registration.go:757) and nothing prunes outbox_events (the feed's retention window is a read-side filter), so:
UPDATE agent_registrations SET activated_at_ms = updated_at_ms
WHERE status IN ('ACTIVE','DEPRECATED')
OR agent_id IN (SELECT agent_id FROM outbox_events WHERE event_type ='AGENT_REGISTERED');
stamps precisely the names that have a TL leaf, and leaves genuinely never-active rows reclaimable.
On agent_application — I would rather not split the table, and I would like to check that with you before building either way. In-flight state is not only the registration row: identity_csrs, issued_certificates and byoc_certificates FK agent_registrations(agent_id); server_cert_renewals and agent_revocations FK agent_registrations(id); and the cert order, ACME challenge and discovery profiles are columns on the row itself (migrations 005/008/010/012). An application accumulates all of that before activation, so a real split means those children either move with it or lose their FK — a five-table rebuild on a schema opened with foreign_keys(1) and ON DELETE CASCADE throughout. That is a lot of blast radius for an invariant fix.
The behaviour in your criteria falls out without it. ans_name is UNIQUE at the DB level, so rather than tolerate duplicate rows I would reclaim in preflightRegistrationConflicts. An existing row for the name is ANS_NAME_TAKEN if it ever activated, or belongs to another owner, or is still pending for this owner. If it is the same owner's terminal, never-activated application, the register transaction drops it and proceeds. Same end state you described — "pre-active cancel/failure simply drops the application row" — with one table, one new column, UNIQUE(ans_name) kept as the backstop, and no window in which two rows race to activate the same name.
One consequence worth naming: dropping the row cascades its agent_revocations audit line. That happens only when the same owner actually re-registers that exact name, not at cancel time, so the record of a cancelled application survives unless the owner reuses the name — but it is a trade, not a free win, and I would rather you weigh it than find it in a diff.
Happy to build the full agent_application split instead if you would rather have the structural separation. Say which and I will do that one.
Either way it comes with the migration, the finalizeServerOrder comment correction, and tests covering cancel then re-register, ever-active names staying burned, and the cross-owner case.
Thanks for working through this. I agree we need a durable distinction between an unpublished attempt and a name that has reached the TL, but there are two things we need to settle before choosing the storage approach.
First, same-owner-only reclamation leaves a name-squatting problem. An authenticated user can submit an otherwise valid request for ans://v1.0.0.agent.google.com without ever proving control of that FQDN. The real domain controller then gets ANS_NAME_TAKEN, including after the first user's challenge expires, because it is a different account. This is the exact name and version on that RA, not a reservation of all of google.com, but it still shouldn't be possible. I reproduced the block before and after expiry without the first applicant attempting domain verification.
We need to let independent applicants reach domain verification for the same name, then establish the exclusive claim atomically after proof and before publication. Keeping unconditional UNIQUE(ans_name) across unverified applications doesn't give us that. I'm not attached to the number of tables, but I'd only keep one table if the uniqueness rules support that separation; otherwise the application table has a real purpose beyond cleanup.
Second, the backfill isn't exact. Activate changes the aggregate in memory, then verify-dns seals the event, then commitActivation saves ACTIVE and writes the outbox row. Cancellation during sealing, or a lost acknowledgment followed by cancellation, can leave a published registration with neither piece of database evidence.
I checked both cases against the real log implementation. Both left an ACTIVE badge with an inclusion proof in the TL, a REVOKED row in the RA, and no activation outbox entry. The proposed SQL would allow the name to be reused.
So absence from the outbox isn't enough to establish that nothing was published. We need durable tracking of the publication attempt and a recovery path for uncertain outcomes. Existing rows with uncertain history need to stay protected unless we can establish what happened. Neither table layout fixes that by itself.
For a straightforward terminal, unpublished attempt, replacing the row when someone actually re-registers is fine. An error response alone isn't enough to make it reclaimable. Your transactional replacement approach sounds right: keep preflight read-only, recheck eligibility in the transaction, and give the replacement a new agentId.
Two cleanup details also need covering: agent_endpoints doesn't cascade, and we must finish outstanding certificate revocation before deleting the records needed for it. The current cancel path doesn't write the agent_revocations audit row described here, so any retention guarantee needs to be explicit.
This also needs the matching ANS-2 change. Previously published names stay consumed; this fix should reclaim genuinely unpublished attempts without letting an unverified applicant block the actual domain controller.
I don't think we need to solve either policy in this fix. The overlap we do need to account for now is keeping unverified applications, current domain claims, and published registration history separate. An abandoned attempt shouldn't reserve a name against the real controller, and cleaning up an application must not erase a registration that already reached the TL.
For recovery, my preference is to allow the existing customer to renew the same registration and version during a fixed window after fresh domain-control proof. That would preserve the option to recover, not extend expired certificates. The duration, final-state behavior, and interaction with a new domain owner are decisions for those follow-ups.
You are right on both counts, and the second one moves me off the one-table design, so let me take them in that order.
The backfill
I went and checked this against the source rather than take it on trust, and it confirms what you reproduced. SealAgentEvent is called at internal/ra/service/registration.go:838, and only after it returns does commitActivation (:703) save ACTIVE (:754) and RecordSealed the outbox row (:757). The comment directly above the seal log line says it outright: logged before the commit, so that if the commit then fails, the log line is what ties the orphaned AGENT_REGISTERED leaf back to this RA. The outbox is a record of commits, not of publications. My SQL would have freed names that are published permanently in a sealed log. Withdrawn.
What I think replaces it: the TL can answer the question exactly, per agent, independent of any RA database state. GET /v1/agents/{agentId}/audit (internal/tl/handler/handler.go:120) returns the events that ever named an agent. That is an exact source where the outbox was a proxy. It has to be a migration-time or admin job rather than an in-transaction call, since the RA's TL client is append-only, and it degrades the right way: if the TL cannot answer, or answers ambiguously, the row stays protected. That is your rule for uncertain history, enforced by the reconciler's failure mode rather than by a promise.
The squatting case
I had not considered an applicant who never attempts verification, and it is decisive. My design leaned on UNIQUE(ans_name) as the backstop that made one table safe. Your case is precisely an argument that unverified applications must not be unique on the name, so the backstop has to go, and most of what made one table attractive goes with it. The separation you are describing is real, and it is not a cleanup convenience.
Where I would still push back is on what gets separated. The blast radius I was worried about comes from moving in-flight state, because identity_csrs, issued_certificates and byoc_certificates FK agent_registrations(agent_id), server_cert_renewals and agent_revocations FK (id), and the cert order, ACME challenge and discovery profiles are columns on the row. None of that is what needs separating. The thing that must be separated is the exclusive claim.
So: leave agent_registrations as the application and working table, with every child FK untouched, and drop UNIQUE(ans_name) from it. Add one narrow table that holds nothing but the claim.
Any number of independent applicants may hold agent_registrations rows for the same ans_name at once, and each can run domain verification. No one is blocked at application time.
The claim row is inserted after proof of control and before publication, in the same transaction that commits the proof. The first applicant to get there wins on the primary key; the losers get ANS_NAME_TAKEN at that moment, which is the first moment it is true.
PUBLISHING is stamped in its own committed transaction immediately before the TL seal. PUBLISHED is stamped after commitActivation.
Only CLAIMED is ever releasable. PUBLISHING and PUBLISHED never are.
Dropping the constraint costs nothing live, for what it is worth: the only name-keyed lookup, FindByAnsName, has no production callers on 83875d0, it is defined in the port and the sqlite store and used from tests. The claim table is the natural place for that index to live once something does need it, and it will return the published row by construction rather than by assuming uniqueness across applications.
That maps onto your three categories directly: unverified applications are registration rows with no claim row, current domain claims are CLAIMED rows, and published registration history is PUBLISHED rows, which are never deleted. It is one new table rather than five rebuilt ones, and it is the table that carries the invariant rather than the paperwork.
The publication attempt, which you correctly said neither layout fixes by itself
PUBLISHING is the durable record of the attempt. A cancellation during sealing, or a lost acknowledgement then a cancellation, leaves the claim row sitting in PUBLISHING: not reclaimable, and precisely identifying the set the TL reconciler has to resolve. Today that same sequence leaves no database evidence at all, which is the hole you found. It also gives the recovery path a finite worklist instead of "every historical row" — reconcile PUBLISHING against the audit endpoint, promote to PUBLISHED or release, and leave anything unresolved protected.
One consequence I want to name rather than have you find it: a CLAIMED row whose holder proves control and then simply stops is the same block one layer up, just behind a real proof instead of no proof at all. It needs a bounded lifetime, probably tied to the freshness of the proof that created it. I suspect the duration is the same conversation as ans-registry#64 and #65 rather than this fix, but the field to expire on should go in now, since adding it later is another migration.
The cleanup details
The claim table makes most of them disappear, because nothing gets deleted any more. A terminal, unpublished application keeps its row, its certificates and its audit trail forever; it simply holds no claim, so it blocks nobody. Re-registration is an ordinary new registration with a new agentId, which is what you asked for anyway. That removes the cascade question, the ordering problem against outstanding certificate revocation, and the retention trade I flagged in my first comment, all three, rather than solving them.
On the two you raised specifically: agent_endpoints having no FK to agent_registrations is real, I hit it in the build and had to add an explicit endpoint delete to stop the reclaim leaking a row per re-registration. Under this design that code is unnecessary. And your point that the cancel path does not write the agent_revocations row described in the issue retires my earlier trade-off note completely, since there was never an audit line there to lose. That gap looks worth its own issue regardless of this one. Happy to file it if you want it filed.
What I would do next
Say the word and I will rebuild on the claim table: migration, the claim store and port, the post-proof claim insert, the PUBLISHING stamp around the seal, the TL reconciler as an admin job, the finalizeServerOrder comment correction, and tests covering two applicants racing to verify the same name, cancel then re-register, an ever-published name staying burned across a missing outbox row, and the cross-owner case.
The activated_at_ms work becomes published_at_ms on the claim row, which is strictly better, because a column on the registration could never express the uncertain state.
Two things I would like settled before I start. Whether you want the matching ANS-2 change in the same PR or a separate one. And whether the CLAIMED expiry belongs here or in #64 and #65, since it changes whether the field ships in this migration.
Activity
sparkmastergrape commentedon Sep 7, 2026
I'd like to take this one. Working through the acceptance criteria I hit a fork on the first bullet, so I want your call before I open a PR.
The burn point needs a durable "was this name ever ACTIVE" marker, not a status test.
REVOKEDis reachable both fromACTIVE(must stay burned) and from a pre-active cancel (must free the name), so status alone cannot separate the two. I would addactivated_at_mstoagent_registrations, stamped inAgentRegistration.Activate, and make that the exclusivity predicate — it reads as exactly the boundary you state in the notes.The backfill can be exact rather than conservative.
commitActivationis the only writer of the sealedAGENT_REGISTEREDoutbox row (internal/ra/service/registration.go:757) and nothing prunesoutbox_events(the feed's retention window is a read-side filter), so:stamps precisely the names that have a TL leaf, and leaves genuinely never-active rows reclaimable.
On
agent_application— I would rather not split the table, and I would like to check that with you before building either way. In-flight state is not only the registration row:identity_csrs,issued_certificatesandbyoc_certificatesFKagent_registrations(agent_id);server_cert_renewalsandagent_revocationsFKagent_registrations(id); and the cert order, ACME challenge and discovery profiles are columns on the row itself (migrations 005/008/010/012). An application accumulates all of that before activation, so a real split means those children either move with it or lose their FK — a five-table rebuild on a schema opened withforeign_keys(1)andON DELETE CASCADEthroughout. That is a lot of blast radius for an invariant fix.The behaviour in your criteria falls out without it.
ans_nameisUNIQUEat the DB level, so rather than tolerate duplicate rows I would reclaim inpreflightRegistrationConflicts. An existing row for the name isANS_NAME_TAKENif it ever activated, or belongs to another owner, or is still pending for this owner. If it is the same owner's terminal, never-activated application, the register transaction drops it and proceeds. Same end state you described — "pre-active cancel/failure simply drops the application row" — with one table, one new column,UNIQUE(ans_name)kept as the backstop, and no window in which two rows race to activate the same name.One consequence worth naming: dropping the row cascades its
agent_revocationsaudit line. That happens only when the same owner actually re-registers that exact name, not at cancel time, so the record of a cancelled application survives unless the owner reuses the name — but it is a trade, not a free win, and I would rather you weigh it than find it in a diff.Happy to build the full
agent_applicationsplit instead if you would rather have the structural separation. Say which and I will do that one.Either way it comes with the migration, the
finalizeServerOrdercomment correction, and tests covering cancel then re-register, ever-active names staying burned, and the cross-owner case.csnitker-godaddy commentedon Sep 9, 2026
Thanks for working through this. I agree we need a durable distinction between an unpublished attempt and a name that has reached the TL, but there are two things we need to settle before choosing the storage approach.
First, same-owner-only reclamation leaves a name-squatting problem. An authenticated user can submit an otherwise valid request for
ans://v1.0.0.agent.google.comwithout ever proving control of that FQDN. The real domain controller then getsANS_NAME_TAKEN, including after the first user's challenge expires, because it is a different account. This is the exact name and version on that RA, not a reservation of all of google.com, but it still shouldn't be possible. I reproduced the block before and after expiry without the first applicant attempting domain verification.We need to let independent applicants reach domain verification for the same name, then establish the exclusive claim atomically after proof and before publication. Keeping unconditional
UNIQUE(ans_name)across unverified applications doesn't give us that. I'm not attached to the number of tables, but I'd only keep one table if the uniqueness rules support that separation; otherwise the application table has a real purpose beyond cleanup.Second, the backfill isn't exact.
Activatechanges the aggregate in memory, then verify-dns seals the event, thencommitActivationsaves ACTIVE and writes the outbox row. Cancellation during sealing, or a lost acknowledgment followed by cancellation, can leave a published registration with neither piece of database evidence.I checked both cases against the real log implementation. Both left an ACTIVE badge with an inclusion proof in the TL, a REVOKED row in the RA, and no activation outbox entry. The proposed SQL would allow the name to be reused.
So absence from the outbox isn't enough to establish that nothing was published. We need durable tracking of the publication attempt and a recovery path for uncertain outcomes. Existing rows with uncertain history need to stay protected unless we can establish what happened. Neither table layout fixes that by itself.
For a straightforward terminal, unpublished attempt, replacing the row when someone actually re-registers is fine. An error response alone isn't enough to make it reclaimable. Your transactional replacement approach sounds right: keep preflight read-only, recheck eligibility in the transaction, and give the replacement a new
agentId.Two cleanup details also need covering:
agent_endpointsdoesn't cascade, and we must finish outstanding certificate revocation before deleting the records needed for it. The current cancel path doesn't write theagent_revocationsaudit row described here, so any retention guarantee needs to be explicit.This also needs the matching ANS-2 change. Previously published names stay consumed; this fix should reclaim genuinely unpublished attempts without letting an unverified applicant block the actual domain controller.
csnitker-godaddy commentedon Sep 9, 2026
I filed two related follow-ups in the spec repo:
I don't think we need to solve either policy in this fix. The overlap we do need to account for now is keeping unverified applications, current domain claims, and published registration history separate. An abandoned attempt shouldn't reserve a name against the real controller, and cleaning up an application must not erase a registration that already reached the TL.
For recovery, my preference is to allow the existing customer to renew the same registration and version during a fixed window after fresh domain-control proof. That would preserve the option to recover, not extend expired certificates. The duration, final-state behavior, and interaction with a new domain owner are decisions for those follow-ups.
fix(client,cli): remove unimplemented name/version reuse promise; ref…
sparkmastergrape commentedon Sep 18, 2026
You are right on both counts, and the second one moves me off the one-table design, so let me take them in that order.
The backfill
I went and checked this against the source rather than take it on trust, and it confirms what you reproduced.
SealAgentEventis called atinternal/ra/service/registration.go:838, and only after it returns doescommitActivation(:703) save ACTIVE (:754) andRecordSealedthe outbox row (:757). The comment directly above the seal log line says it outright: logged before the commit, so that if the commit then fails, the log line is what ties the orphanedAGENT_REGISTEREDleaf back to this RA. The outbox is a record of commits, not of publications. My SQL would have freed names that are published permanently in a sealed log. Withdrawn.What I think replaces it: the TL can answer the question exactly, per agent, independent of any RA database state.
GET /v1/agents/{agentId}/audit(internal/tl/handler/handler.go:120) returns the events that ever named an agent. That is an exact source where the outbox was a proxy. It has to be a migration-time or admin job rather than an in-transaction call, since the RA's TL client is append-only, and it degrades the right way: if the TL cannot answer, or answers ambiguously, the row stays protected. That is your rule for uncertain history, enforced by the reconciler's failure mode rather than by a promise.The squatting case
I had not considered an applicant who never attempts verification, and it is decisive. My design leaned on
UNIQUE(ans_name)as the backstop that made one table safe. Your case is precisely an argument that unverified applications must not be unique on the name, so the backstop has to go, and most of what made one table attractive goes with it. The separation you are describing is real, and it is not a cleanup convenience.Where I would still push back is on what gets separated. The blast radius I was worried about comes from moving in-flight state, because
identity_csrs,issued_certificatesandbyoc_certificatesFKagent_registrations(agent_id),server_cert_renewalsandagent_revocationsFK(id), and the cert order, ACME challenge and discovery profiles are columns on the row. None of that is what needs separating. The thing that must be separated is the exclusive claim.So: leave
agent_registrationsas the application and working table, with every child FK untouched, and dropUNIQUE(ans_name)from it. Add one narrow table that holds nothing but the claim.agent_registrationsrows for the sameans_nameat once, and each can run domain verification. No one is blocked at application time.ANS_NAME_TAKENat that moment, which is the first moment it is true.PUBLISHINGis stamped in its own committed transaction immediately before the TL seal.PUBLISHEDis stamped aftercommitActivation.CLAIMEDis ever releasable.PUBLISHINGandPUBLISHEDnever are.Dropping the constraint costs nothing live, for what it is worth: the only name-keyed lookup,
FindByAnsName, has no production callers on83875d0, it is defined in the port and the sqlite store and used from tests. The claim table is the natural place for that index to live once something does need it, and it will return the published row by construction rather than by assuming uniqueness across applications.That maps onto your three categories directly: unverified applications are registration rows with no claim row, current domain claims are
CLAIMEDrows, and published registration history isPUBLISHEDrows, which are never deleted. It is one new table rather than five rebuilt ones, and it is the table that carries the invariant rather than the paperwork.The publication attempt, which you correctly said neither layout fixes by itself
PUBLISHINGis the durable record of the attempt. A cancellation during sealing, or a lost acknowledgement then a cancellation, leaves the claim row sitting inPUBLISHING: not reclaimable, and precisely identifying the set the TL reconciler has to resolve. Today that same sequence leaves no database evidence at all, which is the hole you found. It also gives the recovery path a finite worklist instead of "every historical row" — reconcilePUBLISHINGagainst the audit endpoint, promote toPUBLISHEDor release, and leave anything unresolved protected.One consequence I want to name rather than have you find it: a
CLAIMEDrow whose holder proves control and then simply stops is the same block one layer up, just behind a real proof instead of no proof at all. It needs a bounded lifetime, probably tied to the freshness of the proof that created it. I suspect the duration is the same conversation as ans-registry#64 and #65 rather than this fix, but the field to expire on should go in now, since adding it later is another migration.The cleanup details
The claim table makes most of them disappear, because nothing gets deleted any more. A terminal, unpublished application keeps its row, its certificates and its audit trail forever; it simply holds no claim, so it blocks nobody. Re-registration is an ordinary new registration with a new
agentId, which is what you asked for anyway. That removes the cascade question, the ordering problem against outstanding certificate revocation, and the retention trade I flagged in my first comment, all three, rather than solving them.On the two you raised specifically:
agent_endpointshaving no FK toagent_registrationsis real, I hit it in the build and had to add an explicit endpoint delete to stop the reclaim leaking a row per re-registration. Under this design that code is unnecessary. And your point that the cancel path does not write theagent_revocationsrow described in the issue retires my earlier trade-off note completely, since there was never an audit line there to lose. That gap looks worth its own issue regardless of this one. Happy to file it if you want it filed.What I would do next
Say the word and I will rebuild on the claim table: migration, the claim store and port, the post-proof claim insert, the
PUBLISHINGstamp around the seal, the TL reconciler as an admin job, thefinalizeServerOrdercomment correction, and tests covering two applicants racing to verify the same name, cancel then re-register, an ever-published name staying burned across a missing outbox row, and the cross-owner case.The
activated_at_mswork becomespublished_at_mson the claim row, which is strictly better, because a column on the registration could never express the uncertain state.Two things I would like settled before I start. Whether you want the matching ANS-2 change in the same PR or a separate one. And whether the
CLAIMEDexpiry belongs here or in #64 and #65, since it changes whether the field ships in this migration.