feat(agent): stamp archie-agent's build and report it back to the daemon

archied's own build has carried a compiled-in gatewayVersion and an
internal/installtype stamp since archie-core-522/b5d08d0, but
archie-agent's build had neither -- its Taskfile.yml and Dockerfile
build steps passed no -ldflags at all, so even a daemon that wanted to
verify what agent build is actually in service had nothing to check
against. daemonRunningVersions said as much explicitly: the agent was
left out of every verification on purpose, because nothing self-reported
a real value.

Every archie-agent process is task-scoped and ephemeral (spawned per
task, dies after), not a long-lived process the daemon can poll on
demand the way it polls Telegram's gateway. So there's no "ask the
agent its version" request -- the only channel back is whatever a
worker includes in the taskrun.Response it already sends on every
completed task.

Stamp archie-agent's build the same way archied's is (installtype,
plus a new agentworker.Version()), have executeTaskRequest report both
in its Response, and have the daemon record the latest observation in
a new mutex-guarded AgentStatus, fed from runViaAgent on every
successful response only -- never off a request that never reached an
agent, or one describing a failed/parked task. daemonRunningVersions
now includes the agent component once (and only once) something has
actually been observed, so Report.Verify gets a real value to check
future update claims against instead of omitting the component
entirely.

Part 1/3 of archie-core-1786751948782-3-837a8fd0 point 4. Closes
archie-core-1786751948782-3-837a8fd0.1.
This commit is contained in:
sam committed 2026-08-23 23:18:00 +10:00
1 parent 8809d44505
commit ed33ab5380
15 files changed
+313 -30

No files matched your search

