From a56414cf7af0eda3c02e405c344cd00f337062e4 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 7 Sep 2026 00:29:53 +1000 Subject: [PATCH] fix(archied): preserve channel turn ledger with remote gateway --- internal/app/archied/bootstrap.go | 8 ++-- .../archied/chat_store_composition_test.go | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 internal/app/archied/chat_store_composition_test.go diff --git a/internal/app/archied/bootstrap.go b/internal/app/archied/bootstrap.go index c50d98741..32f8c72a4 100644 --- a/internal/app/archied/bootstrap.go +++ b/internal/app/archied/bootstrap.go @@ -45,7 +45,6 @@ import ( "github.com/samcharles93/archie-core/internal/infrastructure/configuration/overlay" infraembedding "github.com/samcharles93/archie-core/internal/infrastructure/embedding" "github.com/samcharles93/archie-core/internal/infrastructure/eventbus/nats" - "github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc" infraMemory "github.com/samcharles93/archie-core/internal/infrastructure/memory" "github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog" "github.com/samcharles93/archie-core/internal/infrastructure/sessioncurator" @@ -544,9 +543,8 @@ func (b *boot) setupLLMAndChat() error { return err } b.addCleanup(cleanup) - if remote, ok := contract.(*gatewayrpc.Client); ok { - b.chatSessionStore = remote - } + // Channel routers execute turns locally and need the SQLite TurnLedger. + // The remote contract serves web chat; it must not replace their store. b.web.Chat = &webui.ChatService{Contract: contract, Updates: b.updateService} b.web.WorkRequests = b.chatTasks b.setupReadinessProbes() @@ -1016,7 +1014,7 @@ func (b *boot) setupCurators(ctx context.Context) { // doesn't declare Manifest.Skills, per curator not per instance. Skills: skillcurator.NewStore(skillsRoot), // Conversations backs the session-memory curator; b.chatSessionStore - // is set by setupLLMAndChat, which Run() calls before setupCurators. + // is opened by openChatSessions before setupCurators. Conversations: sessioncurator.NewAdapter(b.chatSessionStore, b.cfg.BotUser), LLM: curatorLLMRunner{rt: b.llm}, // b.chatModels.ActiveModel() is the same source sendChatTurn uses diff --git a/internal/app/archied/chat_store_composition_test.go b/internal/app/archied/chat_store_composition_test.go new file mode 100644 index 000000000..5438f1b76 --- /dev/null +++ b/internal/app/archied/chat_store_composition_test.go @@ -0,0 +1,41 @@ +package archied + +import ( + "log/slog" + "path/filepath" + "testing" + + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/gateway" + "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/webui" +) + +func TestRemoteChatCompositionPreservesChannelTurnLedger(t *testing.T) { + cfg := config.Config{DBPath: filepath.Join(t.TempDir(), "tasks.db")} + cfg.Services.Gateway.Target = "127.0.0.1:1" + st, err := store.Open(t.Context(), cfg.DBPath) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = st.Close() }) + b := &boot{cfg: cfg, st: st, log: slog.Default(), web: &webui.Server{Cfg: config.NewHolder(cfg)}} + t.Cleanup(b.cleanup) + if err := b.openChatSessions(t.Context()); err != nil { + t.Fatal(err) + } + sessions := b.chatSessionStore + if err := b.setupLLMAndChat(); err != nil { + t.Fatal(err) + } + if b.chatSessionStore != sessions { + t.Fatal("remote web chat replaced the channel conversation store") + } + ledger, ok := b.chatSessionStore.(gateway.TurnLedger) + if !ok { + t.Fatal("channel conversation store does not implement TurnLedger") + } + if err := ledger.RecoverTurns(t.Context(), "test-owner"); err != nil { + t.Fatal(err) + } +}