carlos / platform Public

fix: register demo claim seed route writers

CompareSeedGate and DeleteSeedRoute join the route writer table with an
explicit forward-row fence.
codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 6531954ced0ce37b9a012ebb29a31394727a5660 parent e75b0b8
2 files changed, +34 −2
  • internal/registry/demo_claim_seed.go +2 −2
  • internal/registry/forward_writers_test.go +32 −0
diff --git a/internal/registry/demo_claim_seed.go b/internal/registry/demo_claim_seed.go
index 012b099b3..c58fc7892 100644
--- a/internal/registry/demo_claim_seed.go
+++ b/internal/registry/demo_claim_seed.go
@@ -6,7 +6,7 @@ func (r *Registry) CompareSeedGate(listed Route, source, gate string) error {
if r.remote != nil {
return errRemoteMethod
}
- result, err := r.sql.Exec(`UPDATE routes SET seed_source=?, import_gate=? WHERE host=? AND kind='instance' AND provisioned=1 AND account=? AND app=? AND incarnation=? AND serving_seq=? AND seed_source=? AND import_gate=? AND created_at=?`,
+ result, err := r.sql.Exec(`UPDATE routes SET seed_source=?, import_gate=? WHERE host=? AND kind='instance' AND kind <> 'forward' AND provisioned=1 AND account=? AND app=? AND incarnation=? AND serving_seq=? AND seed_source=? AND import_gate=? AND created_at=?`,
source, gate, listed.Host, listed.Account, listed.App, listed.Incarnation, listed.ServingSeq, listed.SeedSource, listed.ImportGate, listed.CreatedAt)
if err != nil {
return err
@@ -39,7 +39,7 @@ func (r *Registry) DeleteSeedRoute(listed Route) (bool, error) {
if r.remote != nil {
return false, errRemoteMethod
}
- result, err := r.sql.Exec(`DELETE FROM routes WHERE host=? AND kind='instance' AND provisioned=1 AND account=? AND app=? AND incarnation=? AND serving_seq=? AND seed_source=? AND import_gate=? AND created_at=?`,
+ result, err := r.sql.Exec(`DELETE FROM routes WHERE host=? AND kind='instance' AND kind <> 'forward' AND provisioned=1 AND account=? AND app=? AND incarnation=? AND serving_seq=? AND seed_source=? AND import_gate=? AND created_at=?`,
listed.Host, listed.Account, listed.App, listed.Incarnation, listed.ServingSeq, listed.SeedSource, listed.ImportGate, listed.CreatedAt)
if err != nil {
return false, err
diff --git a/internal/registry/forward_writers_test.go b/internal/registry/forward_writers_test.go
index e6f2e3b67..689cc4cb1 100644
--- a/internal/registry/forward_writers_test.go
+++ b/internal/registry/forward_writers_test.go
@@ -162,6 +162,8 @@ type writerCase struct {
// refuses: on a forward host the writer answers ErrForwardRow. Otherwise
// it answers no error and reports no change.
refuses bool
+ // A conditional writer can report a stale identity without changing a row.
+ forwardError error
// moves is a host whose row the forward arm may change (the carry
// entries' non-forward source); every other row must stay.
moves string
@@ -317,6 +319,8 @@ func replicaWriterCase(name string) writerCase {
func routeWriterCases() []writerCase {
ctx := context.Background()
cases := []writerCase{
+ demoClaimSeedWriterCase("CompareSeedGate"),
+ demoClaimSeedWriterCase("DeleteSeedRoute"),
replicaWriterCase("SetReplicaAssignment"),
replicaWriterCase("SeedReplicaAssignment"),
replicaWriterCase("DeleteReplicaAssignment"),
@@ -570,6 +574,7 @@ func routeWriterCases() []writerCase {
// boolWriters are the cases whose writer answers with a bool: the positive
// arm must see true.
var boolWriters = map[string]bool{
+ "DeleteSeedRoute": true,
"DeleteReplicaAssignment": true, "ReplaceReplicaAssignment": true,
"InstallLifetimeIf": true, "SetHoldIf": true, "SetHoldIfSeq": true, "HandHold": true, "ReleaseHold": true,
"ReleaseHoldSeq": true, "DeleteIfHold": true, "DeleteIfHoldWithTimers": true, "DeleteIfUnchanged": true,
@@ -624,6 +629,10 @@ func TestEveryRouteWriterRefusesAForwardRow(t *testing.T) {
if !errors.Is(err, ErrForwardRow) {
t.Errorf("on a forward row: err = %v, want ErrForwardRow", err)
}
+ } else if c.forwardError != nil {
+ if !errors.Is(err, c.forwardError) || changed {
+ t.Errorf("on a forward row: changed %v, err %v; want %v", changed, err, c.forwardError)
+ }
} else if err != nil || changed {
t.Errorf("on a forward row: changed %v, err %v; want no change and no error", changed, err)
}
@@ -843,3 +852,26 @@ func TestBulkSettersCheckEveryHostBeforeTheirFirstWrite(t *testing.T) {
})
}
}
+
+// Both writers must change a matching instance and leave a forward row byte
+// identical, even when every owner, lifetime and seed column still matches.
+func demoClaimSeedWriterCase(name string) writerCase {
+ c := writerCase{name: name, encloses: []string{name}}
+ if name == "CompareSeedGate" {
+ c.forwardError = ErrHostHeld
+ }
+ c.setup = func(t *testing.T, r *Registry) (string, writerCall) {
+ host := plainRow(t, r, func(rt *Route) {
+ rt.Kind, rt.Provisioned = "instance", true
+ rt.SeedSource, rt.ImportGate = "seed", ImportGateClosed
+ })
+ listed := mustRoute(t, r, host)
+ return host, func(bool) (bool, error) {
+ if name == "CompareSeedGate" {
+ return false, r.CompareSeedGate(listed, "next-seed", "verify-hash")
+ }
+ return r.DeleteSeedRoute(listed)
+ }
+ }
+ return c
+}