+13 -3
View File
@@ -131,11 +131,19 @@ type boot struct {
providerRegistry *toolprovider.Registry
d *daemon.Daemon
// agentStatus records the most recent version/install-type an
// archie-agent worker reported about itself. Allocated up front, before
// any gateway goroutine (Telegram, webui) that might read it via
// RunningVersions starts, so those closures never see a nil pointer or
// race its assignment -- only its own internal mutex guards concurrent
// Observe/Snapshot calls once tasks start completing.
agentStatus *daemon.AgentStatus
cleanups []func()
}
func newBootstrap() *boot {
return &boot{log: slog.New(slog.NewJSONHandler(os.Stderr, nil))}
return &boot{log: slog.New(slog.NewJSONHandler(os.Stderr, nil)), agentStatus: &daemon.AgentStatus{}}
}
func (b *boot) addCleanup(fn func()) {
@@ -307,7 +315,8 @@ func (b *boot) setupObservability() {
}
b.web = &webui.Server{Store: b.st, Log: log, LogFeed: b.logFeed, TaskLogs: b.taskLogs, Cfg: config.NewHolder(cfg), Channels: b.channelManager, Events: bus}
b.web.UpdateReportPath = updateReportPath(cfg.WorkDir, "webui")
b.web.RunningVersions = daemonRunningVersions
agentStatus := b.agentStatus
b.web.RunningVersions = func() map[string]string { return daemonRunningVersions(agentStatus) }
b.web.SetProvenance(configProvenance)
b.web.ReloadChannel = func(ctx context.Context, id string) error {
if id != "telegram" || b.restartTelegram == nil {
@@ -517,7 +526,7 @@ func (b *boot) setupGateways(ctx context.Context, cfgPath, overlayPath string) b
DefaultChatIdentity: b.defaultChatIdentity, SessionStore: b.chatSessionStore, Updates: b.updateService,
Bus: b.bus,
RegisterRestart: func(request func() error) { b.restartTelegram = request }, Log: log,
ChannelManager: b.channelManager,
ChannelManager: b.channelManager, AgentStatus: b.agentStatus,
})
if !ok {
return false
@@ -1016,6 +1025,7 @@ func (b *boot) buildDaemon() {
Curators: b.curatorRegistry,
Identities: b.identityRunners,
TaskLogs: b.taskLogs,
AgentStatus: b.agentStatus,
}
b.web.TaskStopper = b.d
// web and the daemon must share ONE Holder: a reload swaps d.Cfg and
+32 -13
View File
@@ -16,6 +16,7 @@ import (
channelruntime "github.com/samcharles93/archie-core/internal/channels"
"github.com/samcharles93/archie-core/internal/channels/telegram"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/daemon"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
@@ -56,6 +57,10 @@ type telegramSetup struct {
Bus *events.Bus
Log *slog.Logger
ChannelManager *channelruntime.Manager
// AgentStatus is the composition root's shared tracker for the most
// recently observed archie-agent version (see daemon.AgentStatus).
// Nil disables the agent component of RunningVersions.
AgentStatus *daemon.AgentStatus
}
// setupTelegramGateway initialises the Telegram chat gateway when a
@@ -97,7 +102,8 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
},
}
tg.UpdateReportPath = updateReportPath(cfg.WorkDir, cfg.BotUser)
tg.RunningVersions = daemonRunningVersions
agentStatus := s.AgentStatus
tg.RunningVersions = func() map[string]string { return daemonRunningVersions(agentStatus) }
tg.Reload = makeTelegramReload(s)
sessionStore := s.SessionStore
@@ -123,19 +129,32 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
}
// daemonRunningVersions reports the component versions this process can
// vouch for from its own build, for checking a pending update report against
// (see releaseupdate.Report.Verify).
// vouch for, for checking a pending update report against (see
// releaseupdate.Report.Verify).
//
// Only the daemon is listed, and that is the whole point: gatewayVersion is
// compiled into this binary, so if an installer claims it put a version into
// service and this value disagrees, the installer is wrong. runtimeVersion
// is deliberately NOT reported for the agent -- it records the agent version
// archied's own release pipeline stamped, not the version the agent
// container is actually running, and the two diverge in exactly the
// situation this check exists to detect. An unverifiable component is left
// out so it is reported as unchecked rather than as confirmed.
func daemonRunningVersions() map[string]string {
return map[string]string{releaseupdate.ComponentDaemon: gatewayVersion}
// The daemon component is always vouched for from its own build:
// gatewayVersion is compiled into this binary, so if an installer claims it
// put a version into service and this value disagrees, the installer is
// wrong. runtimeVersion is deliberately NOT used for the agent component --
// it records the agent version archied's own release pipeline stamped, not
// the version an agent container is actually running, and the two diverge in
// exactly the situation this check exists to detect.
//
// The agent component is included only once agentStatus has actually
// observed one running -- self-reported by an archie-agent worker in a
// taskrun.Response (see daemon.AgentStatus), since every archie-agent
// process is task-scoped and ephemeral, not something this process can query
// directly. Before the first task completes, or when agentStatus is nil
// (composition never wired one), the agent component is left out entirely
// so it reports as unchecked rather than as confirmed.
func daemonRunningVersions(agentStatus *daemon.AgentStatus) map[string]string {
versions := map[string]string{releaseupdate.ComponentDaemon: gatewayVersion}
if agentStatus != nil {
if version, _, ok := agentStatus.Snapshot(); ok {
versions[releaseupdate.ComponentAgent] = version
}
}
return versions
}
func configureTelegramUpdates(tg *telegram.Gateway, s telegramSetup) {
+27 -9
View File
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/daemon"
"github.com/samcharles93/archie-core/internal/installtype"
"github.com/samcharles93/archie-core/internal/releaseupdate"
)
@@ -28,15 +29,17 @@ func TestMakeUpdateServiceWiresInstallType(t *testing.T) {
}
}
// TestDaemonRunningVersionsVouchesOnlyForItself: the point of checking a
// pending update report against running versions is that the value checked
// against is ground truth. This process's own compiled-in version is; the
// agent's is not, because runtimeVersion records what archied's release
// pipeline stamped, not what the agent container is actually running.
// Including a guess here would recreate the false success the check exists
// to catch, so its absence is the assertion.
func TestDaemonRunningVersionsVouchesOnlyForItself(t *testing.T) {
running := daemonRunningVersions()
// TestDaemonRunningVersionsVouchesOnlyForItselfWithoutAgentStatus: the point
// of checking a pending update report against running versions is that the
// value checked against is ground truth. This process's own compiled-in
// version is; a guess at the agent's is not, because runtimeVersion records
// what archied's release pipeline stamped, not what an agent container is
// actually running. Before any task has reported an observed agent version
// (agentStatus nil, or nothing observed yet), including one would recreate
// the false success the check exists to catch, so its absence is the
// assertion.
func TestDaemonRunningVersionsVouchesOnlyForItselfWithoutAgentStatus(t *testing.T) {
running := daemonRunningVersions(nil)
if got := running[releaseupdate.ComponentDaemon]; got != gatewayVersion {
t.Errorf("running[%q] = %q, want gatewayVersion = %q", releaseupdate.ComponentDaemon, got, gatewayVersion)
@@ -46,3 +49,18 @@ func TestDaemonRunningVersionsVouchesOnlyForItself(t *testing.T) {
releaseupdate.ComponentAgent, running)
}
}
// TestDaemonRunningVersionsIncludesObservedAgent: once a task response has
// actually self-reported an agent version (daemon.AgentStatus.Observe), that
// -- not archied's release pipeline's expectation -- is ground truth for
// what is running, so it belongs in the verification set.
func TestDaemonRunningVersionsIncludesObservedAgent(t *testing.T) {
var status daemon.AgentStatus
status.Observe("1.9.11", "container")
running := daemonRunningVersions(&status)
if got := running[releaseupdate.ComponentAgent]; got != "1.9.11" {
t.Errorf("running[%q] = %q, want the observed version %q", releaseupdate.ComponentAgent, got, "1.9.11")
}
}