Skip to content

Commit 084cf47

Browse files
committed
fix: pass atespace on self-suspend in agent-secret demo
Host parsing dropped the atespace label, so SuspendActor always failed with atespace required. Now uses resources.ParseActorDNSName to get both atespace and actor name. Renamed actorID to actorName throughout to match repo convention.
1 parent c1ab095 commit 084cf47

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

demos/agent-secret/main.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"strings"
2626
"time"
2727

28+
"github.com/agent-substrate/substrate/internal/resources"
2829
"github.com/agent-substrate/substrate/pkg/proto/ateapipb"
2930
"google.golang.org/grpc"
3031
"google.golang.org/grpc/credentials"
@@ -60,27 +61,24 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
6061
log.Printf("DEBUG: Request received. Path=%s Host=%s", r.URL.Path, r.Host)
6162

6263
// 1. Identify Actor (Robust extraction)
63-
actorID := r.Header.Get("X-AgentSet-Session")
64-
if actorID == "" {
65-
actorID = r.Header.Get("x-agentset-session")
64+
actorName := r.Header.Get("X-AgentSet-Session")
65+
if actorName == "" {
66+
actorName = r.Header.Get("x-agentset-session")
6667
}
67-
if actorID == "" {
68+
var atespace string
69+
if actorName == "" {
6870
host := r.Host
6971
if host == "" {
7072
host = r.Header.Get("Host")
7173
}
72-
// Extract the actor id (first label) from <id>.<atespace>.actors.resources.substrate.ate.dev
73-
parts := strings.Split(host, ".")
74-
if len(parts) > 1 {
75-
actorID = parts[0]
76-
}
74+
atespace, actorName, _ = resources.ParseActorDNSName(host)
7775
}
7876

79-
if actorID == "" {
80-
actorID = "unknown"
77+
if actorName == "" {
78+
actorName = "unknown"
8179
}
8280

83-
log.Printf("DEBUG: Identified ActorID: [%s]", actorID)
81+
log.Printf("DEBUG: Identified ActorName: [%s]", actorName)
8482

8583
body, _ := io.ReadAll(r.Body)
8684
message := string(body)
@@ -90,8 +88,8 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
9088

9189
// 1. Respond to user
9290
var sb strings.Builder
93-
sb.WriteString(fmt.Sprintf("Agent Response: [%s] | Identity: %s | Session: %s\n", message, residentSecret, actorID))
94-
if actorID == "" {
91+
sb.WriteString(fmt.Sprintf("Agent Response: [%s] | Identity: %s | Session: %s\n", message, residentSecret, actorName))
92+
if actorName == "" {
9593
sb.WriteString("DEBUG: ID Missing. Headers received:\n")
9694
for k, v := range r.Header {
9795
sb.WriteString(fmt.Sprintf(" %s: %v\n", k, v))
@@ -103,17 +101,17 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
103101
w.Write([]byte(response))
104102

105103
// 2. Self-Suspend (Zero-Idle)
106-
if actorID != "" && actorID != "localhost" && !strings.Contains(actorID, ":") {
104+
if actorName != "" && actorName != "localhost" && !strings.Contains(actorName, ":") {
107105
// Use a goroutine to avoid blocking the HTTP response
108106
go func() {
109107
// We linger for 7 seconds in this demo to make the multiplexing visible in the CLI.
110108
time.Sleep(7 * time.Second)
111-
suspendSelf(actorID)
109+
suspendSelf(atespace, actorName)
112110
}()
113111
}
114112
}
115113

116-
func suspendSelf(id string) {
114+
func suspendSelf(atespace, actorName string) {
117115
apiAddr := os.Getenv("ATE_API_ADDR")
118116
if apiAddr == "" {
119117
apiAddr = "api.ate-system.svc.cluster.local:443"
@@ -129,8 +127,8 @@ func suspendSelf(id string) {
129127

130128
client := ateapipb.NewControlClient(conn)
131129

132-
log.Printf("Yielding compute. Requesting self-suspension for actor %s...", id)
133-
_, err = client.SuspendActor(context.Background(), &ateapipb.SuspendActorRequest{Actor: &ateapipb.ObjectRef{Name: id}})
130+
log.Printf("Yielding compute. Requesting self-suspension for actor %s...", actorName)
131+
_, err = client.SuspendActor(context.Background(), &ateapipb.SuspendActorRequest{Actor: &ateapipb.ObjectRef{Atespace: atespace, Name: actorName}})
134132
if err != nil {
135133
log.Printf("Failed to self-suspend: %v", err)
136134
}

0 commit comments

Comments
 (0)