The backend no longer broadcasts topic lifecycle events to Fabric. The
new model (per design discussion 2026-05-23 evening):
- Proposing agent posts a single recruitment fabric-send-message
immediately after creating a topic (carries topic_id + signup
window + debate window + title).
- Downstream agents that decide to participate book a HF on_call
slot covering the debate window via `hf calendar schedule on_call
<time> <duration> --job DEBATE-<topic_id>`.
- HF wakes the agent naturally at slot start; the wake payload
carries event_data with the DEBATE-<topic_id> code so the agent
knows why it was woken.
- The backend stays a pure data + state-machine service and doesn't
know about Fabric.
Code removed:
- internal/fabric/announce.go (entire file + empty dir)
- ticker.go: broadcastLifecycle + broadcastAnnouncement + topicTarget
helpers; announcer field on Ticker; announce field/arg on NewTicker
- models/topic.go: AnnounceGuildBaseURL + AnnounceChannelID fields
- store/topic_store.go: same fields on CreateTopicInput + INSERT
- handlers/topics.go: same fields on createTopicBody + validation +
parameter passing to store
- handlers/verdict.go: announcer field + lifecycle broadcast on
verdict submit
- config/config.go: FabricSystemAPIKey field + DIALECTIC_FABRIC_SYSTEM_API_KEY
env read
- main.go + routes.go: announcer wiring
Database:
- migrations/003_drop_topic_announce_target.sql drops the two columns
added by migration 002. Counterpart commit on the deployment side
needs DIALECTIC_FABRIC_SYSTEM_API_KEY env removed from
docker-compose.yml; harmless if left as the backend no longer
reads it.
Pairs with:
- Dialectic.OpenclawPlugin: rip announce_* params from
dialectic_propose_topic (next commit)
- Fabric.Backend.Center: rip serviceEndpoint field + cli
- Fabric.Backend.Guild: rip system-key bypass on ApiKeyGuard and
announce-only-system limit on messaging.controller
- ClawSkills: rewrite participate-debate + analyze-intel step 4 +
delete rotate-fabric-system-key workflow
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
// Dialectic.Backend.Go — entrypoint.
|
|
//
|
|
// Greenfield Go rewrite of the Python v1 backend; agent-only debate
|
|
// platform per /home/hzhang/arch/DIALECTIC-V2-DESIGN.md.
|
|
//
|
|
// This file: load config → open db → run migrations → mount routes →
|
|
// serve until SIGINT/SIGTERM. Everything else lives in internal/.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/config"
|
|
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/db"
|
|
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/httpapi"
|
|
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/orchestrator"
|
|
"git.hangman-lab.top/hzhang/Dialectic.Backend/internal/store"
|
|
)
|
|
|
|
// Version is overridden at build time via -ldflags="-X main.Version=...".
|
|
var Version = "dev"
|
|
|
|
func main() {
|
|
log.SetFlags(log.LstdFlags | log.Lmicroseconds | log.Lshortfile)
|
|
|
|
cfg, err := config.LoadFromEnv()
|
|
if err != nil {
|
|
log.Fatalf("config: %v", err)
|
|
}
|
|
log.Printf("starting dialectic-backend %s mode=%s addr=%s", Version, cfg.Mode, cfg.HTTPAddr)
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
conn, err := db.Open(ctx, cfg.DSN())
|
|
if err != nil {
|
|
log.Fatalf("db open: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
if err := db.RunMigrations(ctx, conn); err != nil {
|
|
log.Fatalf("migrations: %v", err)
|
|
}
|
|
log.Printf("migrations: ok")
|
|
|
|
// Wire orchestrator + start the ticker. Backend no longer broadcasts
|
|
// to Fabric — proposers post a single recruitment fabric-send-message,
|
|
// downstream agents book HF on_call slots to be woken at debate time.
|
|
topicStore := store.NewTopicStore(conn)
|
|
signupStore := store.NewSignupStore(conn)
|
|
campStore := store.NewCampStore(conn)
|
|
roundStore := store.NewRoundStore(conn)
|
|
ticker := orchestrator.NewTicker(conn, topicStore, signupStore, campStore, roundStore,
|
|
cfg.OrchestratorTickInterval)
|
|
go ticker.Run(ctx)
|
|
|
|
srv := &http.Server{
|
|
Addr: cfg.HTTPAddr,
|
|
Handler: httpapi.Mount(cfg, conn, Version),
|
|
ReadHeaderTimeout: 10 * time.Second,
|
|
}
|
|
|
|
// Graceful shutdown on SIGINT/SIGTERM.
|
|
shutdown := make(chan os.Signal, 1)
|
|
signal.Notify(shutdown, os.Interrupt, syscall.SIGTERM)
|
|
go func() {
|
|
<-shutdown
|
|
log.Printf("shutdown signal received")
|
|
ctx2, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
if err := srv.Shutdown(ctx2); err != nil {
|
|
log.Printf("http shutdown error: %v", err)
|
|
}
|
|
}()
|
|
|
|
log.Printf("http server listening on %s", cfg.HTTPAddr)
|
|
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
log.Fatalf("http serve: %v", err)
|
|
}
|
|
log.Printf("bye")
|
|
}
|