feat(curator): trigger accounting — primary-input wake path (archie-core-035)

A completed chat turn is published as turn_completed from the single
responder choke point shared by the telegram and web gateways
(redeliveries return earlier and never emit). The runtime wake path
forwards ONLY primary-input kinds to input-driven curators; curator-
produced activity (curator_run/action/error and any future derived
kinds) never appears on that path, so a curator that writes memories
cannot schedule itself again — the feedback-loop guard, with the
rationale recorded in the regression test so it is not removed as
redundant.

The bus subscription is bounded and dropping, so the wake path can
never backpressure the chat publisher; a dropped event only delays a
run to the next check-in.
This commit is contained in:
sam committed 2026-08-05 15:00:29 +10:00
1 parent 4ece064026
commit 36d00963a5
5 files changed
+165 -2

No files matched your search

+8 -1
View File
@@ -402,7 +402,7 @@ func run() int {
Cfg: cfg, St: st, LLM: llm, ChatModels: chatModels, ToolReg: toolReg,
Personas: personas, ChatTasks: chatTasks, ChatController: chatController,
DefaultChatIdentity: defaultChatIdentity, SessionStore: chatSessionStore,
Log: log,
Bus: bus, Log: log,
}
webRouter.LLM, webRouter.LLMStream = makeChatLLMResponder(ctx, "web", webSetup, chatSessionStore, webRouter)
web.Chat = &webui.ChatService{
@@ -427,6 +427,7 @@ func run() int {
St: st, LLM: llm, ChatModels: chatModels, ToolReg: toolReg,
Personas: personas, ChatTasks: chatTasks, ChatController: chatController,
DefaultChatIdentity: defaultChatIdentity, SessionStore: chatSessionStore, Updates: updateService,
Bus: bus,
RegisterRestart: func(request func() error) { restartTelegram = request }, Log: log,
})
if !ok {
@@ -657,6 +658,12 @@ func run() int {
// (cancels in-flight passes, then stops curator lifecycle), then the
// registry's own Stop below, which is a no-op by then.
curatorRuntime := curator.NewRuntime(curatorRegistry, curator.RuntimeConfig{})
// Primary chat turns wake input-driven curators (archie-core-035):
// the forwarder consumes only primary-input kinds, and curator
// output never produces them, so derived work cannot feed its own
// trigger. The subscriber buffer is bounded and dropping — a slow
// curator can never backpressure the chat publisher.
curator.WakeOnPrimaryInput(ctx, bus, curatorRuntime, events.KindTurnCompleted)
defer func() {
stopCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
+20 -1
View File
@@ -15,6 +15,7 @@ import (
"github.com/samcharles93/archie-core/internal/channels/telegram"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/nell"
@@ -43,7 +44,11 @@ type telegramSetup struct {
Updates telegram.UpdateService
Dangerous gateway.DangerousCommandAuthority
RegisterRestart func(func() error)
Log *slog.Logger
// Bus carries primary-input events (archie-core-035): a completed
// chat turn is published here so input-driven curators can wake. Nil
// disables turn events (tests, minimal setups).
Bus *events.Bus
Log *slog.Logger
}
// setupTelegramGateway initialises the Telegram chat gateway when a
@@ -249,6 +254,20 @@ func makeChatLLMResponder(ctx context.Context, channel string, s telegramSetup,
if err := sessionStore.SaveMessage(ctx, sk, gateway.Message{From: s.Cfg.BotUser, Text: text}); err != nil {
return "", fmt.Errorf("save outbound chat message: %w", err)
}
// The turn is complete: both messages are persisted. Announce it
// as primary input (archie-core-035). Publish is non-blocking
// with bounded dropping subscriber buffers, so this never delays
// the chat path; a dropped event only delays a curator run to its
// next check-in. Curator output never produces this kind, so
// derived work cannot feed its own trigger. Redeliveries return
// above and never reach here.
if s.Bus != nil {
s.Bus.Publish(events.Event{
Kind: events.KindTurnCompleted,
Detail: sk,
Data: map[string]any{"session": sk, "channel": channel},
})
}
return text, nil
}
return func(ctx context.Context, msg gateway.Message) (string, error) {