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:
h z
2026-05-23 15:02:58 +01:00
parent 15bb942d9b
commit b2a0cac460
4 changed files with 111 additions and 8 deletions

View File

@@ -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,