carlos / platform Public

Incarnation moves to provision; db forward and carlos run call it there

provision.Incarnation is hostclaim.Incarnation's body unchanged. The
console's db read and run doors, the box's dbreads agent and run worker
call it directly; hostclaim.Incarnation delegates for the claim code and
still reports a malformed legacy identity as ErrMalformed. Golden vectors
pass for both.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev a90c9dd93e579b01dcd597f41b29b3b04f37814b parent e7c58be
8 files changed, +60 −20
  • internal/console/apidbforward.go +1 −2
  • internal/console/apiruns.go +1 −2
  • internal/dbreads/agent.go +1 −2
  • internal/host/runexec.go +1 −2
  • internal/hostclaim/claim.go +8 −11
  • internal/provision/incarnation.go +32 −0
  • internal/provision/incarnation_golden_test.go +15 −0
  • internal/runs/runs.go +1 −1
diff --git a/internal/console/apidbforward.go b/internal/console/apidbforward.go
index 3b6a66777..2d4d9ccc8 100644
--- a/internal/console/apidbforward.go
+++ b/internal/console/apidbforward.go
@@ -25,7 +25,6 @@ import (
"github.com/carlosframework/platform/internal/dbdoor"
"github.com/carlosframework/platform/internal/dbquery"
"github.com/carlosframework/platform/internal/dbreads"
- "github.com/carlosframework/platform/internal/hostclaim"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
@@ -412,7 +411,7 @@ func (s *Server) admitDBRead(w http.ResponseWriter, r *http.Request) (dbReadAdmi
if err != nil {
return fail("mint id", err)
}
- inc, err := hostclaim.Incarnation(acct.Sqid, app, host, rec.CreatedAt)
+ inc, err := provision.Incarnation(acct.Sqid, app, host, rec.CreatedAt)
if err != nil {
return fail("incarnation", err)
}
diff --git a/internal/console/apiruns.go b/internal/console/apiruns.go
index b60d6a9a7..b9d61437c 100644
--- a/internal/console/apiruns.go
+++ b/internal/console/apiruns.go
@@ -15,7 +15,6 @@ import (
"os"
"time"
- "github.com/carlosframework/platform/internal/hostclaim"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
@@ -534,7 +533,7 @@ func (s *Server) handleAPIRunCreate(w http.ResponseWriter, r *http.Request) {
jsonErrorCode(w, http.StatusBadGateway, runCodeRecordFailed, runRecordFailedMsg)
return
}
- inc, err := hostclaim.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt)
+ inc, err := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt)
if err != nil {
jsonErrorCode(w, http.StatusBadGateway, runCodeRecordFailed, runRecordFailedMsg)
return
diff --git a/internal/dbreads/agent.go b/internal/dbreads/agent.go
index 78ac62fee..6d7abe273 100644
--- a/internal/dbreads/agent.go
+++ b/internal/dbreads/agent.go
@@ -17,7 +17,6 @@ import (
mrand "math/rand/v2"
"github.com/carlosframework/platform/internal/dbdoor"
- "github.com/carlosframework/platform/internal/hostclaim"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
@@ -215,7 +214,7 @@ func (a *Agent) check(ctx context.Context, req Request) (provision.Record, strin
if err != nil {
return provision.Record{}, "", err
}
- inc, ierr := hostclaim.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt)
+ inc, ierr := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt)
_, fleet := registry.FleetPlacement(rec.Region)
switch {
case ierr != nil, inc != req.Incarnation, rec.Account != req.Account, rec.App != req.App,
diff --git a/internal/host/runexec.go b/internal/host/runexec.go
index 5266f47af..8168142a6 100644
--- a/internal/host/runexec.go
+++ b/internal/host/runexec.go
@@ -11,7 +11,6 @@ import (
"time"
"github.com/carlosframework/platform/internal/activator"
- "github.com/carlosframework/platform/internal/hostclaim"
"github.com/carlosframework/platform/internal/instancectl"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
@@ -100,7 +99,7 @@ func runResultForLaunch(err error) runs.Result {
// recordIncarnation is the incarnation request.json must carry for rec;
// "" when it cannot be computed, which matches no request.
func recordIncarnation(rec provision.Record) string {
- inc, err := hostclaim.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt)
+ inc, err := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt)
if err != nil {
return ""
}
diff --git a/internal/hostclaim/claim.go b/internal/hostclaim/claim.go
index ee4caffcd..e917d2dc5 100644
--- a/internal/hostclaim/claim.go
+++ b/internal/hostclaim/claim.go
@@ -7,7 +7,6 @@
package hostclaim
import (
- "crypto/sha256"
"encoding/hex"
"errors"
"fmt"
@@ -15,7 +14,7 @@ import (
"time"
"github.com/carlosframework/platform/internal/controlname"
- "github.com/carlosframework/platform/internal/maintenanceguard"
+ "github.com/carlosframework/platform/internal/provision"
)
const (
@@ -187,17 +186,15 @@ func Key(host string) (string, error) {
return "control/hosts/" + host + ".json", nil
}
-// Incarnation is §2's identity. A record with a zero CreatedAt (written
-// before CreatedAt existed) gets the domain-separated legacy identity.
+// Incarnation is §2's identity: provision.Incarnation, which claims-off
+// code calls directly, with a malformed legacy identity reported as
+// ErrMalformed for the claim code that still calls it here.
func Incarnation(account, app, host string, created time.Time) (string, error) {
- if created.IsZero() {
- if !controlname.ValidAccount(account) || !controlname.ValidApp(app) || !controlname.ValidHostShape(host) {
- return "", ErrMalformed
- }
- sum := sha256.Sum256([]byte("carlos-legacy-incarnation-v1\x00" + account + "\x00" + app + "\x00" + host))
- return hex.EncodeToString(sum[:]), nil
+ inc, err := provision.Incarnation(account, app, host, created)
+ if errors.Is(err, provision.ErrMalformedIncarnation) {
+ return "", ErrMalformed
}
- return maintenanceguard.RecordIdentity(account, app, host, created)
+ return inc, err
}
// sidecarSuffix restates provision.SidecarSuffix (no import: avoids a cycle).
diff --git a/internal/provision/incarnation.go b/internal/provision/incarnation.go
new file mode 100644
index 000000000..83c208887
--- /dev/null
+++ b/internal/provision/incarnation.go
@@ -0,0 +1,32 @@
+package provision
+
+import (
+ "crypto/sha256"
+ "encoding/hex"
+ "errors"
+ "time"
+
+ "github.com/carlosframework/platform/internal/controlname"
+ "github.com/carlosframework/platform/internal/maintenanceguard"
+)
+
+// ErrMalformedIncarnation is Incarnation refusing a legacy identity whose
+// account, app or host is not well formed.
+var ErrMalformedIncarnation = errors.New("provision: malformed incarnation identity")
+
+// Incarnation is an instance record's identity: what db forward and carlos
+// run requests carry, and what the console and the box each compute and
+// must agree on. A record with a zero CreatedAt (written before CreatedAt
+// existed) gets the domain-separated legacy identity; any other gets
+// maintenanceguard.RecordIdentity. It moved here from hostclaim in claims
+// cleanup R1 with its bytes unchanged (incarnation_golden_test.go).
+func Incarnation(account, app, host string, created time.Time) (string, error) {
+ if created.IsZero() {
+ if !controlname.ValidAccount(account) || !controlname.ValidApp(app) || !controlname.ValidHostShape(host) {
+ return "", ErrMalformedIncarnation
+ }
+ sum := sha256.Sum256([]byte("carlos-legacy-incarnation-v1\x00" + account + "\x00" + app + "\x00" + host))
+ return hex.EncodeToString(sum[:]), nil
+ }
+ return maintenanceguard.RecordIdentity(account, app, host, created)
+}
diff --git a/internal/provision/incarnation_golden_test.go b/internal/provision/incarnation_golden_test.go
index 4bf960252..3b5052fe1 100644
--- a/internal/provision/incarnation_golden_test.go
+++ b/internal/provision/incarnation_golden_test.go
@@ -1,10 +1,12 @@
package provision_test
import (
+ "errors"
"testing"
"time"
"github.com/carlosframework/platform/internal/hostclaim"
+ "github.com/carlosframework/platform/internal/provision"
)
// incarnationVectors are the identities db forward and carlos run carry
@@ -30,6 +32,8 @@ var incarnationVectors = []struct {
}
var incarnationImpls = map[string]func(string, string, string, time.Time) (string, error){
+ "provision.Incarnation": provision.Incarnation,
+ // The claim code's delegate, until claims cleanup deletes hostclaim.
"hostclaim.Incarnation": hostclaim.Incarnation,
}
@@ -49,3 +53,14 @@ func TestIncarnationGoldenVectors(t *testing.T) {
}
}
}
+
+// hostclaim's claim callers still see hostclaim.ErrMalformed for a malformed
+// legacy identity; claims-off callers see provision.ErrMalformedIncarnation.
+func TestIncarnationMalformedErrors(t *testing.T) {
+ if _, err := provision.Incarnation("BAD", "shop", "alpha.shop.example.com", time.Time{}); !errors.Is(err, provision.ErrMalformedIncarnation) {
+ t.Fatalf("provision.Incarnation error = %v", err)
+ }
+ if _, err := hostclaim.Incarnation("BAD", "shop", "alpha.shop.example.com", time.Time{}); !errors.Is(err, hostclaim.ErrMalformed) {
+ t.Fatalf("hostclaim.Incarnation error = %v", err)
+ }
+}
diff --git a/internal/runs/runs.go b/internal/runs/runs.go
index 227df8a47..a93e065e7 100644
--- a/internal/runs/runs.go
+++ b/internal/runs/runs.go
@@ -170,7 +170,7 @@ type File struct {
}
// Request is runs/<id>/request.json (run spec §5.1). Incarnation is the
-// record's (hostclaim.Incarnation of account, app, host and CreatedAt).
+// record's (provision.Incarnation of account, app, host and CreatedAt).
type Request struct {
Schema int `json:"schema"`
ID string `json:"id"`