carlos / platform Public

console: HA create journal names the app; temporary HA is refused

Branch review R1, Fable P3-1, P3-2 and P3-4. haCreateChoice passes the
app's name to the pool gate's journal line. The CONSOLE_HA_POOL_ACCOUNTS
comment lists all four gated doors. claimAppWith refuses a temporary
claim born HA before anything is read or written, rather than dropping
the pool silently.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 39d3239d1c09e7e661a0319a85218ee90826edf7 parent c2e4ab4
5 files changed, +70 −9
  • cmd/console/main.go +6 −3
  • internal/console/apicli.go +1 −1
  • internal/console/apicli_ha_test.go +49 −0
  • internal/console/hapool.go +5 −4
  • internal/console/server.go +9 −1

CI failed — run details

Intent

Attributed to this commit: 11.9 g CO₂e (1,515,757 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on g6-pool, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/cmd/console/main.go b/cmd/console/main.go
index 9d237a380..f5b6fbbb6 100644
--- a/cmd/console/main.go
+++ b/cmd/console/main.go
@@ -66,9 +66,12 @@
// CONSOLE_HA_POOL_ACCOUNTS (comma-separated account sqids) names the accounts
// that may put a record into a restricted pool: any pool named in any
// region's ha_pools in CONSOLE_HA_CAPACITY_CONFIG, whatever the record's
-// region or kind (internal/console/hapool.go). The instance create and
-// standalone sidecar create doors answer 403 ha-pool-not-allowed to every
-// other account. Unset or empty is NOBODY, the opposite of
+// region or kind (internal/console/hapool.go). Four doors gate on it and
+// refuse every other account (403 ha-pool-not-allowed at a JSON door, a
+// flash on the browser form): the instance create door, the standalone
+// sidecar create door, app create with "ha" (the API's and the browser
+// form's), and the instance enable door's first create of a born-HA app's
+// manifest. Unset or empty is NOBODY, the opposite of
// CARLOS_SIDECAR_ACCOUNTS on purpose, and operators are not exempt: an
// operator account must be listed too. The list is read once at startup, so
// changing it is a console restart. It parses like CARLOS_SIDECAR_ACCOUNTS:
diff --git a/internal/console/apicli.go b/internal/console/apicli.go
index 5bf8eec64..338de2c58 100644
--- a/internal/console/apicli.go
+++ b/internal/console/apicli.go
@@ -533,7 +533,7 @@ func (s *Server) handleAPICreateApp(w http.ResponseWriter, r *http.Request) {
var haPool, haRegion string
if req.HA {
var ref *doorRefusal
- if haPool, haRegion, ref = s.haCreateChoice(p, acct, req.Region, place); ref != nil {
+ if haPool, haRegion, ref = s.haCreateChoice(p, acct, name, req.Region, place); ref != nil {
writeHARefusal(w, ref)
return
}
diff --git a/internal/console/apicli_ha_test.go b/internal/console/apicli_ha_test.go
index 770c3d203..5751ce2c8 100644
--- a/internal/console/apicli_ha_test.go
+++ b/internal/console/apicli_ha_test.go
@@ -1,10 +1,12 @@
package console
import (
+ "bytes"
"context"
"crypto/sha256"
"errors"
"fmt"
+ "log"
"maps"
"net/http"
"os"
@@ -12,6 +14,7 @@ import (
"strings"
"sync"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/apppolicy"
"github.com/carlosframework/platform/internal/provision"
@@ -543,3 +546,49 @@ func TestAPICreateAppHARegionBinding(t *testing.T) {
status, res = w.refused(t, "shop", haAllow{}, post)
wantHARefusal(t, "retry, switch off", status, res, http.StatusBadRequest, fmt.Sprintf(haCopyRegion, w.srv.offlinePlace("us")), "")
}
+
+// TestHACreateRefusalLogNamesTheApp (branch review R1, Fable P3-1): the
+// pool gate's journal line at app create names the app it refused.
+func TestHACreateRefusalLogNamesTheApp(t *testing.T) {
+ w := haRegionFixture(t, haRegionOpts{Accounts: []string{"cdef"}})
+ var buf bytes.Buffer
+ prev := log.Writer()
+ log.SetOutput(&buf)
+ t.Cleanup(func() { log.SetOutput(prev) })
+ status, res := postJSON(t, newAppURL(w.consoleFixture), map[string]any{"name": "shop", "region": "us", "ha": true}, w.token)
+ log.SetOutput(prev)
+ wantHARefusal(t, "unlisted ha", status, res, http.StatusForbidden, haCopyNotAllowed, haPoolNotAllowedCode)
+ if want := "app create bab/shop: pool ha refused"; !strings.Contains(buf.String(), want) {
+ t.Errorf("the refusal's journal line does not name the app: want %q in\n%s", want, buf.String())
+ }
+}
+
+// TestClaimTemporaryHARefused (branch review R1, Fable P3-4): a claim
+// asking for a temporary app born HA is refused before anything is read
+// or written. haRegion is the home, where a temporary claim lands, so
+// without the refusal the claim would pass its region binding and the
+// temporary insert would drop the pool silently. Control: the same
+// temporary claim without HA creates the app, with no pool.
+func TestClaimTemporaryHARefused(t *testing.T) {
+ w := haRegionFixture(t, haRegionOpts{Accounts: []string{"bab"}})
+ acct := opsAccount(t, w.consoleFixture)
+ ctx, name, expires := context.Background(), "tmp-docs", time.Now().Add(time.Hour)
+ var got claimOutcome
+ w.refused(t, name, haAllow{}, func() (int, map[string]any) {
+ got, _, _ = w.srv.claimAppWith(ctx, acct, name, "paul@keymail.dev", "", false, regionReq{haPool: "ha"}, expires)
+ return 0, nil
+ })
+ if got != claimCreateFailed {
+ t.Errorf("temporary HA claim = %v, want claimCreateFailed", got)
+ }
+ // Control: the same claim without HA.
+ if got, _, _ := w.srv.claimAppWith(ctx, acct, name, "paul@keymail.dev", "", false, regionReq{}, expires); got != claimOK {
+ t.Fatalf("control: temporary claim = %v, want claimOK", got)
+ }
+ if has, err := w.st.HasAppIn(OpsAccountID, name); err != nil || !has {
+ t.Fatalf("control: HasAppIn = %v %v, want the row", has, err)
+ }
+ if pool, _, err := w.st.AppHAPool(ctx, OpsAccountID, name); err != nil || pool != "" {
+ t.Fatalf("control: AppHAPool = %q %v, want none", pool, err)
+ }
+}
diff --git a/internal/console/hapool.go b/internal/console/hapool.go
index 0d3f48144..9fbed18c7 100644
--- a/internal/console/hapool.go
+++ b/internal/console/hapool.go
@@ -120,8 +120,9 @@ func (s *Server) refuseHAPool(w http.ResponseWriter, acct *Account, app, pool, d
// haCreateChoice is the app create option "ha": true (G6 Task 2): the pool
// the new app is born into and the region (record vocabulary, "" is the
-// home) that pool was admitted for, or the refusal. raw is the request's
-// region (a name, "" or "@auto"), place its already-validated placement.
+// home) that pool was admitted for, or the refusal. app is the new app's
+// name (for the journal line), raw the request's region (a name, "" or
+// "@auto"), place its already-validated placement.
// The door carries both into regionReq; claimAppWith writes the pool only
// at that region.
//
@@ -131,7 +132,7 @@ func (s *Server) refuseHAPool(w http.ResponseWriter, acct *Account, app, pool, d
// never one. With the region switch off every create lands on the home, so
// only the home can be named. The allowlist check is the pool gate,
// haPoolAllowed, which never consults a region.
-func (s *Server) haCreateChoice(p Principal, acct *Account, raw, place string) (pool, region string, ref *doorRefusal) {
+func (s *Server) haCreateChoice(p Principal, acct *Account, app, raw, place string) (pool, region string, ref *doorRefusal) {
if p.Kind != PrincipalUser {
return "", "", &doorRefusal{Status: http.StatusForbidden, Msg: haCopyNotAllowed, Code: haPoolNotAllowedCode}
}
@@ -147,7 +148,7 @@ func (s *Server) haCreateChoice(p Principal, acct *Account, raw, place string) (
return "", "", &doorRefusal{Status: http.StatusBadRequest, Msg: fmt.Sprintf(haCopyRegion, s.offlinePlace(code))}
}
if !s.haPoolAllowed(acct, pool) {
- return "", "", s.haPoolRefusal(acct, "", pool, "api create")
+ return "", "", s.haPoolRefusal(acct, app, pool, "app create")
}
return pool, code, nil
}
diff --git a/internal/console/server.go b/internal/console/server.go
index 8e224956b..86ad86f24 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -5548,6 +5548,14 @@ func (s *Server) validateClaimAppName(ctx context.Context, acct *Account, name,
// §3, so any object under the prefix refuses), and inserts the row with its
// expiry in the same statement that claims the name.
func (s *Server) claimAppWith(ctx context.Context, acct *Account, name, addr, placement string, ownerClaim bool, rq regionReq, expiresAt time.Time) (outcome claimOutcome, placed string, held *apexHold) {
+ // A temporary app is never born HA: it stays on the shared fleet at its
+ // own platform address and expires by itself. No door asks for both
+ // today; a caller that does is refused before anything is read or
+ // written, never given one of the two silently.
+ if rq.haPool != "" && !expiresAt.IsZero() {
+ log.Printf("console: claim %s/%s: a temporary app cannot be born HA (pool %s); not created", acct.Sqid, name, rq.haPool)
+ return claimCreateFailed, "", nil
+ }
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
outcome, adoptingExistingApp, held := s.validateClaimAppName(ctx, acct, name, placement, ownerClaim, expiresAt)
@@ -5756,7 +5764,7 @@ func (s *Server) handleNewApp(w http.ResponseWriter, r *http.Request) {
// The HA choice is the API door's "ha", for the person this session
// is, before anything is written.
if ha {
- pool, haRegion, ref := s.haCreateChoice(Principal{Kind: PrincipalUser, Address: addr}, acct, region, "")
+ pool, haRegion, ref := s.haCreateChoice(Principal{Kind: PrincipalUser, Address: addr}, acct, name, region, "")
if ref != nil {
fail(sentenceCase(ref.Msg))
return