fix(agentworker): stop reporting task worker presence (#1807)

This commit is contained in:
sam committed 2026-11-08 17:27:30 +11:00
1 parent 52b5740c39
commit 260e9fc46e
4 files changed
+4 -57

No files matched your search

-16
View File
@@ -3,25 +3,18 @@ package agentworker
import (
"context"
"errors"
"log/slog"
"net/http"
"strconv"
"time"
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/domain/health"
"github.com/samcharles93/archie-core/internal/domain/presence"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
"github.com/samcharles93/archie-core/internal/infrastructure/agentboot"
"github.com/samcharles93/archie-core/internal/infrastructure/agentgit"
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
"github.com/samcharles93/archie-core/internal/infrastructure/readiness"
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
"github.com/samcharles93/archie-core/internal/installtype"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/storage"
"github.com/samcharles93/archie-core/internal/taskrun"
@@ -67,8 +60,6 @@ type workerTransport interface {
Close()
LogPublisher() agentexec.LogPublisher
SubscribeTasks(context.Context, int64, agentnats.TaskHandler, *slog.Logger) (agentnats.Subscription, error)
PutPresence(context.Context, storecontract.Presence) error
BrokerReady() bool
}
type workerDependencies struct {
@@ -174,13 +165,6 @@ func run(ctx context.Context, settings Settings, log *slog.Logger, dependencies
}
}()
registry := health.NewRegistry(readiness.NewContractProbe("nats", 0, func(context.Context) error {
if !transport.BrokerReady() {
return errors.New("broker disconnected")
}
return nil
}))
go presence.Run(ctx, presence.Agent, presence.Build{InstanceID: strconv.FormatInt(taskID, 10), Version: Version(), InstallType: installtype.Type()}, transport, registry, log)
log.InfoContext(ctx, "archie-agent ready", "nats", settings.NATSURL)
dependencies.wait(ctx, log)
return nil
@@ -17,7 +17,6 @@ import (
"go.opentelemetry.io/otel/propagation"
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
"github.com/samcharles93/archie-core/internal/events"
@@ -377,12 +376,3 @@ func (*Transport) respondTask(msg *natsio.Msg, response *taskrun.Response, runEr
log.Error("taskrun respond failed", "err", err)
}
}
// PutPresence publishes the worker's task-scoped record.
func (t *Transport) PutPresence(ctx context.Context, record storecontract.Presence) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
return t.state.PutPresence(ctx, record)
}
func (t *Transport) BrokerReady() bool { return t.conn.IsConnected() }
@@ -7,7 +7,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"strconv"
"time"
"google.golang.org/grpc"
@@ -18,7 +17,6 @@ import (
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/presence"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
"github.com/samcharles93/archie-core/internal/events"
@@ -89,17 +87,6 @@ func authorizesTaskScopedCall(fullMethod string, req any, taskID int64) bool {
// taskScopedTargets maps each RPC a task grant may call to the task ID its
// request targets.
var taskScopedTargets = map[string]func(any) int64{
pb.StatusService_PutPresence_FullMethodName: func(req any) int64 {
r, ok := req.(*pb.PutPresenceRequest)
if !ok || r.Presence == nil || r.Presence.Service != presence.Agent {
return 0
}
id, err := strconv.ParseInt(r.Presence.InstanceId, 10, 64)
if err != nil || id <= 0 || strconv.FormatInt(id, 10) != r.Presence.InstanceId {
return 0
}
return id
},
pb.TaskService_Update_FullMethodName: func(req any) int64 {
r, ok := req.(*pb.UpdateRequest)
if !ok || r.Task == nil {
@@ -6,23 +6,9 @@ import (
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
)
func TestWorkerPresenceAuthority(t *testing.T) {
for _, tt := range []struct {
name, service, instance string
allowed bool
}{
{"own task", "archie-agent", "7", true},
{"another task", "archie-agent", "8", false},
{"daemon", "archied", "7", false},
{"broker", "nats", "7", false},
{"noncanonical task", "archie-agent", "007", false},
{"no task", "archie-agent", "", false},
} {
t.Run(tt.name, func(t *testing.T) {
req := &pb.PutPresenceRequest{Presence: &pb.Presence{Service: tt.service, InstanceId: tt.instance}}
if got := authorizesTaskScopedCall(pb.StatusService_PutPresence_FullMethodName, req, 7); got != tt.allowed {
t.Fatalf("authorized = %v, want %v", got, tt.allowed)
}
})
func TestTaskGrantRejectsPutPresence(t *testing.T) {
req := &pb.PutPresenceRequest{Presence: &pb.Presence{Service: "archie-agent", InstanceId: "7"}}
if authorizesTaskScopedCall(pb.StatusService_PutPresence_FullMethodName, req, 7) {
t.Fatal("task grant authorised PutPresence")
}
}