feat: lifecycle broadcasts on signup_closed / cancelled / debating / completed
Phase 3 push-wakeup mechanism without adding a new push channel. Topic state transitions now post short messages to the same Fabric announce channel used for the initial signup announcement. Agents subscribed to announce + not currently busy get woken via the existing Phase 1 inbound path; busy-discard already filters appropriately. No SSE, no per-agent DM fanout, no plugin changes — reuses existing infra end-to-end. Changes: - ticker.go: after signup_close transition, broadcasts signup_closed (with pro/con/judge agent IDs + debate-start time) OR cancelled (with reason). After debate_start transition, broadcasts debating with debate-end time. - announce.go: new PostLifecycleEvent helper - same headers/auth as PostTopicAnnouncement, different format. - verdict.go: after successful judge submission, broadcasts completed with the judge id. Best-effort + async so a slow Fabric does not slow the judge response. - routes.go: instantiates the announcer once + passes to VerdictHandler. Workflow participate-debate step 5 should be updated to expect wakeups instead of polling - separate follow-up edit on lyn/ClawSkills.
This commit is contained in:
@@ -1,27 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/auth"
|
||||
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/fabric"
|
||||
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/models"
|
||||
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/store"
|
||||
)
|
||||
|
||||
type VerdictHandler struct {
|
||||
db *struct{} // placeholder; we don't use the raw conn directly here
|
||||
topics *store.TopicStore
|
||||
camps *store.CampStore
|
||||
verdicts *store.VerdictStore
|
||||
topics *store.TopicStore
|
||||
camps *store.CampStore
|
||||
verdicts *store.VerdictStore
|
||||
announcer *fabric.Announcer // optional; nil-safe via Enabled() check
|
||||
}
|
||||
|
||||
func NewVerdictHandler(t *store.TopicStore, c *store.CampStore, v *store.VerdictStore) *VerdictHandler {
|
||||
return &VerdictHandler{topics: t, camps: c, verdicts: v}
|
||||
func NewVerdictHandler(t *store.TopicStore, c *store.CampStore, v *store.VerdictStore, ann *fabric.Announcer) *VerdictHandler {
|
||||
return &VerdictHandler{topics: t, camps: c, verdicts: v, announcer: ann}
|
||||
}
|
||||
|
||||
type submitVerdictBody struct {
|
||||
@@ -114,6 +117,18 @@ func (h *VerdictHandler) Submit(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("x-warn", "verdict saved but status update failed: "+err.Error())
|
||||
}
|
||||
|
||||
// Lifecycle broadcast — completed event. Best-effort; runs async
|
||||
// outside the request context so a slow Fabric doesn't slow the
|
||||
// judge's response.
|
||||
if h.announcer != nil {
|
||||
go func(t *fabric.Announcer, tID, title string, judge string) {
|
||||
summary := fmt.Sprintf("verdict published by judge=%s. Use dialectic_view_verdict to see the structured result.", judge)
|
||||
if err := t.PostLifecycleEvent(context.Background(), tID, title, "completed", summary); err != nil {
|
||||
// silent failure; the announcer logs internally
|
||||
}
|
||||
}(h.announcer, verdict.TopicID, topic.Title, caller.ID)
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusCreated, map[string]any{
|
||||
"id": verdict.ID,
|
||||
"topic_id": verdict.TopicID,
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/auth"
|
||||
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/config"
|
||||
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/fabric"
|
||||
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/httpapi/handlers"
|
||||
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/store"
|
||||
)
|
||||
@@ -62,7 +63,13 @@ func Mount(cfg *config.Config, db *sqlx.DB, version string) http.Handler {
|
||||
topicsH := handlers.NewTopicsHandler(topicStore)
|
||||
signupsH := handlers.NewSignupsHandler(topicStore, signupStore)
|
||||
argsH := handlers.NewArgumentsHandler(topicStore, campStore, roundStore, argStore)
|
||||
verdictH := handlers.NewVerdictHandler(topicStore, campStore, verdictStore)
|
||||
announcer := fabric.NewAnnouncer(fabric.AnnounceConfig{
|
||||
GuildBaseURL: cfg.FabricGuildBaseURL,
|
||||
ChannelID: cfg.FabricAnnounceChannelID,
|
||||
SystemAPIKey: cfg.FabricSystemAPIKey,
|
||||
BotBearerToken: cfg.FabricBotBearerToken,
|
||||
})
|
||||
verdictH := handlers.NewVerdictHandler(topicStore, campStore, verdictStore, announcer)
|
||||
adminH := handlers.NewAdminHandler(db, cfg.AgentAPIKeyPepper, cfg.DialecticAdminAPIKey)
|
||||
|
||||
// Routes.
|
||||
|
||||
Reference in New Issue
Block a user