Merge pull request #563 from samcharles93/fix/update-runtime-personality-wiring

fix: keep Telegram updates alive and wire personalities
This commit is contained in:
sam authored and GitHub committed 2026-08-23 15:54:44 +10:00
commit 5a29dedbcd
5 files changed
+104 -1

No files matched your search

+1
View File
@@ -202,6 +202,7 @@ func buildTelegramRouter(ctx context.Context, tg *telegram.Gateway, s telegramSe
router := gateway.NewRouter(s.St, nil, "telegram")
router.Models = s.ChatModels
router.Updates = s.Updates
router.Personas = s.Personas
router.InitSessions(sessionStore)
router.Titles = newChatTitleGenerator(s)
router.Log = s.Log
@@ -0,0 +1,27 @@
package main
import (
"context"
"log/slog"
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/gateway"
)
func TestBuildTelegramRouterWiresPersonas(t *testing.T) {
personas := gateway.NewPersonaRegistry(gateway.DefaultPersonas())
sessions := gateway.NewSessionStoreMemory()
t.Cleanup(func() { _ = sessions.Close() })
router := buildTelegramRouter(context.Background(), nil, telegramSetup{
Cfg: config.NewHolder(config.Config{}),
Personas: personas,
SessionStore: sessions,
Log: slog.Default(),
}, sessions)
if router.Personas != personas {
t.Fatalf("router.Personas = %p, want the configured registry %p", router.Personas, personas)
}
}
+8 -1
View File
@@ -147,6 +147,12 @@ func (g *Gateway) dispatchUpdateAction(ctx context.Context, b *bot.Bot, query *m
}
g.answerModelCallback(ctx, b, query.ID, "Starting update…", false)
g.editUpdateMessage(ctx, b, query, "Update approved. Starting now…")
// The callback context belongs to Telegram's short-lived update
// handler and is cancelled as soon as this handler returns. The
// installer may build an image for several minutes, so detach only
// the install operation from that request lifetime. Progress and
// final-message edits still use ctx and may harmlessly fail when the
// callback request is gone.
go g.installUpdate(ctx, b, query)
default:
g.answerModelCallback(ctx, b, query.ID, "That update action is no longer valid.", true)
@@ -196,7 +202,8 @@ func (g *Gateway) installUpdate(ctx context.Context, b *bot.Bot, query *models.C
}
}
result, err := g.Updates.Install(ctx, meta, progress)
installCtx := context.WithoutCancel(ctx)
result, err := g.Updates.Install(installCtx, meta, progress)
if err != nil {
g.log.Error("approved update failed", "error", err)
lines = append(lines, formatInstallFailure(err))
@@ -0,0 +1,62 @@
package telegram
import (
"context"
"log/slog"
"testing"
"time"
"github.com/go-telegram/bot/models"
"github.com/samcharles93/archie-core/internal/releaseupdate"
)
type contextAwareUpdateStub struct {
started chan struct{}
seen context.Context
}
func (s *contextAwareUpdateStub) Check(context.Context, int64) (releaseupdate.Snapshot, error) {
return releaseupdate.Snapshot{}, nil
}
func (s *contextAwareUpdateStub) Defer(context.Context, int64, releaseupdate.Snapshot) error {
return nil
}
func (s *contextAwareUpdateStub) CanInstall() bool { return true }
func (s *contextAwareUpdateStub) Install(ctx context.Context, _ releaseupdate.InstallMeta, _ func(string)) (releaseupdate.Result, error) {
s.seen = ctx
close(s.started)
return releaseupdate.Result{}, nil
}
func TestInstallUpdateDetachesInstallerFromCallbackContext(t *testing.T) {
g := New("1:test", "", "", []int64{42}, slog.Default())
stub := &contextAwareUpdateStub{started: make(chan struct{})}
g.Updates = stub
b, _ := newTelegramTestBot(t)
callbackCtx, cancel := context.WithCancel(context.Background())
message := &models.Message{Chat: models.Chat{ID: 7}, ID: 100}
done := make(chan struct{})
go func() {
g.installUpdate(callbackCtx, b, &models.CallbackQuery{
From: models.User{ID: 42},
Message: models.MaybeInaccessibleMessage{Message: message},
})
close(done)
}()
<-stub.started
cancel()
select {
case <-stub.seen.Done():
t.Fatal("installer context was cancelled with the callback context")
case <-time.After(20 * time.Millisecond):
}
select {
case <-done:
case <-time.After(time.Second):
t.Fatal("installUpdate did not finish")
}
}
+6
View File
@@ -35,6 +35,12 @@ PREV_RT="$(git describe --tags --match 'archie/v*' 2>/dev/null | sed 's|^archie
echo "==> fetching"
git pull --ff-only
# Refresh the installed adapters from the checkout just fetched. The running
# shell continues with the old script, but the next /update uses the current
# implementation even when this invocation was started by an older install.
install -m755 "$REPO/scripts/archie-update-install" "$BIN_DIR/archie-update-install"
install -m755 "$REPO/scripts/archie-update-watchdog" "$BIN_DIR/archie-update-watchdog"
GW="$(git describe --tags --match 'archied/v*' | sed 's|^archied/v||')"
RT="$(git describe --tags --match 'archie/v*' | sed 's|^archie/v||')"
echo "==> building archied $GW / archie-agent $RT"