From 8f7c14e5c6b7a377fec8833eafee2ef80eae13a0 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 9 Oct 2026 03:05:51 +1100 Subject: [PATCH] fix(gateway): read task logs through state store --- internal/app/archiegateway/chat_tasks.go | 19 +++++-------------- internal/app/archiegateway/gateway_runtime.go | 2 +- internal/app/archiegateway/server.go | 4 +--- internal/gateway/task_tools.go | 4 ++-- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/internal/app/archiegateway/chat_tasks.go b/internal/app/archiegateway/chat_tasks.go index 6e2bb2f21..68a9b74bb 100644 --- a/internal/app/archiegateway/chat_tasks.go +++ b/internal/app/archiegateway/chat_tasks.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/taskactions" "github.com/samcharles93/archie-core/internal/domain/workflow" "github.com/samcharles93/archie-core/internal/gateway" @@ -115,7 +116,7 @@ func (a chatTaskListerAdapter) ListChatTasks(ctx context.Context, identity strin // identity through the tool input. type chatTaskLogReaderAdapter struct { tasks func(context.Context, int64) (*workflow.Task, error) - taskLogs *logging.TaskRegistry + taskLogs storecontract.TaskLogStore } func (a chatTaskLogReaderAdapter) ReadChatTaskLogs( @@ -141,19 +142,9 @@ func (a chatTaskLogReaderAdapter) ReadChatTaskLogs( if attempt <= 0 { attempt = task.Attempt } - path := a.taskLogs.Path(taskID, attempt) - if path == "" { - return gateway.ChatTaskLogResult{Attempt: attempt, Entries: []gateway.ChatTaskLogEntry{}}, nil - } - - page, err := logging.Page(path, logging.Query{ - Component: q.Component, - Contains: q.Contains, - Levels: q.Levels, - Since: q.Since, - Until: q.Until, - Limit: q.Limit, - }, q.AfterID) + page, err := a.taskLogs.TaskLog(ctx, taskID, attempt, logging.Query{ + Component: q.Component, Contains: q.Contains, Levels: q.Levels, Since: q.Since, Until: q.Until, Limit: q.Limit, BeforeID: q.AfterID, + }) if err != nil { return gateway.ChatTaskLogResult{}, err } diff --git a/internal/app/archiegateway/gateway_runtime.go b/internal/app/archiegateway/gateway_runtime.go index f1f012d96..05550a7d7 100644 --- a/internal/app/archiegateway/gateway_runtime.go +++ b/internal/app/archiegateway/gateway_runtime.go @@ -238,7 +238,7 @@ func (b *server) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskAct LLM: b.chatLLM, ChatModels: b.chatModels, ToolReg: b.toolReg, Soul: b.soul, ChatTasks: b.chatTasks, ChatTaskLister: chatTaskListerAdapter{tasks: b.stateStore.Tasks}, - ChatTaskLogs: chatTaskLogReaderAdapter{tasks: b.stateStore.TaskByID, taskLogs: b.taskLogs}, + ChatTaskLogs: chatTaskLogReaderAdapter{tasks: b.stateStore.TaskByID, taskLogs: b.stateStore}, ChatTaskActor: actor, DefaultChatIdentity: b.defaultChatIdentity, Bus: b.bus, Log: b.log, diff --git a/internal/app/archiegateway/server.go b/internal/app/archiegateway/server.go index 5105a0d01..ca62f9080 100644 --- a/internal/app/archiegateway/server.go +++ b/internal/app/archiegateway/server.go @@ -33,7 +33,6 @@ import ( "github.com/samcharles93/archie-core/internal/infrastructure/secretengine" "github.com/samcharles93/archie-core/internal/infrastructure/staterpc" "github.com/samcharles93/archie-core/internal/infrastructure/taskactions" - "github.com/samcharles93/archie-core/internal/logging" "github.com/samcharles93/archie-core/internal/plugin" "github.com/samcharles93/archie-core/internal/ratelimit" "github.com/samcharles93/archie-core/internal/releaseupdate" @@ -63,7 +62,6 @@ type server struct { cfgHolder *config.Holder cfgPath string log *slog.Logger - taskLogs *logging.TaskRegistry secrets *secret.Registry engines *secretengine.Runner @@ -167,7 +165,7 @@ func (b *server) loadConfig(cfgPath, overlayPath string) error { b.catalog = modelcatalog.NewCatalog(cfgPath) b.cfgHolder = config.NewHolder(b.cfg) logs := servicekit.Logging(b.cfg, "gateway") - b.log, b.taskLogs = logs.Log, logs.TaskLogs + b.log = logs.Log b.addCleanup(func() { _ = logs.Closer.Close() }) b.secrets = secret.NewRegistry() return nil diff --git a/internal/gateway/task_tools.go b/internal/gateway/task_tools.go index ad7426d1d..7c3af965c 100644 --- a/internal/gateway/task_tools.go +++ b/internal/gateway/task_tools.go @@ -106,8 +106,8 @@ type ChatTaskLogQuery struct { // time disables the bound. Until time.Time // AfterID is the byte-offset cursor returned in the previous page's - // Cursor field. Zero means "start at the beginning of the scanned - // window". The model treats this as opaque and just passes it back + // Cursor field, used to read the next older page. Zero selects the most + // recent page. The model treats this as opaque and just passes it back // unchanged; the byte offset is not intended to be human-readable. AfterID int64 // Limit caps returned entries.